• CentOS一键ftp


    # Version      : 1.0
    # Author       : 果子
    # Date         : 2013-12-14 14:34:12
    # Description  : 只需要三步即可完成安装
    #                chmod a+x install_vsftpd.sh
    #                ./install_vsftpd install_server 安装相关服务
    #                ./install_vsftpd add_user   配置用户信息
    #                ./install_vsftpd start   启动服务
    # Usage        : 在浏览器或计算机地址中输入:ftp://192.168.0.1 即可访问,192.168.0.1为主机地址。
    # More         : 后续将增加一些安全性控制和批量创建用户
    #
    #
    #!/bin/bash
    #set -x #调试用
    allow=YES
    deny=NO
    Sname=vsftpd
    VFconf="/etc/vsftpd/vsftpd.conf"
    VFstart="/etc/init.d/vsftpd"
    VUser="/etc/vsftpd/vuser"
    VUCdirectory="/etc/vsftpd/vuconf"
    VFpam="/etc/pam.d/vsftpdd"
    VFDirectory="/var/www/html"
    DB4=db4
    DB4UTILS="db4-utils"
    DB4DEVEL="db4-devel"
    sys_tem="/lib64"
    http=apache
    #----------主配置文件--------------
    main_config()
    {
        if [ -d $sys_tem ];then
        echo "Your system is 64bit"
        systems=$sys_tem
        else
        echo "Your system is 32bit"
        systems=/lib
        fi
        #     touch $VFpam
        sed -i 's/anonymous_enable=YES/anonymous_enable=NO/g' $VFconf
        sed -i 's/#chown_uploads=YES/chown_uploads=NO/g' $VFconf
        sed -i 's/#xferlog_file/xferlog_file/g' $VFconf
        sed -i 's/#async_abor_enable=YES/async_abor_enable=YES/g' $VFconf
        sed -i 's/#ascii_upload_enable=YES/ascii_upload_enable=YES/g' $VFconf
        sed -i 's/#ascii_download_enable=YES/ascii_download_enable=YES/g' $VFconf
        sed -i 's/#chroot_local_user=YES/chroot_local_user=YES/g' $VFconf
        sed -i 's/pam_service_name=vsftpd/pam_service_name=vsftpdd/g' $VFconf
        {
        echo "guest_enable=$allow"
        echo "guest_username=$http"
        echo "user_config_dir=$VUCdirectory"
        echo "virtual_use_local_privs=$allow"
        } >> $VFconf
        touch $VFpam
        {
        echo "auth sufficient $systems/security/pam_userdb.so db=$VUser"
        echo "account sufficient $systems/security/pam_userdb.so db=$VUser"
        } > $VFpam
    }
    #------------用户配置-----------------------
    user_config ()
    {
        Uname=$1
        userhome="local_root="
        userworld="anon_world_readable_only="
        userupload="anon_upload_enable="
        usermkdir="anon_mkdir_write_enable="
        userothen="anon_mkdir_write_enable="
        userwrite="write_enable="
        echo -e "33[31;40m ===Now configure the config file=== 33[0m"
        if [ -d $VUCdirectory ];then
        echo "The directory $VUCdirectory exsits."
        else
        mkdir $VUCdirectory
        fi
        echo "Your want to configure user is :$Uname"
        read -p "Please input user home directory(default $VFDirectory)" home_dir
        if [ "x$home_dir" != "x" ]
        then
        VFDirectory=$home_dir
        fi
        echo "Your home directory is: $VFDirectory"
        touch "$VUCdirectory/$Uname"  && echo -e "33[31;40mSuccess to configure file=== 33[0m"
        {
        echo "$userhome$VFDirectory"
        echo "$userwrite$allow"
        echo "$userworld$deny"
        echo "$userupload$allow"
        echo "$usermkdir$allow"
        echo "$userothen$allow"
        } > $VUCdirectory/$Uname
        chown -R $http:$http $VFDirectory
        chmod -R 755 $VFDirectory
    }
    #----------------增加用户---------------------
    add_user()
    {
        echo "start add user..."
        while [ 1 ]
        do
        isok=y
        echo -n "Do you want to add user?"
        read -p "[Y/N]:" ok
        if [ "x$ok" = "x" ]
        then
            continue
        elif [ "x$ok" = "xN" ]
        then
            echo "=============Finish add user============="
            break
        fi
        isok=$ok
        if [ "x$isok" != "xY" ]
        then
            echo "Error input! please input Y/N "
            continue
        else
            read -p "Input username: " username
            read -p "Input userpasswd: " userpasswd
            echo "Your username is: $username"
            echo "Your userpasswd is: $userpasswd"
            {
            echo "$username"
            echo "$userpasswd"
            } >> $VUser
            user_config $username
        fi
        done
        db_load -T -t hash -f  $VUser $VUser.db
    }
    #-----------------安装服务---------------------
    install_server()
    {
        rpm -q $Sname
        if [ $? -eq 0 ];then
        echo "vsftpd service has installed. "
        else
        yum install -y $Sname
        fi
        yum -y install "db4*"
    }
    #------------------------------------------------
    case $1 in
        install_server)
        echo "start install $Sname:"
        install_server
        main_config
        ;;
        add_user)
        add_user
        ;;
        restart)
        $VFstart restart
        ;;
        start)
        $VFstart start
        ;;
        stop)
        $VFstart stop
        ;;
        *)
        echo "Usage: $0 install_server|add_user|restart|start|stop"
        exit 1
    esac
    exit 0

    保存为 OneClickFtp.sh

    具体操作看开头的注释

  • 相关阅读:
    vue-cli3搭建可视化项目架构
    select框修改默认样式
    修改checkbox的默认样式
    input和textarea修改placehold的文字颜色
    checkbox更改默认样式,以及选中文字也可以选中checkbox
    自封装 ajax 函数,ajax原理
    git@github.com: Permission denied (publickey)
    EAS webservice安全模式
    DB2 根据id查表
    office web apps server安装
  • 原文地址:https://www.cnblogs.com/mahatmasmile/p/5626316.html
Copyright © 2020-2023  润新知