Skip to content

Instantly share code, notes, and snippets.

@caseyamcl
Last active October 8, 2024 10:27
Show Gist options
  • Save caseyamcl/53f0c91e9ef1b42abb57 to your computer and use it in GitHub Desktop.
Save caseyamcl/53f0c91e9ef1b42abb57 to your computer and use it in GitHub Desktop.
Linux CLI Password Generator
#!/bin/bash
#
# Need to generate passwords frequently on the Linux CLI?
#
# This script creates a password and copies it to the clipboard.
#
# 1. Ensure you have 'pwgen' and 'xclip' installed
# (sudo apt-get install pwgen xclip)
# 2. Download this script and make it executable:
# (sudo wget -O /usr/bin/pw https://gist.githubusercontent.com/caseyamcl/53f0c91e9ef1b42abb57/raw/pw && sudo chmod 755 /usr/bin/pw)
#
PW=`pwgen 16 1`
GR='\e[0;32m' # Green
NC='\e[0m' # No Color
echo -n $PW | xclip -i -selection clipboard
echo -e "\nGenerated password '${GR}$PW${NC}' and copied it to the clipboard\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment