为什么要禁用密码登录
开启远程登录且允许密码登录时(特别是通过内网穿透将服务暴露在公网),存在被暴力破解的风险,使用 SSH 密钥登录可以完全避免此问题。
配置步骤
- 修改 ssh 配置文件
ShellScript
sudo vim /etc/ssh/sshd_config
添加或修改以下配置:
Plaintext
# 禁用基于密码的身份验证
PasswordAuthentication no
# 禁用基于质询响应的身份验证
ChallengeResponseAuthentication no
# 禁用键盘交互式认证
kbdInteractiveAuthentication no
- 重启 ssh 服务
ShellScript
sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist