1·生成ssh密钥对(如果没有现成的密钥)
本地机器终端并运行以下命令:
ssh-keygen -t ed255192·将公钥复制到目标服务器(id_ed25519.pub)
mkdir -p /root/.ssh && touch /root/.ssh/authorized_keyschmod 600 /root/.ssh/authorized_keys && chmod 700 /root/.sshecho "ssh公钥" >> /root/.ssh/authorized_keysecho "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEKbgop4Jr9ghbH3PdLsM6w4yi57rgrOPJ4VQjLBFL/s yishang@DESKTOP-BMVT1P1" >> /root/.ssh/authorized_keys- 注意:也可以直接复制公钥到/root/.ssh/authorized_keys
3·修改ssh配置文件
/etc/ssh/sshd_configPubkeyAuthentication yes # 启用公钥认证
AuthorizedKeysFile .ssh/authorized_keys # 公钥存储位置
PasswordAuthentication no # 禁用密码登录4·重启ssh服务
systemctl restart ssh