? ? ? ? 大家好,我是jstart千語。最近在將項目推送到github的時候,突然github就拒絕訪問了,即使掛了VPN,網頁也進不去,通過git也不能把代碼推送上去。
? ? ? ? 即使后面看別人的一些解決方案,比如取消代理啊、更換ssh的方式、該22端口號為443等等,通通都解決不了。
具體報錯如下:
使用https的方式推送:
fatal: unable to access 'https://github.com/js***018/qi*********ackend.git/': Failed to connect to github.com port 443 after 21031 ms: Couldn't connect to server
改用SSH的方式推送:?
ssh: connect to host ssh.github.com port 22: Connection refused
fatal: Could not read from remote repository.Please make sure you have the correct access rights
and the repository exists.
改用443端口也報了這個錯誤:?
ssh: connect to host ssh.github.com port 443: Connection refused
fatal: Could not read from remote repository.Please make sure you have the correct access rights
and the repository exists.
后面通過更改host文件
添加了一些git配置,結果:github網頁可以正常訪問,但本地代碼還是推送不上去
秘鑰正常運行情況
使用命令
ssh-add -l # 查看已加載密鑰
ssh-add ~/.ssh/id_rsa # 手動加載密鑰
報錯:
Could not open a connection to your authentication agent.
這表明 SSH 認證代理(
ssh-agent
)沒有正常運行。ssh-agent
?用于管理 SSH 私鑰,在使用?ssh-add
?命令時需要它處于運行狀態。
使用命令解決:?
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
?但最終還是不能成功推送代碼上去
連接github的debug日志
使用命令:
ssh -T git@github.com -v # -v參數顯示詳細過程
報錯信息:
OpenSSH_9.7p1, OpenSSL 3.2.1 30 Jan 2024
debug1: Reading configuration data /c/Users/28435/.ssh/config
debug1: /c/Users/28435/.ssh/config line 1: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to ssh.github.com [127.0.0.1] port 443.
debug1: connect to address 127.0.0.1 port 443: Connection refused
debug1: Connecting to ssh.github.com [::1] port 443.
debug1: connect to address ::1 port 443: Connection refused
ssh: connect to host ssh.github.com port 443: Connection refused
調試信息來看,問題出在 SSH 客戶端嘗試連接?
ssh.github.com
?的 443 端口時,卻連接到了本地回環地址?127.0.0.1
(IPv4)和?::1
(IPv6),并且連接被拒絕,這通常意味著 DNS 解析出現了錯誤。
解決:
一、清除host相關錯誤配置
hosts 文件位于 C:\Windows\System32\drivers\etc\hosts。你可以使用文本編輯器(需以管理員身份運行)打開該文件,查看是否存在關于 ssh.github.com 的錯誤配置。若有,將其刪除或注釋掉。
二、更改 DNS 服務器
使用公共 DNS 服務器,如 Google 的 DNS(8.8.8.8 和 8.8.4.4)或者阿里云的 DNS(223.5.5.5 和 223.6.6.6)。
Windows系統:
打開 “控制面板”,選擇 “網絡和 Internet” -> “網絡連接”。(或直接搜索“網絡連接”)
右鍵點擊你正在使用的網絡連接,選擇 “屬性”。
在 “此連接使用下列項目” 列表中,選中 “Internet 協議版本 4 (TCP/IPv4)”,然后點擊 “屬性”。
選擇 “使用下面的 DNS 服務器地址”,輸入公共 DNS 服務器地址。
macOS 系統
- 打開 “系統偏好設置”,選擇 “網絡”。
- 選擇你正在使用的網絡連接,點擊 “高級”。
- 在 “DNS” 選項卡中,點擊 “+” 號添加公共 DNS 服務器地址。
總之,進入類似這樣的界面:
?具體更改情況:
驗證是否解決:
再次輸入命令:
ssh -T git@github.com -v # -v參數顯示詳細過程
日志:
嘗試推送代碼:成功