下面例子演示创建ftpuser 并且设置密码为ftpuser,ftpuser的目录为/root/ftpuser

#!/bin/bash

rpm -ivh vsftpd-2.2.2-21.el6.x86_64.rpm
username=ftpuser
useradd -d /root/$username $username
echo "$username"|passwd --stdin $username

#这种方式避免交互式的设置密码操作,直接shell脚本设置密码

setsebool -P ftpd_disable_trans 1
service vsftpd restart

sed -i 's/^[#]*\(userlist_enable=\).*$/\1NO/' /etc/vsftpd/vsftpd.conf
sed -i 's/^[#]*\(anonymous_enable=\).*$/\1NO/' /etc/vsftpd/vsftpd.conf
sed -i 's/^[#]*\(chroot_list_enable=\).*$/\1YES/' /etc/vsftpd/vsftpd.conf
sed -i 's/^[#]*\(chroot_list_file=\).*$/\1\/etc\/vsftpd\/chroot_list/' /etc/vsftpd/vsftpd.conf
sed -i '$a ftpuser' /etc/vsftpd/user_list
touch /etc/vsftpd/chroot_list
sed -i '$a ftpuser' /etc/vsftpd/chroot_list
setsebool -P ftpd_disable_trans 1
service vsftpd restart
chmod 777 ftpuser

05-07 15:44