Chinaunix首页 | 论坛 | 博客
  • 博客访问: 66228
  • 博文数量: 21
  • 博客积分: 100
  • 博客等级: 民兵
  • 技术积分: 273
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-30 09:56
文章分类

全部博文(21)

文章存档

2013年(18)

2012年(3)

我的朋友

分类: LINUX

2013-08-08 20:22:11


点击(此处)折叠或打开

  1. #!/bin/bash
  2. ###############################
  3. # The:    JiangFeng.Cai
  4. # Form: Baustem
  5. # Date: 2011.7.1
  6. # add nodel 2013.6.3
  7. #
  8. ################################


  9. readme ()
  10. {
  11. if [ -f $0 ];then
  12. echo "################################"
  13. echo "# This script to create a linux "
  14. echo "#     virtual users ."
  15. echo "# Format: $0 {UserNanme} {passwd} {up&down&nodel}"
  16. echo "# "
  17. echo "################################"
  18. fi
  19. }
  20. chk ()
  21. {
  22. [ -f $ftpdir/ok ] || touch $ftpdir/ok
  23. cat $ftpdir/ok |grep -q '#vsftpok'
  24. if [ $? -ne 0 ];then
  25. rpm -qa |grep -q vsftp
  26. if [ ! $? -eq 0 ];then
  27. echo "vsftp RPM not install.";
  28. exit 1;
  29. else
  30. echo '#vsftpok' >> $ftpdir/ok
  31. fi
  32. fi
  33. cat $ftpdir/ok |grep -q '#db4-utilsok'
  34. if [ $? -ne 0 ];then
  35. rpm -qa|grep -q 'db4-utils'
  36. if [ ! $? -eq 0 ];then
  37. echo "db4 RPM not install."
  38. exit 2
  39. else
  40. echo '#db4-utilsok' >> $ftpdir/ok
  41. fi
  42. fi
  43. [ -d ${vftpdir} ] || mkdir -p ${vftpdir}
  44. [ -f ${login} ] || touch ${login}
  45. [ -d /ftp ] || mkdir /ftp
  46. chmod 700 ${login}
  47. cat /etc/passwd|awk -F: '{print $1}'|grep -q virtual
  48. if [ ! $? -eq 0 ];then
  49. useradd virtual
  50. echo 123456 | passwd --stdin virtual
  51. fi
  52. }
  53. conf ()
  54. {
  55. [ -f ${ftpconf} ] || touch ${ftpconf}
  56. if [ -f ${ftpconf} ];then
  57. cat ${ftpconf}|grep -q '#vsftpd.conf#'
  58. if [ ! $? -eq 0 ];then
  59. mv ${ftpconf} ${ftpdir}/vsftpd.conf.`date +%Y-%m-%d%M%S`.bak;
  60. touch ${ftpconf};
  61. echo "#vsftpd.conf#" >> ${ftpconf}
  62. echo "anonymous_enable=NO" >> ${ftpconf}
  63. echo "local_enable=YES" >> ${ftpconf}
  64. echo "write_enable=YES" >> ${ftpconf}
  65. echo "local_umask=022" >> ${ftpconf}
  66. echo "dirmessage_enable=YES" >> ${ftpconf}
  67. echo "xferlog_enable=YES" >> ${ftpconf}
  68. echo "connect_from_port_20=YES" >> ${ftpconf}
  69. echo "xferlog_std_format=YES" >> ${ftpconf}
  70. echo "xferlog_file=/var/log/vsftpd.log" >> ${ftpconf}
  71. echo "" >> ${ftpconf}
  72. echo "pam_service_name=vsftpd.vu" >> ${ftpconf}
  73. echo "userlist_enable=YES" >> ${ftpconf}
  74. echo "listen=YES" >> ${ftpconf}
  75. echo "tcp_wrappers=YES" >> ${ftpconf}
  76. echo "guest_enable=YES" >> ${ftpconf}
  77. echo "guest_username=virtual" >> ${ftpconf}
  78. echo "user_config_dir=/etc/vsftpd/vsftpd_user_conf" >> ${ftpconf}
  79. fi
  80. fi


  81. [ -f ${pamftp} ] || touch ${pamftp}


  82. if [ $? -eq 0 ];then
  83. cat ${pamftp}|grep -q '#pamftp#'
  84. if [ ! $? -eq 0 ];then
  85. echo "auth required pam_userdb.so db=/etc/vsftpd/login" >> ${pamftp}
  86. echo "account required pam_userdb.so db=/etc/vsftpd/login" >> ${pamftp}
  87. echo "#pamftp#" >> ${pamftp}
  88. fi
  89. fi
  90. }
  91. Vaddftp ()
  92. {
  93. ls ${vftpdir}|grep -q "^${user}$"
  94. if [ $? -eq 0 ];then
  95. echo "username exies."
  96. exit 3
  97. else
  98. echo "${user}" >> ${login}
  99. echo "${pass}" >> ${login}
  100. fi
  101. }
  102. up ()
  103. {
  104. touch ${vftpdir}/${user}
  105. echo "local_root=${vuserftpdir}/${user}" >> ${vftpdir}/${user}
  106. echo "anon_world_readable_only=NO" >> ${vftpdir}/${user}
  107. echo "write_enable=YES" >> ${vftpdir}/${user}
  108. echo "anon_mkdir_write_enable=YES" >> ${vftpdir}/${user}
  109. echo "anon_upload_enable=YES" >> ${vftpdir}/${user}
  110. echo "anon_other_write_enable=YES" >> ${vftpdir}/${user}


  111. mkdir -p ${vuserftpdir}/${user}
  112. chmod 777 -R ${vuserftpdir}
  113. db_load -T -t hash -f ${login} /etc/vsftpd/login.db
  114. }
  115. down ()
  116. {
  117. touch ${vftpdir}/${user}
  118. echo "local_root=${vuserftpdir}/${user}" >> ${vftpdir}/${user}
  119. echo "anon_world_readable_only=NO" >> ${vftpdir}/${user}


  120. mkdir -p ${vuserftpdir}/${user}
  121. chmod 755 -R ${vuserftpdir}
  122. db_load -T -t hash -f ${login} /etc/vsftpd/login.db
  123. }


  124. no_del ()
  125. {
  126. echo "local_root=${vuserftpdir}/${user}" >> ${vftpdir}/${user}
  127. echo "anon_world_readable_only=NO" >> ${vftpdir}/${user}
  128. echo "write_enable=YES" >> ${vftpdir}/${user}
  129. echo "anon_mkdir_write_enable=YES" >> ${vftpdir}/${user}
  130. echo "anon_upload_enable=YES" >> ${vftpdir}/${user}
  131. echo "anon_other_write_enable=YES" >> ${vftpdir}/${user}
  132. echo "cmds_allowed=ABOR,CWD,LIST,MDTM,MKD,NLST,PASS,PASV,PORT,PWD,QUIT,RETR,RNFR,RNTO,SIZE,STOR,TYPE,USER,REST,CDUP,HELP,MODE,NOOP,REIN,STAT,STOU,STRU,SYST,FEAT" >> ${vftpdir}/${user}
  133. mkdir -p ${vuserftpdir}/${user}
  134. chmod 777 -R ${vuserftpdir}
  135. db_load -T -t hash -f ${login} /etc/vsftpd/login.db
  136. }
  137. #ok let's begin. {


  138. user=$1
  139. pass=$2
  140. updown=$3
  141. ftpdir=/etc/vsftpd
  142. login=${ftpdir}/login.txt
  143. ftpconf=/etc/vsftpd/vsftpd.conf
  144. vftpdir=/etc/vsftpd/vsftpd_user_conf
  145. pamftp=/etc/pam.d/vsftpd.vu
  146. vuserftpdir=/ftp
  147. case $1 in
  148. h | H | -h | -H | help)    readme;
  149. exit 0;
  150. ;;
  151. esac
  152. if [ $# -ne 3 ];then
  153. readme;
  154. exit 0;
  155. fi
  156. echo '1.chk '
  157. chk
  158. echo '2.conf'
  159. conf
  160. echo '3.addftp'
  161. Vaddftp
  162. echo '4.user'
  163. case ${updown} in
  164. up)    up;
  165. ;;
  166. down)    down;
  167. ;;
  168. nodel) no_del;
  169. ;;
  170. *)    no_del;
  171. ;;
  172. esac


  173. if [ $? -eq 0 ];then
  174. echo "#################################"
  175. echo "#    $user add done"
  176. echo "#    Name:    $user"
  177. echo "#    passwd:    $pass"
  178. echo "#    FtpDir: /ftp/$user"
  179. echo "#    userconfig: $vftpdir/$user"
  180. echo "#################################"
  181. fi
  182. service vsftpd restart
  183. #End }

阅读(598) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~