Skip to content

Instantly share code, notes, and snippets.

@amineHY
Last active December 21, 2023 18:25
Show Gist options
  • Save amineHY/be4875d87ebb1d56b8b38025116a4b94 to your computer and use it in GitHub Desktop.
Save amineHY/be4875d87ebb1d56b8b38025116a4b94 to your computer and use it in GitHub Desktop.
This script generates and outputs a 16-character password that includes symbols and is secure # It uses the pwgen utility, which needs to be installed first # To run this script, save it as password_generator.sh and make it executable with chmod +x password.sh # Then execute it with ./password_generator.sh
#!/bin/bash
# This script generates and outputs a 15-character password that includes symbols and is secure
# It uses the pwgen and xclip utilities, which need to be installed first
# 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 sudo apt-get install pwgen
echo "pwgen is not installed. Installing it now..."
sudo apt-get install pwgen
fi
# Check if xclip and an X11 display are available
if command -v xclip &>/dev/null && [[ -n "$DISPLAY" ]]; then
# 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" | xclip -selection clipboard
# Confirm that the password is copied
echo "The password is copied to your clipboard."
else
# If xclip or an X11 display is not available, output the password without copying it
password=$(pwgen -ys 15 1)
echo "Your password is: $password"
echo "xclip or an X11 display is not available, so the password could not be copied."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment