Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git clone over https 401 error and not asking for username or password

Tags:

git

https

ubuntu

I have a private git repository on Codaset. Normally when I try to clone it over HTTPS on my Windows machine, it asks me for my username and password. When I try to clone it on an Ubuntu server, it never asks me for a username or password and it fails with a 401 error. What do I need to do differently?

Here is what I am doing:

git clone https://codaset.com/username/project_name.git destination_folder_name.git
like image 689
still_dreaming_1 Avatar asked Apr 26 '11 20:04

still_dreaming_1


People also ask

How do I clone a git repository without username and password?

One way to clone a repository without having to enter your password would be to create an app-password and use it while cloning. That done, git won't prompt for user name and password. Mind that this is a URL and needs to be encoded as an URL then. This will leave the password in the git configuration.

Why does git not ask for password?

You can avoid being prompted for your password by configuring Git to cache your credentials for you. Once you've configured credential caching, Git automatically uses your cached personal access token when you pull or push a repository using HTTPS.

How do I resolve authentication failed in git clone?

If you can directly login to the Github with the username and password, the issue might be mostly with Two Factor Authentication (2FA). Check whether the 2FA authentication is enabled in Github. Navigate to Settings -> Security section. Check whether the Two-factor authentication is Enabled.


2 Answers

I got it to work using this format:

https://username:[email protected]/username/project_name.git destination_folder

However according to these 2 posts, using that method could be a security problem:

Can a username and password be sent safely over HTTPS via URL parameters?

Username and password in https url

like image 191
still_dreaming_1 Avatar answered Sep 18 '22 13:09

still_dreaming_1


To avoid having to enter a password at all (on Windows or Unix), you can:

  • check that HOME is defined (on Windows, it isn't by default)
  • setup a _netrc file with the following content:
    machine codaset.com
    login your_codaset_login
    password your_codaset_password

Note: %HOME%\_netrc on Windows, $HOME/.netrc on Unix

That way, when you are cloning your repo, instead of typing:

 git clone https://[email protected]/username/project_name.git destination_folder_name.git

, you can remove the initial username:

git clone https://codaset.com/username/project_name.git destination_folder_name.git

and you won't have to enter a password.


If you don't want to put your credentials (in particular your password) in plain text in an .netrc file, you can encrypt that netrc file with gpg: see "Is there a way to skip password typing when using https:// github"

like image 24
VonC Avatar answered Sep 18 '22 13:09

VonC