Friday, March 25, 2011

ssh client config: hosts

Slightly embarrassed that in more than a decade of daily ssh use I've never made use of ssh client config to simplify connecting to commonly used hosts. The idea is you can just ssh foo rather than ssh -p 12345 fluffy@foo.blah-blah.on.ca .... This is especially useful if you connect to a lot of EC2 hosts frequently and don't want to remember their ugly names (or setup DNS). Best understood by example:

Contents of ~/.ssh/config:
host ec2-webserver
    hostname ec2-123-456-78-90.compute-1.amazonaws.com
    user root
    identityfile ~/my-ec2-key.pem
    compression yes
    protocol 2

host home
    hostname my.place.com
    port 51000
    user fluffy
    identityfile ~/.ssh/id_dsa
    ServerAliveInterval 15
    ServerAliveCountMax 4
    compression yes
    protocol 2

After this is setup, you can simply type ssh ec2-webserver or ssh home rather than the full ssh command. There are a million other ssh client config options you can set, too. As expected, all the ssh tools like scp honour these settings.

No comments:

Post a Comment