http://www.linuxplanet.com/linuxplanet/tips/6674/1

Back to article

More Fun With SSH Shortcuts

SSH Speed Tricks

February 20, 2009

Juliet Kemp
Last week's Tip of the Trade looked at how to stop your SSH session from dropping out, using the .ssh/config file. This file can also set many other settings, either globally or on a per-host basis. Note that SSH uses the first option it encounters, so per-host options should go before global options in the file.

SSH keys and ssh-add are useful to minimize password-typing. But you don't necessarily want to use the same key for all the machines you log onto, which requires more typing, to -i keyfile on the command line. Alternatively, you can set the identify file per host with a section like this in your ~/.ssh/config file:

Host ssh.example.com
IdentityFile ~/.ssh/example_id_rsa
Similarly, the -X and -Y command-line options enable X11 forwarding and trusted X11 forwarding, respectively. If you always want to forward X11 but only want trusted X11 for a particular machine, try this:

Host desktop.example.com
ForwardX11Trusted yesHost *
ForwardX11 yes
You can also use the .ssh/config file to set hostname abbreviations. This is useful if you regularly log into a particular machine that has an inconveniently long name. Similarly, you can use the User setting to specify the user to log in as. So:

Host longname.machine.example.com
HostName lmach
User julietkemp-longname
will enable me to log in to that machine simply by typing ssh lmach rather than ssh julietkemp-longname@longname.machine.example.com. You could do something similar with a bash alias; however, scp will also use settings from the .ssh/config file, so it's a more generalized solution.

Article courtesy of Serverwatch

Sitemap | Contact Us