git clone over https 401 错误而不要求输入用户名或密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5796171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git clone over https 401 error and not asking for username or password
提问by still_dreaming_1
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?
我在 Codaset 上有一个私人 git 存储库。通常,当我尝试在我的 Windows 机器上通过 HTTPS 克隆它时,它会询问我的用户名和密码。当我尝试在 Ubuntu 服务器上克隆它时,它从不要求我输入用户名或密码,并且失败并显示 401 错误。我需要做什么不同的事情?
Here is what I am doing:
这是我在做什么:
git clone https://codaset.com/username/project_name.git destination_folder_name.git
回答by still_dreaming_1
I got it to work using this format:
我使用这种格式让它工作:
https://username:[email protected]/username/project_name.gitdestination_folder
https://username:[email protected]/username/project_name.gitdestination_folder
However according to these 2 posts, using that method could be a security problem:
但是,根据这 2 个帖子,使用该方法可能存在安全问题:
Can a username and password be sent safely over HTTPS via URL parameters?
能否通过 URL 参数通过 HTTPS 安全地发送用户名和密码?
回答by VonC
To avoid having to enter a password at all (on Windows or Unix), you can:
为了完全避免输入密码(在 Windows 或 Unix 上),您可以:
- check that HOME is defined (on Windows, it isn't by default)
- setup a
_netrc
file with the following content:
- 检查 HOME 是否已定义(在 Windows 上,默认情况下不是)
- 设置一个
_netrc
包含以下内容的文件:
machine codaset.com login your_codaset_login password your_codaset_password
Note: %HOME%\_netrc
on Windows, $HOME/.netrc
on Unix
注意:%HOME%\_netrc
在 Windows 上,$HOME/.netrc
在 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 textin an .netrc
file, you can encrypt that netrc
file with gpg
: see "Is there a way to skip password typing when using https:// github"
如果您不想将您的凭据(特别是您的密码)以纯文本形式放入.netrc
文件中,您可以使用以下命令加密该netrc
文件gpg
:请参阅“使用 https://github 时是否可以跳过密码输入”
回答by manojlds
You can do:
你可以做:
git clone https://[email protected]/username/project_name.git destination_folder_name.git
to make it prompt for password.
使其提示输入密码。