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?
Asked
Active
Viewed 483 times
2 Answers
0
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

cgdave
- 77
- 1
- 4
-
Not working like that (anymore?) – Sixtyfive Mar 10 '22 at 15:25
-
It still works perfectly in my case... I get a list of all SSH **deploy** keys for each of my repos (I am not speaking of the account's SSH keys) – cgdave Mar 15 '22 at 07:38
-
Thanks for responding to this cgdave, that made me investigate now. Turns out that the github-cli version that comes with Solus OS doesn't understand `gh repo -R`. Compiled 2.5.2 from sources and all working fine now. – Sixtyfive Mar 15 '22 at 09:03
-1
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"

NearHuscarl
- 66,950
- 18
- 261
- 230
-
1This command lists the ssh key associated with your account, not the deploy keys configured per project – Bruno Nov 29 '21 at 11:05