SSH Client: Saving Server Configuration (Alias, Port, Username)

There may be occasions where you want to connect to a host with a long host name, for example ssh servername.example.com – now it’s not massive, but it’s not as quick as ssh servername

If you’ve been following droptips.com, you’ll have noticed my other post about setting the port number in the SSH config file (~/.ssh/config for individual users) – you can also use this config file to connect to shortened hostnames (aliases).

So, if you want to be able to ssh into servername.example.com but just doing ssh servername, you would add the following to the ~/.ssh/config file:

Host servername
  HostName servername.example.com

Now that’s great if you login to your local machine with the same username as the remote server, but what if it isn’t?  You’d have to do ssh remoteusername@servername but we can also get around this by adding User username to the host section:

Host servername
  HostName servername.example.com
  User remoteusername

You can also tie this into having the port number as per my other post like so:

Host servername
  HostName servername.example.com
  User remoteusername
  Port 1234

Once you’ve done this, whatever you put on the Host line, will work by just doing the following with whatever options the configuration file says:

ssh host

Hopefully this will allow you to speed up connecting to servers you connect to a lot!