[ Lab 1.1 ] Password Change Script - smitja21/group-a-oe2 GitHub Wiki

The following script changes the password on linux machines, using hash password generated by the openssl tool.

[!NOTE] Password was hashed with the following command: openssl passwd -1

  1. Use nano to create the script:

nano passwordchange.sh

  1. Paste the following script:
#!/bin/bash

if [ $EUID -ne 0 ](/smitja21/group-a-oe2/wiki/-$EUID--ne-0-); then
  echo "This script must be run as root (use sudo)"
  exit 1
fi


USERNAME="group-a"
PASSWORD_HASH='$1$QNpb50qh$G6Wk1TdtG41OKTzBy36xj0'

echo "$USERNAME:$PASSWORD_HASH" | chpasswd -e
  1. Change the permissions to allow execution of the script:

chmod u+x passwordchange.sh

  1. Run the script as sudo:

sudo ./passwordchange.sh

  1. Enter old password to confirm changes.

Generative AI Usage Disclaimer

ChatGPT was used as a tool to help create this script. The prompt is as follows:

"I'm looking at creating a script for a linux machine which resets the password for the user group a allow me to set the password as a hash and have the username set in the script"