Shortcuts for SSH hosts

Are you tired of typing full length host-names while connecting via SSH? Do you frequently scp files from one server to another and have to lookup what the host-names are? Do you want to rsync between local and remote host easily with a a simple command? Then, read-on.

The hard-way:

# connect
ssh username@clustername.hostdomain.dept.edu
# scp
scp yourfile username@clustername.hostdomain.dept.edu:/path/to/destination/
# rsync
rsync -e 'ssh -c aes128-ctr' -rts your_folder username@clustername.hostdomain.dept.edu:/path/to/destination/

As you can see, if you have a bunch of hosts, it gets really hairy to retype them everytime you want to do any of these things.

The Solution:

Create a config file under the ~/.ssh directory, with the short name for these host-names. Then you can simply connect to the server by using the short name instead of the full host-name!

First, edit the file

vi ~/.ssh/config

and add the details:

Host sweet
  Hostname clustername.hostdomain.dept.edu
  User username
  ForwardX11 yes
Host sugary
  Hostname anothercluster.hostdomain.dept.edu
  User username
  ForwardX11 yes

Set permissions straight:

chmod 600 ~/.ssh/config

Now, have fun! the above commands can now be done using:

# connect
ssh sweet
# scp
scp yourfile sweet:/path/to/destination/
# rsync
rsync -e 'ssh -c aes128-ctr' -rts your_folder sweet:/path/to/destination/

You can read more about the config by opening the man page:

man ssh-config

Hope this trick will make your life little easier!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s