告诉 SSH 为特殊用户使用特殊的 IdentityFile
Tell SSH to to use special IdentityFile for special user
我需要告诉 SSH 为特殊用户使用特殊的 IdentityFile。
例如主机规格 wizard@host1.com
wizard@any-other-host.org
应该使用密钥 ~/.ssh/id_wizard
我想写
User wizard
IdentityFile ~/.ssh/id_wizard
但是man ssh_config
中没有这个选项。
您应该可以使用 Match directive。 Match 是 Host 指令的更通用形式:
Match
Restricts the following declarations (up to the next Host or Match
keyword) to be used only when the conditions following the Match
keyword are satisfied. Match conditions are specified using one or
more criteria or the single token all which always matches. The
available criteria keywords are: canonical, exec, host, originalhost,
user, and localuser. The all criteria must appear alone or immediately
after canonical. Other criteria may be combined arbitrarily. All
criteria but all and canonical require an argument. Criteria may be
negated by prepending an exclamation mark (‘!’).
...
The other keywords' criteria must be single entries or comma-separated
lists and may use the wildcard and negation operators described in the
PATTERNS section. ... The user keyword
matches against the target username on the remote host.
所以:
Match user wizard
IdentityFile ~/.ssh/id_wizard
我需要告诉 SSH 为特殊用户使用特殊的 IdentityFile。
例如主机规格 wizard@host1.com
wizard@any-other-host.org
应该使用密钥 ~/.ssh/id_wizard
我想写
User wizard
IdentityFile ~/.ssh/id_wizard
但是man ssh_config
中没有这个选项。
您应该可以使用 Match directive。 Match 是 Host 指令的更通用形式:
Match
Restricts the following declarations (up to the next Host or Match keyword) to be used only when the conditions following the Match keyword are satisfied. Match conditions are specified using one or more criteria or the single token all which always matches. The available criteria keywords are: canonical, exec, host, originalhost, user, and localuser. The all criteria must appear alone or immediately after canonical. Other criteria may be combined arbitrarily. All criteria but all and canonical require an argument. Criteria may be negated by prepending an exclamation mark (‘!’).
...
The other keywords' criteria must be single entries or comma-separated lists and may use the wildcard and negation operators described in the PATTERNS section. ... The user keyword matches against the target username on the remote host.
所以:
Match user wizard
IdentityFile ~/.ssh/id_wizard