SSH configuration files¶
Setting up an SSH configuration file allows you to simplify connecting to the server - rather than having to include all the different options when you run the ssh command, we can define all of these in the configuration file and then initiate a connection with less effort.
If you setup a connection using Visual Studio Code then this will have already created a configuration file for you.
File location¶
Your configuration file is a text file called config, which lives inside the .ssh directory in your home/user directory.
Open or create this file using a text editor (like Visual Studio Code).
Standard format¶
The configuration file follows a standard format - a Host block for each machine we want to be able to connect to using SSH, with a set of directives which define how this connection should be setup.
A very simple configuration file would look like this:
A connection can then be launched by referencing the relevant Host in the SSH connection command, without any additional arguments required:
Specifiying an SSH key¶
Unless you specify otherwise, the SSH program will try to authenticate you to the server using keys stored in a standard way - saved in the .ssh folder in your home/user profile, and named after one of the available key algorithms that can be used to generate them.
Example
If the rsa key algorithm was used to generate a public and private key pair, by default these would be saved as id_rsa.pub and id_rsa respectively.
The IdentityFile directive is used to specify the private key file that should be presented when it is saved in a non-standard location, or named differently. Set this directive to point to the correct private key to use.