More Fun With SSH

By Juliet Kemp (Send Email)
Posted Feb 17, 2009

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.

Tip of the Trade: SSH can set a host of settings on either a global or per-host basis. Check out these especially useful ones.

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:

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 yes

Host *
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.

Page 1 of 1

Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date