Skip to content

Instantly share code, notes, and snippets.

@hboetes
Created December 3, 2021 12:42
Show Gist options
  • Save hboetes/50aa2cdd1e64003d6cac966baae96da4 to your computer and use it in GitHub Desktop.
Save hboetes/50aa2cdd1e64003d6cac966baae96da4 to your computer and use it in GitHub Desktop.
findunsecuredsshkeys
#!/bin/sh
for dir in $(getent passwd|awk -F : '{print $6}'); do
if [ ! -d $dir/.ssh ]; then
continue
fi
find $dir/.ssh -type f | while read file; do
if ! file "$file" | grep -iq 'private key'; then
continue
fi
if ssh-keygen -P '' -y -f "$file" > /dev/null 2>&1; then
echo "Unsecured ssh private key found! $file"
fi
done
done
@hboetes
Copy link
Author

hboetes commented Dec 3, 2021

This scriptlet can find unencrypted private ssh keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment