亲测有效解决ssh: connect to host github.com port 22: Connection timed out问题
- 百度一直说的密钥问题,修改了依然没解决,后来发现添加几行代码到Git的位置就好了,话不多说上解决方案。
1.问题
运行hexo g -d
就报如下错误
On branch master
nothing to commit, working tree clean
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.
FATAL {
err: Error: Spawn failed
at ChildProcess.<anonymous> (D:\hexo\GitHub\blog\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:51:21)
at ChildProcess.emit (events.js:315:20)
at ChildProcess.cp.emit (D:\hexo\GitHub\blog\node_modules\cross-spawn\lib\enoent.js:34:29)
at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12) {
code: 128
}
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.htmlxxxxxxxxxx On branch masternothing to commit, working tree cleanssh: connect to host github.com port 22: Connection timed outfatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.FATAL { err: Error: Spawn failed at ChildProcess.<anonymous> (D:\hexo\GitHub\blog\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:51:21) at ChildProcess.emit (events.js:315:20) at ChildProcess.cp.emit (D:\hexo\GitHub\blog\node_modules\cross-spawn\lib\enoent.js:34:29) at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12) { code: 128 }} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.htmlhexo g -djava
2.分析
当出现:ssh: connect to host github.com port 22: Connection timed out时,这表明连接超时
3.解决方法
连接超时,首先找到git的安装目录,找到/etc/ssh/ssh_config文件,使用记事本打开它。
把如下内容复制到ssh_config文件的末尾处:并记得保存。
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
添加完成后如下图
再输入
hexo g -d
,完美解决。希望能帮到你