使用 https 连接 github。
Error 今天 push 不上 github ,很郁闷。胡乱检查了一通。
1 2 3 4 5 6 7 8 9 10 11 ssh -vT git@github.com OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f 31 Mar 2020 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files debug1: /etc/ssh/ssh_config line 21: Applying options for * debug1: Connecting to github.com [::1] port 22. debug1: connect to address ::1 port 22: Connection refused debug1: Connecting to github.com [127.0.0.1] port 22. debug1: connect to address 127.0.0.1 port 22: Connection refused ssh: connect to host github.com port 22: Connection refused
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 nslookup github.com Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: Name: github.com Address: 127.0.0.1 Name: github.com Address: ::1 nslookup -query=ns github.com Server: 127.0.0.53 Address: 127.0.0.53#53 Non-authoritative answer: github.com nameserver = ns-520.awsdns-01.net. github.com nameserver = dns1.p08.nsone.net. github.com nameserver = dns3.p08.nsone.net. github.com nameserver = ns-1283.awsdns-32.org. github.com nameserver = dns2.p08.nsone.net. github.com nameserver = ns-421.awsdns-52.com. github.com nameserver = ns-1707.awsdns-21.co.uk. github.com nameserver = dns4.p08.nsone.net. Authoritative answers can be found from:
dig 一下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ping github.com PING github.com(ip6-localhost (::1)) 56 data bytes 64 字节,来自 ip6-localhost (::1): icmp_seq=1 ttl=64 时间=0.056 毫秒 64 字节,来自 ip6-localhost (::1): icmp_seq=2 ttl=64 时间=0.098 毫秒 64 字节,来自 ip6-localhost (::1): icmp_seq=3 ttl=64 时间=0.164 毫秒 64 字节,来自 ip6-localhost (::1): icmp_seq=4 ttl=64 时间=0.103 毫秒 dig github.com ; <<>> DiG 9.16.1-Ubuntu <<>> github.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32912 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 65494 ;; QUESTION SECTION: ;github.com. IN A ;; ANSWER SECTION: github.com. 275 IN A 127.0.0.1 ;; Query time: 0 msec ;; SERVER: 127.0.0.53#53(127.0.0.53) ;; WHEN: 五 5月 27 17:49:36 CST 2022 ;; MSG SIZE rcvd: 55
github 的 a 记录是 127.0.0.1 ,怎么看都不对啊。DNS 污染了。
然后看了一下 hosts , 没有 github.com 的。我也懒得加了,毕竟总是会被干扰,干脆直接用 https 连接算了。
https 看了眼文档,本来以为帐号密码就可以登录的了,结果更新成令牌了。问题不大。
令牌 在 github 的个人 setting
的 developer settings
里找到 Personal access tokens
,new 一个就行,有效期和权限视需求随便勾了几个。然后记录下显示的令牌。
连接 原来的 ssh 算是废了,代理也不想折腾了。换 https ,官方也推荐。push 不上就多来几次,毕竟走的系统代理。
1 2 3 4 git remote -v git remote rm origin git remote add origin https://your_repo_adress git push -u origin main
缓存 不能每次都要打帐号密码吧,不能明文存个令牌吧。那就缓存进去好了。
1 git config --global credential.helper store
hosts 当然了,修改host也是可以的
win10 hosts 文件在 C:\WINDOWS\system32\drivers\etc
,管理员打开命令行,notepad hosts
,末尾添加 140.82.113.4 github.com
Linux hosts 文件一般在 /etc/hosts
,sudo 添加即可。
在 win10 测试了修改 hosts 之后 ssh 还是可以正常连接的,,不过我不想用了。