Multiple SSH private keys Examples

摘要: To allow multiple private keys connect to different servers, edit ~/.ssh/config :

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 :

  1. linode-us (10.10.10.1)
  2. 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 username@200.20.20.1

References

  1. OpenSSH Config File Examples

上一篇: Spring @Value default value
下一篇: MongoDB Allow remote access
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号