服务器 SSH 安全配置

3,941 阅读1分钟

配置项

优先级:DenyUsers > AllowUsers > DenyGroups > AllowGroups

示例配置

# user1 只能在 ip1 登录
# user2 只能在 ip2 登录
# user3 和 user4 不限制 ip
AllowUsers user1@ip1 user2@ip2 user3@* user4

SSHD 推荐配置

# 建议修改 SSH 端口
Port 8722

# 禁止 root 用户登录
PermitRootLogin no
# 禁止密码登录
PasswordAuthentication no

# 使用密钥登录
PubkeyAuthentication yes
# 当 PasswordAuthentication 开启时,禁止使用空密码登录
PermitEmptyPasswords no
# 公钥存放文件
AuthorizedKeysFile .ssh/authorized_keys

# 限制用户的登录
DenyUsers blockuser1
AllowUsers user1@ip1 user2@ip2 user3@* user4
DenyGroups blockgroup1
AllowGroups allowgroup1

RSAAuthentication 配置在 CentOS 7.4 中被废弃,直接使用 PubkeyAuthentication 配置秘钥登录,参考 CentOS7.4配置SSH登录密码与密钥身份验证踩坑

参考文档