vsftpd(very secure FTP daemon)是一个完全免费,开源的FTP服务器软件。
## vsftpd
查询vsftpd
```
yum info vsftpd
```
安装和配置vsftpd服务
```
yum install vsftpd -y
systemctl start vsftpd
systemctl enable vsftpd
systemctl status vsftpd
```
查询socket statistics状态
```
ss -antp | grep vsftpd
```
设置防火墙例外
```
firewall-cmd --permanent --add-service=ftp
firewall-cmd --reload
firewall-cmd --list-services
```
创建本地用户,ftp目录,设置权限
```
useradd user01
passwd user01
mkdir -p /home/user01/ftp
mkdir -p /home/user01/ftp/upload
chmod 550 /home/user01/ftp
chmod 750 /home/user01/ftp/upload
chown -R user01:user01 /home/user01/ftp
```
修改配置文件vi /etc/vsftpd/vsftpd.conf
```
# 禁止匿名访问
anonymous_enable=NO
# 将用户限制在主目录
chroot_local_user=YES
# ftp用户根目录为家目录下的ftp
user_sub_token=$USER
local_root=/home/$USER/ftp
# ftp用户允许列表/etc/vsftpd/user_list
userlist_enable=YES
userlist_deny=NO
```
清空配置文件/etc/vsftpd/user_list里用户,然后添加用户user01
```
cat /etc/vsftpd/user_list | grep -v "^#"
user01
```
重启vsftpd服务
```
systemctl restart vsftpd
```
禁止ssh登录
```
# Modify user's login to /sbin/nologin in /etc/passwd
grep user01 /etc/passwd
user01:x:1000:1000::/home/user01:/sbin/nologin
# Add /sbin/nologin into /etc/shells
cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/sbin/nologin
```
Pasv Mode (可选)
```
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=31000
```
TLS / SSL / FTPS(可选)
生成证书
```
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout /etc/vsftpd/vsftpd.pem -out /etc/vsftpd/vsftpd.pem
```
修改配置文件vi /etc/vsftpd/vsftpd.conf(添加下面内容)
```
rsa_cert_file=/etc/vsftpd/vsftpd.pem
rsa_private_key_file=/etc/vsftpd/vsftpd.pem
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
```
## tftp
查询tftp
```
yum info tftp
yum info tftp-server
yum info xinetd
```
安装和配置tftp服务
```
yum install tftp tftp-server xinetd -y
systemctl start tftp xinetd
systemctl enable tftp xinetd
systemctl status tftp
systemctl status xinetd
```
修改配置文件vi /etc/xinetd.d/tftp
```
server_args = -c -s /var/lib/tftpboot
disable = no
```
修改tftp目录(默认)权限
```
chmod 777 /var/lib/tftpboot
```
设置防火墙例外
```
firewall-cmd --permanent --add-service=tftp
firewall-cmd --reload
firewall-cmd --list-services
```
设置SELINUX
```
setsebool -P tftp_anon_write on
setsebool -P tftp_home_dir on
getsebool -a | grep tftp
```