ssh認證的完整描述:https://www.ibm.com/developerworks/cn/linux/security/openssh/part1/html
說明:點我去查看linux
今天咱們只說生成ssh的key,從而達到免密碼登錄的目的。dom
不知道ssh是什麼的本身看說明。好了,不廢話了。ssh
系統:CentOS 5.8ide
確認當前用戶是你須要的用戶!加密
$ whoami froad #froad用戶,根據你本身的需求選擇用戶。我這兒用froad用戶演示。
$ cd ~ #回到用戶目錄,不回去也沒有關係 $ ssh-keygen #可使用-t選項選擇加密方式,包括 RSA 和 DSA 兩種密鑰 #例如:$ssh-keygen -t dsa 或者ssh-keygen -t rsa #加密方式不一樣,key的名稱不一樣,其餘沒有區別 #若是沒有指定密鑰,默認RSA Generating public/private rsa key pair. Enter file in which to save the key (/home/froad/.ssh/id_rsa): #私鑰存放的位置,默認會存放在用戶目錄的.ssh文件夾,直接回車 Enter passphrase (empty for no passphrase): #默認,回車 Enter same passphrase again: #默認,回車 Your identification has been saved in /home/froad/.ssh/id_rsa.#私鑰路徑 Your public key has been saved in /home/froad/.ssh/id_rsa.pub.#公鑰路徑 The key fingerprint is: e8:b6:e6:xxxxxxxxxxxxxxxxx:ec:b5:d8 froad@localhost.localdomain $ cat id_***.pub >> authorized_keys #***表明加密方式,將公鑰拷貝到authorized_keys文件中。若是你有不少的電腦須要配置,將全部的id_***.pub公鑰拷貝到一個authorized_keys文件中便可
將authorized_keys文件拷貝到須要被管理的電腦上。注意:放在用戶目錄下.ssh文件夾中。Linux用戶會限制你的訪問權限spa
驗證code
$ ssh root@192.168.2.xxx #root是用戶名,能夠根據你的需求改變 The authenticity of host '192.168.2.xxx (192.168.2.xxx)' can't be established. RSA key fingerprint is ff:07:49:4d:xxxxxxxxxxe:2c:38. Are you sure you want to continue connecting (yes/no)? yes #贊成將指紋添加到本地 Warning: Permanently added '192.168.2.xxx' (RSA) to the list of known hosts. Last login: Wed Oct 23 13:58:32 2013 from 192.168.1.xxx
只能在你生成key的電腦上訪問authorized_keys的電腦,若是你想兩臺電腦互相訪問均免密碼。那麼你還須要重複上面的步驟(機器的配置恰好相反)。htm
若是添加指紋的時候提示添加失敗,是由於你之前添加過了這個ip的指紋。blog
解決辦法:將.ssh目錄的known_hosts文件刪除掉(好粗暴啊( ⊙ o ⊙ )啊!),也能夠打開這個文件把對於ip的那條記錄刪除(這個就精細多了O(∩_∩)O哈哈~)
若是操做步驟都正確,可是依然要求輸入密碼。通常是由於權限的問題。命令以下
chmod 644 ~/.ssh/authorized_keys
轉:http://www.cnblogs.com/zz0412/p/jenkins_jj_09.html 點擊打開連接