0x00 SSH默认配置文件

文件路径

/etc/ssh/sshd_config

0x01 安全配置

vim /etc/ssh/sshd_config

* 修改默认端口,将22端口修改至其他
port -> 22 -> xxx

* 禁用root登录
PermitRootLogin no

* 禁用密码验证
PasswordAuthentication no

* 禁用基于主机的身份验证
HostbasedAuthentication no

* 禁止使用空密码登录
PermitEmptyPasswords no

* 设置闲置回话超时时间和尝试次数
ClientAliveInterval 600  //600秒无动作后自动断开

ClientAliveCountMax 12

配置完成后重启ssh服务
/etc/init.d/sshd restart或者systemctl restart sshd

0x02 限制IP

修改sshd_config配置文件,允许test用户ssh访问服务器(以空格分开用户;添加完允许,默认拒绝其他所有用户)

echo "AllowUsers test" >> /etc/ssh/sshd_config

编辑hosts.deny配置文件,追加一行内容

echo "sshd:ALL" >> /etc/hosts.deny

使用iptables限制ip

iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport xxx -j ACCEPT

655 对 “SSH安全配置”的想法;