Generate random root password instead of using admin password

This commit is contained in:
isscbta 2024-09-19 17:32:22 +02:00 committed by GitHub
commit c32bd2c709
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -535,11 +535,11 @@ do
echo "--- New settings ---"
grep '^PermitRoot' /etc/ssh/sshd_config
echo "--------------------"
adminline=$(grep '^admin:' /etc/shadow)
adminline=${adminline:6}
adminline="root:$adminline"
sed -i "s#^root:.*#$adminline#" /etc/shadow
echo "root password is now the same as admin password."
root_password=$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | head -c 32)
hashed_root_password=$(openssl passwd -6 "$root_password")
sed -i "s#^root:.*#root:$hashed_root_password#" /etc/shadow
echo "Root password is now a new random password."
echo "New root password: $root_password"
echo "--------------------"
grep '^root:' /etc/shadow
grep '^admin:' /etc/shadow
@ -549,7 +549,6 @@ do
echo "--------------------"
fi
if [ "$answer" = 'r' ] || [ "$answer" = 'R' ]; then
echo "============================="
echo "== Rebooting the server"