OpenSSH | custom configuration

OpenSSH | custom configuration

Every time you log into a server, you must specify your username and password.  If the server has a long hostname, this can be frustrating to type multiple times if you are logging into a server on multiple different windows.  In order to speed up this process, OpenSSH allows you to have a configuration script that you can set up to apply aliases to your login information.

For example, this is how the user foo could login to the server on the command line using ssh by typing everything out.

Instead of typing this out every time you can create a config file inside your .ssh directory in your home directory that will hold all of this information and give you a alias to use instead.

Edit this file and set up your configuration for each of the servers you want a alias for.  For example here we set up the alias for the above foo user on the server.

The Host is the name of the alias (this name is up to you).  The HostName is the hostname of the server, User is your user name, the IdentityFile is a private key that you want to use (if you don’t have one or don’t know what this is then just skip it).

You can have as many of these custom configurations as you want, just continue to put them in the ~/.ssh/config file.

Once you have this set up, you can start to use your alias on the command line instead of typing everything out like you were doing before.  For example now we can just ssh into the server with the foo user by just typing:

You can also use this syntax in any other program that uses ssh in the background, for example scp or git:

This can save you a lot of time typing and will make connecting to remote servers a lot simpler!

Comments are closed.