-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.sh
executable file
·47 lines (42 loc) · 1.29 KB
/
create.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
#!/bin/bash
# In The Name of God
# ========================================
# [] File Name : create.sh
#
# [] Creation Date : 03-05-2019
#
# [] Created By : Parham Alvani <[email protected]>
# =======================================
while read -r -a up
do
echo "'${up[0]}'"
echo "'${up[1]}'"
if [ $(id -u) -eq 0 ]; then
username="${up[0]}"
password="${up[1]}"
# checking if username already exists
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
continue
else
# adding user and setting it's password
useradd -m $username -s /bin/bash
echo $username:$password | chpasswd
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
# setting up ftp settings and folders
mkdir /home/$username/ftp
chown nobody:nogroup /home/$username/ftp
chmod a-w /home/$username/ftp
mkdir /home/$username/ftp/files
touch /home/$username/ftp/files/README.txt
chown -R $username:$username /home/$username/ftp/files
# adding username to vsftpd userlist
echo $username >> /etc/vsftpd.userlist
echo "if you see this file it means your ftp user is active!"
else
echo "Only root may add a user to the system"
exit 2
fi
done