【发布时间】:2009-04-10 02:48:32
【问题描述】:
当连接到一个特定的主机时,我怎样才能确信 id_dsa 没有存储在 ~/.ssh 中。
显而易见的问题是为什么。答案是这个密钥更敏感,需要密码保护,而另一个用于自动化。
虽然这不是编程问题,但得知这需要编程解决方案我不会感到惊讶。
【问题讨论】:
-
我认为这与编程相关的唯一原因是,许多 SCM 工具使用 ssh 作为其工作方法的一部分,而 SCM 工具肯定与编程相关。
当连接到一个特定的主机时,我怎样才能确信 id_dsa 没有存储在 ~/.ssh 中。
显而易见的问题是为什么。答案是这个密钥更敏感,需要密码保护,而另一个用于自动化。
虽然这不是编程问题,但得知这需要编程解决方案我不会感到惊讶。
【问题讨论】:
你可以使用一个方便的技巧让它变得非常简单,奇怪的是,我刚刚在 30 分钟前和一个朋友讨论过这个问题。
~/.ssh/config
身份文件 ~/.ssh/ident/%r@%h 身份文件 ~/.ssh/id_rsa 身份文件 ~/.ssh/id_dsa这使得使用后备模式变得非常容易,因为选项从上到下运行。
然后要为“Bob@someHost”指定一个特定的键,你只需要创建文件
~/.ssh/ident/Bob@someHost它会在登录该主机时首先尝试。
如果找不到文件,或者key被拒绝,它会尝试下一个,在这种情况下,
~/.ssh/id_rsa这种技术的好处是您不必每次添加另一个主机时都添加一个新条目,您所要做的就是在正确的位置创建密钥文件,其余的会自动完成。
【讨论】:
在您的 .ssh/config 中,设置如下内容:
Host somehost
IdentityFile /path/to/extra_secret_key
我有一台主机将IdentityFile 设置为~/.ssh/iddsa_aux,但参数应该接受任何路径名。
【讨论】:
来自 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).
【讨论】: