New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hub pull-request with SSH #978

Open
tybenz opened this Issue Aug 14, 2015 · 13 comments

Comments

Projects
None yet
10 participants
@tybenz

tybenz commented Aug 14, 2015

I am trying to use hub with GitHub Enterprise. My company's enterprise account is set up to only use SSH keys when pulling/pushing. I think they've disabled basic auth altogether. When using hub pull-request, hub prompts me for my username/password for GitHub Enterprise, which I do not have. Our web portal requires a username + 2FA token. Tried to use that to no avail.

Is there a way for hub to use the GitHub API and use an SSH key to authenticate itself?

Or am I out of luck?

@nightpool

This comment has been minimized.

nightpool commented Aug 17, 2015

You can't auth to the API over an ssh key, but you can get a oauth token and put that into hub manually.

@nightpool

This comment has been minimized.

@mislav

This comment has been minimized.

Member

mislav commented Aug 17, 2015

Hub accesses GitHub API via HTTPS, so it needs some kind of authentication such as Basic Auth or OAuth. SSH keys won't help because they're only used by git when pushing/pulling.

Because you don't have a password you can authenticate with, only 2FA token, that means you will probably need to generate a Personal access token manually. You can do that from your settings in the web interface. Then, add that token to ~/.config/hub like so:

---
myenterprise.com:
- protocol: https
  user: tybenz
  oauth_token: YOURTOKEN

@mislav mislav closed this Aug 17, 2015

@rayrrr

This comment has been minimized.

rayrrr commented Jun 25, 2017

This is a very old Issue thread with incredible search engine placement. I searched just for "hub ssh," ended up here, tried this and it didn't work. Looking at the docs here it seems the proper way to do this nowadays is to simply set an environment variable with the name GITHUB_TOKEN containing the value of your GitHub Personal Access Token. That worked for me!

@youcandanch

This comment has been minimized.

youcandanch commented Jul 17, 2017

whoa @rayrrr what are you doing here

@miohtama

This comment has been minimized.

miohtama commented Aug 15, 2017

I have two-factor authentication enabled. hub ends up asking password even if I put manually generated token to ~/.hub/config or GITHUB_TOKEN environment variable.

  • Why is this? (I guess no one knows)

  • Is there a way to get debug information from hub to know why it fails to authenticate?

@mislav

This comment has been minimized.

Member

mislav commented Aug 15, 2017

  1. When ~/.config/hub (mind the actual file name) already contains the user and oauth_token keys (perhaps you've pasted in a manually generated token; that's ok), you will never be prompted for password. Hub will try to use that oauth token and fail with an error message if the token is invalid.

  2. You can set HUB_VERBOSE=1 to have hub output extra debugging information.

@levithomason

This comment has been minimized.

levithomason commented Jan 8, 2018

Can this get added to the docs or README?

@holdenk

This comment has been minimized.

holdenk commented Jun 28, 2018

It also checks for an env variable called GITHUB_TOKEN which was surprising for me since all of the docs pointed to deleting the config value -- just incase anyone else gets stuck on this like I do.

@chrowe

This comment has been minimized.

chrowe commented Jul 13, 2018

The documentations on https://hub.github.com/hub.1.html seems to still indicate that git is the default
with git config --global hub.protocol https being an override. Unfortunately git and ssh options do not seem to work.

In the short term, using the full git@github.com/... url works for some things

@chris-fran

This comment has been minimized.

chris-fran commented Nov 8, 2018

Can we get some more explicit documentation? Specifically on these topics

  1. I intend to use only SSH key for Git operations, NO OAuth2. Do I still need to set GITHUB_TOKEN? If yes, a brief explanation would help people understand
  2. What's the difference of git config --global hub.protocol vs HUB_PROTOCOL? In what use cases I would pick one over the other?
  3. Is this required git config --global --add hub.host MY.GIT.ORG? I'm pretty sure I set mine up without this line, but only the GITHUB_HOST and it worked
@mislav

This comment has been minimized.

Member

mislav commented Nov 12, 2018

Until there is better documentation:

  1. I intend to use only SSH key for Git operations, NO OAuth2. Do I still need to set GITHUB_TOKEN?

Yes, because hub needs access to the GitHub API, which can only be accessed via HTTP(S) Oauth2 and not SSH.

2. What's the difference of git config --global hub.protocol vs HUB_PROTOCOL?

There is no difference. Use the one you're more comforable with.

3. Is this required git config --global --add hub.host MY.GIT.ORG?

It's required in case GITHUB_HOST isn't set.

@mislav

This comment has been minimized.

Member

mislav commented Nov 12, 2018

Reopening until there are better docs.

More about the SSH vs. HTTPS communication during hub operations: #1644 (comment)

@mislav mislav reopened this Nov 12, 2018

@mislav mislav added the docs label Nov 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment