0

I'm trying to automate logins to GitHub using a private key, so that I can do "git pull/add/commit/push" from a BASH script. If I put this in ~/.ssh/config, it works:

Hostname github.com
User git
IdentityFile ~/.ssh/mygitkey.pem

Unfortunately, this causes all SSH connections to be routed to Github.com, which I don't want.

So I tried this:

Host GitHub
   Hostname github.com
   User git
   IdentityFile ~/.ssh/mygitkey.pem

But this causes the "user" and "identityFile" options to be ignored when connecting to GitHub.

John Heyer
  • 181
  • 2
  • 8
  • See also: https://stackoverflow.com/questions/14762034/push-to-github-without-password-using-ssh-key – stark Apr 03 '20 at 18:41

1 Answers1

0

You probably want something like this:

Host github.com
   IdentityFile ~/.ssh/mygitkey.pem

(Possibly the User if it serves a purpose for you, but the remotes in your repositories presumably already say git@github.com, which would make it pointless to specify the User here too)

The config in the question looks like it should technically work, but you would have to change all references (like the remotes in your repositories) from github.com to GitHub.

Håkan Lindqvist
  • 33,741
  • 5
  • 65
  • 90
  • Yeah I already tried that, no luck. Running`ssh -v git@github.com` I see it does connect to GitHub, but only tries the default private keys (i.e. `~/.ssh/id_rsa`) but not the `~/.ssh/mygitkey.pem` My OpenSSH client is 7.2p2 which is getting quite old, so perhaps this is is the issue – John Heyer Apr 03 '20 at 21:34