forked from lasyman/lasyman_setup_proftp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproftpd_vhost.sh
115 lines (95 loc) · 2.48 KB
/
proftpd_vhost.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
#!/bin/bash
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, use sudo sh $0"
exit 1
fi
clear
echo "========================================================================="
echo "Add ProFTPd Virtual Host "
echo "========================================================================="
echo ""
echo "begin to create ftp user..."
echo ""
echo "========================================================================="
username=""
read -p "Please input a username:" username
if [ "$username" = "" ]; then
echo "UserName can't be NULL!"
sleep 2
exit 1
fi
if cat /etc/passwd | awk -F : '{print $1}' | grep $username >/dev/null 2>&1
then
echo "User: $username is exist!"
echo "Please rerun this script,input a new username!"
sleep 5
exit 1
else
echo "User $username will add to your system."
fi
userpass=""
echo "Please set password for $username:"
read userpass
if [ "$userpass" == "" ]; then
echo "Password can't be NULL!"
sleep 2
exit 1
else
echo "Password: $userpass"
fi
userdir=""
echo "Please set the directory of $username"
read -p "Please input full path:" userdir
if [ "$userdir" == "" ]; then
echo "Directory can't be NULL!"
sleep 2
exit 1
else
echo "Directory: $userdir"
fi
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to start create ProFTPd virtul host..."
char=`get_char`
if [ ! -d /usr/local/proftpd/etc/vhost ]; then
mkdir /usr/local/proftpd/etc/vhost
fi
if [ ! -d $userdir ]; then
echo "Create Virtul Host directory......"
mkdir $userdir
fi
groupadd -g 31 ftpgroup
useradd -s /sbin/nologin -d $userdir -c "proftpd user" -g ftpgroup $username
cat >/tmp/$user.passwd<<eof
$username:$userpass
eof
chpasswd < /tmp/$user.passwd
cat >/usr/local/proftpd/etc/vhost/$username.conf<<eof
<Directory $userdir>
<Limit ALL>
AllowUser $username
</Limit>
</Directory>
eof
echo "Restart ProFTPd......"
/etc/init.d/proftpd stop
/etc/init.d/proftpd start
echo "========================================================================="
echo "Add ProFTPd Virtual Host "
echo "========================================================================="
echo ""
echo "Your UserName:$username"
echo "Your Password:$userpass"
echo "Directory of $username:$userdir"
echo ""
echo "========================================================================="