简体   繁体   English

如何使git clone与ssh一起使用?

[英]How to get git clone working with ssh?

I am a gitnewbie trying to clone my githubrepo with ssh. 我是一个gitnewbie,试图用ssh克隆我的githubrepo。 I followed these steps: https://help.github.com/articles/generating-an-ssh-key/ . 我按照以下步骤操作: https : //help.github.com/articles/generating-an-ssh-key/

Working in a proxy environment so got a gut feeling it might be related to this. 在代理环境中工作使自己感到直觉,这可能与此有关。 When I go:git clone git@github.com:myuser/myrepo.git, i get this error: 当我去:git clone git@github.com:myuser / myrepo.git时,出现此错误:

ssh: connect to host github.com port 22: Connection timed out

How can I fix this error? 如何解决此错误?

You can fix it the same way you'd fix any ssh problem. 您可以用解决任何ssh问题的相同方法来修复它。 Remove Git from the equation and just try to log in using ssh. 从方程式中删除Git,然后尝试使用ssh登录。 If it works you should see something like this. 如果有效,您应该会看到类似这样的信息。

$ ssh git@github.com
PTY allocation request failed on channel 0
Hi schwern! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

If it doesn't work, you need to debug your ssh session. 如果不起作用,则需要调试ssh会话。 Usually you do this by using ssh -v (and you can add more -v 's for more verbosity). 通常,您可以通过使用ssh -v来执行此操作(也可以添加更多的-v以获得更多的详细信息)。

$ ssh -v foo@example.com
OpenSSH_7.1p2, OpenSSL 1.0.2e 3 Dec 2015
debug1: Reading configuration data /opt/local/etc/ssh/ssh_config
debug1: Connecting to example.com [93.184.216.34] port 22.

If it hangs at this point, the either you can't connect to the host at all, or it doesn't have an ssh server listening on port 22, or the port is blocked by a firewall. 如果此时挂起,则可能根本无法连接到主机,或者没有SSH服务器监听端口22,或者该端口已被防火墙阻止。

Since this is Github which definitely has an ssh server and is working for me, I suspect the last one: you're behind a firewall. 由于这是Github,肯定有一个ssh服务器并且在为我工作,我怀疑最后一个:您在防火墙后面。 You can test this by trying to ssh to somewhere else. 您可以尝试通过ssh到其他地方进行测试。

In that case either use a VPN to get around the firewall, or try using an HTTPS connection instead. 在这种情况下,请使用VPN绕过防火墙,或者尝试使用HTTPS连接。

git clone https://github.com/myuser/myrepo.git

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM