Skip to content

Instantly share code, notes, and snippets.

@threeiem
Last active February 23, 2022 23:19
Show Gist options
  • Save threeiem/a93ec99d5842dbbbd9197c6159a54d45 to your computer and use it in GitHub Desktop.
Save threeiem/a93ec99d5842dbbbd9197c6159a54d45 to your computer and use it in GitHub Desktop.
Get Golang v1.17+ `go get` to enforce `ssh`

Go 1.17+ Terminal Prompts

After upgrading to go 1.17+ then you will start to see this error.

fatal: could not read Username for 'https://github.com': terminal prompts disabled

Common Error

After version 1.16 you will enconter this and need to modify how go downloads private modules on your system.

Set ENV variable GOPRIVATE

Go has a special environment variable that tells it to switch to git@github.com: vs. https://github.com/ for private URLs. You can add this to your .rc files for your shell.

export GOPRIVATE=github.com/{private-space}

This can also be done using go env.

go env -w GOPRIVATE=github.com/{private-space}

Update .gitconfig (DO NOT DO THIS!)

You need to configure git to change these URLs to use ssh vs. https for it to use the keys in your agent.

git config --global --add url."git@github.com:".insteadOf "https://github.com/"

Or edit the git config directly.

# Enforce SSH
[url "git@github.com/"]
  insteadOf = https://github.com/
[url "git@gitlab.com/"]
  insteadOf = https://gitlab.com/
[url "git@bitbucket.org/"]
  insteadOf = https://bitbucket.org/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment