如何让ssh使用不同的id_dsa
当连接到一个特定的主机时,我如何确定id_dsa没有存储在~/.ssh中 显而易见的问题是为什么。答案是这个密钥更敏感,需要密码保护,而另一个用于自动化 虽然这不是一个编程问题,但如果我知道这需要一个编程解决方案,我不会感到惊讶。从ssh手册页:如何让ssh使用不同的id_dsa,ssh,key,Ssh,Key,当连接到一个特定的主机时,我如何确定id_dsa没有存储在~/.ssh中 显而易见的问题是为什么。答案是这个密钥更敏感,需要密码保护,而另一个用于自动化 虽然这不是一个编程问题,但如果我知道这需要一个编程解决方案,我不会感到惊讶。从ssh手册页: -i identity_file Selects a file from which the identity (private key) for RSA or DSA authentication is read
-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
中,设置如下内容:
Host somehost
IdentityFile /path/to/extra_secret_key
我有一台主机的
IdentityFile
设置为~/.ssh/iddsa_aux
,但是参数应该接受任何路径名。有一个简单的技巧可以让它变得非常简单,奇怪的是,我30分钟前刚和一个朋友讨论过这个问题
~/.ssh/config
IdentityFile~/.ssh/ident/%r@%h
IdentityFile~/.ssh/id_rsa
IdentityFile~/.ssh/id_dsa
这使得使用回退模式变得非常容易,因为选项是自上而下运行的
然后为“”指定特定的键Bob@someHost“您只需创建文件
~/.ssh/ident/Bob@someHost
~/.ssh/ident/Bob@someHost
它将在登录到该主机时首先尝试这样做
如果找不到文件或密钥被拒绝,它将尝试下一个,在这种情况下
~/.ssh/id_rsa
~/.ssh/id\u rsa
这种技术的好处是,您不必每次添加另一个主机时都添加一个新条目,您所要做的就是在正确的位置创建密钥文件,它会自动完成其余的工作 我认为这与编程相关的唯一原因是,许多SCM工具使用ssh作为其工作方法的一部分,SCM工具当然与编程相关。太好了。这正是我一直在寻找的东西,却找不到。你不会相信我差一点就制作了ssh的第二个副本,并用hexeditor修改了它。 ~/.ssh/id_rsa