02月26日, 2020 443 views

其实配置这个很简单,我以Debian9为例~其中又有点坑需要注意,只有自己趟过才知道。。。
我这里没有用系统自带的生成key的方式,如果想用系统自带方式,运行这条命令
ssh-keygen -t rsa -b 4096
系统会提示rsa key 存放位置,默认回车就好。完成后务必将 .ssh 文件夹下文件保存到本地!
运行命令 cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys ( mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys 也可以)
chmod 600 /root/.ssh/authorized_keys chmod 700 /root/.ssh/
vi /etc/ssh/sshd_config 修改 #PubkeyAuthentication yes 为 PubkeyAuthentication yes (改为key方式登录,貌似不改也中,系统默认开启)
修改 PasswordAuthentication yes 为 PasswordAuthentication no (禁用密码登录)
图省事有批量命令行~
cd /etc/ssh/
sed -i "/PasswordAuthentication no/c PasswordAuthentication no" sshd_config
sed -i "/RSAAuthentication no/c RSAAuthentication yes" sshd_config
sed -i "/PubkeyAuthentication no/c PubkeyAuthentication yes" sshd_config
sed -i "/PasswordAuthentication yes/c PasswordAuthentication no" sshd_config
sed -i "/RSAAuthentication yes/c RSAAuthentication yes" sshd_config
sed -i "/PubkeyAuthentication yes/c PubkeyAuthentication yes" sshd_config
无脑粘过去回车就好(笑
修改完需要重启ssh ,各个版本系统命令可能不同,我这里使用这个命令 service sshd restart ,断开当前SSH链接重新登录就看到效果啦~
还有最后的一步,记得删除服务器上的 id_rsa 文件~
Bitvise SSH
最后的最后推荐使用putty或者Bitvise SSH ,简单方便
