LEEUNITYAssets / Content / 博客.asset
层级
⌄ Lee / Homepage
INSPECTOR
Type
Content
Name
博客
lee@mtftm.com ↗GitHub ↗
N035SYSTEM / LINUX

技术 / 简体中文

使用 ssh 密钥登陆服务器并禁用密码登陆

- 使用指令 ssh-keygen 生成密钥,或使用已有密钥 - 将对应公钥拷贝到 root/.ssh/authorized keys 文件内。

更新
2025.04.21
阅读
1 分钟
语言
简体中文

配置 ssh 密钥登陆

  • 使用指令 ssh-keygen 生成密钥,或使用已有密钥
  • 将对应公钥拷贝到 root/.ssh/authorized_keys 文件内。

禁用密码登陆

编辑 /etc/ssh/sshd_config 文件,修改以下参数:

PubkeyAuthentication yes
PasswordAuthentication no

重启 ssh 服务

sudo systemctl restart sshd

如不生效,删除 etc/ssh/sshd_config.d 内的所有文件。