1.11. SSH Tricks

1.11.1. Storing hostnames

Remembering IP addresses or long hostnames can be really cumbersome. Use the ~/.ssh/config file to make shortcuts to hosts you commonly use.

Example ~/.ssh/config:

Host gw017
    HostName RigadoGateway-080020317-00017.local
    StrictHostKeyChecking no
    UserKnownHostsFile=/dev/null
    User root

Host gw000
    HostName RigadoGateway-081020317-00000.local
    StrictHostKeyChecking no
    UserKnownHostsFile=/dev/null
    User root

Host gw001
    HostName RigadoGateway-081020317-00001.local
    StrictHostKeyChecking no
    UserKnownHostsFile=/dev/null
    User root

Host gw131
    HostName 076020317-00131.local
    StrictHostKeyChecking no
    UserKnownHostsFile=/dev/null
    User root

Host buildbot3
    HostName buildbot3.local
    User developer

Host tunnel
    HostName colio.example.com
    IdentityFile ~/.ssh/coolio.example.key
    LocalForward 9906 127.0.0.1:3306
    User coolio

1.11.2. Known hosts

SSH is very careful about security and keeps track of information that identifies the host cryptographically. If you re-build your project or update the operating system on the Gateway, you may get a different randomly-generate SSH fingerprint. Normally, SSH will display a nasty warning about “THIS HOST FINGERPRINT CONFLICTS WITH THE HOSTS FILE”, which can be very annoying during development in a controlled environment.

The above ~/.ssh/config example sets StrictHostKeyChecking to no to prevent it from checking and asking you if you approve a new host. It also redirects the UserKnownHostsFile to /dev/null so that this fingerprint is not stored in the known hosts file.