root@c86bf8bed861:/# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa Your public key has been saved in /root/.ssh/id_rsa.pub
vim /etc/ssh/sshd_config #要确保下面这两项没有注释 PubkeyAuthentication yes #允许公钥认证 AuthorizedKeysFile .ssh/authorized_keys #指定包含用于用户身份验证的公钥的文件 #为了安全考虑,可以禁用root账户登录(不禁用也不影响免密登陆),或者在选项前面可以加#号 PermitRootLogin no #有了证书登录,可以禁用密码登录(不禁用也不影响免密登陆),或者在选项前面可以加#号 PasswordAuthentication no
重启一下B主机的ssh服务,这样ssh配置免密登陆才能生效
1 2
service ssh restart ssh root@81.110.26.20 -p 9000 # 这时不需要密码就可以登陆了