Finding all GitHub Repo Deploy Keys?

Viewed 268

I am trying to add a new SSH key to my GitHub account, but it says the key is already in use. I have hundreds of repos, and I don't want to click through each one to find out which is using this SSH key for deployments. Is there a way to automate this?

2 Answers

This is now available in gh-cli 1.6.0+. To list all ssh-keys, execute the below command:

gh ssh-key list

To add a new ssh-key:

gh ssh-key add [<key-file>] --title "Your Key Name"

Reference.

My approach to list the deploy keys (not the account-level keys) of all my repos:

for repo in `gh repo list | awk '{print $1}'`;\
  do echo "==== $repo ====";\
  gh repo -R $repo deploy-key list;\
done
Related