Mac OS命令行通过GitHub进行身份验证

时间:2019-07-22 22:28:54

标签: git authentication ssh cocoapods

尝试连接到GitHub验证我的podspec时,我不断收到以下错误消息:

  

致命:无法访问'https://github.com/myAccount/myRepo.git/':无法连接到159.82.13.140端口80:操作超时

这似乎是我与GitHub的特定连接,因为从命令行进行克隆会引发相同的错误:

git clone https://github.com/myAccount/myRepo.git ~/Desktop/testClone
Cloning into '/Users/myAccount/Desktop/project'...
fatal: unable to access 'https://github.com/myAccount/myRepo.git/': Failed to connect to 159.82.13.140 port 80: Operation timed out

通常我通过Xcode管理VCS,这使我可以输入身份验证凭据,但是我意识到我需要设置ssh密钥。

设置完成后,它应该可以工作了:

ssh -T git@github.com
Hi myAccount! You've successfully authenticated, but GitHub does not provide shell access.

但是,尝试运行pod spec lintgit clone时,错误仍然存​​在。我重新启动了终端外壳,作为Mac用户(Mojave),我了解到我需要在~/.ssh/config中创建一个文件,内容如下:

Host github.com
   AddKeysToAgent yes
   UseKeychain yes
   IdentityFile ~/.ssh/id_rsa

对下一步有任何想法吗?

我在KeyChain Access中看不到密钥。不应该在那里吗?如果是这样,我该如何导入?

更新:

尝试使用this article连接生成的令牌;但仍然出现相同的错误。还用这些字段更新了我的配置,这些字段可能没有被指向或其他东西。

Host github.com   
User git
Hostname github.com
PreferredAuthentications ~/.ssh/id_rsa.pub
Port 80
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa

直到尝试使用生成的令牌之前,我都能成功使用ssh -T git@github.com进行ssh插入,但是现在出现以下错误:

ssh_exchange_identification: Connection closed by remote host 

我以某种方式使情况变得更糟?尝试使用以下命令进行重置:

git config --global credential.helper osxkeychain

并且还删除了我的〜/ .ssh目录,但没有提示输入密码,仍然超时失败。

尽管我可以通过直接连接再次成功:

ssh -T git@github.com
The authenticity of host 'github.com (192.30.255.112)' can't be established.
RSA key fingerprint is SHA256.*******
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.255.112' (RSA) to the list of known hosts.
Hi ******! You've successfully authenticated, but GitHub does not provide shell access.

有人有反正我可以重设它并尝试重新开始吗?还是知道为什么我可以使用ssh -T进行身份验证但无法克隆?

确认我仍然可以通过Xcode访问。下载了Github Desktop并进行了身份验证,因为我读到这会有所帮助。仍然没有提示您输入密码。

brew install hub

这提示我输入密码,但仍然超时!!!!

1 个答案:

答案 0 :(得分:2)

git clone https://github.com/myAccount/myRepo.git ~/Desktop/testClone

只要您使用https://...,就可以整天调整SSH配置...它将被忽略。

首先尝试使用 SSH URL:git clone git@github.com:myAccount/myRepo.git,然后查看问题是否仍然存在。