作者:妹纸叫BLACK | 来源:互联网 | 2014-05-28 09:06
建立了vsftpd之后添加用户总是要做很多操作,写了一个shell,自己用,也就没有处理得很详细。共享给网友们,希望对大家有用。#!/bin/bash##Date:2008.8.20#author:lastbus#function:addvirtualvsftpduser
建立了vsftpd之后添加用户总是要做很多操作,写了一个shell,自己用,也就没有处理得很详细。共享给网友们,希望对大家有用。
#!/bin/bash
#==========================================
#Date:2008.8.20
#author:lastbus
#function:add virtual vsftpd user
#==========================================
U=vftpuser #vsftpd的对应的用户名
G=vftpuser #vsftpd的对应的用户名所属的组
v_usershadow_loc="/etc/vsftpd/user.txt" #存放用户名和密码的文件
v_userdb_loc="/etc/vsftpd/vuser.db" #pam认证DB
v_user_conf_loc="/etc/vsftpd/vsftpd_user_conf/" #用户配置文件存放目录
v_dir="/other/vftpuser/" #ftp根目录,所有用户将以自己的用户名作为主目录,直接存放于此目录之下
privileges="anon_world_readable_only=no
anon_mkdir_write_enable=YES write_enable=YES anon_upload_enable=YES
anon_other_write_enable=YES" #基础的权限集合
usernameok=0 #用户名验证结果
passwordok=0 #密码与确认密码是否相等
read -p "Please enter username:" username
Checkusername ( )
{
for user in `ls ${v_user_conf_loc}` ;do
if [ "${username}" = "${user}" ] ;then
usernameok=0
echo "User name exsit"
exit
fi
done
usernameok=1
}
Checkusername
read -p "Please enter password:" password
read -p "Please confirm the password:" confirm_passpord
Checkpassword ( )
{
if [ "${password}" = "${confirm_passpord}" ] ;then
passwordok=1
else
echo "confirm password error"
fi
}
Setprivilege ( )
{
userdir="${v_dir}${username}"
usercOnf="${v_user_conf_loc}${username}"
mkdir ${userdir}
chown -R "${U}"."${G}" ${userdir}
touch ${userconf}
chmod 644 ${userconf}
echo
"local_root=/other/vftpuser/${username}">>${userconf}
for privilege in $privileges ;do
echo ${privilege}
read -n1 -p "Add this privilege?[Y/N]"
confirm
if [ "$confirm" = "y" ] ;then
echo $privilege>>${userconf}
elif [ "$confirm" = "n" ] ;then
echo "your choice is N";
else
echo "Error"
fi
done
}
Addusertodb ( )
{
echo $username>>${v_usershadow_loc}
echo $password>>${v_usershadow_loc}
db_load -T -t hash -f ${v_usershadow_loc} ${v_userdb_loc}
chmod 644 ${v_userdb_loc}
}
Checkpassword
if [ "${passwordok}" = "1" ] && [ "${usernameok}" = "1" ]
;then
Setprivilege
Addusertodb
else
echo "Please Try again"
fi