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