2009-04-10 71 views
8

如何說服id_dsa在連接到某個特定主機時未存儲在〜/ .ssh中。如何讓ssh使用不同的id_dsa

明顯的問題是爲什麼。答案是這個鍵更敏感,需要密碼保護,而另一個用於自動化。

雖然這不是一個編程問題,但我不會感到驚訝,學習這需要一個編程解決方案。

+0

我認爲這是編程相關的唯一原因是許多SCM工具使用ssh作爲其工作方法的一部分,而SCM工具肯定與編程有關。 – 2009-04-10 03:04:56

回答

6

在你.ssh/config,設置是這樣的:

Host somehost 
    IdentityFile /path/to/extra_secret_key 

我有了IdentityFile設置爲~/.ssh/iddsa_aux一臺主機,但參數應該接受任何路徑名稱。

+0

太好了。到底我在找什麼,找不到。你不會相信我有多接近製作ssh的第二個副本並用hexeditor修改它。 – Joshua 2009-04-10 03:36:41

2

從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). 
+0

補給它。我閱讀手冊頁並錯過了它。 – Joshua 2009-04-10 03:10:58

12

Theres是一個非常方便的技巧,你可以用它來使它變得非常簡單,奇怪的是,我剛剛在30分鐘前與一位朋友討論過這個問題。

的〜/ .ssh/config中

 
IdentityFile ~/.ssh/ident/%[email protected]%h 
IdentityFile ~/.ssh/id_rsa 
IdentityFile ~/.ssh/id_dsa 

這使得它很容易使用回退模式,因爲選項是通過頂部運行至底部。

然後指定一個特定的密鑰「鮑勃@,某」你只需要創建文件

 
~/.ssh/ident/[email protected] 

並登錄到該主機時,它會首先嚐試一下。

如果該文件不能被發現,或密鑰被拒絕,它會嘗試下一個,在這種情況下,

 
~/.ssh/id_rsa 

這種技術的好處是,你不必添加新每次添加另一臺主機時都需要輸入密鑰文件,您只需在正確的位置創建密鑰文件,然後自動執行其他操作。