FTP安全配置和SSH安全配置
部分参考文献
https://www.ibadboy.net/archives/1519.html
https://blog.csdn.net/weixin_53567573/article/details/114067265
http://blog.chinaunix.net/uid-10697776-id-3341317.html
https://www.cnblogs.com/relax1949/p/8971439.html
(一)FTP安全配置
1. 修改配置文件,将ftp服务预设端口改为2121,并对iptables进行配置。
修改端口号
修改配置文件
vi /etc/vsftpd/vsftpd.conf
添加端口号
listen_port=2121
修改services文件
vi /etc/services
修改ftp端口号
ftp 2121/tcp
ftp 2121/udp
重启vsftpd服务
systemctl restart vsftpd
验证端口号修改
查看端口号
netstat -lntp
浏览器
ftp://192.168.10.112:2121
2.修改配置文件,禁止匿名用户登录。
禁止匿名用户登录配置
vi /etc/vsftpd/vsftpd.conf
修改一下内容
anonymous_enable=NO
3.修改ftp默认主目录为/ftp文件夹,并将用户锁定在主目录内。
创建/ftp文件夹
mkdir /ftp
修改FTP默认主目录
local_root 针对系统用户;anon_root 针对匿名用户;chroot_local_user=YES 将用户锁定在主目录内;
vi /etc/vsftpd/vsftpd.conf
local_root=/ftp
chroot_local_user=YES
anon_root=/ftp
重启vsftpd服务
systemctl restart vsftpd
4.修改配置文件,关闭ls -R命令,防止服务器被DoS攻击。
修改配置文件
vi /etc/vsftpd/vsftpd.conf
ls_recurse_enable=NO
the presence of the “-R” option, so there is a strong case for enabling it.
存在“-R”选项,因此有充分的理由启用它。
You may activate the “-R” option to the builtin ls. This is disabled by
您可以激活内置ls的“-R”选项。此功能已被禁用
5.修改配置文件,关闭ascii模式下载,防止被用于DoS攻击。
修改配置文件
vi /etc/vsftpd/vsftpd.conf
关闭ascii模式下载
ascii_download_enable=NO
(二)SSH安全配置
1. 修改ssh配置文件,禁止root用户通过ssh登录。
配置文件
vi /etc/ssh/sshd_config
修改PermitRootLogin
PermitRootLogin NO
重启sshd服务
service sshd restart
2.配置TCP Wrappers ,对远程主机进行访问控制,仅允许192.168.1.0/24网段使用ssh进行登录。
配置允许访问的配置
vi /etc/hosts.allow
sshd:192.168.1.0/255.255.255.0
配置拒绝访问的配置
vi /etc/hosts.deny
sshd:ALL
3. 修改ssh配置文件,控制通过ssh登录的用户,仅允许用户名为dcn的用户进行登录。
修改sshd配置文件
vi /etc/ssh/sshd_config
设置AllowUsers
#仅dnc dnc1两个用户可以登录。
AllowUsers dcn dcn1
重启服务
systemctl restart sshd
4.修改ssh配置文件,设置每300秒判断一次客户端是否超时,允许超时次数5次。
修改sshd配置文件
vi /etc/ssh/sshd_config
设置ClientAliveInterval(客户端生存间隔)
#server每隔300秒发送一次请求给client,然后client响应,从而保持连接
ClientAliveInterval 300
设置ClientAliveCountMax(客户端超时次数)
#server发出请求后,客户端没有响应得次数达到5,就自动断开连接,正常情况下,client不会不响应
ClientAliveCountMax 5
5.修改ssh配置文件,禁止使用空密码进行登录,设置最大尝试次数为5次。
个人理解-作用
为了防止密码爆破,设置MaxAuthTryes值
修改sshd配置文件
vi /etc/ssh/sshd_config
设置PermitEmptyPasswords(允许空密码)
PermitEmptyPasswords no
设置PasswordAuthentication
#关闭之后只能使用密钥进行登陆
PasswordAuthentication yes
#尝试次数5次
MaxAuthTries 5
重启sshd服务
systemctl restart sshd