Last active
September 29, 2024 04:59
-
-
Save NotYusta/007c3f579c3d062775367f910fb8b29e to your computer and use it in GitHub Desktop.
Reset SSH Password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NEW_PASSWORD="$1" | |
# Check if a password argument is provided | |
if [ "$#" -ne 1 ]; then | |
echo "bash script.sh <new_password>" | |
exit 1 | |
fi | |
# Check if the script is running as root | |
if [ "$EUID" -ne 0 ]; then | |
echo "Please run as root." | |
exit 1 | |
fi | |
# Reset the root password | |
echo "Resetting root password..." | |
echo "root:$NEW_PASSWORD" | chpasswd | |
# Confirm the change | |
if [ $? -eq 0 ]; then | |
echo "Root password successfully updated." | |
else | |
echo "Failed to update root password." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment