是否可以在忽略默认的 .ssh
目录的情况下运行 ssh
,并指定其他目录或更好地指定私钥?
例如:
ssh --private-key other_id_rsa login@host
是否可以在忽略默认的 .ssh
目录的情况下运行 ssh
,并指定其他目录或更好地指定私钥?
例如:
ssh --private-key other_id_rsa login@host
-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.
id_rsa
文件,你可以将其写入到~/.ssh/config
文件中:...
Host host_alias
HostName host_name
IdentityFile ~/.ssh/id_rsa_you_want
...
那么,您可以简单地使用:
ssh host_alias
而且将使用id_rsa_you_want
,以及您可能应用于连接的任何进一步配置。有关可用指令的完整列表,请参见man ssh_config
。
另一种方法是在使用ssh之前手动使用ssh-agent和ssh-add命令。
ssh-agent (if not running already)
ssh-add /path/to/private_key
example:
ssh-agent
ssh-add ~/.ssh/id_rsa
eval \
ssh-agent -s``。这些是反引号。 - ccalvert
chmod 400 private_rsa_key.pem
然后ssh -i private_rsa_key.pem user@host
。 - Daniel