Linux VPS禁用root密码并配置SSH-KEY登录
SSH-KEYgen -t rsa
Enter file in which to save the key (/root/.ssh/id_rsa): 建议直接回车使用默认路径 Enter passphrase (empty for no passphrase): 输入密码短语(留空则直接回车) Enter same passphrase again: 重复密码短语
此时在/root/.ssh/
目录下生成了2个文件,id_rsa
为私钥,id_rsa.pub
为公钥。私钥自己下载到本地电脑妥善保存(丢了服务器可就没法再登陆了),为安全,建议删除服务器端的私钥。公钥则可以任意公开。
2、导入KEY文件
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
3、修改SSH的配置文件/etc/SSH/SSHd_config
可以借助winscp
工具登录vps
进行编辑修改!
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeys File .SSH/authorized_keys PasswordAuthentication no
进行上述修改后我们就完成了关闭root
并启用SSH-KEY
登录方式。
重启SSH
服务
/etc/init.d/sshd restart #CentOS系统 /etc/init.d/ssh restart #debian,Ubuntu系统
4、通过Xshell用SSH-KEY方式登录
最后导入密匙即可!