代码之家  ›  专栏  ›  技术社区  ›  Joshua

如何让ssh使用不同的id_dsa

  •  8
  • Joshua  · 技术社区  · 16 年前

    当连接到一个特定的主机时,我如何才能说服ID_DSA不存储在~/.ssh中。

    显而易见的问题是为什么。答案是这个密钥更敏感,需要密码保护,而另一个用于自动化。

    虽然这不是一个编程问题,但当我了解到这需要一个编程解决方案时,我不会感到惊讶。

    3 回复  |  直到 16 年前
        1
  •  6
  •   Ingo Karkat    10 年前

    在你 .ssh/config ,设置如下:

    Host somehost
         IdentityFile /path/to/extra_secret_key
    

    我有一个主人 IdentityFile 设置为 ~/.ssh/iddsa_aux ,但参数应接受任何路径名。

        2
  •  12
  •   Kent Fredric    16 年前

    有一个方便的诀窍,你可以用来让它变得非常容易,奇怪的是,我30分钟前刚和一个朋友讨论过这个。

    ~/.ssh/CONFIG

    IdentityFile ~/.ssh/ident/%r@%h
    IdentityFile ~/.ssh/id_rsa
    IdentityFile ~/.ssh/id_dsa
    

    这使得使用回退模式非常容易,因为选项是从上到下运行的。

    然后要为“bob@somehost”指定一个特定的键,只需创建文件

    ~/.ssh/ident/Bob@someHost
    

    当登录到主机时,它将首先尝试这个方法。

    如果找不到文件,或者密钥被拒绝,它将尝试下一个文件,在这种情况下,

    ~/.ssh/id_rsa
    

    这种技术的好处是,您不必每次添加另一个主机时都添加一个新条目,您所要做的就是在正确的位置创建关键文件,其余的都会自动执行。

        3
  •  2
  •   Schwern    16 年前

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