[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$fMntGGnqC-gB1TA2mYaO8xHhU6_uy65gF5ZtOCiqhYKI":3},{"code":4,"message":5,"data":6},200,"成功",{"id":7,"createdAt":8,"title":9,"content":10,"summary":11,"image":12,"uid":13,"user":14,"categoryId":21,"category":22,"subCategoryId":24,"subCategory":25,"comments":27,"status":17,"reason":28,"notice":28,"visitCount":29,"commentCount":30,"keywords":31},168,"2025-09-09T10:18:10.105Z","ssh -T git@github.com  Connection closed by 127.0.0.1 port 7897","这篇文章，简要介绍当git操作时，git命令提示could not read from remote repository的问题，且终端命令执行ssh -T时，connection被terminated。\n\n## 一、问题：\n在`git pull`时：\n```console\ngit pull\nConnection closed by 127.0.0.1 port 7897\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n\n```\n在`ssh -T git@github.com`时：\n```terminal\nssh -T git@github.com\nConnection closed by 127.0.0.1 port 789\n```\n\n### 1.1 截图：\n![git pull error](https://image.xinwei.ltd/image1757411010326.png)\n\n![ssh error](https://image.xinwei.ltd/image1757411065611.png)\n\n\n## 二、原因\n从上面的问题中可以看出，是自己的电脑127.0.0.1:7897中断了链接，那么问题出现在自己的电脑中。这种情况通常容易出现在科学上网的场景下，需要我们配置本地的代理配置上。\n\n大家应该了解电脑的hosts文件，是允许自定义配置电脑对某些域名、ip访问的文件。\n\n然后对于github而言，都是要求https进行安全访问，那么就涉及到端口号443的配置。\n\n另外github仓库的ssh访问，身份校验也是需要在本地电脑和github上配置访问的ssh 公开/私密 密钥的，并且ssh也是有一个配置文件的。\n\n\n## 三、解决方法\n通过上面的问题分析，我们可以推导出合适的解决方案：我们在ssh的配置文件中，配置好对github的443访问，那么GitHub ssh的身份鉴权问题就能解决，从而git pull等指令和github进行交互时，GitHub就能知道git指令是来自通过了身份鉴权的安全电脑环境，就不会有access right问题。\n\n## 四、操作步骤\n下面的操作是在mac上进行的，目录和文件仅限mac环境。\n\n### 4.1 找到ssh config文件\n- mac上的ssh配置文件，都是在`.ssh`这个文件夹中；\n- `.ssh`文件夹处于mac的资源库目录下，是一个隐藏文件夹(显示隐藏文件及文件夹的操作，大家可以自行搜索一下)；\n- 如果没有config文件，那么就新建一个。\n\n示例：\n![.ssh目录](https://image.xinwei.ltd/image1757412513960.png)\n\n如果没有`config`文件可以新建一个\n```terminal\ntouch config\n```\n\n### 4.2 配置ssh config文件\n```config文件\nHost github.com\n  Hostname ssh.github.com\n  Port 443\n  User git\n  ProxyCommand nc -X 5 -x 127.0.0.1:7897 %h %p\n```\n\n### 4.3 重新验证ssh\n```terminal\nssh -T git@github.com\n```\n![add knowlist](https://image.xinwei.ltd/image1757412925954.png)\n\n执行这步时，就会提示443配置将加到同目录下的`known_hosts`文件中。\n最后那行表示已经成功通过github的ssh身份鉴权，可以使用git相关指令了。\n\n\n至此结束，希望对大家有帮助。\n","这篇文章，简要介绍当git操作时，git命令提示could not read from remote repository的问题，且终端命令ssh -T时，connection被terminated。","https://image.xinwei.ltd/image1757411010326.png",499668042977349,{"phone":15,"userId":13,"nickName":16,"vipType":17,"avatar":18,"sign":19,"createdAt":20},"13121171998","全栈老韩",1,"https://image.xinwei.ltd/images/IMG_5430.JPG","全栈工程师，擅长iOS App开发、前端（vue、react、nuxt、小程序&Taro）开发、Flutter、React Native、后端（midwayjs、golang、express、koa）开发、docker容器、seo优化等。","2024-01-01T16:14:30.305Z",2,{"id":21,"name":23},"IT技术",31,{"id":24,"name":26,"parentId":21},"git&svn",[],"",39,0,"git connection,git ssh,ssh -T,ssh git,github,git,ssh connect"]