ftp:linux下利用shell脚本添加虚拟用户并赋予权限

首先ftp配置应为虚拟用户登录模式

用户密码文本目录为/etc/vsftpd/vftpuser,代码如下:

#!/bin/bash
#
if [ $# -eq 3 ];then
    username=$1
    password=$2
    homepath=$3
    for U in `sed -n '1~2p' /etc/vsftpd/virtual_list`;do
        if [ $username == $U ];then
            echo "user '$username' already exists"
            exit 1
        fi
    done
    if [ ! -d "$homepath" ];then
        mkdir -p $homepath
    fi
    echo -e "$username
$password" >> /etc/vsftpd/virtual_list
    db_load -T -t hash -f /etc/vsftpd/virtual_list /etc/vsftpd/virtual_list.db
    touch /etc/vsftpd/virtual_conf/$username
cat >>/etc/vsftpd/virtual_conf/$username <<EOF
local_root=$homepath
anon_world_readable_only=YES
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO
EOF
else
    echo "Please input username、password and homepath"
fi

运行此脚本

  #sh useradd.sh hello world /app/vsftpd/one

  就会完成添加ftp虚拟用户,用户名为hello,密码为world,家目录为/app/vsftpd/one。

原文地址:https://www.cnblogs.com/houyongchong/p/7885558.html