进入服务器后,使用命令编辑sshd_config
vim /etc/ssh/sshd_config
开启使用ssl登录(去除#注释)
PubkeyAuthentication yes
拷贝自己本地ssh生成id_rsa.pub
例:
ssh-rsa CAAAB3NzaC1yc2EAAAADAQABAAABAQDLm/KAZ62+FXyELnW1i54jITqsfMvyGq0Vn1HBGmkVu+CDvMsPcmjcwiM16zzBajCcBRx3smBhXMKYjLwEB1iJPcxPCYOLcMeKUPFCb5T/aFuhXZPd7XSLSPmBH5897mSk/psmzhTfact3QiKs5ZMVv82Ajj+7U+HCeCklCgQp7PpfcMe93lcKCng6N9oJAxSDIWBfLNO9r3v27RA5RMpLinu9HYHYb/hhNtj9HkRtmPsmD724cWdMqRg3qUYn9dBRJVMg1EJlY93jrBKIFKJXVTIe/eJxiq1JTWTmtsG236vTzss+kgztIoiflGZbQvwFBQhRa+tEpgivMkmE9p97 ray.lei@ezhy.cn
添加至服务器的 ~/.ssh/authorized_keys 中
记得重启下sshd.service
systemctl restart sshd.service
添加后,可以在本地尝试使用ssh进行登录
Host test_1
Hostname 192.168.166.209
Port 22
User root
IdentityFile ~/.ssh/id_rsa
PreferredAuthentications publickey
成功进入服务器后说明配置成功,可以禁用服务器的密码登录了(sshd_config)
PasswordAuthentication no
记得重启下sshd.service
systemctl restart sshd.service