编辑 SSH 配置文件
sudo vim /etc/ssh/sshd_config
生成 ed25519 标准的公私钥对
ssh-keygen -t ed25519 -C "xxx@xxx.com"
把公钥上传到
~/.ssh/authorized_keys
重启 SSH 服务
sudo systemctl restart sshd
如果还是不行,查看登录日志
sudo tail -f /var/log/secure
建议设置为 prohibit-password (允许密钥,禁止密码)
# 打开文件
vim /etc/ssh/sshd_config
#设置禁止密码登录
PermitRootLogin prohibit-password