Introduction: When a simple go get turns into a puzzle
\n\nHave you ever tried to run go get github.com/your-account/private-repository and received a cold, unfriendly message in response?
go get github.com/your-account/private-repository: \n module github.com/your-account/private-repository: \n git ls-remote -q origin in /tmp/...: exit status 128:\n remote: Invalid username or password.\n fatal: Authentication failed for 'https://github.com/your-account/private-repository.git'\n\nOr, even more mysteriously:
\ngo get github.com/your-account/private-repository: \n terminal prompts disabled\n Confirm the import path was entered correctly.\n If this is a private repo, see https://golang.org/doc/faq#git_https\n\nSound familiar? If so, you've come to the right place. This error is a classic stumbling block for Go developers working with private repositories on GitHub. On Stack Overflow, this question has gathered thousands of views, and today we'll break it down once and for all.
\n\nIn this article, we won't just solve the problem — we'll understand why it occurs, and learn to configure our environment so that go get works with private repositories like a charm. Let's go!
Why does Go refuse to work with private repositories?
\n\nTo understand the cause, we need to look under the hood of Go. When you run go get, the Go toolchain does several things:
- \n
- It tries to clone the repository via HTTPS (the default protocol). \n
- If the repository is private, Git requests authentication (username/password). \n
- By default, Go disables interactive terminal prompts — this is the very "terminal prompts disabled" message. \n
Why does Go do this? It's simple: during automated builds or in CI/CD pipelines, interactive password input is impossible. Therefore, Go prefers to fail with an error rather than hang waiting for input.
\n\nKey idea: The "terminal prompts disabled" error is not a bug, but a feature. Go is telling you: "I can't ask you for a password, give me ready-made credentials." And our task is to provide them.
\n\nMethod 1: Using SSH (the most reliable and correct way)
\n\nThis is the recommended method. SSH keys are secure, convenient, and don't require entering a password every time.
\n\nStep 1. Generate an SSH key (if you don't have one)
\nOpen your terminal and run:
\nssh-keygen -t ed25519 -C "your_email@example.com"\nPress Enter to save the key to the default folder (~/.ssh/id_ed25519). You can add a passphrase — this will increase security.
Step 2. Add the key to the SSH agent
\neval "$(ssh-agent -s)"\nssh-add ~/.ssh/id_ed25519\n\nStep 3. Add the public key to GitHub
\nCopy the contents of ~/.ssh/id_ed25519.pub:
cat ~/.ssh/id_ed25519.pub\nGo to GitHub → Settings → SSH and GPG keys → New SSH key. Paste the key and save.
\n\nStep 4. Configure Git to use SSH
\nNow for the most important part: you need to make Go use SSH instead of HTTPS. To do this, edit the ~/.gitconfig file:
[url "git@github.com:"]\n insteadOf = https://github.com/\nThis directive tells Git: "When you see https://github.com/ — use git@github.com: (SSH)".
Step 5. Try again
\ngo get github.com/your-account/private-repository@latest\nIf everything is configured correctly, the error will disappear. Go will use SSH for authentication, and the SSH agent will provide the key.
\n\nMethod 2: Using a Personal Access Token (PAT) — for CI/CD and scripts
\n\nSSH is great for local development