sshd安全设置

2016-05-12 21:07  3217人阅读  评论 (0)
Tags: linuxsshd

修改端口

vim /etc/ssh/sshd_config
修改Port 22,如果需要监听多个端口,添加多行Port xxx
或者
ListenAddress 0.0.0.0:22

在SELinux中添加sshd的端口

yum install -y policycoreutils-python
semanage port -l | grep ssh
semanage port -a -t ssh_port_t -p tcp 10022
semanage port -l | grep ssh

ssh协议版本

Protocol 2

禁用root登录

PermitRootLogin no

仅允许指定用户登录

AllowUsers jack tom

禁用密码登录

PasswordAuthentication no

空密码登录

PermitEmptyPasswords no

su限制

只有wheel组的用户可以使用su命令

sudo配置

尽量使用sodo,避免直接使用root用户

防止暴力破解

denyhosts
fail2ban

禁止root本地登陆

禁止root本地登陆,但可以sudo、su使用或切换到root用户 
在/etc/pam.d/login的第一行添加如下信息 
auth required pam_succeed_if.so user != root quiet

客户端连接时常

ClientAliveInterval 60 # 每次检测时常 单位秒
ClientAliveCountMax 3 # 重复多少次没有响应就断开

自动登录设置

添加公钥 authorized_keys 文件中, 并设置文件权限.

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

重启sshd

# 一定要确定防火墙或者安全组开启`sshd`对应端口
systemctl restart sshd

查看并确认端口

netstat -tunpl | grep 10022
豫ICP备09035262号-1