Reading time: 2 minutes
In order to connect to remote servers, we can use the .ssh folder configuration and the config file that Ubuntu and Windows use to create SSH connections.
This tool is presented as an alternative to Putty.
The first thing we need to do is create our .ssh directory:
- In Ubuntu, it goes in the Home directory of our user.
/home/{username}
- In Windows, it’s exactly the same, but with the Windows user.
C:\Users\{username}
Once you’ve located the directory, create the .ssh folder inside it:
Ubuntu: /home/{username}/.ssh Windows: C:\Users\{username}/.ssh
Inside this folder, create a new file and name it config.
Host NAME_YOU_WANT HostName IP_OR_DOMAIN User USERNAME Port SSH_PORT PubKeyAuthentication yes IdentitiesOnly yes IdentityFile PATH_TO_KEY
Let me explain the file we’ve created:
- Host: It’s the name of the host you want to assign, for example, TEST.
- HostName: It’s the IP or address you want to connect to.
- User: It’s the user that authenticates with SSH.
- Port: It’s the SSH port; by default, it’s 22, but it can be changed (SSH server configuration).
- PubKeyAuthentication: Indicates that we will use key authentication.
- IdentitiesOnly: Indicates that we will use the key file.
- IdentityFile: Indicates the path where we store our key.
The example file would look like this:
Host TEST HostName www.google.com User google Port 22 PubKeyAuthentication yes IdentitiesOnly yes IdentityFile ~/.ssh/key
In order for this configuration to work, we need to copy the RSA public key inside .ssh and name it key.
Additionally, set the permissions to 400 to allow using the key. Run the following command:
chmod 400 key
Once the permissions are set, you can use the created connection.
Type the ssh command followed by the chosen HostName (autocompletion is available).
ssh TEST
Furthermore, you can add more configurations in your config file as follows:
Host TEST HostName www.google.com User google Port 22 PubKeyAuthentication yes IdentitiesOnly yes IdentityFile ~/.ssh/key Host TEST_2 HostName www.yahoo.com User yahoo Port 22 PubKeyAuthentication yes IdentitiesOnly yes IdentityFile ~/.ssh/yahoo_key
If you want to create a configuration without an RSA key, you can use the following code in the config file:
Host TEST HostName www.google.com User google Port 22
As you can see, it’s a good way to keep our SSH connections well-organized.