使用ssh手动加载私钥

hsz*_*hsz 11 ssh bash private-key

是否可以ssh忽略默认.ssh目录并指定其他一个或更好指定的私钥来运行?

例如:

ssh --private-key other_id_rsa login@host
Run Code Online (Sandbox Code Playgroud)

Chr*_*our 13

您可以使用该-i选项.

资源: man ssh

-i identity_file
    Selects a file from which the identity (private key) for public key authentication 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.  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 configuration
    files).  ssh will also try to load certificate information from the filename obtained by appending -cert.pub to identity filenames.
Run Code Online (Sandbox Code Playgroud)


Rub*_*ens 5

您还可以向您访问的每个主机添加特定配置,这与保留 ssh 中可用标志的使用几乎相同。

有一个完整的可用标志世界,并且针对所提供的每个不同的服务专业化都有一些映射。在您的情况下,使用特定id_rsa文件,您可以写入您的~/.ssh/config文件:

...

Host host_alias
    HostName host_name
    IdentityFile ~/.ssh/id_rsa_you_want

...
Run Code Online (Sandbox Code Playgroud)

然后,您可以简单地使用:

ssh host_alias
Run Code Online (Sandbox Code Playgroud)

并且id_rsa_you_want将使用 - 以及您可能应用于连接的任何进一步配置。请参阅man ssh_config参考资料 获取可用指令的完整列表。