Linux设置远程免密登录

1.生成公钥 / 私钥对

[root@localhost ~]# ssh-keygen -t rsa -P ''

-P表示密码,-P '' 就表示空密码,也可以不用-P参数,这样就要三车回车,用-P就一次回车。
该命令将在用户/root/目录下面产生一个隐藏文件目录 .ssh,使用ls -a可以查看,/root/.ssh命令下面存放着一对密钥id_rsa和id_rsa.pub

 

2.创建authorized_keys文件,将id_rsa.pub内容复制到文件里面

[root@localhost ~]#  touch authorized_keys
[root@localhost ~]#  cat /root/.ssh/id_rsa.pub >> authorized_keys
[root@localhost ~]#  chmod 600 authorized_keys

 authorized_keys的权限最小要是600!!!

3.修改 sshd 的配置文件 /etc/ssh/sshd.conf ,取消注释

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile      .ssh/authorized_keys

4. 重启sshd

[root@localhost ~]#  service sshd restart

5 . 使用 id_rsa远程登录

扫描二维码关注公众号,回复: 1516156 查看本文章

猜你喜欢

转载自www.cnblogs.com/jinxiblog/p/9152739.html