Git:有没有设置默认登录凭据的方法?

Git:有没有设置默认登录凭据的方法?,git,Git,我正在使用mac终端并运行线路 git push origin master 每次它都会要求我输入github.com的用户名和密码, 有没有办法让它自动使用我的凭据 我一直在犯错误 error: The requested URL returned error: 403 while accessing https://github.com/atheycreek/churchdeploy.git/info/refs 所以我把它改成了 [remote "origin"] fetc

我正在使用mac终端并运行线路

git push origin master
每次它都会要求我输入github.com的用户名和密码,
有没有办法让它自动使用我的凭据


我一直在犯错误

error: The requested URL returned error: 403 while accessing 
https://github.com/atheycreek/churchdeploy.git/info/refs

所以我把它改成了

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git:github.com/atheycreek/churchdeploy.git
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com/atheycreek/churchdeploy.git
现在我明白了

kirkstrobeck:churchdeploy kirkstrobeck$ git push origin master
ssh: Could not resolve hostname git: nodename nor servname provided, or not known
fatal: The remote end hung up unexpectedly

我把它改成了

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git:github.com/atheycreek/churchdeploy.git
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com/atheycreek/churchdeploy.git
现在我得到

kirkstrobeck:churchdeploy kirkstrobeck$ git push origin master
fatal: 'git@github.com/atheycreek/churchdeploy.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

使用空密码短语适当地设置ssh密钥,并且无需输入凭据:

使用空密码短语被认为是不好的做法。引述:

密码不是很安全,你已经知道了。如果你用一个 这很容易记住,更容易猜测或使用暴力。如果你 使用一个随机的,很难记住的,因此你更容易记忆 倾向于写下密码。这两个都很糟糕 东西™. 这就是为什么要使用ssh密钥

但是使用不带密码短语的密钥基本上与编写密码相同 在你的计算机上的一个文件中记下那个随机密码。任何获得 访问您的驱动器已获得访问您使用的每个系统的权限 用钥匙。这也是一件非常糟糕的事情™。解决办法显而易见:添加 密码短语


正确的解决方案是使用-这样,Git在每个会话中只会请求您的密码一次。有关如何在系统上设置它的提示,请参阅。

设置API令牌和SSH凭据(密码较少,但最好使用带有代理的密码)


另一个答案中也提供了这方面的说明。具体查看底部的第2步。

从您对事情的描述来看,您的[Project Dir]/.git/config文件是用
url=https…
行设置的,而不是
url=git@github.com...
。你能检查一下那个文件看它写了什么吗?如果你能发布整个“远程来源”部分,那就太好了。它可能看起来像这样:

[remote "origin"]
    url = https://github.com/atheycreek/churchdeploy.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[remote "origin"]
    url = git@github.com:atheycreek/churchdeploy.git
    fetch = +refs/heads/*:refs/remotes/origin/*
但需要使用ssh而不是http,如下所示:

[remote "origin"]
    url = https://github.com/atheycreek/churchdeploy.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[remote "origin"]
    url = git@github.com:atheycreek/churchdeploy.git
    fetch = +refs/heads/*:refs/remotes/origin/*

如果在OSX上,您应该能够使用osxkeychain帮助器。您可以通过键入以下内容检查是否已安装:

git credential-osxkeychain
如果您收到一条消息说这不是有效的git命令,您可以通过执行以下操作来安装它:

curl -s -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
chmod u+x git-credential-osxkeychain
sudo mv git-credential-osxkeychain `dirname \`which git\``
然后告诉git将其用于:

git config --global credential.helper osxkeychain

下次执行拉/推操作时,将要求您再次提供凭据。从那时起,git应该记住你的信息。

他说他在使用mac,所以这本指南更合适:@Eloff-对,谢谢。只是ssh部分几乎是一样的,不起作用。我已经成功地完成了该页面,但它仍然每次都请求凭据@KirkStrobeck-另外,您能确认您正在使用ssh吗?在教程的第5步中,它让您仔细检查它是否工作。我能做到,效果很好。。但是当我运行push命令时,我仍然有auth prompt,这应该在serverfault.com上吗,因为它与管理相关?有任何解决方案吗?我认为这是解决方案,但我在实现它时遇到了困难。不确定理论是否成立。几乎所有能访问我的硬盘的人都可以安装键盘记录器。除非对密码短语的请求来自可能受到危害的用户控制之外的服务器,否则它实际上不会增加额外的保护,但会增加不便,更重要的是,通过鼓励密码重用,可能会泄露本来安全的密码。对我来说,这似乎主要是给人虚假的信心。也不要忘记,自动化不需要密码短语。只是为了澄清一下,您当前的配置应该有一个https url,但您希望它像上面提供的示例一样使用ssh。如果您确实有https url,请将其更改为
url=git@github.com:atheycreek/churchdeploy.git
你应该可以走了。我在顶部更新了我的帖子,我想你可能有什么发现。将其更改为
git@github.com
not
git:github.com
Hey!这就解决了问题!//现在,我如何使它在将来默认情况下以这种方式写入配置?您真的不必做任何事情。从GitHub克隆现有存储库时,请确保使用ssh url。当您在本地创建一个存储库,然后将其添加到GitHub时,一切都已就绪,因为提供的说明使用了ssh url。如果您在Linux中,则说明略有不同,而使用
libgnome keyring dev
credential.helper
。我在博客上贴了一篇详细的说明: