How a configuration file can resolve your SSH issues when using multiple RSA-keys
Table of Contents
Introduction
When you first start using SSH with passwordless logins or just using your own private RSA key everything will work perfectly, but once you start creating different private keys for online services you will run into problems. By default the SSH client will scan your .ssh folder and try all the keys in there but after a couple tries the SSH server will stop accepting tries.
SSH Configuration File
If you also have the same problem as above, you should probably setup your SSH configuration file, in here you can define every single key for the host or even a subnet of hosts.
Create a file called “config” in your ~/.ssh/ directory. (~ refers to your home directory)
The syntax is really simple, let’s take a look.
Host example
Hostname 127.0.0.1
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
User samy
Name | Description |
---|---|
Host | this is a name that you can define yourself, use something memorable that describes the instance that you want to connect to. It’s similar to using your own DNS entries, you could also change your /etc/hosts but this file will only apply to SSH. |
Hostname | the hostname or IP-adress of the server. |
IdentitiesOnly | set to “yes” to use a RSA key instead of a password. |
IdentityFile | your private key, this will probably be in you .ssh folder with an accompanying file that ends with .pub |
User | The user used to login to the SSH server. |
An example if you only want to use passwords is:
Host example
Hostname 127.0.0.1
PreferredAuthentications password
PubkeyAuthentication no
User samy
You can also define settings for all servers with a wildcard.
Host *
ServerAliveInterval 300
ServerAliveCountMax 2