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遠程登陸登錄

相關文章
相關標籤/搜索