在一个客户端上使用多个 SSH 私钥的最佳方式 [英] Best way to use multiple SSH private keys on one client

查看:22
本文介绍了在一个客户端上使用多个 SSH 私钥的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用多个私钥连接到不同的服务器或同一服务器的不同部分(我的用途是服务器的系统管理、Git 的管理以及同一服务器内的正常 Git 使用).我尝试简单地将密钥堆叠在 id_rsa 文件中,但无济于事.

I want to use multiple private keys to connect to different servers or different portions of the same server (my uses are system administration of server, administration of Git, and normal Git usage within the same server). I tried simply stacking the keys in the id_rsa files to no avail.

显然,一个简单的方法是使用命令

Apparently a straightforward way to do this is to use the command

ssh -i <key location> login@server.example.com 

这很麻烦.

有关如何更轻松地完成此操作的任何建议?

Any suggestions as to how to go about doing this a bit easier?

推荐答案

来自我的.ssh/config:

Host myshortname realname.example.com
    HostName realname.example.com
    IdentityFile ~/.ssh/realname_rsa # private key for realname
    User remoteusername

Host myother realname2.example.org
    HostName realname2.example.org
    IdentityFile ~/.ssh/realname2_rsa  # different private key for realname2
    User remoteusername

然后就可以使用以下方式进行连接了:

Then you can use the following to connect:

ssh myshortname

ssh myother

等等.

这篇关于在一个客户端上使用多个 SSH 私钥的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆