码迷,mamicode.com
首页 > 系统相关 > 详细

linux系统脚本配置ftp服务器

时间:2017-09-11 18:19:32      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:linux ftp


[root@xuegod63 test]# vim vsftp_home.sh

#############################################
#####   date    2017-09-10
#####   name    ftp服务器
#####   anth    joker
#############################################
#!/bin/bash
. /root/test/vsftp_function.sh
while true
do
        #clear
        cat<<-eof
        *************************************
        ***        不要重复操作           ***
        *************************************
        ****    1       安装ftp服务
        ****    2       配置临时ftp服务器
        ****    3       配置企业ftp服务器
        ****    4       配置虚拟ftp服务器
        ****    5       退出
        *************************************
        eof
#选择
        read -p "请输入您的选择 [1-5]:" CHOISE
        case $CHOISE in
        1)
                install_ftp
        ;;
        2)
                install_provisional_server
        ;;
        3)
                install_enterprise_server
        ;;
        4)
                install_Virtualaccount_server
        ;;
        5)
                exit 520
        ;;
        esac
done


[root@xuegod63 test]# vim vsftp_function.sh

####检查服务,安装服务函数
install_ftp(){
        service vsftpd status &>/dev/null
#       STATE1=`service vsftpd status | awk ‘{print $3}‘`
        case $? in
        0)
                echo "FTP服务已经安装,正在检查服务是否启动......"
                STATE1=`service vsftpd status | awk ‘{print $3}‘`
                if [ $STATE1 == "stopped"  ];then
                        /etc/init.d/vsftpd start
                         STATE2=`service sshd status|awk -F"[ .]+" ‘{print $5}‘`
                        if [ $STATE2 == "running" ];then
                                echo "服务已经启动......"
                        else
                                echo "请检查服务"
                        fi
                else
                        echo "服务已经启动......"
                fi

        ;;
        1)
                yum -y install vsftpd lftp

        esac
}

####配置临时ftp服务器
install_provisional_server(){
        SOURCE=/etc/vsftpd/vsftpd.conf
        sed -i ‘s/#anon_mkdir_write_enable=YES/anon_mkdir_write_enable=YES/‘ $SOURCE
        sed -i ‘s/#anon_upload_enable=YES/anon_upload_enable=YES/‘ $SOURCE
        chown ftp.ftp /var/ftp/pub
        /bin/ls /var/ftp/xuegoddate
        if [ $? -ne 0 ];then
                mkdir /var/ftp/xuegoddate
        else
                echo "已经存在"
        fi
        chown ftp.ftp /var/ftp/xuegoddate
        service vsftpd restart
}

##配置系统账号FTP服务器
install_enterprise_server(){
#添加两个账户
        for i in ` cat /etc/passwd|awk -F: ‘{print $1}‘`
        do
                if [ $i != "team1" ];then
                        useradd -s /sbin/nologin team1
                        echo "123456"|passwd --stdin team1
                fi
                if [ $i != "team2" ];then
                        useradd -s /sbin/nologin team2
                        echo "123456"|passwd --stdin team2
                fi
        done &>/dev/null
#配置vsftpd.conf配置文件
        SOURCE=/etc/vsftpd/vsftpd.conf
        sed -i ‘s/anonymous_enable=YES/anonymous_enable=NO/‘ $SOURCE
        sed -i ‘s/#chroot_list_enable=YES/chroot_list_enable=YES/‘ $SOURCE
        sed -i ‘s@#chroot_list_file=/etc/vsftpd/chroot_list@chroot_list_file=/etc/vsftpd/chroot_list@‘ $SOURCE
        echo "local_root=/var/www/html">>$SOURCE
#配置chroot_list文件
        echo -e "team1\nteam2">/etc/vsftpd/chroot_list
#       echo "team2">>/etc/vsftpd/chroot_list
#查看/var/www/html是否存在
        ls /var/www/html
        if [ $? -ne 0 ];then
                mkdir -p /var/www/html
        else
                echo "已经存在!!"
        fi
        chmod -R o+w /var/www/html
        service vsftpd restart
}

##创建虚拟账号ftp服务器
install_Virtualaccount_server(){

#创建用户数据库
        echo -e "commuser\n123456\nvipuser\n123456">/etc/vsftpd/vsftpd_virtualuser.txt
        which db_load
        if [ $? -ne 0 ];then
                yum install -y db
        fi
        chmod 600 /etc/vsftpd/vsftpd_virtualuser.db

#配置PAM
        cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.`date +%F`.bak
        >/etc/pam.d/vsftpd
        echo "auth      required        /lib64/security/pam_userdb.so  db=/etc/vsftpd/vsftpd_virtualuser">>/etc/pam.d/vsftpd
        echo "account   required        /lib64/security/pam_userdb.so  db=/etc/vsftpd/vsftpd_virtualuser">>/etc/pam.d/vsftpd
#创建虚拟账号对应的系统账号
        for i in ` cat /etc/passwd|awk -F: ‘{print $1}‘`
        do
                if [ $i != "ftpuser" ];then
                        useradd -d /var/ftp/share ftpuser
                        chmod -R 500 /var/ftp/share
                fi
                if [ $i != "ftpvip" ];then
                        useradd -d /var/ftp/vip ftpvip
                        chmod -R 700 /var/ftp/vip
                fi
        done &>/dev/null

#配置主文件
        SOURCE=/etc/vsftpd/vsftpd.conf
        sed -i ‘s/anonymous_enable=YES/anonymous_enable=NO/‘ $SOURCE
        sed -i ‘s/local_enable=YES/local_enable=YES/‘ $SOURCE
        echo "user_config_dir=/etc/vsftpd/vuserconfig">>$SOURCE
        echo "max_clients=300">>$SOURCE
        echo "max_per_ip=10">>$SOURCE

#建立虚拟账号配置文件
        mkdir /etc/vsftpd/vuserconfig
        touch /etc/vsftpd/vuserconfig/commuser
        touch /etc/vsftpd/vuserconfig/vipuser
        echo -e "guest_enable=yes\nguest_username=ftpuser\nanon_world_readable_only=no\nanon_max_rate=50000">/etc/vsftpd/vuserconfig/commuser
        echo -e "guest_enable=yes\nguest_username=ftpvip\nanon_world_readable_only=no\nwrite_enable=yes\nanon_mkdir_write_enable=yes\nanon_upload_enable=yes\nanon_max_rate
=100000">/etc/vsftpd/vuserconfig/vipuser
        service vsftpd restart


}


本文出自 “Linux_小红帽” 博客,请务必保留此出处http://baidjay.blog.51cto.com/12582052/1964339

linux系统脚本配置ftp服务器

标签:linux ftp

原文地址:http://baidjay.blog.51cto.com/12582052/1964339

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!