Git 从命令行询问密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4731059/
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 asking for password from command line
提问by erich
I setup git and gitosis on a server to manage my repos. It's working properly for the initial shell account I set it up with, i.e. I can run:
我在服务器上设置了 git 和 gitosis 来管理我的存储库。它适用于我设置的初始 shell 帐户,即我可以运行:
git clone git@MYSERVER:gitosis-admin.git
But when I try to use the separate accounts I've created (via gitosis.conf) it keeps asking for a password:
但是当我尝试使用我创建的单独帐户(通过 gitosis.conf)时,它不断要求输入密码:
git clone johndoe@MYSERVER:gitosis-admin.git
I setup the SSH key and pushed a copy to the keydir on the server. This question seems to address the same problem, but the solution given is for tortoisegit.
我设置了 SSH 密钥并将副本推送到服务器上的 keydir。这个问题似乎解决了同样的问题,但给出的解决方案是针对 tortoisegit。
How do I tell git to use the ssh key instead of asking for a password?
我如何告诉 git 使用 ssh 密钥而不是要求输入密码?
回答by ebneter
You don't use your user name, you always say:
你不用你的用户名,你总是说:
git clone git@MYSERVER:<repository>
Gitosis associates your name in its config file with the name of your key on the server. That is, you have lines like
Gitosis 将您在其配置文件中的名称与您在服务器上的密钥名称相关联。也就是说,你有像
[group users]
members = johndoe janeroe
writable = repo1 repo2
in gitosis.conf, and files johndoe.pub, janedoe.pub in gitosis-admin/keydir; gitosis will use the appropriate key for the user but you always use "git" as the user in the URL. That's because it's always using the "git" account.
在 gitosis.conf 中,以及在 gitosis-admin/keydir 中的文件 johndoe.pub、janedoe.pub;gitosis 将为用户使用适当的密钥,但您始终在 URL 中使用“git”作为用户。那是因为它始终使用“git”帐户。
回答by Walter Mundt
Well, I just read about gitosis, and AFAICT you should never ever be cloning from johndoe@MYSERVER
when using it. Always clone from git@
, and make sure your ssh keys are set up correctly so that the server can use those to differentiate (for example) johndoe from janedoe.
好吧,我刚刚读了关于 gitosis 的文章,而且 AFAICTjohndoe@MYSERVER
在使用它时永远不应该克隆它。始终从 克隆git@
,并确保您的 ssh 密钥设置正确,以便服务器可以使用这些密钥来区分(例如)johndoe 和 janedoe。
What you do on the client side is add johndoe's SSH key to your keychain, remove any others the server will accept, and set your git user and email settings to id you as johndoe. The server will compare the two, see that they match, and let you commit. If you configure SSH to use someone else's key and then try to commit as johndoe with git, you may be able to connect to the server, but it will not let you proceed with a commit.
您在客户端所做的是将 johndoe 的 SSH 密钥添加到您的钥匙串中,删除服务器将接受的任何其他密钥,并将您的 git 用户和电子邮件设置设置为将您标识为 johndoe。服务器将比较两者,查看它们是否匹配,然后让您提交。如果您将 SSH 配置为使用其他人的密钥,然后尝试使用 git 以 johndoe 的身份提交,您可能能够连接到服务器,但它不会让您继续提交。
OTOH, because gitosis does not create actual user accounts, you can't ssh as johndoe into the machine, which also means you can't use johndoe@... addresses for the repository in git. If you need to do that, you'll have to set your git server up another way.
OTOH,因为 gitosis 不会创建实际的用户帐户,所以你不能以 johndoe 的身份进入机器,这也意味着你不能在 git 中使用 johndoe@... 地址作为存储库。如果你需要这样做,你必须以另一种方式设置你的 git 服务器。