设置默认的SSH密钥位置

时间:2020-03-05 18:59:03  来源:igfitidea点击:

ssh默认会在〜/ .ssh文件夹中查找其键。我想强迫它始终在另一个位置查看。

我正在使用的解决方法是将密钥从非标准位置添加到代理中:

ssh-agent
ssh-add /path/to/where/keys/really/are/id_rsa

(在Linux和Windows上的MingW32 shell上)

解决方案

回答

man ssh给我这个选项可能会有用。

-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).

因此,我们可以在bash配置中使用以下方式创建别名:

alias ssh="ssh -i /path/to/private_key"

我没有查看过ssh配置文件,但是像-i选项一样,它也可以使用别名。

-F configfile
               Specifies an alternative per-user configuration file.  If a con-
               figuration file is given on the command line, the system-wide
               configuration file (/etc/ssh/ssh_config) will be ignored.  The
               default for the per-user configuration file is ~/.ssh/config.

回答

如果我们只是想为身份文件指向其他位置,则可以使用以下条目来修改〜/ .ssh / config文件:

IdentityFile ~/.foo/identity

man ssh_config查找其他配置选项。