Linux设置远程免密登陆

1.生成公钥 / 私钥对ssh

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

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

 

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

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

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

 

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

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

 

4. 重启sshdclass

[root@localhost ~]#  service sshd restart

 

5 . 使用 id_rsa远程登陆登录

相关文章
相关标签/搜索