Skip to content

Commit 6831e66

Browse files
committed
Refer to CHANGELOG.md
1 parent ed72c81 commit 6831e66

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

hardening/Root Locker/root-locker

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,40 @@
11
#!/bin/bash
22
#
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
64
#
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
813
# License: MIT License
914
# Copyright (c) 2020-2024 Hunter T. (StrangeRanger)
1015
#
1116
########################################################################################
12-
####[ Script Wide Variables ]###########################################################
13-
14-
15-
green="$(printf '\033[0;32m')"
16-
red="$(printf '\033[1;31m')"
17-
nc="$(printf '\033[0m')"
1817

19-
20-
####[ Prepping ]########################################################################
18+
C_GREEN="$(printf '\033[0;32m')"
19+
C_RED="$(printf '\033[1;31m')"
20+
C_NC="$(printf '\033[0m')"
2121

2222

2323
## Check if this script was executed with root privilege.
2424
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
2626
echo -e "\nExiting..."
2727
exit 1
2828
fi
2929

3030

31-
####[ Main ]############################################################################
32-
33-
3431
read -rp "We will now disable the root account. Press [Enter] to continue."
3532

3633
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
3936
echo -e "\nExiting..."
4037
exit 1
4138
}
4239

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

Comments
 (0)