知識點055-ssh無密鑰登錄

該服務比較簡單,原理就是鎖和鑰匙的概念。ssh

主機A 和主機B 優化

A主機經過ssh-keygen命令(輸入3次回車) 在/root/.ssh/目錄下生成祕鑰和公鑰,把公鑰id_rsa.pub發送給主機Bthis

發送的命令: scp /root/.ssh/id_rsa.pub root@10.0.0.88:/home/chkusr/ spa

主機B 收到了A的公鑰後,將其移動到/root/.ssh/ 目錄下,而且重命名爲 authorized_keys rest

權限改小 chmod 600 /root/.ssh/authorized_keys code

這時候A主機就能夠不輸入密碼直接登錄B主機 ip

[root@cnsz142728 ~]# ssh-keygen -t rsa        (空格3次)

[root@cnsz142728 ~]# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@cnsz142728 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@cnsz142727
root@cnsz142727's password: 

[root@cnsz142728 ~]# ssh cnsz142727
Last login: Mon Oct  9 14:01:10 2017
WARNING: If you are not authorized to access this private computer system, disconnect now. All activities on this system will be monitored and recorded without prior notification or permission!
**************************************************************************
*                                                                        *
*Attention: Auditing process will report your every action!              *
*Warning: Don't delete any files in directory /root/slogs!!              *
*                                                                        *
*                          -PING AN INSURANCE (GRP) COMPANY OF CHINA,LTD.*
**************************************************************************
Script started, file is /root/slogs/2017-10-16_13:39:58pts-5root.log
[root@cnsz142727 ~]# ^C
[root@cnsz142727 ~]# exit

 

須要注意的幾點:it

1.確保A機器私鑰文件名是id_rsa,不然會由於識別不到私鑰文件而不會執行免密rsa登陸;io

2.確保B機器上.ssh/authorized_keys文件的屬性是600,不然要使用命令ast

3.若是還不行,則將這三行註釋掉(/etc/ssh/sshd_config)

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
 

優化的項目(/etc/ssh/sshd_config):

UseDNS no    ### 不使用DNS 

GSSAPIAuthentication  no  ### 加速ssh登錄

PermitEmptyPasswords no   ### 禁止空密碼登錄

Permitrootlogin no  ###禁止root 的遠程登錄,yes 是容許的意思

Port 22                    ### 22數字能夠更改,默認是22 登錄時候 ssh -p321 10.0.0.1便可

相關文章
相關標籤/搜索