Linux ssh 证书登录

生成私钥和公钥

ssh-keygen -t rsa -C user@localhost

将公钥拷贝至服务器

scp ~/.ssh/id_rsa.pub root@192.168.1.168:~/id_rsa.pub

在服务器上将公钥添加到authorized_keys

cat ~/id_rsa.pub >> ~/.ssh/authorized_keys

如果提示:-bash: /root/.ssh/authorized_keys: No such file or directory

mkdir ~/.ssh
touch ~/.ssh/authorized_keys

禁止密码登录

vim /etc/ssh/sshd_config
PasswordAuthentication no

重启ssh服务

systemctl restart sshd

证书ssh登录服务器

ssh -i ~/.ssh/id_rsa root@192.168.1.168

Leave a comment

Your email address will not be published. Required fields are marked *