背景
1.运维工作难以避免文件上传需求,开源vsftp 比较好用;
2.脚本内容;
#!/bin/bash
install_vsftp ()
{
yum install -y vsftpd
if [ $? -eq 0 ];then
create_conf $1 $2
else
echo "install error"
fi
setsebool -P allow_ftpd_anon_write on
setsebool -P allow_ftpd_full_access on
}
create_conf ()
{
cat > /etc/vsftpd/vsftpd.conf << EOF
allow_writeable_chroot=YES
listen=YES
listen_port=21
connect_from_port_20=NO
tcp_wrappers=YES
one_process_model=NO
use_localtime=YES
pasv_enable=YES
pasv_min_port=4480
pasv_max_port=4500
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=NO
pam_service_name=vsftpd.chen
nopriv_user=nobody
max_clients=300
max_per_ip=20
local_max_rate=0
anon_max_rate=0
connect_timeout=60
accept_timeout=60
data_connection_timeout=300
idle_session_timeout=300
banner_file=/etc/vsftpd/issue
dirmessage_enable=YES
anonymous_enable=NO
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
anon_world_readable_only=NO
no_anon_password=YES
anon_umask=022
guest_enable=YES
guest_username=nobody
virtual_use_local_privs=NO
user_config_dir=/etc/vsftpd/roles
local_enable=YES
local_umask=022
write_enable=NO
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list
userlist_enable=YES
userlist_deny=YES
userlist_file=/etc/vsftpd/user_list
EOF
touch /etc/vsftpd/chroot_list
cat > /etc/vsftpd/issue << EOF
==== Welcome to use chenjl ftp server ====
EOF
cat > /etc/pam.d/vsftpd.chen << EOF
#%PAM-1.0
auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/accounts
account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/accounts
EOF
cat > /etc/vsftpd/ << EOF
/usr/bin/db_load -T -t hash -f /etc/vsftpd/accounts /etc/vsftpd/accounts.db
chmod 0600 /etc/vsftpd/accounts.db
EOF
cat > /etc/vsftpd/ << EOF
passwd=\`openssl rand -base64 12\`
echo "\$1" >>/etc/vsftpd/accounts
echo "\$passwd" >> /etc/vsftpd/accounts
echo "\$1 passwd: \$passwd"
EOF
mkdir -p /etc/vsftpd/roles
}
if [ $# != 2 ];then
echo "input user dir \$1 is user \$2 is dir"
else
install_vsftp
/bin/bash /etc/vsftpd/ $1
/bin/bash /etc/vsftpd/
cat > /etc/vsftpd/roles/$1 << EOF
write_enable=YES
anon_world_readable_only=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_root=$2
EOF
if [ -d $2 ];then
chmod -R 777 $2
else
mkdir -p $2
chmod -R 777 $2
fi
systemctl restart vsftpd
fi3.执行结果;

4.测试;

5.验证上传结果;

















