Skip to content

Instantly share code, notes, and snippets.

@AlexHowansky
Created February 8, 2025 19:33
Show Gist options
  • Save AlexHowansky/151e9356628875f5a8c5fe9f18ef8dac to your computer and use it in GitHub Desktop.
Save AlexHowansky/151e9356628875f5a8c5fe9f18ef8dac to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This script will continually generate random SSH key pairs until it encounters
# a public key that ends in a dictionary word. Maybe it helps you keep track of
# keys, maybe it's just goofy.
#
# Examples:
# ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAACUKGU7MtlJ0KHHRzDP9xL+5Yn7zH5lmkG4XOxJpeg
# ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFF0NVJpm/num+IkOny/n5bVpfLe2Ank31XZ6SjeWIPe
# ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKLIZqz/heaJ48QOHfLdeXtJCORmD6iNiLZL1dZPFETa
# ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMAvEGEZc+Om30uoO34otsR6Hguj6VAYKnH7Busuveil
# ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILhblj+60kd6a1vkn1b6mHI5Kd0IDV9Ewie9e3w6NOUn
DICT="/usr/share/dict/words"
if [ ! -f "${DICT}" ]
then
echo "No dictionary found. Try: apt install dictionaries-common"
exit 1
fi
echo "Using size: ${1:-4}"
if [ ${#} -eq 0 ]
then
echo "Invoke with an argument to override this default. Note that large values may take a very long time to generate."
fi
while :
do
rm -f key key.pub
ssh-keygen -q -t ed25519 -f ./key -N ''
KEY=$(cut -d' ' -f2 < ./key.pub)
WORD=${KEY: -${1:-4}}
echo -n .
grep -iq "^${WORD}$" "${DICT}" && break
done
echo
echo
echo "Found key: ${KEY}"
echo
echo "If you want to keep this key, add a comment and a passphrase:"
echo " ssh-keygen -c -f key"
echo " ssh-keygen -p -f key"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment