[Linux] 使用Public Key (OpenSSH) 不用密碼登陸

 步驟如下:

1.建立公鑰與私鑰
# ssh-keygen -t dsa -f ~/.ssh/idc (DSA算法比RSA算法支持的平臺更多,idc名字可以自定義:例如aaa、bbb等)
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/idc): ← 鑰匙的文件名,這裏保持默認直接回車
Enter passphrase (empty for no passphrase): ← 輸入口令,如想無口令認證直接回車
Enter same passphrase again:
Your identification has been saved in /root/.ssh/idc.
Your public key has been saved in /root/.ssh/idc.pub.
The key fingerprint is:
1e:16:9e:d5:d2:6a:b6:e2:a0:de:14:b2:eb:d1:5e:03 [email protected]
#cd ~/.ssh← 進入用戶SSH配置文件的目錄
# ls -l ← 列出文件
total 8
-rw------- 1 root root 668 Feb 26 14:01 idc ← 確認私鑰已被建立
-rw-r--r-- 1 root root 616 Feb 26 14:01 idc.pub ← 確認公鑰已被建立
# cat idc.pub >>authorized_keys← 公鑰內容輸出到相應文件中
# chmod 400 authorized_keys ← 將新建立的公鑰文件屬性設置爲400

2.分別把idc  idc.pub 拷貝到Client端
3.刪除Server端的公鑰
#rm -f ~/.ssh/idc.pub← 刪除原來的公鑰文件
4.修改ssh配置文件
#cd /etc/ssh  ← 進入ssh配置文件
#cp sshd_config sshd_configback  ← 備份ssh配置文件
# vi sshd_config  ← 編輯配置文件修改一下參數信息
PubkeyAuthentication yes /*啓用PublicKey認證
AuthorizedKeysFile .ssh/authorized_keys /*PublicKey文件路徑
PasswordAuthentication no /*禁止密碼驗證登錄

 

更多詳細內容:http://iblog.daobidao.com/linux-uses-public-key-openssh-without-password-to-login.DaoBiDao

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章