Last active
May 17, 2021 17:41
-
-
Save starkers/234909caf153904e5428 to your computer and use it in GitHub Desktop.
generate password and copy it into clipboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# See: https://gist.github.com/starkers/234909caf153904e5428 | |
#Check xpass exists | |
if [ ! -x "$(which xclip)" ]; then | |
echo "Please install xclip" ; exit 1 | |
fi | |
#Length of string: | |
LEN=32 | |
#Generate it | |
PASS="$(head -1000 /dev/urandom | tr -dc A-Za-z0-9 | tail -1 | cut -c 1-$LEN)" | |
#Import it into the clipboard | |
printf "$PASS" | xclip -i -selection clipboard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
generate a random password and have it ready for pasting
TL;DR =
apt-get install xclip -y
The Objective is the quickly and easily generate a new password.
I bind this to a shortcut on my desktop environment to make life easier
Firstly lets consider how we're generating the password.
Good little read linux password generation
I'm using the kernels own generator.. good 'ol:
/dev/urandom
It works fairly well on all the machines I've used it on:
Example urandom usage:
For some reason this just doesn't work reliably.. perhaps bash versions or something related to the initial STDIN "<". I don't care.. I just adapted it to this and so far so good:
alternative to /dev/urandom
if you're sticking to linux:
apt-get install pwgen -y
Important Note!!
its essential that you remove trailing white-space and newlines (aka:
\n
orCR
) before piping into xclip!Bad
pwgen
example:Good
pwgen
example: