You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Random Data, Cryptographic Hash Functions, Text and String Manipulation
#!/bin/bash# ============================================================# The main goals of this scripts are:# - Generates a list of random passwords# ============================================================# A random number as a password.
PASSWORD="${RANDOM}"echo"${PASSWORD}"# Three random numbers together.
PASSWORD="${RANDOM}${RANDOM}${RANDOM}"echo"${PASSWORD}"# Use the current date/time as the basis for the password.
PASSWORD=$(date +%s)echo"${PASSWORD}"# Use nanoseconds to act as randomization.
PASSWORD=$(date +%s%N)echo"${PASSWORD}"# A better password.
PASSWORD=$(date +%s%N | sha256sum | head -c32)echo"${PASSWORD}"# A even better password.
PASSWORD=$(date +%s%N${RANDOM}${RANDOM}| sha256sum | head -c48)echo"${PASSWORD}"# Append a special character to the password.
SPECIAL_CHARACTER=$(echo '!@#$%^&*()_-+='| fold -w1 | shuf | head -c1)echo"${PASSWORD}${SPECIAL_CHARACTER}"
We can use the RANDOM variable and date command to generate the password.
To be more secure, combine the shuf and fold command.
$ head -n1 /etc/passwd
$ head -n 1 /etc/passwd
$ head -1 /etc/passwd
$ head -2 /etc/passwd
$ head -n2 /etc/passwd
$ head -n 2 /etc/passwd
$ head -c1 /etc/passwd
$ head -c2 /etc/passwd
Positional Parameters, Arguments, For Loops and Special Parameters
#!/bin/bash# ============================================================# The main goals of this scripts are:# - Generates a random password for each user specified on# the command line.# ============================================================# Display what the user typed on the command lineecho"You executed this command: ${0}"# Display the path and the filename of the scriptecho"You used $(dirname ${0}) as the path to the $(basename ${0}) script."# Tell them how many arguments they passed in.# (Inside the script they are parameters, outside they are arguments.)
NUMBER_OF_PARAMETERS="${#}"echo"You supplied ${NUMBER_OF_PARAMETERS} argument(s) on the command line."# Make sure they at least supply one argument.if [[ "${NUMBER_OF_PARAMETERS}"-lt 1 ]];thenecho"Usage: ${0} USER_NAME [USER_NAME]..."exit 1
fi# Generate and display a password for each parameter.forUSER_NAMEin"${*}";do
PASSWORD=$(date +%s%N | sha256sum | head -c48)echo"${USER_NAME}: ${PASSWORD}"done