Skip to content

Instantly share code, notes, and snippets.

@apjyotirmay
Last active April 14, 2025 19:22
Show Gist options
  • Save apjyotirmay/9115d4ea19b35d5b18729cedbab313cf to your computer and use it in GitHub Desktop.
Save apjyotirmay/9115d4ea19b35d5b18729cedbab313cf to your computer and use it in GitHub Desktop.
Export public keys from your ssh agent keyring
#!/usr/bin/env bash
# This script exports your public keys from ssh keyring and saves it in ~/.ssh/pub
# with the name. This makes it easy to avoid brute forcing all key in the agent
[[ -e $HOME/.ssh/pub ]] || mkdir $HOME/.ssh/pub
while read -r line
do
FILENAME=$(echo $line | awk '{print $3}')
echo $line > "${HOME}/.ssh/pub/${FILENAME}.pub"
chmod 600 "${HOME}/.ssh/pub/${FILENAME}.pub"
done < <(ssh-add -L)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment