简体   繁体   English

使用HTTP存储git命令的凭据

[英]Store credentials for git commands using HTTP

I would like to store Git credentials for git pulls permenantly on a linux machine, and git credential.helper doesn't work ( I think because I'm not using SSH ) - I get that error "Fatal: could not read password for 'http://....': No such device or address". 我想将git pull的Git凭证永久存储在Linux机器上,并且git credential.helper无法正常工作(我认为是因为我没有使用SSH)-我收到错误消息“致命:无法读取' http:// ....':没有此类设备或地址”。 Given that I'm not the administrator of the repository and only HTTP is allowed for authentication, and fortunately I don't care about the safety of the password. 鉴于我不是存储库的管理员,并且只允许HTTP进行身份验证,幸运的是,我并不关心密码的安全性。 What can I do to put the git pull command in a bash file and avoid prompting the user for password? 如何将git pull命令放在bash文件中,并避免提示用户输入密码?

I hope there is a way around it. 我希望有办法解决。

Two things wrong with this question: 这个问题有两点错误:

  1. Most repositories such as GitHub require HTTPS. 大多数存储库(例如GitHub)都需要HTTPS。 Even if you try to clone over HTTP, it just switches it on the backend to HTTPS and pushes require it as well. 即使您尝试通过HTTP克隆,它也只是将其在后端切换到HTTPS,而推送也需要它。

  2. Pulls don't require a password, unless it's a private repo. 拉取不需要密码,除非它是私人存储库。 Like #1, since you've given no info about your repo it's hard to comment further on this. 像#1一样,由于您没有提供有关回购的任何信息,因此很难对此进一步发表评论。

Now, what I do is this: 现在,我要做的是:

git config --global credential.helper store

Then the first time you push it will ask for your credentials. 然后,第一次按下时,它将要求您提供凭据。 Once you've entered them they are stored in ~/.git-credentials . 输入它们后,它们将存储在~/.git-credentials Note that they are stored in plain text, you have been advised. 请注意,建议您以纯文本格式存储它们。

I'm assuming that your repository requires authentication for pulls, or else git wouldn't ask you for a password for the pull. 我假设您的存储库要求对请求进行身份验证,否则git不会要求您输入请求密码。

The recommended way to bypass the user password prompt is to create an SSH key on that machine, add the public key to the git server, then use the SSH url for the remote instead of the HTTP/S url. 推荐的绕过用户密码提示的方法是在该计算机上创建SSH密钥,将公钥添加到git服务器,然后将SSH URL用于远程而不是HTTP / S URL。 But since you specifically said: 但是,由于您明确地说:

I don't care about the safety of the password 我不在乎密码的安全性

you can actually just specify the password inline for the git pull like this: 您实际上可以只为git pull指定内联密码,如下所示:

git pull http://username:password@mygithost.com/my/repository

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM