Home > Enterprise >  How can I test that a specific SSH key (a github deploy key specific to a repo) is valid?
How can I test that a specific SSH key (a github deploy key specific to a repo) is valid?

Time:01-05

I have minted the keys and stored the public key in the deploy keys settings of the target repo.

When I minted the keys I sent them to ~/.ssh/my-repo and ~/.ssh/my-repo.pub. In my ~/.ssh/config file I have updated it,

Host *.github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/my-repo

However, when I try to clone the repo via SSH I get prompted to enter my passphrase for .../.ssh/id_ed25519, which is my default SSH key. I know this one works. I'd like to test the one I minted specifically for my-repo.

Thanks for any pointers.

The end goal is to have a remote server clone the repo using this deploy key. At the moment it's hitting a Permission denied (public key) issue.

Update:

When using the command below,

ssh -i ~/.ssh/my-repo git clone [email protected]:user/my-repo.git

I get a timeout,

ssh: connect to host git port 22: Operation timed out

CodePudding user response:

ssh: connect to host git port 22: Operation timed out
                ^^^^^^^^

ssh -i ~/.ssh/my-repo git clone [email protected]:user/my-repo.git does not run a git command over ssh. It tries to ssh into the hostname git. That host doesn't exist, so it times out.

Instead, follow the instructions in Testing your SSH connection.

ssh -T [email protected]

Your ssh configuration Host *.github.com does not match github.com; it would match something.github.com. Try Host github.com.

In addition, AddKeysToKeychain and Usekeychain probably shouldn't be restricted to a particular host.

AddKeysToAgent yes
UseKeychain yes

Host github.com
  IdentityFile ~/.ssh/my-repo

CodePudding user response:

I would recommend using a Host entry different from github.com, precisely to make unambiguous the fact you are using a custom SSH URL:

Host gh
  Hostname github.com
  User git
  IdentityFile ~/.ssh/my-repo

Then your test becomes

ssh -Tv gh

And your URL becomes:

git clone gh:me/myRepo

No more git@..., since since the config file includes User git.

  • Related