释放双眼,带上耳机,听听看~!
centos6一键安装vsftpd脚本
手动安装vsftpd参考教程:Centos下安装Vsftpd的图文教程
vsftpd脚本功能:
1
2
3
4
5
6 11.安装 (命令执行:sh xxx.sh)
2
32.添加ftp用户 (命令执行:sh xxx.sh add)
4
53.卸载vsftpd (命令执行:sh xxx.sh uninstall)
6
测试环境:centos6 x64 centos6 x86(测试centos7以上无法安装)
vsftpd shell脚本代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 1#!/bin/bash
2Stack=$1
3if [ "${Stack}" = "" ]; then
4 Stack="install"
5else
6 Stack=$1
7fi
8install_vsftp()
9{
10 echo "#######################"
11 echo -e "\033[33mUsage: $0 {install|add|uninstall}\033[0m"
12 echo -e "\033[33msh $0 (default:install)\033[0m"
13 echo -e "\033[33msh $0 add (Add FTP user)\033[0m"
14 echo -e "\033[33msh $0 uninstall (Uninstall FTP)\033[0m"
15 echo "#######################"
16 A=`head -c 500 /dev/urandom | tr -dc a-zA-Z | tr [a-z] [A-Z]|head -c 1`
17 B=`head -c 500 /dev/urandom | tr -dc a-z0-9A-Z | head -c 6`
18 C=`echo $RANDOM|cut -c 2`
19 rpm -q vsftpd
20 if [ "$?" -eq "0" ]; then
21 echo "You have to install VSFTPD!"
22 else
23 netstat -ntulp |grep -w 21
24 if [ "$?" -eq "0" ]; then
25 echo "Other FTP is already installed"
26 else
27 read -p "The FTP access directory(default:/home): " directory
28 if [ "${directory}" != "" ]; then
29 directorys="${directory}"
30 else
31 directorys="/home"
32 fi
33 read -p "Please enter the FTP user: " ftp_user
34 read -p "Enter the FTP password(default:$A$B$C): " ftp_pass
35 if [ "${ftp_pass}" != "" ]; then
36 ftp_passa="${ftp_pass}"
37 else
38 ftp_passa="$A$B$C"
39 fi
40 yum -y install vsftpd
41 if [ "$?" -eq "0" ]; then
42 if [ -d ${directorys} ]; then
43 chmod -R 777 ${directorys}
44 fi
45 useradd -d ${directorys} -g ftp -s /sbin/nologin ${ftp_user}
46 echo "${ftp_passa}" | passwd --stdin ${ftp_user} > /dev/null
47 sed -i 's/^anonymous_enable=YES/anonymous_enable=NO/g' /etc/vsftpd/vsftpd.conf
48 sed -i 's/^#chroot_local_user=YES/chroot_local_user=YES/g' /etc/vsftpd/vsftpd.conf
49 sed -i 's/^#chroot_list_enable=YES/chroot_list_enable=YES/g' /etc/vsftpd/vsftpd.conf
50 echo "userdel ${ftp_user}" >> /etc/vsftpd/user_list.sh
51 echo "" > /etc/vsftpd/chroot_list
52 chkconfig vsftpd on
53 service vsftpd restart
54 echo "###################################"
55 echo "FTP user:${ftp_user}"
56 echo "Ftp password:${ftp_passa}"
57 echo "The FTP directory:${directorys}"
58 echo "-----------------------------------"
59 else
60 echo "VSFTPD installation failed!"
61 fi
62 fi
63 fi
64}
65add_ftp()
66{
67 A=`head -c 500 /dev/urandom | tr -dc a-zA-Z | tr [a-z] [A-Z]|head -c 1`
68 B=`head -c 500 /dev/urandom | tr -dc a-z0-9A-Z | head -c 6`
69 C=`echo $RANDOM|cut -c 2`
70 read -p "The FTP access directory(Such as:/home): " directory
71 if [ "${directory}" != "" ]; then
72 directorys="${directory}"
73 else
74 directorys="/home"
75 fi
76 read -p "Please enter the FTP user: " ftp_user
77 read -p "Enter the FTP password(default:$A$B$C): " ftp_pass
78 if [ -d ${directorys} ]; then
79 chmod -R 777 ${directorys}
80 fi
81 useradd -d ${directorys} -g ftp -s /sbin/nologin ${ftp_user}
82 if [ "${ftp_pass}" != "" ]; then
83 ftp_passa="${ftp_pass}"
84 else
85 ftp_passa="$A$B$C"
86 fi
87 echo "${ftp_passa}" | passwd --stdin ${ftp_user} > /dev/null
88 echo "userdel ${ftp_user}" >> /etc/vsftpd/user_list.sh
89 if [ -d ${directorys} ]; then
90 chmod -R 777 ${directorys}
91 fi
92 echo "###################################"
93 echo "FTP user:${ftp_user}"
94 echo "Ftp password:${ftp_passa}"
95 echo "The FTP directory:${directorys}"
96 echo "-----------------------------------"
97
98}
99uninstall_ftp()
100{
101yum -y remove vsftpd*
102sh /etc/vsftpd/user_list.sh
103echo "" > /etc/vsftpd/user_list.sh
104}
105case "${Stack}" in
106 install)
107 install_vsftp
108 ;;
109 add)
110 add_ftp
111 ;;
112 uninstall)
113 uninstall_ftp
114 ;;
115 *)
116 echo "Usage: $0 {install|add|uninstall}"
117 ;;
118esac
119
centos6一键安装vsftpd脚本下载:
1
2 1wget http://www.tieww.com/soft/vsftp_root.sh && sh vsftp_root.sh
2