全面转用 rsaauthentication

Posted on 2009-04-14 10:01  wanderxjtu  阅读(283)  评论(0编辑  收藏  举报
首先在本地生成一对rsa密钥:(1)
localuser@localbox:~$ ssh-keygen -t rsa

把公钥拷到远程机器:
localuser@localbox:~$ scp ~/.ssh/id_rsa.pub remoteuser@remotebox:~/

传统方式远程过去:
localuser@localbox:~$ ssh -l remoteuser remotebox

添加密钥:(2)
remoteuser@remotebox:~$ cat id_rsa.pub >> .ssh/authorized_keys

用rsa方式登录一下:
localuser@localbox:~$ ssh -l remoteuser remotebox

修改远程sshd:
remotebox:~# sed -e 's/PasswordAuthentication yes/PasswordAuthentication no/g' -e 's/^#PasswordAuthentication/PasswordAuthentication/g' -i /etc/ssh/sshd_config

重启sshd:(3)
remotebox:~# /etc/init.d/ssh restart

(1) 最好还是加密密钥,这是私钥丢失后的重要防范。
(2) authorized_keys 这个文件名由 sshd_config 指定,debian 默认为此。
另外注意公钥文件必须为remoteuser所有。
(3) debian 的为 ssh,其它发行版可能为 sshd

Copyright © 2024 wanderxjtu
Powered by .NET 8.0 on Kubernetes