-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvsftp_root.sh
127 lines (121 loc) · 3.49 KB
/
vsftp_root.sh
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
120
121
122
123
124
125
126
127
#!/bin/bash
#使用方法:1、安装 (命令执行:sh xxx.sh)
#使用方法:2、添加ftp用户 (命令执行:sh xxx.sh add)
#使用方法:3、卸载vsftpd (命令执行:sh xxx.sh uninstall)
#本脚本适用于Centos6平台,不适用于Centos7平台
Stack=$1
if [ "${Stack}" = "" ]; then
Stack="install"
else
Stack=$1
fi
install_vsftp()
{
echo "#######################"
echo -e "\033[33mUsage: $0 {install|add|uninstall}\033[0m"
echo -e "\033[33msh $0 (default:install)\033[0m"
echo -e "\033[33msh $0 add (Add FTP user)\033[0m"
echo -e "\033[33msh $0 uninstall (Uninstall FTP)\033[0m"
echo "#######################"
A=`head -c 500 /dev/urandom | tr -dc a-zA-Z | tr [a-z] [A-Z]|head -c 1`
B=`head -c 500 /dev/urandom | tr -dc a-z0-9A-Z | head -c 6`
C=`echo $RANDOM|cut -c 2`
rpm -q vsftpd
if [ "$?" -eq "0" ]; then
echo "You have to install VSFTPD!"
else
netstat -ntulp |grep -w 21
if [ "$?" -eq "0" ]; then
echo "Other FTP is already installed"
else
read -p "The FTP access directory(default:/home): " directory
if [ "${directory}" != "" ]; then
directorys="${directory}"
else
directorys="/home"
fi
read -p "Please enter the FTP user: " ftp_user
read -p "Enter the FTP password(default:$A$B$C): " ftp_pass
if [ "${ftp_pass}" != "" ]; then
ftp_passa="${ftp_pass}"
else
ftp_passa="$A$B$C"
fi
yum -y install vsftpd
if [ "$?" -eq "0" ]; then
if [ -d ${directorys} ]; then
chmod -R 777 ${directorys}
fi
useradd -d ${directorys} -g ftp -s /sbin/nologin ${ftp_user}
echo "${ftp_passa}" | passwd --stdin ${ftp_user} > /dev/null
sed -i 's/^anonymous_enable=YES/anonymous_enable=NO/g' /etc/vsftpd/vsftpd.conf
sed -i 's/^#chroot_local_user=YES/chroot_local_user=YES/g' /etc/vsftpd/vsftpd.conf
sed -i 's/^#chroot_list_enable=YES/chroot_list_enable=YES/g' /etc/vsftpd/vsftpd.conf
echo "userdel ${ftp_user}" >> /etc/vsftpd/user_list.sh
echo "" > /etc/vsftpd/chroot_list
chkconfig vsftpd on
service vsftpd restart
echo "###################################"
echo "FTP user:${ftp_user}"
echo "Ftp password:${ftp_passa}"
echo "The FTP directory:${directorys}"
echo "-----------------------------------"
else
echo "VSFTPD installation failed!"
fi
fi
fi
}
add_ftp()
{
A=`head -c 500 /dev/urandom | tr -dc a-zA-Z | tr [a-z] [A-Z]|head -c 1`
B=`head -c 500 /dev/urandom | tr -dc a-z0-9A-Z | head -c 6`
C=`echo $RANDOM|cut -c 2`
read -p "The FTP access directory(Such as:/home): " directory
if [ "${directory}" != "" ]; then
directorys="${directory}"
else
directorys="/home"
fi
read -p "Please enter the FTP user: " ftp_user
read -p "Enter the FTP password(default:$A$B$C): " ftp_pass
if [ -d ${directorys} ]; then
chmod -R 777 ${directorys}
fi
useradd -d ${directorys} -g ftp -s /sbin/nologin ${ftp_user}
if [ "${ftp_pass}" != "" ]; then
ftp_passa="${ftp_pass}"
else
ftp_passa="$A$B$C"
fi
echo "${ftp_passa}" | passwd --stdin ${ftp_user} > /dev/null
echo "userdel ${ftp_user}" >> /etc/vsftpd/user_list.sh
if [ -d ${directorys} ]; then
chmod -R 777 ${directorys}
fi
echo "###################################"
echo "FTP user:${ftp_user}"
echo "Ftp password:${ftp_passa}"
echo "The FTP directory:${directorys}"
echo "-----------------------------------"
}
uninstall_ftp()
{
yum -y remove vsftpd*
sh /etc/vsftpd/user_list.sh
echo "" > /etc/vsftpd/user_list.sh
}
case "${Stack}" in
install)
install_vsftp
;;
add)
add_ftp
;;
uninstall)
uninstall_ftp
;;
*)
echo "Usage: $0 {install|add|uninstall}"
;;
esac