Skip to content

Instantly share code, notes, and snippets.

@amineHY
Created December 22, 2023 09:00
Show Gist options
  • Save amineHY/c6ba8643ed7801b5237ebc7bf85e1770 to your computer and use it in GitHub Desktop.
Save amineHY/c6ba8643ed7801b5237ebc7bf85e1770 to your computer and use it in GitHub Desktop.
This script generates and outputs a 15-character password that includes symbols and is secure
#!/bin/bash
# This script generates and outputs a 15-character password that includes symbols and is secure
# It uses the pwgen utility, which needs to be installed first (e.g., with brew install pwgen)
# To run this script, save it as password.sh and make it executable with chmod +x password.sh
# Then execute it with ./password.sh
# Check if pwgen is installed
if ! command -v pwgen &>/dev/null; then
# If not, install it with brew install pwgen
echo "pwgen is not installed. Installing it now..."
brew install pwgen
fi
# Generate the password and store it in a variable
password=$(pwgen -ys 15 1)
# Output the password
echo "Your password is: $password"
# Copy the password to the clipboard
echo "$password" | pbcopy
# Confirm that the password is copied
echo "The password is copied to your clipboard."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment