Skip to content

Instantly share code, notes, and snippets.

@NotYusta
Last active September 29, 2024 04:59
Show Gist options
  • Save NotYusta/007c3f579c3d062775367f910fb8b29e to your computer and use it in GitHub Desktop.
Save NotYusta/007c3f579c3d062775367f910fb8b29e to your computer and use it in GitHub Desktop.
Reset SSH Password
#!/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