我想这样操作:当文件在 /Users/skline/.ssh/id_rsa.pub 中查找 ssh 密钥时,它也会自动查找目录 /var/root/.ssh/id_rsa.pub(我的 ssh 实际位于该目录)。如何在 OSX 上执行此操作?我是终端新手,所以谢谢 :)
答案1
如果它与我使用的 SSH 类似,那么您应该能够使用“-i”选项。
例如 ssh 主机 -i /var/root/.ssh/id_rsa
从手册页中:
-i identity_file
Selects a file from which the identity (private key) for RSA or
DSA authentication is read. The default is ~/.ssh/identity for
protocol version 1, and ~/.ssh/id_rsa and ~/.ssh/id_dsa for pro-
tocol version 2. Identity files may also be specified on a per-
host basis in the configuration file. It is possible to have
multiple -i options (and multiple identities specified in config-
uration files).
或者为了永久解决问题,请将以下选项(带路径)添加到您的 ~/.ssh/config
IdentityFile /var/root/.ssh/id_rsa
再次,适当的手册页条目:
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.