为什么错误从powershell命令行连接到github?

时间:2017-08-20 05:36:42

标签: github visual-studio-code

第一次使用GitHub 在github.com上创建了存储库。现在我想推送到那个存储库。出现“连接失败”错误。

当我运行“ssh -Tv git@github.com”时,我会收到“connection timed out” 并且“ssh -T -p 443 git@ssh.github.com”失败并显示:Permission denied

我关闭了Windows防火墙。同样的错误。

怎么办?如何连接到GitHub?
我正在使用VSCode。使用powershell命令行。

以下是我尝试过的命令:

    PS C:\gitsteve\maker> ssh -Tv git@github.com
OpenSSH_7.1p2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.255.112] port 22.
debug1: connect to address 192.30.255.112 port 22: Connection timed out
debug1: Connecting to github.com [192.30.255.113] port 22.
debug1: connect to address 192.30.255.113 port 22: Connection timed out
ssh: connect to host github.com port 22: Connection timed out

PS C:\gitsteve\maker> git push -u origin master
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

PS C:\gitsteve\maker> ssh -T -p 443 git@ssh.github.com
The authenticity of host '[ssh.github.com]:443 ([192.30.253.123]:443)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[ssh.github.com]:443,[192.30.253.123]:443' (RSA) to the list of known hosts.
Permission denied (publickey).

PS C:\gitsteve\maker> ssh-add -l
Could not open a connection to your authentication agent.

PS C:\gitsteve\maker> ssh -T -p 443 git@ssh.github.com
Warning: Permanently added the RSA host key for IP address '[192.30.253.122]:443' to the list of known hosts.
Permission denied (publickey).

Please make sure you have the correct access rights
and the repository exists.

PS C:\gitsteve\maker> ssh-agent -s
SSH_AUTH_SOCK=/tmp/ssh-W7z0JBkeNSBz/agent.14164; export SSH_AUTH_SOCK;
SSH_AGENT_PID=14148; export SSH_AGENT_PID;
echo Agent pid 14148;

PS C:\gitsteve\maker> ssh-add -l -E md5
Could not open a connection to your authentication agent.

PS C:\gitsteve\maker> ssh -T -p 443 git@ssh.github.com
Permission denied (publickey).

1 个答案:

答案 0 :(得分:1)

如果出于任何原因阻止了SSH,请尝试切换到https网址

 cd /path/to/repo
 git remote set-url origin https://github.com/<username>/<reponame>.git

然后再试一次

 git push -u origin master

然后第一次,它应该需要您的GitHub用户名/密码(与您在私有SSH密钥上设置的密码无关:它需要您的GitHub帐户密码)

如果您安装了Git credential helper (as in this answer),那么这些GitHub凭据将被缓存(这意味着vscode在下次推送时不会再次询问您的用户名/密码)
首先检查git config credential.helper的值:如果看到manager,则无需执行任何操作。