bash 使用 ssh 手动加载私钥
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13778787/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Load private key manually with ssh
提问by hsz
Is it possible to run sshwith ignoring default .sshdirectory and specify other one or - better - specified private key ?
是否可以ssh忽略默认.ssh目录并指定另一个或更好地指定的私钥来运行?
For example:
例如:
ssh --private-key other_id_rsa login@host
回答by Chris Seymour
You can use the -ioption.
您可以使用该-i选项。
Source: man ssh
来源: 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.
回答by Rubens
You can also add a specific configuration to each host you access, which is pretty much the same as persisting the usage of the flags available in ssh.
您还可以为您访问的每个主机添加一个特定的配置,这与在 ssh 中保留可用标志的使用几乎相同。
There's an entire world of flags available, and there are some mappings for each different service specialization provided. In your case, using specific id_rsafiles, you could write down to your ~/.ssh/configfile:
有一个完整的标志世界,并且提供的每个不同的服务专业化都有一些映射。在您的情况下,使用特定id_rsa文件,您可以写下您的~/.ssh/config文件:
...
Host host_alias
HostName host_name
IdentityFile ~/.ssh/id_rsa_you_want
...
Then, you can simply use:
然后,您可以简单地使用:
ssh host_alias
And the id_rsa_you_wantwill be used -- as well as any further configurations you may apply to the connection. See man ssh_configfor the entire list of available directives.
并且id_rsa_you_want将使用 - 以及您可能应用于连接的任何进一步配置。有关man ssh_config可用指令的完整列表,请参见。

