1、上传vsftpd的rpm包
、ftp.sh
至任意路径;
2、用root用户执行ftp脚本,具体如下:
[root@localhost ~]# bash ftp.sh ${ftp用户} ${ftp密码} ${被动模式最小端口号} ${被动模式最大端口号}
# 示例:
[root@localhost ~]# bash ftp.sh ftp 123456 60000 61000
cat ftp.sh
#!/bin/bash
ftpuser=$1
ftppasswd=$2
minport=$3
maxport=$4
file=/etc/vsftpd/vsftpd.conf
if ! rpm -q vsftpd &>/dev/null;then
rpm -ivh vsftpd-*.rpm
fi
useradd -d /var/$ftpuser -s /bin/bash -m $ftpuser
echo "$ftppasswd" | passwd $ftpuser --stdin
setfacl -m d:u:$ftpuser:rwx /var/$ftpuser
setfacl -m d:g:$ftpuser:rwx /var/$ftpuser
cat /dev/null > /etc/vsftpd/ftpusers
echo "$ftpuser" > /etc/vsftpd/user_list
sed -i 's/^anonymous_enable=.*$/anonymous_enable=NO/' $file
sed -i 's/^listen=.*$/listen=YES/' $file
sed -i 's/^listen_ipv6=\(.*$\)/#listen_ipv6=\1/' $file
cat >> $file << EOF
userlist_deny=NO
userlist_enable=YES
local_root=/var/$ftpuser
pasv_enable=YES
pasv_min_port=$minport
pasv_max_port=$maxport
EOF
if ! systemctl status firewalld &>/dev/null; then
systemctl stop firewalld
fi
if systemctl status vsftpd &>/dev/null; then
systemctl restart vsftpd
else
systemctl start vsftpd
fi
systemctl status vsftpd