Debain 系统
1、SSH启用密钥登录
修改配置文件/etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
2、SSH禁用密码登录
PasswordAuthentication no
针对Vultr的VPS,配置文件在/etc/ssh/sshd_config文件下,禁用密码时需要修改/etc/ssh/sshd_config.d/文件夹下的文件,否则修改无效。
3、禁用root用户
PermitRootLogin no
PermitRootLogin可以限定root用户通过ssh的登录方式,如禁止登陆、禁止密码登录、仅允许密钥登陆和开放登陆,以下是对可选项的概括:
| 参数类别 | 是否允许ssh登陆 | 登录方式 | 交互shell |
|---|---|---|---|
| yes | 允许 | 没有限制 | 没有限制 |
| without-password | 允许 | 除密码以外 | 没有限制 |
| forced-commands-only | 允许 | 仅允许使用密钥 | 仅允许已授权的命令 |
| no | 不允许 | N/A | N/A |
以上选项中,yes和no的功能显而易见,只是很粗暴的允许、禁止root用户进行登陆。without-password在yes的基础上,禁止了root用户使用密码登陆。
修改/etc/ssh/sshd_config配置文件后需要重启sshd服务
service sshd restart #centos系统
service ssh restart #ubuntu系统
/etc/init.d/ssh restart #debian系统