35

Is there some way to use ssh-based authentication when accessing the GitHub API through the command line (via, e.g., curl, etc.?).

FWIW, I tried many variations of the following (varying the way I specified my public ssh key file) but in every case I was still prompted for my password:

% curl --pubkey ~/.ssh/id_rsa.pub --user yrstruly https://api.github.com/user/repos

CharlesB
  • 86,532
  • 28
  • 194
  • 218
kjo
  • 33,683
  • 52
  • 148
  • 265

1 Answers1

12

If you are using ssh, then you would never logon as 'yrstruly'. You would always connect as 'git'.
Your public key would be enough for GitHub to recognize you as 'yrstruly'.
And since you are using an https address, and not an ssh one, that --pubkey option is likely to be ignored.

A valid ssh address would be: ssh://git@api.github.com, and I don't think Github proposes that kind of access for its api.

The curl --user option would be necessary for https address only, as in "Having trouble downloading Git archive tarballs from Private Repo":

curl -sL --user "${username}:${password}" https://github.com...
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Regarding your last point, there's a ton of commands in the GitHub API that modify a repo, and for which authentication would obviously be necessary. Furthermore, authentication aside, at least some of these commands *could not possibly work* without a `-u` parameter because they'd be ambiguous. E.g. where would `curl -u yrstruly -d '{"name":"newrepo"}' https://api.github.com/user/repos` create the new repo "newrepo" if a `-u` parameter was not specified? – kjo Feb 24 '13 at 00:52
  • @kjo I agree, -u is necessary and it is what I use in my answer (with username and password). However, I would not use any pubkey, since ssh isn't involved here. – VonC Feb 24 '13 at 01:03
  • 1
    @VonC Is this still the case in 2018? It's possible to create Deploy Keys which are ssh and presumably intended to be used with the API but I can't work out how – Mark Adamson Apr 23 '18 at 19:55
  • @MarkAdamson did you try with `curl -u git: --key ~/.ssh/yourKey ...`? But yes, ssh is not accessible from the outside for GitHub. – VonC Apr 23 '18 at 20:01
  • @VonC reading around a bit more I realise that Deploy Keys do not give access to the GitHub API, they are just to work with native Git operations – Mark Adamson Apr 24 '18 at 20:50