如何避免在Windows上使用Git Bash时每次都需要输入解密私钥的密码?
我有一个自动构建服务,可以从 git 私人存储库下载。 问题是,当它尝试克隆存储库时,它需要提供密码,因为它不被记住;因此,由于没有人为交互,它会永远等待密码。 我如何强制它记住 id_rsa.pub?
I've an automatic building service which download from a git private repository.
The problem is that when it tries to clone repository it need to provide the password, because it is not remembered; so because there is no human interaction, it waits forever the password.
How can I force it to remember from id_rsa.pub?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
对于 Windows 用户,请注意,这就是我设置 Git Bash 环境的方式,以便在启动时登录一次。我编辑我的
~/.bashrc
文件:因此,当我启动 Git Bash 时,它看起来像:
现在我可以 ssh 到其他服务器,而无需每次都登录。
For Windows users, just a note that this is how I set up the Git Bash environment to log me in once when I start it up. I edit my
~/.bashrc
file:So when I start Git Bash, it looks like:
And now I can ssh to other servers without logging in every time.
这个答案解释了如何永久存储 GitHub 用户名和密码,而不是 SSH 密钥密码。
在 Windows 中,只需运行
这意味着下次推送时,您将输入您的用户名和 密码像往常一样输入密码,但它们将保存在 Windows 凭据中。之后您无需再次输入它们。
如推送到 GitHub无需每次都输入用户名和密码(Windows 上的 Git Bash)。
This answer explains how to get the GitHub username and password to be stored permanently, not the SSH key passphrase.
In Windows, just run
This means that the next time you push, you'll enter your username and password as usual, but they'll be saved in Windows credentials. You won't have to enter them again, after that.
As in, Push to GitHub without entering username and password every time (Git Bash on Windows).
我不想在打开新终端时输入 SSH 密码;不幸的是starmonkey 的解决方案要求每次会话都输入密码。相反,我在我的
.bash_profile
文件中包含此内容:这也会记住我的新终端会话的密码;当我启动后打开第一个终端时,我只需输入一次。
我想感谢我从哪里得到这个;这是对别人作品的修改,但我不记得它来自哪里。感谢匿名作者!
2019-07-01更新:我认为这一切都是不必要的。现在,我通过确保我的
.bash_profile
文件运行 ssh-agent 来始终保持此功能:然后我设置了一个
ssh
配置文件,如下所示:I prefer not to have to type my SSH passphrase when opening new terminals; unfortunately starmonkey's solution requires the password to be typed in for every session. Instead, I have this in my
.bash_profile
file:This will remember my passphrase for new terminal sessions as well; I only have to type it in once when I open my first terminal after booting.
I'd like to credit where I got this; it's a modification of somebody else's work, but I can't remember where it came from. Thanks anonymous author!
Update 2019-07-01: I don't think all this is necessary. I now consistently have this working by ensuring my
.bash_profile
file runs the ssh-agent:Then I set up an
ssh
configuration file like this:如果我正确理解这个问题,您已经在构建服务中使用了授权的 SSH 密钥,但您想避免为每个克隆键入密码?
我可以想到两种方法来执行此操作:
如果您的构建服务是以交互方式启动的:在启动构建服务之前,以足够长的超时启动
ssh-agent
(- t
选项)。然后在启动构建服务之前使用 ssh-add (msysGit 应该有这些)添加您需要的所有私钥。您仍然需要输入所有密码,但每次服务启动只需输入一次。如果您想完全避免输入密码,您可以随时从 SSH 密钥中删除密码,如 https://serverfault.com/questions/50775/how-do-i-change-my-private-key-passphrase< /em>,通过设置一个空的新密码。这应该完全消除密码提示,但它比以前的选项更不安全。
If I understand the question correctly, you're already using an authorized SSH key in the build service, but you want to avoid having to type the passphrase for every clone?
I can think of two ways of doing this:
If your build service is being started interactively: Before you start the build service, start
ssh-agent
with a sufficiently long timeout (-t
option). Then usessh-add
(msysGit should have those) to add all the private keys you need before you start your build service. You'd still have to type out all the passphrases, but only once per service launch.If you want to avoid having to type the passphrases out at all, you can always remove the passphrases from the SSH keys, as described in https://serverfault.com/questions/50775/how-do-i-change-my-private-key-passphrase, by setting an empty new passphrase. This should do away with the password prompt entirely, but it is even less secure than the previous option.
当我尝试推送我的代码时,出现以下错误:
经过几个小时的研究,我发现我需要使用以下命令:
执行上述命令后,我收到输入 GitHub 用户名和密码的提示。提供正确的凭据后,我就可以推送我的代码。
When I tried to push my code, I got the below error:
After a few hours of research, I found I need to use the below command:
After executing the above command, I got the prompt for entering my GitHub username and password. After providing the correct credentials, I am able to push my code.
正确的解决方案是:
运行 Windows 默认终端 - cmd 并获取主配置文件的目录
在上面的目录中运行 Git Bash 并使用以下命令创建
.bashrc
文件< /p>使用您喜欢的文本打开
.bashrc
文件编辑器并粘贴来自 GitHub 帮助的代码进入该文件:重新启动 Git Bash,它会要求您输入密码(仅限第一次)并完成。不再需要密码麻烦。
The right solution is:
Run the Windows default terminal - cmd and get the directory of your master profile
Run Git Bash in the directory above and create the
.bashrc
file with the commandOpen the
.bashrc
file with your favourite text editor and paste code from GitHub Help into that file:Restart Git Bash and it asks you for your password (only first time) and done. No password bothering again.
您需要在要连接到存储库服务器的用户的
.ssh
文件夹下创建authorized_keys
文件。例如,假设您在repo.server
上使用用户名buildservice
,您可以运行:然后您必须检查以下内容:
对应的
id_rsa 私钥位于
[email protected]:~/.shh/id_rsa
。repo.server 的指纹存储在
[电子邮件受保护]:~/.ssh/known_hosts
文件。通常,这将在第一次尝试ssh
连接到repo.server
后完成。You need to create the
authorized_keys
file under the.ssh
folder of the user under which you are going to connect to the repository server. For example, assuming you use usernamebuildservice
onrepo.server
you can run:Then you have to check the following things:
That corresponding
id_rsa
private key is presented in[email protected]:~/.shh/id_rsa
.That fingerprint of repo.server is stored in the
[email protected]:~/.ssh/known_hosts
file. Typically that will be done after the first attempt ofssh
to connect to therepo.server
.