-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNukeUsers.sh
More file actions
40 lines (31 loc) · 1.19 KB
/
Copy pathNukeUsers.sh
File metadata and controls
40 lines (31 loc) · 1.19 KB
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
#!/bin/bash
# Check if script is running as root
if [ "$(id -u)" -ne 0 ]; then
echo "Please run this script as root."
exit 1
fi
# Create a list of directories users are allowed to access
allowed_directories=("/home" "/var" "/tmp")
# Create a list of basic commands users are allowed to execute
allowed_commands=("ls" "cd")
# Revoke sudo access for all non-root users
echo "Revoking sudo access for all non-root users..."
for user in $(getent passwd | grep -vE '^root:|:0:' | cut -d: -f1); do
usermod -G sudo -R $user
done
# Limit user permissions
echo "Limiting user permissions..."
for user in $(getent passwd | grep -vE '^root:|:0:' | cut -d: -f1); do
# Restricting user's shell to /bin/rbash
usermod --shell /bin/rbash $user
# Granting access to allowed directories
chown $user:$user ${allowed_directories[@]}
# Creating symbolic links to allowed commands in user's home directory
mkdir -p /home/$user/bin
for cmd in "${allowed_commands[@]}"; do
ln -s $(which $cmd) /home/$user/bin/$cmd
done
# Adding the user's bin directory to the PATH
echo 'export PATH="$HOME/bin:$PATH"' >> /home/$user/.bashrc
done
echo "User permissions limited successfully."