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 bar.com on the command line using ssh by typing everything out.

1

$ssh foo@bar.com

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.

1

$vi~/.ssh/config

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 bar.com server.

1

2

3

4

Host bar

HostName bar.com

User foo

IdentityFile~/.ssh/bar

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 bar.com server with the foo user by just typing:

1

$ssh bar

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

1

2

$scp bar:~/foo.txt.

$git clonebar:repo

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