Skip to content

Commit 25d3798

Browse files
author
Hunter T
committed
func: refer to info below
- Modified exit codes - No longer backs up /etc/shadow
1 parent 114cb43 commit 25d3798

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

hardening/root-locker.sh

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22
#
33
# Locks the root account and erases it's current password.
44
#
5-
# Version: v1.0.3
5+
# Version: v1.0.4
66
# License: MIT License
7-
# Copyright (c) 2020-2021 Hunter T.
7+
# Copyright (c) 2020-2022 Hunter T. (StrangeRanger)
88
#
99
########################################################################################
1010
#### [ Variables ]
1111

1212

13-
config_file_bak="/etc/shadow.bak"
14-
config_file="/etc/shadow"
1513
green=$'\033[0;32m'
16-
cyan=$'\033[0;36m'
1714
red=$'\033[1;31m'
1815
nc=$'\033[0m'
1916

@@ -27,7 +24,7 @@ nc=$'\033[0m'
2724
if [[ $EUID != 0 ]]; then
2825
echo "${red}Please run this script as or with root privilege$nc" >&2
2926
echo -e "\nExiting..."
30-
exit 1
27+
exit 2
3128
fi
3229

3330

@@ -38,19 +35,13 @@ fi
3835

3936
read -rp "We will now disable the root account. Press [Enter] to continue."
4037

41-
## Backup 'shadow' if 'shadow.bak' doesn't already exist.
42-
if [[ ! -f $config_file_bak ]]; then
43-
echo "Backing up original 'shadow'..."
44-
cp "$config_file" "$config_file_bak" || {
45-
echo "${red}Failed to back up shadow" >&2
46-
echo "${cyan}Please create a backup of the original 'shadow' before continuing$nc"
47-
exit 1
48-
}
49-
fi
50-
5138
echo "Disabling root account..."
52-
passwd -dl root && echo -e "\n${green}The root account has been locked$nc" \
53-
|| echo -e "\n${red}Failed to lock the root account$nc"
39+
passwd -dl root || {
40+
echo -e "\n${red}Failed to lock the root account$nc"
41+
exit 1
42+
}
43+
44+
echo -e "\n${green}The root account has been locked$nc"
5445

5546

5647
#### End of [ Main ]

0 commit comments

Comments
 (0)