<a target="_blank" href="http://baike.baidu.com/view/16184.htm">從用戶端來看,SSH提供兩種級别的安全驗證。</a>
第一種級别(基于密碼的安全驗證)
隻要你知道自己帳号和密碼,就可以登入到遠端主機。所有傳輸的資料都會被加密, 但是不能保證你正在連接配接的伺服器就是你想連接配接的伺服器。可能會有别的伺服器在冒充真正的伺服器, 也就是受到“中間人”這種方式的攻擊。
第二種級别(基于密匙的安全驗證)
需要依靠密匙,也就是你必須為自己建立一對密匙,并把公用密匙放在需要通路的伺服器上。 如果你要連接配接到SSH伺服器上,用戶端軟體就會向伺服器送出請求,請求用你的密匙進行安全驗證。伺服器收到請求之後, 先在該伺服器上你的主目錄下尋找你的公用密匙,然後把它和你發送過來的公用密匙進行比較。如果兩個密匙一緻, 伺服器就用公用密匙加密“質詢”(challenge)并把它發送給用戶端軟體。 用戶端軟體收到“質詢”之後就可以用你的私人密匙解密再把它發送給伺服器。 用這種方式,你必須知道自己密匙的密碼。但是,與第一種級别相比,第二種級别不需要在網絡上傳送密碼。 第二種級别不僅加密所有傳送的資料,而且“中間人”這種攻擊方式也是不可能的(因為他沒有你的私人密匙)。 但是整個登入的過程可能需要10秒
ssh采用的是不對稱加密方式傳輸,分一個公匙和一個私匙
公匙用來加密 私匙用來解密,是以私匙放在client,公匙放在 server !
~/.ssh/authorized_keys -其他機器生成的公匙放在,ssh伺服器的宿主目錄下!比如/home/dn/ 下,名字必須是authorized_keys
RSA 與 DSA 加密算法的差別
RSA,是一種加密算法(PS:RSA也可以進行數字簽名的),它的簡寫的來由是Ron Rivest、Adi Shamir和 Leonard Adleman這三個人名字的第一個字母連接配接起來就是RSA。
DSA就是數字簽名算法的英文全稱的簡寫,即Digital Signature Algorithm,簡寫就是DSA,
RSA既可以進行加密,也可以進行數字簽名實作認證,而DSA隻能用于數字簽名進而實作認證
選擇 rsa 算法即可,以下是具體步驟!
ssh-keygen -t rsa 之後一直回車
$ ssh-keygen –t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/dn/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): <---按enter
Enter same passphrase again: <---按enter
Your identification has been saved in /home/dn/.ssh/id_rsa.
Your public key has been saved in /home/dn/.ssh/id_rsa.pub.
The key fingerprint is:
e8:8a:5e:ae:c7:13:45:d0:81:cd:3f:e6:1e:f8:88:5a [email protected]
生成私匙 id_rsa 與 公匙 id_rsa.pub 配置檔案
$ ll
總計 20
-rw------- 1 dn dn 1675 Nov 25 11:07 id_rsa
-rw-r--r-- 1 dn dn 407 Nov 25 11:07 id_rsa.pub
-rw-r--r-- 1 dn dn 9086 Nov 24 14:54 known_hosts
把公匙檔案上傳到ssh 伺服器的宿主目錄下,以下兩條指令任選一個即可!
$ cat ~/.ssh/id_rsa.pub | ssh dn@www9 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat - >~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys"
測試
$ ssh www9
The authenticity of host 'www9 (10.100.100.9)' can't be established.
RSA key fingerprint is a3:29:76:03:8c:43:4d:1b:45:52:6e:d9:d5:fd:1e:aa.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'space9,10.100.100.9' (RSA) to the list of known hosts.
Last login: Fri Nov 25 11:47:33 2011 from 10.100.100.1
擴充
<a href="http://dngood.blog.51cto.com/446195/703347/#ssh_key" target="_blank">shell 腳本, 批量上傳ssh id_rsa.pub 公匙</a>
結束
<a target="_blank" href="http://blog.csdn.net/iloveyaoge/article/details/6298635">參考文檔</a>
本文轉自 dongnan 51CTO部落格,原文連結:http://blog.51cto.com/dngood/724207