安裝vsftpd用戶 for循環

#!/bin/bashbash

#2017年8月18日21:32:13ide

#auto create vsftpd for virtual userspa

#by author www.jfedu.net.net

########################rest

CONF_DIR="/etc/vsftpd"ci

VIR_USER="$*"hash

SYS_USER="ftpuser"it

LOGIN_DB="vsftpd_login"class


if [ $# -eq 0 ];thenftp

echo -e "\033[32m---------------------\033[0m"

echo -e "\033[32mUsage:{/bin/sh $0 jfedu001 jfedu002|jfedu003}\033[0m"

exit 0

fi


if [ ! -f $CONF_DIR/vsftpd.conf ];then

yum install vsftpd* db4* -y

else

continue

fi


for i in `echo $VIR_USER`

do

grep "$i" $CONF_DIR/${SYS_USER}s.txt

if [ $? -ne 0 ];then

cat>>$CONF_DIR/${SYS_USER}s.txt<<EOF

$i

pwd_$i

EOF

fi

done


db_load -T -t hash -f $CONF_DIR/${SYS_USER}s.txt $CONF_DIR/$LOGIN_DB.db

chmod 700 $CONF_DIR/${SYS_USER}s.txt

chmod 700 $CONF_DIR/$LOGIN_DB.db


cat>/etc/pam.d/vsftpd<<EOF

auth    sufficient      /lib64/security/pam_userdb.so      db=$CONF_DIR/$LOGIN_DB

account sufficient      /lib64/security/pam_userdb.so      db=$CONF_DIR/$LOGIN_DB

EOF

useradd -s /sbin/nologin $SYS_USER


grep "guest_"  $CONF_DIR/vsftpd.conf

if [ $? -ne 0 ];then

cat>>$CONF_DIR/vsftpd.conf<<EOF

guest_enable=YES

guest_username=$SYS_USER

pam_service_name=vsftpd

user_config_dir=$CONF_DIR/vsftpd_user_conf

virtual_use_local_privs=YES

EOF

fi


for j in `echo $VIR_USER`

do

mkdir -p $CONF_DIR/vsftpd_user_conf/

cat>$CONF_DIR/vsftpd_user_conf/$j <<EOF

local_root=/home/$SYS_USER/$j

write_enable=YES

anon_world_readable_only=YES

anon_upload_enable=YES

anon_mkdir_write_enable=YES

EOF

mkdir -p /home/$SYS_USER/$j/

done


chown -R $SYS_USER.$SYS_USER /home/$SYS_USER

service vsftpd restart

相關文章
相關標籤/搜索