Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kaatinga/2f27968e38365ad63dea0c4650335713 to your computer and use it in GitHub Desktop.
Save kaatinga/2f27968e38365ad63dea0c4650335713 to your computer and use it in GitHub Desktop.
How to fix 'fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled'

Ops. https://gitlab.com': terminal prompts disabled

Ops. Username for 'https://codeberg.org':

Ops. etc

If you see this message, there is a short solution how to fix it here. In my case it appeared and it did not want to get fixed by many ways that are offered on the internet.

Some of the pieces of advice that did not work:

  1. Set git config --global --add credential.helper manager
  2. To add GIT_TERMINAL_PROMPT=1 to the enviroments.
  3. Use HTTPS authentification instead of SSH
  4. etc.

The actual reason is you do not have a key pair to work with your repository and/or you did not update git settings to use ssh.

step 1. Create a key pair. Fallowing the description on the page https://docs.gitlab.com/ee/ssh/, just add the public key to your SSH setting on gitlab.com, put your private key to .ssh folder (in my case it was id_rsa file) and check if it works by ssh -T [email protected] command (ssh -T [email protected], ssh -T [email protected]).

It will allow to access your repository using a private key.

step 2. Only for Golang: Point out that your repository or repositories are private. Use come to deparate patterns/repos. Set go env -w GOPRIVATE="gitlab.com/your_name*,github.com/your_name*,codeberg.org/your_name*".

step 3. Set git config --global url."[email protected]:".insteadOf "https://gitlab.com/". This will make Git use ssh to fetch and push changes (https must be disabled) even if you use https link to clone.

step 4. Optional: If you cloned a repo using https before to fix your settings in .gitconfig, like: git clone https://codeberg.org/your_name/your_repo.git you need to switch that repo to ssh. Go to the repo folder and run: git remote set-url origin [email protected]:your_name/your_repo.git

After the key is used, all the private packages are pulled and pushed without any trouble.

@joanderencora
Copy link

Thank you very much ! You saved my day :)

@NewZAZ
Copy link

NewZAZ commented Apr 25, 2023

Thank you for this, work perfectly !

@firgavin
Copy link

And you, my friend, are a true hero!

@mvlootman
Copy link

Step 2 made the difference for me.
Thanks for writing this gist!

@jfroffice
Copy link

Nice! work perfectly !

@Jahangir-Sh
Copy link

After the mentioned steps I failed to get a private dependency again and got the following message:

go: downloading gitlab.com/<package-path>
go: gitlab.com/<package-path>: verifying module: gitlab.com/<package-path>: reading https://sum.golang.org/lookup/gitlab.com/<package-path>: 404 Not Found
	server response:
	not found: gitlab.com/<package-path>: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/<signature>: exit status 128:
		fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled
	Confirm the import path was entered correctly.
	If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.

The message indicates that the package manager couldn't find the package in the public database - https://sum.golang.org for authentication. You can fix it using the GONOSUMDB environment variable, a comma-separated list of module suffixes that checksum database queries should be disabled instead of disabling authentication entirely by using GOSUMDB=off and disabling security guarantee of verified downloads for all modules.

@sergoMedvedev
Copy link

Thank you!

@gmrmn
Copy link

gmrmn commented Dec 21, 2023

👍

@charlos
Copy link

charlos commented Jan 10, 2024

ty ❤️

@MadisonLopez
Copy link

MadisonLopez commented Apr 11, 2024

It is working for me. Thank you so much.

@SagarNagalgawe
Copy link

Thank you !

@Hefan-scut
Copy link

It works! Thanks for saving my days!

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