- root账户生成pem文件
- 取消输入密码登录
root账户生成pem文件背景:云服务,一直被别人登录,尝试使用秘钥文件,禁用密码登录
创建秘钥
ssh-keygen -t rsa -C "root的密钥" -f "root_key" #-f 指定生成的秘钥文件名 -C选项是公钥文件中的备注 #回车后输入你使用公钥时的密码 #再次回车输入相同密码 #普通用户在自己家目录执行该命令生成密钥
cd /root/.ssh cp root_key root_key.pem #生成pem文件,使用远程工具可直接登录 cat root_key.pub >> authorized_keys #追加公钥到authorized_keys,如果没有authorized_keys 文件就touch一个 chmod 600 authorized_keys #富裕文件权限
vim /etc/ssh/sshd_config #编辑ssh的配置文件
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile %h/.ssh/authorized_keys
systemctl restart sshd #重启服务,
取消输入密码登录到此已经可以使用密钥登录了 将root_key.pem文件拷贝到本地,选择密钥为root_key.pem文件登录即可,但还是可以密码登录,需要下列设置才可以只通过pem文件登录
vim /etc/ssh/sshd_config PasswordAuthentication yes # 修改 PasswordAuthentication 的yes 为no systemctl restart sshd #重启服务



