用root登陆执行以下命令
cd /root/.ssh/
rm -f id_rsa 删除原密钥
ssh-keygen -m PEM -t rsa -b 4096 三次回车生成密钥(强制生成RSA格式密钥)
cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys 在服务器上安装公钥
cd /root/.ssh/;chmod 600 authorized_keys;chmod 700 ~/.ssh 修改文件权限
service sshd restart 重启ssh
sz /root/.ssh/id_rsa 下载密钥
sed -i -e 's/#PubkeyAuthentication/PubkeyAuthentication/g' /etc/ssh/sshd_config 打开密钥登陆
sz /root/.ssh/id_rsa 下载密钥文件用于CRT登陆
验证密钥可以登陆后取消密码登陆
sed -i -e 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config 取消密码登陆
网友评论