
SSH is great. There is so many thing you can do with it other than just a remote secure shell like X forwarding, port forwarding, authenticate using a private/public key, compress the transmitted stream....
If you have different account that you use on an every day basis, it becomes quickly cumbersome to type those lengthly command lines.
One could work around this by using aliases, the right way would be to use ~/.ssh/config
This tutorial will show some customization examples that should cover most ssh use cases.
All along this tutorial, the changes will be made in ~/.ssh/config and will therefore be available only for your user.
If you wish to make changes server wide, you will have to edit /etc/ssh/ssh_config .
Most of your ssh connection might look like:
$ ssh user1@server1.example.com
By adding the following to your ~/.ssh/config :
Host server1 Hostname server1.example.com User user1
You can shorten the typing to:
$ ssh server1
If you identity file is named ~/.ssh/id_rsa or ~/.ssh/id_dsa , those file will be tried automatically by ssh.
In case you have different key files, you have to inform ssh about it with -i , which look like:
$ ssh -i ~/.ssh/id_rsa_server2 user2@server2.example.com
Adding the following to ~/.ssh/config :
Host server2 Hostname server2.example.com User user2 IdentityFile ~/.ssh/id_rsa_server2
will allow you to type:
$ ssh server2
to get the same result.
Forwarding port with ssh requires a command line like:
$ ssh -L 8888:127.0.0.1:7777 -i .ssh/id_rsa_server3 user3@server3.example.com
The following in ~/.ssh/config :
Host server3 Hostname server3.example.com User user3 IdentityFile ~/.ssh/id_rsa_server3 Localforward 8888 127.0.0.1:7777
will shorten the command to:
$ ssh server3
The 3 examples above cover my needs with for my day to day use of ssh. There is plenty of other options that you might find useful.
You can find more info from :
$ man ssh_config







