centos6 ssh-keygen 免密碼 自動登陸

分類: LINUX

環境: centos6a,centos6b,centos6c
需求:從centos6a免密碼,自動登陸到centos6b或者centos6c
步驟:

1 修改每臺機器的/etc/hosts文件,內容如下
127.0.0.1 localhost
192.168.0.2 centos6a
192.168.0.3 centos6b
192.168.0.4 centos6c

2 本機創建ssh密鑰 

centos6a#:  ssh-keygen -t rsa -'' -f ~/.ssh/id_dsa
-P表示密碼,-P '' 就表示空密碼,也可以不用-P參數,這樣就要三車回車,用-P就一次回車。

3  拷貝密鑰到“被登陸機”輸入密碼,

centos6a#:~/.ssh#scp id_rsa.pub centos6b:~/.ssh/
centos6a#:~/.ssh#scp id_rsa.pub centos6c:~/.ssh/  

4 ssh到“被登陸機”(centos6b,centos6c)把密鑰改成 “authorized_keys”

           centos6b#:~/.ssh# mv id_rsa.pub authorized_keys
           centos6c#:~/.ssh# mv id_rsa.pub authorized_keys

5  在“被登陸機”(centos6b,centos6c)上執行命令 restorecon 
說明:There is a bug in CentOS 6 / SELinux that results in all client presented certificates to be ignored when SELinux is set to Enforcing. To fix this simply: 

      centos6b#:restorecon -R -v ~/.ssh
     centos6c#:restorecon -R -v ~/.ssh
或者 

     centos6b#: setenforce 0
     centos6c#: setenforce 0

6 ssh centos6b 這樣就實現無密碼登陸

發佈了8 篇原創文章 · 獲贊 5 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章