好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

linux中vsftpd虚拟用户配置脚本示例 - linux教程

linux中vsftpd虚拟用户配置脚本示例

下面来看一段linux中vsftpd虚拟用户配置脚本示例,希望这个例子能帮助到各位快速成功配置好自己的vsftpd服务器.

每次新安装服务器后,都要进行一系列的配置,安装软件,修改配置等,为了今后更好的部署vsftpd,特此写了个脚本用于部署.

登录FTP有三种方式,匿名登录、本地用户登录和虚拟用户登录.

匿名登录: 在登录FTP时使用默认的用户名,一般是ftp或anonymous.

本地用户登录:使用系统用户登录,在/etc/passwd中.

虚拟用户登录:这是FTP专有用户,有两种方式实现虚拟用户,本地数据文件和数据库服务器。

FTP虚拟用户是FTP服务器的专有用户,使用虚拟用户登录FTP,只能访问FTP服务器提供的资源,大大增强了系统的安全,代码如下:

  • #!/bin/bash 
  • ######################################### 
  • ######### descprition ################## 
  • # 1.安装vsftpd 
  • # 2.配置vsftpd虚拟化 
  • ######################################## 
  • #init variables 
  • PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local /bin:/usr/ local /sbin:~/bin 
  • export PATH 
  •  
  • ff_outputdir=/tmp/liufofu 
  • curdate=$(date  +%Y%m%d) 
  • curtime=$(date  +%H%M%S) 
  • ff_logfile=${ff_outputdir}/$$.log 
  • if [ ! -e ${ff_outputdir} ];then  
  •     mkdir -p ${ff_outputdir} 
  • fi 
  •  
  • #处理过程中产生的日志由日志函数来进行处理记录 
  • function  log() 
  •     echo "`date +" %Y:%m:%d %H-%M-%S "` $1 "   >> ${ff_logfile} 
  •  
  • yum -y install vsftpd 
  • yum -y install db4-utils 
  • #生成vsftpd配置文件 
  • cat > /etc/vsftpd/vsftpd.conf<<EOF 
  • anonymous_enable=NO  
  • local_enable=YES 
  • write_enable=YES 
  • local_umask=022 
  • log_ftp_protocol=YES 
  • dirmessage_enable=YES 
  • xferlog_enable=YES 
  • connect_from_port_20=YES 
  • xferlog_file=/var/log/xferlog 
  • xferlog_std_format=YES 
  • chroot_list_enable=YES 
  • chroot_list_file=/etc/vsftpd/chroot_list 
  • listen=YES 
  • pam_service_name=vsftpd 
  • guest_enable=YES 
  • #guest_username=www 
  • dual_log_enable=YES 
  • vsftpd_log_file=/var/log/vsftpd.log 
  • user_config_dir=/etc/vsftpd/vuser_conf 
  • userlist_enable=YES 
  • tcp_wrappers=YES 
  • #listen_address=172.20.1.175 
  • #listen_port=21000 
  • virtual_use_local_privs=YES 
  • EOF 
  • log "生成vsftpd配置文件"  
  • #创建虚拟用户目录 
  • if [ ! -e /etc/vsftpd/vuser_conf ];then  
  •     mkdir -p /etc/vsftpd/vuser_conf 
  • fi 
  • log "创建虚拟用户目录"  
  • #创建测试用户的根目录 
  • if [ ! -e /var/www/html/liufofu ];then  
  •      mkdir -p /var/www/html/liufofu 
  • fi 
  • log "创建虚拟用户目录"  
  • #创建测试用户 
  • cat >/etc/vsftpd/vuser_conf/liufofu<<EOF 
  • local_root=/var/www/html/liufofu 
  • write_enable=YES 
  • anon_world_readable_only=NO  
  • anon_upload_enable=YES 
  • anon_mkdir_write_enable=YES 
  • anon_other_write_enable=YES 
  • EOF 
  •  
  • #限制虚拟用户的虚根 
  • ls -l /etc/vsftpd/vuser_conf| grep -v total | awk '{print $NF}'  > /etc/vsftpd/chroot_list  
  •  
  • #设置虚拟用户名和密码 
  • cat >/etc/vsftpd/ftplogins.txt<<EOF 
  • liufofu 
  • liufofu 
  • EOF 
  •  
  • if [ -f /etc/vsftpd/ftplogins.txt ];then  
  •     chmod 600 /etc/vsftpd/ftplogins.txt 
  • fi 
  •  
  • #设置vsftpd的虚拟验证方法 
  • if [ $(uname -a | grep x86_64 | wc -l) -eq 1 ];then  
  • cat >/etc/pam.d/vsftpd<<EOF 
  • #%PAM-1.0 
  • auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd  
  • account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd 
  • EOF 
  • else   
  • cat >/etc/pam.d/vsftpd<<EOF 
  • #%PAM-1.0 
  • auth required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd  
  • account required /lib/security/pam_userdb.so db=/etc/vsftpd/vsftpd 
  • EOF 
  • fi 
  • log "设置vsftpd的虚拟验证方法"  
  • #建立vsftpd的宿主用户 
  • if [ $(grep vsftpd /etc/passwd) -lt 1 ];then  
  •     useradd vsftpd -s /sbin/nologin 
  •     usermod -a -G www vsftpd 
  • fi  --phpfensi.com  
  • log "建立vsftpd的宿主用户"  
  •  
  • db_load -T -t hash -f /etc/vsftpd/ftplogins.txt /etc/vsftpd/vsftpd.db 
  • log "生成虚拟用户数据库"  
  • #启动vsftpd 
  • service vsftpd start

    查看更多关于linux中vsftpd虚拟用户配置脚本示例 - linux教程的详细内容...

  •   阅读:76次