背景
1.运维工作难以避免文件上传需求,开源vsftp 比较好用;
2.脚本内容;#!/bin/bashinstall_vsftp (){ yum install -y vsftpd if [ $? -eq 0 ];then create_conf $1 $2 else echo \”install error\” fisetsebool -P allow_ftpd_anon_write on setsebool -P allow_ftpd_full_access on}create_conf (){cat > /etc/vsftpd/vsftpd.conf << EOFallow_writeable_chroot=YESlisten=YESlisten_port=21connect_from_port_20=NOtcp_wrappers=YESone_process_model=NOuse_localtime=YESpasv_enable=YESpasv_min_port=4480pasv_max_port=4500xferlog_enable=YESxferlog_file=/var/log/vsftpd.logxferlog_std_format=NOpam_service_name=vsftpd.chennopriv_user=nobodymax_clients=300max_per_ip=20local_max_rate=0anon_max_rate=0connect_timeout=60accept_timeout=60data_connection_timeout=300idle_session_timeout=300banner_file=/etc/vsftpd/issuedirmessage_enable=YESanonymous_enable=NOanon_upload_enable=NOanon_mkdir_write_enable=NOanon_other_write_enable=NOanon_world_readable_only=NOno_anon_password=YESanon_umask=022guest_enable=YESguest_username=nobodyvirtual_use_local_privs=NOuser_config_dir=/etc/vsftpd/roleslocal_enable=YESlocal_umask=022write_enable=NOchroot_local_user=YESchroot_list_enable=YESchroot_list_file=/etc/vsftpd/chroot_listuserlist_enable=YESuserlist_deny=YESuserlist_file=/etc/vsftpd/user_listEOFtouch /etc/vsftpd/chroot_listcat > /etc/vsftpd/issue << EOF==== Welcome to use chenjl ftp server ====EOFcat > /etc/pam.d/vsftpd.chen << EOF#%PAM-1.0auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/accountsaccount sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/accountsEOFcat > /etc/vsftpd/create.sh << EOF/usr/bin/db_load -T -t hash -f /etc/vsftpd/accounts /etc/vsftpd/accounts.dbchmod 0600 /etc/vsftpd/accounts.dbEOFcat > /etc/vsftpd/createuser.sh << EOFpasswd=\\`openssl rand -base64 12\\`echo \”\\$1\” >>/etc/vsftpd/accountsecho \”\\$passwd\” >> /etc/vsftpd/accountsecho \”\\$1 passwd: \\$passwd\”EOFmkdir -p /etc/vsftpd/roles}if [ $# != 2 ];then echo \”input user dir \\$1 is user \\$2 is dir\”else install_vsftp /bin/bash /etc/vsftpd/createuser.sh $1 /bin/bash /etc/vsftpd/create.shcat > /etc/vsftpd/roles/$1 << EOFwrite_enable=YESanon_world_readable_only=YESanon_upload_enable=YESanon_mkdir_write_enable=YESanon_other_write_enable=YESlocal_root=$2EOFif [ -d $2 ];then chmod -R 777 $2else mkdir -p $2 chmod -R 777 $2fisystemctl restart vsftpd fi
3.执行结果;
4.测试;
5.验证上传结果;