# 生成密钥
ssh-keygen -t ed25519 -C "info@liehua.me"
# 将公钥写入授权文件
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
# 修复权限(权限不对会直接导致密钥登录静默失效)
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
# 修改 ssh 配置(数字越小,优先级越高)
sudo vi /etc/ssh/sshd_config.d/00-custom.conf
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
PermitRootLogin prohibit-password
# 下载私钥(在本地电脑的终端中执行)
scp root@192.168.0.100:/root/.ssh/id_ed25519 .
# 重启 ssh 服务
sudo systemctl reload ssh
# 其他
sudo sshd -t
sudo sshd -T | grep -i author