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

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


当前回答

SSH密钥-仍然要求密码和密码短语

如果在Windows上使用PuTTY作为SSH密钥生成器,这个快速而简单的解决方案是我使用普通Windows命令行的唯一工作解决方案:

Your PuTTY installation should come with several executable, among others, pageant.exe and plink.exe When generating a SSH key with PuttyGen, the key is stored with the .ppk extension Run "full\path\to\your\pageant.exe" "full\path\to\your\key.ppk" (must be quoted). This will execute the pageant service and register your key (after entering the password). Set environment variable GIT_SSH=full\path\to\plink.exe (must not be quoted). This will redirect git ssh-communication-related commands to plink that will use the pageantservice for authentication without asking for the password again.

完成了!

注1:本文档警告使用GIT_SHH环境变量设置时的一些特殊情况。我可以用任意数量的附加参数对命令进行推、拉、取,一切都很好地为我工作(不需要像其中建议的那样编写额外的脚本)。

注2:PuTTY安装路径一般在Path中,可以省略。不管怎样,我更喜欢指定完整的路径。

自动化:

在使用git之前,可以从命令行运行以下批处理文件。它说明了设置的用法:

git-init.bat
   @ECHO OFF
   :: Use start since the call is blocking
   START "%ProgramFiles%\PuTTY\pageant.exe" "%HOMEDRIVE%%HOMEPATH%\.ssh\id_ed00000.ppk"
   SET GIT_SSH=%ProgramFiles%\PuTTY\plink.exe

无论如何,我已经在SystemPropertiesAdvanced.exe >中设置了GIT_SSH变量,并将pageant.exe添加为运行注册表键(*)。

(*)添加“运行注册表项>”步骤

run regedit.exe Navigate to HKEY_CURRENT_USER > Software > Microsoft > Windows > CurrentVersion > Run Do (menu) Edit > New > String Value Enter an arbitrary (but unique) name Do (menu) Edit > Modify... (or double-click) Enter the quotes-enclosed path to pageant.exe and public key, e.g., "C:\Program Files\PuTTY\pageant.exe" "C:\Users\username\.ssh\id_ed00000.ppk" (notice that %ProgramFiles% etc. variables do not work in here unless choosing Expandable string value in place of the String value in step 3.).

其他回答

正如在通过SSH从VSTS克隆Git回购中所解释的那样,要求密码!意想不到的

这个问题可能是因为公钥认证失败,所以它要求我的公司帐户的密码。

如果公钥身份验证成功,就不会发生这种情况。

你可以检查id_rsa。酒吧,甚至创建一个新的。

一般来说,下面是允许您使用ssh远程连接到服务器的步骤,无需密码:

创建一对rsa私钥和公钥 $ ssh-keygen -t rsa -b 4096 -C "your comments" 复制您的公钥并登录到远程服务器 将您的公钥添加到.ssh/authorized_keys 如果您的计算机中有多个ssh密钥,您可能需要使用ssh-add添加密钥 $ ssh-add /path/to/private/key 然后尝试ssh到服务器 $ SSH username@your_ip_address

来源:http://diary-of-programmer.blogspot.com/2018/08/tips-how-to-ssh-to-your-digitalocean.html

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)

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

添加没有钥匙串的身份

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

你可以这样做:

ssh-add ~/.ssh/id_rsa 

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

使用钥匙串添加身份

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

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

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

TL;DR需要使用ssh agent。为此,打开终端&在推到git之前,执行 ssh-add 在提示时输入您的密码。

点击这里查看StackExchange的原始答案