# vi /etc/ssh/sshd_config ClientAliveInterval 600 # (Set to 600 seconds = 10 minutes) ClientAliveCountMax 0
禁用基于主机的身份验证:
1 2
# vi /etc/ssh/sshd_config HostbasedAuthentication no
禁用用户的 .rhosts 文件:
1 2
# vi /etc/ssh/sshd_config IgnoreRhosts yes
配置防火墙以接受仅来自已知网段的 SSH 连接:
Update /etc/sysconfig/iptables (Redhat specific file) to accept connection only from 192.168.100.0/24 and 209.64.100.5/27, enter:
1 2
-A RH-FW-1-INPUT -s 192.168.100.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT -A RH-FW-1-INPUT -s 209.64.100.5/27 -m state --state NEW -p tcp --dport 22 -j ACCEPT
限制 SSH 将侦听和绑定到的可用接口:
1 2 3
# vi /etc/ssh/sshd_config ListenAddress 192.168.100.17 ListenAddress 209.64.100.15
# < /dev/urandom tr -dc A-Za-z0-9_ | head -c8 oP0FNAUt[
使用 Chroot SSHD 将 SFTP 用户局限于其自己的主目录:
1 2 3 4
# vi /etc/ssh/sshd_config ChrootDirectory /data01/home/%u X11Forwarding no AllowTcpForwarding no
禁用空密码:
1 2
# vi /etc/ssh/sshd_config PermitEmptyPasswords no
在指定时间内对传入端口 2022 连接的数量限速:
Redhat iptables example (Update /etc/sysconfig/iptables):
1 2 3 4 5
-A INPUT -i eth0 -p tcp --dport 2022 -m state --state NEW -m limit --limit 3/min --limit-burst 3 -j ACCEPT
-A INPUT -i eth0 -p tcp --dport 2022 -m state --state ESTABLISHED -j ACCEPT -A OUTPUT -o eth0 -p tcp --sport 2022 -m state --state ESTABLISHED -j ACCEPT
配置 iptables,以便在 30 秒内仅允许在端口 2022 上有三个连接尝试:
Redhat iptables example (Update /etc/sysconfig/iptables):
1 2 3 4
-I INPUT -p tcp --dport 2022 -i eth0 -m state --state NEW -m recent --set
-I INPUT -p tcp --dport 2022 -i eth0 -m state --state NEW -m recent --update --seconds 30 --hitcount 3 -j DR
# vi /etc/ssh/sshd_config VerifyReverseMapping yes # Turn on reverse name checking UsePrivilegeSeparation yes # Turn on privilege separation StrictModes yes # Prevent the use of insecure home directory # and key file permissions AllowTcpForwarding no # Turn off , if at all possible X11Forwarding no # Turn off , if at all possible PasswordAuthentication no # Specifies whether password authentication is # allowed. The default is yes. Users must have # another authentication method available .
# RSAAuthentication yes # PubkeyAuthentication yes # RhostsRSAAuthentication no # HostbasedAuthentication no # RhostsRSAAuthentication and HostbasedAuthentication PasswordAuthentication yes ChallengeResponseAuthentication no # KerberosAuthentication no GSSAPIAuthentication yes