When you’re using SSH frequently throughout your day, I think it’s important to have a ‘comfortable’ environment.
A decent SSH config really delivers on this, here’s an example.
A decent SSH config really delivers on this, here’s an example.
~/.ssh/config
HashKnownHosts no
Host *.example.com
User scott.daniels
IdentityFile ~/.ssh/id_scotty
Host *.asecondexample.com
User contractor
IdentityFile ~/.ssh/id_contracting
Host 192.168.27.*
User testenvironment
Host *
ForwardAgent no
ForwardX11 no
ForwardX11Trusted yes
User ubuntu
Port 22
Protocol 2
ServerAliveInterval 60
ServerAliveCountMax 30
Currently on Ubuntu, if you want auto-complete to work in the terminal. “HashKnownHosts” must be disabled.
Otherwise the bash auto-complete interprets the known_hosts file correctly.
SSH will work through this file. You can see I am able specify different usernames, and different private keys for different hosts. Wildcards are supported, so it’s easy to target a group of hosts.
This file is the difference between me typing:
ssh [email protected] -i ~/.ssh/id_contracting
OR
ssh web01.as<TAB>
I know which I prefer. 🙂
Bonus Round
Ubuntu and other distros run an SSH agent, its useful.
Use “ssh-add ~/.ssh/my_privatekey” and you won’t need to provide your private key password for each new connection.
You can use “ssh-add -D” to remove it prior to ending your session, if you’re conscious of rogue hands.