37

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

1 Answer 1

13

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://[email protected], 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...
Sign up to request clarification or add additional context in comments.

5 Comments

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 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 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
@MarkAdamson did you try with curl -u git: --key ~/.ssh/yourKey ...? But yes, ssh is not accessible from the outside for GitHub.
@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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.