当我克隆一个存储库时,我一直有点“忍受”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.

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


当前回答

如果您使用的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

其他回答

github上的这个页面有你需要的答案。你必须从https切换到ssh认证。

检查它是如何验证的,如下所示。

$ git remote -v
> origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
> origin  https://github.com/USERNAME/REPOSITORY.git (push)

使用git remote set-url命令将远程服务器的URL从HTTPS更改为SSH。

$ git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

再次使用

$ git remote -v
# Verify new remote URL
> origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
> origin  git@github.com:USERNAME/REPOSITORY.git (push)

这是所有。它现在可以工作了。

我必须执行:

eval `ssh-agent -s`
ssh-add

注意:每次重新启动后,您都必须再次执行此操作。如果你想避免它,那就把它写进你的"。bashrc"文件,位于C:\Users\<<USERNAME>>\。Bashrc在窗户上。它可能是隐藏的,所以请确保您可以看到隐藏的文件。

这里找到了解决方案。

添加没有钥匙串的身份

有时,您可能不希望密码短语存储在密钥链中,但又不想一次又一次地输入密码短语。

你可以这样做:

ssh-add ~/.ssh/id_rsa 

这将询问您的密码,输入它,它不会再问,直到您重新启动。

使用钥匙串添加身份

正如@dennis在评论中指出的那样,通过将密码保存在你的钥匙串中,你可以在添加这样的身份时使用——apple-use-keychain选项(Ubuntu的-k):

ssh-add --apple-use-keychain ~/.ssh/id_rsa

再一次,它将要求您输入密码,输入它,这一次它将不再要求您输入这个身份。

在Mac OSX上,您可以使用以下命令将您的私钥添加到keychain:

ssh-add -K /path/to/private_key

如果您的私钥存储在~/。SSH,命名为id_rsa:

ssh-add -K ~/.ssh/id_rsa

然后系统会提示您输入密码,该密码将存储在您的钥匙串中。

编辑-处理重启

为了在重新启动后也不必填写密码,在ssh配置文件中添加以下内容(通常位于~/.ssh/config)

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa

尝试ssh-agent,请参见:https://help.github.com/articles/working-with-ssh-key-passphrases