在 github 中 push 时,为什么 git 没有要求我输入用户名和密码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31793680/
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
When push in github, why git didn't ask me to type username and password?
提问by casamia
This might be stupid question. But I could't find anything about this by search. Maybe, this is stupid question.
这可能是个愚蠢的问题。但我无法通过搜索找到任何关于此的信息。也许,这是一个愚蠢的问题。
I've stored my codes in github.
我已将代码存储在 github 中。
2 hours ago, I want update my codes in repository, but my local doesn't have that code. So I cloned it, modified codes, and pushed it. At this time, git prompt me to type user name of github and password. I typed it and code updated.
2 小时前,我想更新存储库中的代码,但我的本地没有该代码。所以我克隆了它,修改了代码,然后推送了它。这时候git提示我输入github的用户名和密码。我输入了它并更新了代码。
After that, I read my codes in "OTHER" repository. And I found something needed to modify, too. So I cloned that repository to my local computer, modified codes, and pushed it.
之后,我在“其他”存储库中阅读了我的代码。我也发现了一些需要修改的东西。所以我将该存储库克隆到我的本地计算机,修改代码并推送它。
But... at this time, git does not prompt message to input user name and password of github.
但是……这个时候git并没有提示输入github的用户名和密码的信息。
Huh? Is this mean that anyone cloned my codes in github could also push to my github repository? This is very dangerous situation, isn't it?
嗯?这是否意味着任何人在 github 中克隆了我的代码也可以推送到我的 github 存储库?这是非常危险的情况,不是吗?
So I tested with creating new repository in github. I cloned this new repository to my local, made some change, and pushed it. But git does not prompt message to type user name and password, too.
所以我测试了在 github 中创建新存储库。我将这个新存储库克隆到我的本地,进行了一些更改,然后推送了它。但是 git 也不会提示输入用户名和密码的消息。
So, my question is,
所以,我的问题是,
- Does the first pushing save github login information in my local computer, and use it after other push? Then, where it is?
- What is the github repository's default security setting? I didn't register SSH key of this local computer to github account. It seems irrational to anyone push to my repository with master branch, without any requirement of authentication.
- 第一次推送是否将github登录信息保存在我本地电脑中,其他推送后使用?那么,它在哪里?
- github 存储库的默认安全设置是什么?我没有将这台本地计算机的 SSH 密钥注册到 github 帐户。任何人用 master 分支推送到我的存储库,而不需要任何身份验证,这似乎是不合理的。
Below is my commands when doing above works.
以下是我在执行上述工作时的命令。
$git init
$git clone https://github.com/[user name]/[repository name].git
<some change>
$git add *
$git commit -m "change"
$git remote add origin https://github.com/[user name]/[repository name].git
$git push origin master
Added information. For more details, I captured my github setting pages.
添加了信息。有关更多详细信息,我捕获了我的 github 设置页面。
采纳答案by Maelstrom
This might help.. https://help.github.com/articles/caching-your-github-password-in-git/
这可能会有所帮助.. https://help.github.com/articles/caching-your-github-password-in-git/
Git by default saves your passwd in cache for 15 min.
默认情况下,Git 会将您的密码保存在缓存中 15 分钟。
回答by Foolish
You can manually unset credential.helper by running below command.
您可以通过运行以下命令手动取消设置 credential.helper。
git config --global --unset credential.helper
use --global
or --local
or --system
as per your needs.
使用--global
或--local
或--system
根据您的需要。
Then pushing in github will ask for username and password.
然后推入 github 会要求输入用户名和密码。
If you are on windows one other way to do this is as below but note that it will again save your credentials if you use credential.helper with git.
如果您在 Windows 上,另一种方法如下所示,但请注意,如果您将 credential.helper 与 git 一起使用,它将再次保存您的凭据。
Go to control panel
-> Credential Manager
-> Windows Credentials
and remove your git credential entry/entries.
转到control panel
-> Credential Manager
->Windows Credentials
并删除您的 git 凭证条目/条目。
回答by ireshika piyumalie
For Mac users password can be clear by running below command :
对于 Mac 用户,可以通过运行以下命令清除密码:
git credential-osxkeychain erase
host=github.com
protocol=https
回答by Shaun
Problem: When pushing to the remote git will report: remote: Permission to [your/repo] denied to user [bob]
问题:推送到远程git时会报:remote: Permission to [your/repo] denied to user [bob]
The username in the store may be wrong. Powershell this:
商店中的用户名可能有误。Powershell 这个:
cd c:\Program Files\Git\mingw64\libexec\git-core;
git-credential-manager.exe remove [bob];
git push origin [your branch];
you should now be prompted for credentials.
现在应该会提示您输入凭据。
回答by DimiDak
In Linux check
在 Linux 中检查
cat /home/<MyUser>/.git-credentials
回答by Georgy Buranov
As fas as I understand, there are several ways to checkout using git.
据我所知,有几种使用 git 结帐的方法。
Specifically, using http protocol (that uses name/password) and using ssh (that uses ssh public/private key pair)
具体来说,使用 http 协议(使用名称/密码)和使用 ssh(使用 ssh 公钥/私钥对)
It seems you are using ssh, so private/public key pair is used for authorization
看来您正在使用 ssh,因此使用私钥/公钥对进行授权