当我克隆一个存储库时,我一直有点“忍受”Github总是问我的用户名和密码。我想绕过这一步,因为这是我的工作流中的一个烦恼。

我尝试使用本指南设置SSH密钥(我成功地做到了)。https://help.github.com/articles/generating-ssh-keys,我成功了。

我的问题是,当克隆一个存储库(使用SSH)时,我仍然被要求输入我的github密码和密码短语。我的理解是,在我设置了这个SSH密钥之后,我就不再需要这样做了。

我不知道该问什么,所以我就说说我的目标吧。

我希望能够克隆存储库,而不必一直把我的Github信息。

我的SSH密钥丢失了什么?如果有人能提供一些指导或资源,我会很感激,因为当涉及到GitHub中的SSH身份验证时,我总是感到有点失落。

据我所知,这是一个测试事情是否正常工作的命令,下面是来自我的控制台的输出:

~ $ ssh -T git@github.com
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.

当我输入密码时,应该先失败吗?然后,当我输入密码时,它就通过了。


当前回答

这里所有的答案我都试过了,没有一个管用!我的密码将无法在会话/重新启动我的Mac之间保存。

我从OpenRadar和Twitter上的讨论中发现,苹果故意改变了macOS 10.12 Sierra中SSH -agent的行为,不再自动加载以前的SSH密钥。为了保持与酋长岩相同的行为,我做了以下事情:

ssh-add -K ~/.ssh/id_rsa . sh 注意:将路径更改为您的id_rsa密钥所在的位置。 ssh-add—— 创建(如果存在则编辑)以下~/。ssh /配置文件: 主机* UseKeychain是的 AddKeysToAgent是的 IdentityFile ~ / . ssh / id_rsa

现在我的密码在重启我的Mac之间被记住了!

其他回答

确保您的存储库也使用了ssh

mahtab@mahtab-Lenovo-G50-70:~/my-projects/jenkins- case -2017$ git远程-v 来源git@github.com:eMahtab/jenkins-cje-2017.git(获取) 来源git@github.com:eMahtab/jenkins-cje-2017.git(推送)

不要使用https,如果你的远程使用https,那么它会一直要求密码,即使你已经添加了公钥到Github和添加私钥到ssh-agent。下面将始终要求输入密码

mahtab@mahtab-Lenovo-G50-70:~/my-projects/jenkins- case -2017$ git远程-v 来源https://github.com/eMahtab/jenkins-cje-2017.git(获取) 来源https://github.com/eMahtab/jenkins-cje-2017.git(推送)

如果您使用的Windows和GIT没有第三方工具,并且您的密钥没有密码/密码短语保护,请使用以下方法:

Environment Variable HOME must be set to your user profile (e.g. C:\Users\Laptop) Go to C:\Users\Laptop\.ssh\ folder and edit "config" file (or create the file!) Example: C:\Users\Laptop.ssh\config (note: there is no . at the end!) Add your git-server host to the "config" file like so: #Example host entry Host myhostname.com HostName myhostname.com User git IdentityFile c:/users/laptop/.ssh/id_rsa.pub PasswordAuthentication no Port 422 Save the file and clone the repository like this: git clone ssh://myhostname.com/git-server/repos/picalc.git

您可以为“config”文件主机条目使用额外的配置参数。这些可以在你的本地git安装文件夹中找到,例如。“C: \ Program Files \ Git \ etc \ ssh \ ssh_config”。摘录:

# Host *
#   ForwardAgent no
#   ForwardX11 no
#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Protocol 2
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h

如果你使用的是windows,这对我来说是有效的:

eval `ssh-agent -s`
ssh-add ~/.ssh/*_rsa

它会在第二个命令中询问密码短语,就是这样。

将这些行添加到bash配置文件$HOME/中。bash_profile或$HOME/.bashrc。

我想为那些可能还需要进入的人补充一个答案 密码,因为他们已经设置 身份仅为yes。这可能是由多个密钥和身份文件引起的,这些密钥是git或服务器的密钥。

在我生成密钥并将其复制到服务器后:

ssh-keygen
ssh-copy-id -i ~/.ssh/12gpu_server.pub lerner@192.168.20.160

我发现它不管用。

然后我去检查~/。ssh/config文件,我看到这个在 底:

Host *
IdentitiesOnly yes

然后我在上面加上这个:

Host 12gpu
HostName 192.168.20.160
User lerner
IdentityFile ~/.ssh/12gpu_server

我可以通过输入ssh 12gpu登录。

然后,您可以使用自己喜欢的名称添加多个ssh密钥 只需要在配置中添加上述四行设置即可 文件。

Host是连接到服务器时要输入的名称 晚;主机名是服务器的ip或域名,如github.com;“User”为登录的用户名 在服务器端,比如用户名或git for github或gitlab;而IdentityFile是存储 生成的密钥。

这里所有的答案我都试过了,没有一个管用!我的密码将无法在会话/重新启动我的Mac之间保存。

我从OpenRadar和Twitter上的讨论中发现,苹果故意改变了macOS 10.12 Sierra中SSH -agent的行为,不再自动加载以前的SSH密钥。为了保持与酋长岩相同的行为,我做了以下事情:

ssh-add -K ~/.ssh/id_rsa . sh 注意:将路径更改为您的id_rsa密钥所在的位置。 ssh-add—— 创建(如果存在则编辑)以下~/。ssh /配置文件: 主机* UseKeychain是的 AddKeysToAgent是的 IdentityFile ~ / . ssh / id_rsa

现在我的密码在重启我的Mac之间被记住了!