我有多个私钥,用于连接各种盒子。这主要是用于 AWS,它让我导入密钥以连接到机器 - 为此我创建了一个单独的密钥集。而不是不断地做:
ssh -i ~/.ssh/aws-key.pem [email protected]
添加到我的“ssh 钥匙串”的最佳方法是什么,aws-key.pem
以便它除了现有的“id_dsa”密钥之外,还默认检查所有 SSH 请求?
答案1
您有几个选择。
使用SSH 代理。只需对所有私钥使用 ssh-add,然后让您的代理确定要使用哪个密钥。我通常更喜欢使用代理,并且总是在登录系统时启动它,然后添加所有密钥。它使一切变得简单。
更改你的 ssh 配置
# .ssh/config
# per host example
Host blah.example.com
User zoredache
IdentityFile ~/.ssh/username_YYYYMMDD_id_rsa
# global example
Host *
User zoredache
IdentityFile ~/.ssh/key1_YYYYMMDD_id_rsa
IdentityFile ~/.ssh/key2_YYYYMMDD_id_rsa
IdentityFile ~/.ssh/keyn_YYYYMMDD_id_rsa
答案2
用于IdentityFile
~/.ssh/config
如果您只想将其用于特定主机,请将其包含在Host
指令下。
IdentityFile
Specifies a file from which the user's DSA, ECDSA or DSA authentication identity is read. The default is ~/.ssh/identity for protocol version 1, and ~/.ssh/id_dsa,
~/.ssh/id_ecdsa and ~/.ssh/id_rsa for protocol version 2. Additionally, any identities represented by the authentication agent will be used for authentication. ssh(1) will
try to load certificate information from the filename obtained by appending -cert.pub to the path of a specified IdentityFile.
The file name may use the tilde syntax to refer to a user's home directory or one of the following escape characters: ‘%d’ (local user's home directory), ‘%u’ (local user
name), ‘%l’ (local host name), ‘%h’ (remote host name) or ‘%r’ (remote user name).
It is possible to have multiple identity files specified in configuration files; all these identities will be tried in sequence. Multiple IdentityFile directives will add
to the list of identities tried (this behaviour differs from that of other configuration directives).