Creating SSH Shortcuts Using SSH Config

From Center for Cognitive Neuroscience
Jump to navigation Jump to search

SSH Config is a great place to make shortcuts for those long url's your always typing. In just a few seconds you'll never have to type: fmri00-silly.ats.long.hosted.domain.name.that.goes.on.forever.com. We'll take the example of ssh'ing into miles, then into one of the other compute nodes to demonstrate the most awesome power of ssh config.

The ssh config file resides in $HOME/.ssh/config. If it doesn't exist, just create it.

$ vim ~/.ssh/config

Of course, you can use any text editor you want except for TextEdit. Because TextEdit is evil. Trust me. Next, we just need to make a few entries:

# Enter the short name you'd like to use. This is an arbitrary name and can be anything you'd like
  1. Here we use miles, but it could be hoffman, work, home, func, or whatever else you'd like
Host hoffman
# Next, enter the full url to the server you want to log into for the last time! Here we use miles, but it can be any server you'd like to access
# such as hoffman2.idre.ucla.edu for hoffman
  Hostname hoffman2.idre.ucla.edu
# Then enter the user name needed to log into this host. foo is just an example, your username is specific to your account
  User foo
# Finally, set x11 forwarding to yes if you want gui awesomeness
  ForwardX11 yes
# You don't want to get logged out automatically just because you aren't always doing something, so tell the server you'd like it to keep it alive.
# The numerical argument you give here is how often (in seconds) a ping should be sent to keep the connection open.
  ServerAliveInterval 300

That's it! This should be put in the $HOME/.ssh/config that your logging in from.

Don't stop reading! There's one last thing to do. After editing the file you have to make sure the permissions are right or ssh will refuse to use it. So type this when your done editing:

$ chmod 600 ~/.ssh/config

After this is done, all that's needed to ssh into miles from the terminal is:

$ ssh miles


You can even copy/paste it if you like. For a full list of all the magical options available in .ssh/config you can check out the /etc/ssh_config or

$ man ssh_config