Multiple SSH private keys Examples
To allow multiple private keys connect to different servers, edit ~/.ssh/config
:
~/.ssh/config
Host 10.10.10.1
IdentityFile ~/.ssh/linode_rsa
Host 200.20.20.2
IdentityFile ~/.ssh/id_rsa
If you SSH to 10.10.10.1, private key ~/.ssh/linode_rsa
will be used.
If you SSH to 200.20.20.2, private key ~/.ssh/id_rsa
will be used.
1. Single Private Key for Multiple Servers
1.1 You have following public and private keys.
$ cat ~/.ssh/
linode_rsa.pub
linode_rsa
1.2 Public key linode_rsa.pub
is copied to following two servers :
- linode-us (10.10.10.1)
- linode-uk (10.10.10.2)
To SSH above servers with a single private key, edit .ssh/config
:
~/.ssh/config
Host 10.10.10.1 10.10.10.2
IdentityFile ~/.ssh/linode_rsa
Or
/etc/hosts
127.0.0.1 localhost
10.10.10.1 linode-us
10.10.10.2 linode-uk
~/.ssh/config
Host linode-us linode-uk
IdentityFile ~/.ssh/linode_rsa
2. Multiple Private Keys for Multiple Servers
Create another set of public and private keys, and copy the public key new_rsa.pub
to another server, for example 200.20.20.1.
$ cat ~/.ssh/
linode_rsa.pub
linode_rsa
new_rsa.pub
new_rsa
To SSH 200.20.20.1 with the new private key, update ~/.ssh/config
:
~/.ssh/config
Host linode-us linode-uk
IdentityFile ~/.ssh/linode_rsa
Host 200.20.20.1
IdentityFile ~/.ssh/new_rsa
3. Output
Try SSH to the servers.
# Connect with private key - linode_rsa
$ ssh username@linode-us
# Connect with private key - linode_rsa
$ ssh username@linode-uk
# Connect with private key - new_rsa
$ ssh [email protected]
References
About Author
Comments
Subscribe
0 Comments