git SSH 密钥 - 仍然要求输入密码和密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21095054/
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
SSH Key - Still asking for password and passphrase
提问by HelloWorld
I've been somewhat 'putting up' with Github always asking for my username and password when I clone a repository. I want to bypass this step because it is an annoyance within my workflow.
当我克隆一个存储库时,我对 Github 总是要求我的用户名和密码有点“忍受”。我想绕过这一步,因为它是我工作流程中的一个烦恼。
I tried setting up an SSH key (which I successfully did) using this guide. https://help.github.com/articles/generating-ssh-keysand I was successful.
我尝试使用本指南设置 SSH 密钥(我成功地做到了)。https://help.github.com/articles/generating-ssh-keys我成功了。
My problem is that I am still asked for my github password and passphrase when cloning a repository (using SSH). My understanding was that after I set up this SSH key, I would no longer have to do that.
我的问题是,在克隆存储库(使用 SSH)时,仍然要求我提供 github 密码和密码。我的理解是,在我设置了这个 SSH 密钥之后,我就不再需要这样做了。
I am a little unsure what to ask, so I will just state my goal.
我有点不确定要问什么,所以我只是陈述我的目标。
I want to be able to clone repositories without having to put in my Github information all the time.
我希望能够克隆存储库而不必一直输入我的 Github 信息。
What am I missing with my SSH key? If anyone can provide some guidance or resources I would appreciate it, because I've always felt a little lost when it came to SSH authentication in GitHub.
我的 SSH 密钥缺少什么?如果有人可以提供一些指导或资源,我将不胜感激,因为在 GitHub 中进行 SSH 身份验证时,我总是感到有些迷茫。
From my knowledge, this is a command that tests if things are working properly, here are the output from my console:
据我所知,这是一个测试事情是否正常工作的命令,这是我的控制台的输出:
~ $ ssh -T [email protected]
Saving password to keychain failed
Enter passphrase for key '/Users/MYNAME/.ssh/id_rsa':
Hi MYNAME! You've successfully authenticated, but GitHub does not provide shell access.
When I input my password, should that fail first? Then, when I enter my passphrase, it passes.
当我输入密码时,应该先失败吗?然后,当我输入密码时,它就通过了。
采纳答案by Simon Boudrias
If you work with HTTPs
urls, it'll always ask for your username / password.
如果您使用HTTPs
url,它总是会询问您的用户名/密码。
If you're correctly using SSH
when cloning / setting remotes. Then make sure you have a ssh-agent to remember your password. That way, you'll only enter your passphrase once by terminal session.
如果您SSH
在克隆/设置遥控器时正确使用。然后确保您有一个 ssh-agent 来记住您的密码。这样,您只能通过终端会话输入一次密码。
If it is still too annoying, then simply set a ssh-key without passphrase.
如果它仍然太烦人,那么只需设置一个没有密码短语的 ssh-key。
回答by Komu
Add Identity without Keychain
添加没有钥匙串的身份
There may be times in which you don't want the passphrase stored in the keychain, but don't want to have to enter the passphrase over and over again.
有时您可能不想将密码存储在钥匙串中,但又不想一遍又一遍地输入密码。
You can do that like this:
你可以这样做:
ssh-add ~/.ssh/id_rsa
This will ask you for the passphrase, enter it and it will not ask again until you restart.
这将要求您输入密码,输入它,直到您重新启动它才会再次询问。
Add Identity Using Keychain
使用钥匙串添加身份
As @dennis points out in the comments, to persist the passphrase through restarts by storing it in your keychain, you can use the -K
option (-k
for Ubuntu) when adding the identity like this:
正如@dennis 在评论中指出的那样,要通过将密码存储在钥匙串中来通过重新启动来保留密码,您可以在添加如下身份时使用该-K
选项(-k
对于 Ubuntu):
ssh-add -K ~/.ssh/id_rsa
Once again, this will ask you for the passphrase, enter it and this time it will never ask again for this identity.
再一次,这将要求您输入密码,输入它,这一次它永远不会再询问此身份。
回答by Groot
On Mac OSX you can add your private key to the keychain using the command:
在 Mac OSX 上,您可以使用以下命令将您的私钥添加到钥匙串中:
ssh-add -K /path/to/private_key
If your private key is stored at ~/.ssh and is named id_rsa:
如果您的私钥存储在 ~/.ssh 并命名为 id_rsa:
ssh-add -K ~/.ssh/id_rsa
You will then be prompted for your password, which will be stored in your keychain.
然后系统会提示您输入密码,该密码将存储在您的钥匙串中。
Edit - Handle restart
编辑 - 处理重启
In order to not have to fill in your password even after a restart add the following to your ssh configuration file (commonly located at ~/.ssh/config)
为了即使在重新启动后也不必填写密码,请将以下内容添加到 ssh 配置文件(通常位于 ~/.ssh/config)
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
回答by ChrisJF
I tried all the answers here and none of these answers worked! My password would not persist between sessions/restarts of my Mac.
我在这里尝试了所有答案,但这些答案都不起作用!我的密码不会在我的 Mac 的会话/重新启动之间保留。
What I found out from reading this OpenRadarand this Twitter discussionwas that Apple purposely changed the behaviourfor ssh-agent in macOS 10.12 Sierra to no longer automatically load the previous SSH keys. In order to maintain the same behaviour as El Cap I did the following:
我从阅读这个 OpenRadar和这个 Twitter 讨论中发现,Apple 故意改变了macOS 10.12 Sierra 中 ssh-agent的行为,不再自动加载以前的 SSH 密钥。为了保持与 El Cap 相同的行为,我执行了以下操作:
ssh-add -K ~/.ssh/id_rsa
Note: change the path to where your id_rsa key is located.ssh-add -A
Create (or edit if it exists) the following
~/.ssh/config
file:Host * UseKeychain yes AddKeysToAgent yes IdentityFile ~/.ssh/id_rsa
ssh-add -K ~/.ssh/id_rsa
注意:将路径更改为您的 id_rsa 密钥所在的位置。ssh-add -A
创建(或编辑,如果存在)以下
~/.ssh/config
文件:Host * UseKeychain yes AddKeysToAgent yes IdentityFile ~/.ssh/id_rsa
And now my password is remembered between restarts of my Mac!
现在我的密码在我的 Mac 重新启动之间被记住了!
回答by sudo bangbang
You can remove passphrase for the key
您可以删除密钥的密码
$ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]
or you can run
或者你可以运行
$ ssh-keygen -p
you get a prompt for keyfile. By default it ~/.ssh/id_rsa
so press enter
您会收到输入密钥文件的提示。默认情况下它~/.ssh/id_rsa
所以按回车
You'll be prompted for current pass phrase enter it.
系统会提示您输入当前的密码短语。
Then there will be a prompt for new pass phrase, press enter
然后会提示输入新密码,按回车
回答by user3640130
Just run the following command:
只需运行以下命令:
ssh-add -K
It will never ask you to enter the password again.
它永远不会要求您再次输入密码。
回答by Mahtab Alam
Make sure you are using ssh for your repository also
确保您的存储库也使用 ssh
mahtab@mahtab-Lenovo-G50-70:~/my-projects/jenkins-cje-2017$ git remote -v
origin [email protected]:eMahtab/jenkins-cje-2017.git (fetch)
origin [email protected]:eMahtab/jenkins-cje-2017.git (push)
mahtab@mahtab-Lenovo-G50-70:~/my-projects/jenkins-cje-2017$ git remote -v
origin [email protected]:eMahtab/jenkins-cje-2017.git (fetch)
origin [email protected]:eMahtab/jenkins-cje-2017.git (push)
Don't use https, if your remote is using https then it will keep asking for password, even If you have added the public key to Github and added private key to ssh-agent. Below will always ask for password
不要使用 https,如果您的遥控器使用 https,那么它会不断询问密码,即使您已将公钥添加到 Github 并将私钥添加到 ssh-agent。下面总是会要求输入密码
mahtab@mahtab-Lenovo-G50-70:~/my-projects/jenkins-cje-2017$ git remote -v
origin https://github.com/eMahtab/jenkins-cje-2017.git (fetch)
origin https://github.com/eMahtab/jenkins-cje-2017.git (push)
mahtab@mahtab-Lenovo-G50-70:~/my-projects/jenkins-cje-2017$ git remote -v
origin https://github.com/eMahtab/jenkins-cje-2017.git (fetch)
origin https://github.com/eMahtab/jenkins-cje-2017.git (push)
回答by Black
I had to execute:
我必须执行:
eval `ssh-agent -s`
ssh-add
Note: You will have to do this again after every restart. If you want to avoid it, then enter it in your ".bashrc" file which is in C:\Users\<<USERNAME>>\.bashrc
on windows. It is probably hidden, so make sure that you can see hidden files.
注意:每次重新启动后,您都必须再次执行此操作。如果您想避免它,请在 Windows 上的“ .bashrc”文件中输入它C:\Users\<<USERNAME>>\.bashrc
。它可能是隐藏的,因此请确保您可以看到隐藏的文件。
Solution found here.
解决方案在这里找到。
回答by Marina
If you're using windows, this worked for me:
如果您使用的是 Windows,这对我有用:
eval `ssh-agent -s`
ssh-add ~/.ssh/*_rsa
It'll ask for passphrase in the second command, and that's it.
它会在第二个命令中要求输入密码,仅此而已。