Q:

How to copy symlinks as symlinks from one machine to another?

Let's assume I have two identical systems. On the first system I've created a symbolic link. On the second one I want to copy that symlink via sftp and the symlink shall work the same (i.e if the symlink links to /etc/, after  copying it over, only the symlink will be copied and only the symlink (not the linked files) )
Any ideas on how I can do this / if I can do this? I only want to copy the symbolic link, nothing else; just the reference.

A:

If you tar up the symlink, then you can copy the tarball over to the remote machine any way you like.  When you untar it, you'll find that you've only copied the symbolic link and nothing else.  For example:
To test this, first I created a text file.
echo this is a test > file.txt

Then create a symlink to the file and compress it into a tar gzip.
ln -s file.txt link.lnk
tar czvf tarball.tar.gz link.lnk

Transfer this file to your other machine and then uncompress it:
tar xzvf tarball.tar.gz

You will find that the symlink is there, but not the original file that it had pointed to.
Of course, if you wanted to transfer both the original file and the symlink while preserving their relationship, you can put them both in the tarball and they would both be transferred, and the symlink should still be correctly pointed to the original file when you uncompress the tarball in the destination location.

A:

It is a little unclear how exactly you want to deal with the symlink. As I understand it, you want to recreate the symlink on the other system. Symlinks are filesystem dependent, the protocol used to copy files must be aware of that. A good example is using rsync with the -a option.
more specifically, the -l option, but -a is probably what you want.
It will recreate symlinks without pulling the targets over (dereferencing the links).

A:

A very easy solution (for the home directory):
tar -c SYMLINKFILE | ssh machine 'tar -x'

or 
tar -c SYMLINKFILE | ssh machine 'tar -xC /some/other/location  '

e.g.
tar -c .bashrc | ssh another_machine 'tar -x'

to provide a symlinked .bashrc placing to another (e.g. network) destination.

