Reed
Reed

Reputation: 14974

Check if private ssh-key has been added to ssh-agent

In ~/.ssh I have github and bitbucket private key files. Both are encrypted, so when I ssh-add ~/.ssh/github I have to enter a password.

I have a bash script to automate git commands. If the github and/or bitbucket identities have NOT been added yet, then I want to ssh-add them.

I'm looking for a function like:

has_identity_been_added ~/.ssh/github

To simply check if the private, encrypted key file has been added.

I found:

Both of those print the name I gave to the key file like reed@laptop-x1834 (I think that was the automatic name, cause I didn't specify -C in the ssh-keygen, if memory serves).

I'm not sure where to go from here. I don't want to rely upon the ssh-keygen -C "whatever_name".

Upvotes: 5

Views: 4595

Answers (1)

Philippe
Philippe

Reputation: 26397

ssh-add -l print out fingerprint of the keys added.

You can get the fingerprint of a public key with :

ssh-keygen -l -f id_rsa.pub

Upvotes: 6

Related Questions