ServersMore Fun With SSH

More Fun With SSH

ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

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:

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:

HostName lmach
User julietkemp-longname

will enable me to log in to that machine simply by typing ssh lmach
rather than ssh
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.

Get the Free Newsletter!

Subscribe to Daily Tech Insider for top news, trends & analysis

Latest Posts

Related Stories