Recently, I discovered that SSH have some wonderful features and usages that I didn’t know before.
Faster copying directories with
rsync via SSH
When it comes to copying files back and forth to a remote server, I usually go for
scp hello.txt firstname.lastname@example.org:/tmp/
scp even supports to copy a whole directory:
scp -r files/ email@example.com:/tmp
Not until recently, a colleague of mine, Alex, taught me that using
rsync happens to be faster than
scp when it comes to syncing directories between local and remote server.
rsync -a files/ firstname.lastname@example.org:/tmp
The result is fascinating! It is much much faster than
scp when it comes to hundreds of files need to be synced. Better,
rsync only copy files that has been changed.
There are some more advanced use cases with
rsync and SSH like you can establish somehow a
rsync daemon on the remote server so that you can sync files/directories over a bastion host. See “Advanced Usage” on man page of
Check out code
I usually have a need to log in to the server and do a
git clone on that server for testing some code.
Cloning a repository via SSH on a remote server requires that server to have an SSH key-pair registered..
…unless we use
Using SSH Agent Forwarding allows me to SSH into a remote server and do
git clone on without the need to actually transfer my private key to that server.
# First run the ssh-agent daemon in case you haven't. # See https://unix.stackexchange.com/questions/351725/why-eval-the-output-of-ssh-agent for why we gotta use `eval`. $ eval $(ssh-agent -s) # Add your identity key into ssh-agent. # In case you have a key somewhere else, simply specify the path to it. # You can attach multiple keys if you want. $ ssh-add -K # SSH into the remote server using Agent Forwarding option. $ ssh -A email@example.com # On the remote server, perform git clone as usual remote_user@server $ git clone firstname.lastname@example.org/myuser/myrepo.git