1

I am unable to "go get" module from private github repo

I getting following error message

go get 
go: github.com/xxxxx/xxxxx-service@v0.0.0-20230419012042-5a43328285a5: invalid version: git ls-remote -q origin in /usr/local/bin/pkg/mod/cache/vcs/e3eb4c4c224c608f41c609b576ad32d5a979877e8a7f951b716f1242957c7ddd: exit status 128:
        remote: Support for password authentication was removed on August 13, 2021.
        remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
        fatal: Authentication failed for 'https://github.com/xxxxx/xxxxx-service/

I tried with the following method. Added the the github credentials in ~/.netrc:

machine github.com 
login <username> 
password <Personal Access Token>`

Added the following entries in ~/.gitconfig file

[url "git@github.com:"]
        insteadOf = https://github.com/
[url "ssh://git@github.com/"]
        insteadOf = https://github.com/

Added the environment variable

export GOPRIVATE=github.com/<username>/*
export GO111MODULE=on

Still getting the same Authentication error.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • Try these: 1. rollback the changes to `~/.gitconfig` unless you want to authenticate with ssh keys; 2. rollback the changes to `~/.netrc`; 3. since you accept storing plain password to file, use `https://git-scm.com/docs/git-credential-store` is more easy. Run `git config --global credential.helper 'store'` to use this helper; 4. run `git clone https://github.com/xxxxx/xxxxx-service.git` once to make sure your `Personal Access Token` is stored; 5. try `go get` again. – Zeke Lu May 16 '23 at 16:49
  • Thank you @ZekeLu it worked after rolling back the changes to ~/.gitconfig and ~/.netrc And did following changes export GOPRIVATE=github.com/ export GOPROXY=direct git config --global url."https://@github.com/".insteadOf https://github.com/ – Vishwanath Kumar May 19 '23 at 02:12
  • Thank you for the feedback! 1. `GOPROXY=direct`, don't do this. It affects all modules. Setting `GOPRIVATE` is enough. 2. `url."https://@github.com/".insteadOf github.com`, in my opinion, a git credential helper is better than this. – Zeke Lu May 19 '23 at 02:37

1 Answers1

0

Github has disabled simple password authentication from command line interfaces since 2021. Take a look at the third line of the first terminal output block you've sent in your question.

You should create an ssh key and add it to your machine's ssh-agent or install the github-cli package and login through it.

Here are instructions to go get using SSH: https://gist.github.com/StevenACoffman/866b06ed943394fbacb60a45db5982f2

  • But it supports personal access token which is an alternative to using password. See https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#using-a-personal-access-token-on-the-command-line. – Zeke Lu May 16 '23 at 23:01