Setting up aliases to quickly log you in to a different machine

From Docswiki
Jump to navigation Jump to search

Using ssh config

Create the file ~/.ssh/config if it does not exists. Set up the config file. There are lots of guides around. Say you want to log into sinister under a login name xxx100 and enable X forwarding. Then add the following:

Host sin
 Hostname sinister.ch.cam.ac.uk
 User xxx100
 ForwardX11

Now you can enter ssh sin to ssh to sinister.


Using aliases

Tired of having to type ssh -X -C user@cluster all the time to get onto your favourite machine? You could reduce all that down to a single, short shell command by using aliases!

For example, when I log into my workstation and open a shell, I can change machines to cluster by just typing

cluster

cluster is an alias I have defined in my .bashrc file, located in your home directory. You can't normally see it if you type ls but it's there.

To set up your own aliases, first open up your .bashrc file in your favourite editor i.e. vi

vi ~/.bashrc

And then add something like the following onto the bottom:

alias cluster='ssh -X -C user@cluster'

Note: -X sets up X-forwarding and -C is for compression (only makes a difference from outside Cambridge)

Save and exit the file and then open a new shall. You should find that typing cluster will now connect you to the machine you specified! Of course, you still need to enter your password but we can automate that too using ssh-keygen which is dealt with in a different tutorial. You can set up as many aliases as you want, and not just for using ssh, you can make them execute any shell command!

If you're often logging in from outside the department, consider putting the following aliases in your .bashrc file on Chimaera:

alias clust='ssh -X clust'
alias mek='ssh -X mek-quake'
alias volkhan='ssh -X volkhan'