在客户端生成密钥对
ssh-keygen -t rsa -b 4096
将公钥复制到服务器
ssh-copy-id user@remote_host
配置SSH服务端
确保/etc/ssh/sshd_config允许使用公钥登录
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
## 禁用密码登录
PasswordAuthentication no
重启SSH服务
sudo systemctl restart sshd.service