|
1 | 1 | #!/bin/bash |
2 | 2 | # |
3 | | -# This script locks and removes the root account's password (if one is set). This |
4 | | -# prevents users from successfully logging into the root account via su. Note that it |
5 | | -# doesn't prevent users from becoming root via methods such as sudo su. |
| 3 | +# Name: root-locker.bash |
6 | 4 | # |
7 | | -# Version: v1.0.6 |
| 5 | +# Description: |
| 6 | +# This script locks the root account, preventing users from direct logins as root. |
| 7 | +# |
| 8 | +# Note: |
| 9 | +# Locking the root account doesn't prevent users from using something like `sudo su` |
| 10 | +# to gain root access. |
| 11 | +# |
| 12 | +# Version: v1.0.7 |
8 | 13 | # License: MIT License |
9 | 14 | # Copyright (c) 2020-2024 Hunter T. (StrangeRanger) |
10 | 15 | # |
11 | 16 | ######################################################################################## |
12 | | -####[ Script Wide Variables ]########################################################### |
13 | | - |
14 | | - |
15 | | -green="$(printf '\033[0;32m')" |
16 | | -red="$(printf '\033[1;31m')" |
17 | | -nc="$(printf '\033[0m')" |
18 | 17 |
|
19 | | - |
20 | | -####[ Prepping ]######################################################################## |
| 18 | +C_GREEN="$(printf '\033[0;32m')" |
| 19 | +C_RED="$(printf '\033[1;31m')" |
| 20 | +C_NC="$(printf '\033[0m')" |
21 | 21 |
|
22 | 22 |
|
23 | 23 | ## Check if this script was executed with root privilege. |
24 | 24 | if [[ $EUID != 0 ]]; then |
25 | | - echo "${red}Please run this script as or with root privilege${nc}" >&2 |
| 25 | + echo "${C_RED}Please run this script as or with root privilege${C_NC}" >&2 |
26 | 26 | echo -e "\nExiting..." |
27 | 27 | exit 1 |
28 | 28 | fi |
29 | 29 |
|
30 | 30 |
|
31 | | -####[ Main ]############################################################################ |
32 | | - |
33 | | - |
34 | 31 | read -rp "We will now disable the root account. Press [Enter] to continue." |
35 | 32 |
|
36 | 33 | echo "Disabling root account..." |
37 | | -passwd -dl root || { |
38 | | - echo -e "\n${red}Failed to lock the root account${nc}" |
| 34 | +usermod -L root || { |
| 35 | + echo -e "\n${C_RED}Failed to lock the root account${C_NC}" >&2 |
39 | 36 | echo -e "\nExiting..." |
40 | 37 | exit 1 |
41 | 38 | } |
42 | 39 |
|
43 | | -echo -e "\n${green}The root account has been locked${nc}" |
| 40 | +echo -e "\n${C_GREEN}The root account has been locked${C_NC}" |
0 commit comments