-
Notifications
You must be signed in to change notification settings - Fork 259
/
rtremove
executable file
·62 lines (55 loc) · 1.68 KB
/
rtremove
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
#!/bin/bash
######################################################################
#
# Copyright (c) 2015 arakasi72 (https://github.com/arakasi72)
#
# --> Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
#
######################################################################
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin
passfile='/etc/nginx/.htpasswd'
if [ "$(id -u)" != "0" ]; then
echo "Must be run as root, or with sudo"
exit 1
fi
confirm_name=1
while [ $confirm_name = 1 ]
do
read -p "Enter user to delete: " answer
user=$answer
check_name=1
while [ $check_name = 1 ]
do
echo "Warning if you continue you will permanently delete the user and all their data"
read -p "Is $user correct, y to continue, n to exit? " answer
case $answer in [Yy]* ) confirm_name=0 && check_name=0 ;;
[Nn]* ) exit ;;
* ) echo "Enter y or n";;
esac
done
done
if [ "$user" = "$SUDO_USER" ]; then
echo "Cannot delete yourself" && exit
elif [ "$user" = "root" ]; then
echo "Cannot delete root" && exit
elif [ -z "$user" ]; then
echo "User entry is blank" && exit
elif ! id -u $user >/dev/null 2>&1 ; then
echo "$user does not exist" && exit
fi
echo
echo "Deleting $user"
passwd -l $user
killall -KILL -u $user
crontab -u $user -r
if [ -d /var/www/rutorrent/conf/users/$user ]; then
rm -r /var/www/rutorrent/conf/users/$user
fi
htpasswd -D $passfile $user
deluser --remove-home $user
rm -r /var/run/screen/S-$user
ssh_allow=$(grep "$user" /etc/ssh/sshd_config)
if ! [ -z "$ssh_allow" ]; then
sed -i "s/ $user//g" /etc/ssh/sshd_config
service ssh restart
fi