sh 自动化安装配置FTP服务器
1 #!/bin/bash 2 # 3 4 FPATH=/etc/vsftpd/ 5 FILE=/etc/vsftpd/vsftpd.conf 6 USERB=ftp01 7 8 CON() { 9 sed -i "s#anonymous_enable=YES#anonymous_enable=NO#g" $FILE #修改配置文件 10 cat >> $FILE << EOF 11 12 chroot_local_user=YES 13 chroot_list_enable=YES 14 chroot_list_file=/etc/vsftpd/chroot_list 15 16 userlist_enable=YES 17 userlist_deny=NO 18 userlist_file=/etc/vsftpd/vsftpd.user_list 19 chroot_local_user=NO 20 local_root=/ 21 EOF 22 } 23 24 25 USADD() { 26 useradd -s /sbin/nologin $USERB #添加ftp用户 27 echo "username: $USERB" 28 29 echo "123456" | passwd --stdin $USERB &> /dev/null 30 echo "password: 123456 " 31 32 echo "$USERB" >> /etc/vsftpd/chroot_list 33 echo "$USERB" >> /etc/vsftpd/vsftpd.user_list 34 } 35 36 SETU() { 37 yum install vsftpd -y #yum 安装 38 sleep 3 39 if [ ! -d $FPATH ];then 40 echo "Error installation" 41 exit 7 42 else 43 CON 44 USADD 45 fi 46 } 47 48 49 CHOI() { 50 read -p "You suro setup ftp?y|n: " CHOICE #用户确认是否安装 51 case $CHOICE in 52 y|yes) 53 echo "setup..." ;; 54 n|no) 55 echo "exit!!.." 56 exit 1 ;; 57 *) 58 echo "NO command" 59 exit 8 ;; 60 esac 61 } 62 63 if rpm -qa | grep 'vsftp' &> /dev/null;then 64 echo " vsftp Already exist!!" 65 exit 1 66 else 67 echo " setup ftp!... " 68 CHOI 69 SETU 70 sleep 5 71 fi 72 73 /sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT #防火墙配置 74 /etc/rc.d/init.d/iptables save 75 service iptables restart 76 sleep 1 77 service vsftpd start