Skip to content
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

Problem setting up hub for Github Enterprise using SSH #1788

Open
sql-sith opened this issue Jun 23, 2018 · 8 comments
Open

Problem setting up hub for Github Enterprise using SSH #1788

sql-sith opened this issue Jun 23, 2018 · 8 comments
Labels

Comments

@sql-sith
Copy link

sql-sith commented Jun 23, 2018

I am unable to figure out how to git hub working with GHE over SSH. I see that others have had similar issues, notably this one, but none of the articles I've read have had solutions that have worked for me. Of course, I didn't read all of them, so let me know if there is an answer already posted that I missed.

Here's my relevant info:

  • Windows 10, Fall Creator's Update
  • git version 2.17.1.windows.2
  • hub version 2.2.9
  • git is not aliased to hub yet (since it's not fully working yet)

I have set the following environment variables. I have tried this both in cmd.exe and in Powershell with similar results, so I will explicitly list both here in case it helps. I'm not sure where I got the idea that I needed both GITHUB_HOST and HUB_HOST - need to look at the docs again, as I have a feeling that HUB_HOST is not needed as an environment variable.

For cmd:

  • GITHUB_HOST=github.ourserver.net
  • HUB_HOST=github.ourserver.net
  • HUB_PROTOCOL=ssh
  • HUB_CONFIG=~/.config/hub

Similarly, for Powershell:

  • $env:GITHUB_HOST="github.ourserver.net"
  • $env:HUB_HOST="github.ourserver.net"
  • $env:HUB_PROTOCOL="ssh"
  • $env:HUB_CONFIG="~/.config/hub"

I created a personal access token and then created a new file named ~/.config/hub with these contents:

ourserver.net
- user: cleonard
- oauth_token: <my token>
- protocol: https

So here is the problem. Whenever I try to run any command that requires hub, I am prompted for a username (on our server, so hub at least recognizes which server to talk to!). The username I type is not visible on the screen, and when I hit enter, I am shown a prompt for a password, but immediately shown an error message. I'm attaching a screenshot for you to see exactly what I mean.
image

The way I authenticate to our GHE with normal git commands is via SSH using RSA keys. That's how I'd like to use hub as well. Is this possible?

Finally, partway through writing up this issue, I tried running hub alias, which told me Error: couldn't detect shell type. Please specify your shell with "hub alias <shell". So I guessed and tried hub alias powershell and got what might be a very useful error message stating that Powershell is not a supported shell but a number of *nix shells are supported. Is this true? I don't want to delete everything I typed up, in case you do support Powershell! But if I need to use bash, will that work in WSL?

Thanks for reading all of this, and for any reply. Looks like a nice tool (my goal is simply to create pull requests from a CLI :) ).

UPDATE: my original post had my actual oauth_token in it so I have deleted that one and generated a new one.

@mislav
Copy link
Owner

mislav commented Jun 26, 2018

Thank you for the detailed report!

  1. First of all, you shouldn't ever set HUB_HOST. This is an internal and undocumented environment variable which is different than GITHUB_HOST.
  2. You state that your hostname is GITHUB_HOST=github.ourserver.net, but in your ~/.config/hub I see ourserver.net. The hostnames should match.
  3. Check git config --get-all hub.host and add git config --global --add hub.host github.ourserver.net if missing.
  4. You should be using the latest hub version v2.4.0.
  5. See https://github.com/github/hub#powershell and please report if it helps!

@sql-sith
Copy link
Author

sql-sith commented Jun 27, 2018

Thank you for a helpful reply! Based on your response, I have changed a few things and everything is working now. Then I was able to set up hub on a second laptop without any trouble. For others looking for advice on setting up hub for GitHub Enterprise using Powershell, I thought I'd offer a summary of how I did my installation, along with a couple of comments for possible improvements to the documentation.

  1. I installed hub v2.4.0 from the binary installer available here, as mentioned on https://hub.github.com. However, the README.md on GitHub says to use Chocolatey or Scoop to install on Windows. You may want to either change the README to point people to the installation binaries or get the Chocolatey repo up-to-date (I didn't test Scoop).
  2. I ran git config --global --add hub.host github.ourserver.net as required.
  3. I also ran git config --global --add hub.protocol ssh.
  4. I set an alias as suggested: Set-Alias -Name git -Value hub.
  5. With nothing more than this setup, I was able to go into one of my GHE repos and issue an arbitrary command (I chose git browse) to see if things were working. Hub prompted me for credentials and created the file ~/.config/hub, as advertised, with an oauth_token value. After this, I was never prompted for credentials again, but was always logged in transparently.
  6. I have only one environment variable set: $GITHUB_HOST="github.ourserver.net". However, when I try a command such as git clone myrepo, I am still prompted for credentials to github.com when I am inside Powershell. Interestingly, when I am in cmd, git clone pulls from github.ourserver.net as expected. Is this a known issue? If so, I'd offer to fix but I'm just learning go currently. Maybe I'll try it anyway. After all, the best way to learn a new language is to use it.

Generally, I am quite happy with these extensions to git. Thank you!

@mislav
Copy link
Owner

mislav commented Jun 27, 2018

Thank you for the detailed steps!

However, when I try a command such as git clone myrepo, I am still prompted for credentials to github.com when I am inside Powershell.

That sounds like your GITHUB_HOST configuration may not be effective in Powershell. Where exactly do you set that environment variable?

@sql-sith
Copy link
Author

I set it in my profile, and I verify it from the CLI by running echo $GITHUB_HOST.

@sql-sith
Copy link
Author

sql-sith commented Jun 27, 2018

I found the issue. In hosts.go, there is this code:

var (
	GitHubHostEnv = os.Getenv("GITHUB_HOST")
	cachedHosts   []string
)

I used this as the basis for a proof-of-concept locally:

package main

import (
	"fmt"
	"os"
)

func main() {
	GitHubHostEnv := os.Getenv("GITHUB_HOST")
	fmt.Println(GitHubHostEnv)
}

This code successfully prints the environment variable in cmd:

C:\>SET GITHUB_HOST=github.ourserver.net
C:\goApps\hosts.exe
github.ourserver.net

However, in Powershell:

[PS:cahokia] C:\goApps
> $GITHUB_HOST="github.ourserver.net"

[PS:cahokia] C:\goApps
> .\hosts.exe


[PS:cahokia] C:\goApps
> 

I haven't found a fix or workaround yet but will look for one.

@sql-sith
Copy link
Author

Workaround: if I set this variable in Control Panel, everything works. So it appears to have something to do with the visibility of environment variables. Apparently go does not inherit my environment when it runs. This is a bit of a nuisance, however, since I can't switch from our GHE to the public GitHub without modifying my environment variables and starting a new shell. Maybe I can just modify the persistent $GITHUB_HOST from within Powershell (I have a function for that) and then run refreshenv. I'll keep you posted if I dig further. I may just use the fully-qualified project name for those few commands that need to be told which server to use. Thanks for all your help so far!

@mislav
Copy link
Owner

mislav commented Jun 28, 2018

Perhaps setting an environment variable like this $GITHUB_HOST="github.ourserver.net" in powershell only sets it for the current interactive shell, but doesn't “export” it to subprocesses such as hub or hosts.exe.

See https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-6:

To make a persistent change to an environment variable, use System in Control Panel (Advanced tab or the Advanced System Settings item) to store the change in the registry.

@mislav
Copy link
Owner

mislav commented Jul 7, 2018

@sql-sith Is everything resolved here? Is there something we need to fix about our documentation, or can this be closed please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants