Github Access
导言
作为程序员,最经常遇到的问题就是无法访问github,这无异于和世界断开连接。
- 由于http代理可以代理DNS请求,所以不太可能是DNS污染的问题。
- github加速访问两种思路:
- VPN加速
- warp或者wg转发到墙外(linux 服务器)
- 之前能访问,但是现在不能访问,可能是wg配置重启掉了。
Proxy in terminal¶
无法使用ping检查网络,wwww.github.com不会响应ping报文
ssh config¶
linux下通过按照如下修改.ssh/config
设置账号密码,并 ssh -vT [email protected]
,成功后输出Hi Kirrito-k423! You've successfully authenticated, but GitHub does not provide shell access.
。
# .ssh/config
Host github.com
User 943648187@qq.com
Hostname ssh.github.com
PreferredAuthentications publickey
ProxyCommand nc -X 5 -x 127.0.0.1:7890 %h %p #如果通过代理需要这句话
IdentityFile ~/.ssh/id_rsa
Port 443
Host *
# Win报错取消下面三行 getpeername failed: Not a socket getsockname failed: Not a socket
ControlMaster auto
ControlPath /tmp/sshcontrol-%C
ControlPersist 1d
ServerAliveInterval 30
Windows PowerShell 平台
假如是windows下,如果安装了git bash,会有connect.exe
的程序
配置如下1
Host github.com
User git
Port 22
Hostname github.com
# 注意修改路径为你的路径
IdentityFile "C:\Users\Administrator\.ssh\id_rsa"
TCPKeepAlive yes
# 这里的 -a none 是 NO-AUTH 模式,参见 https://bitbucket.org/gotoh/connect/wiki/Home 中的 More detail 一节
ProxyCommand E:\\commonSoftware\\Git\\mingw64\\bin\\connect.exe -S 127.0.0.1:7890 -a none %h %p
Host ssh.github.com
User git
Port 443
Hostname ssh.github.com
# 注意修改路径为你的路径
IdentityFile "C:\Users\Administrator\.ssh\id_rsa"
TCPKeepAlive yes
debug ssh clone/push¶
ssh-git 与 https-git的不同
git config --global http.proxy localhost:7890 # PowerShell proxy
git config --global http.proxy "http://127.0.0.1:7890"
git config --global https.proxy "http://127.0.0.1:7890"
GIT_CURL_VERBOSE=1 GIT_TRACE=1 git clone [email protected]:Kirrito-k423/autoUpdateIpconfigPushGithub.git
Windows PowerShell 平台 git push --verbose
不同于linux平台的GIT_TRACE=1 git push
,Windows PowerShell 平台应该如下设置:
ssh成功,但是git操作还是失败
没使用上指定config
文件,git操作需要明确指定。
http代理¶
There are tons of identical solutions over the internet for defining proxy tunnel for git's downloads like this one, which all is by setting git's https.proxy & http.proxy
config. but those answers are not working when you try to clone/push/pull
etc. over the ssh protocol!
For example, by setting git config --global https.proxy socks5://127.0.0.1:9999
when you try to clone git clone [email protected]:user/repo.git
it does not go through the defined sock5
tunnel!
环境实在是只有https代理, 可以利用github_token的https协议
# Method 1. git http + proxy http
git config --global http.proxy "http://127.0.0.1:1080"
git config --global https.proxy "http://127.0.0.1:1080"
# Method 2. git http + proxy shocks
git config --global http.proxy "socks5://127.0.0.1:1080"
git config --global https.proxy "socks5://127.0.0.1:1080"
# to unset
git config --global --unset http.proxy
git config --global --unset https.proxy
# Method 3. git ssh + proxy http
vim ~/.ssh/config
Host github.com
HostName github.com
User git
ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=1087
# Method 4. git ssh + proxy socks
vim ~/.ssh/config
Host github.com
HostName github.com
User git
ProxyCommand nc -v -x 127.0.0.1:1080 %h %p
%h %p
是host
和post
的意思
或者
After some visiting so many pages, I finally find the solution to my question:
# [step 1] create a ssh-proxy
ssh -D 9999 -qCN [email protected]
# [step 2] make git connect through the ssh-proxy
# [current script only]
export GIT_SSH_COMMAND='ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
# OR [git global setting]
git config --global core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
# OR [one-time only use]
git clone -c=core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"' [email protected]:user/repo.git
# OR [current repository use only]
git config core.sshCommand 'ssh -o ProxyCommand="connect -S 127.0.0.1:9999 %h %p"'
To install connect on Ubuntu:
ssh代理¶
ssh -vT -o "ProxyCommand connect -S 127.0.0.1:7890 %h %p" [email protected]
ssh -vT -o "ProxyCommand nc -X 5 -x 127.0.0.1:7890 %h %p" [email protected]
# 使用HTTP 代理
ssh -o ProxyCommand='corkscrew proxy.net 8888 %h %p' [email protected]
ssh -o ProxyCommand='proxytunnel -p proxy.net:8888 -P username -d %h:%p' [email protected]
Wireguard 代理¶
post request forward is an all-in-one solution.
interface: warp
public key: fcDZCrGbcpz3sKFqhBw7PtdInygUOtEJfPAs08Wwplc=
private key: (hidden)
listening port: 51825
peer: bmXOC+F1FxEMF9dyiK2H5/1SUtzH0JuVo51h2wPfgyo=
endpoint: [2606:4700:d0::a29f:c001]:1701
allowed ips: 172.16.0.0/24, 0.0.0.0/0, ::/0
latest handshake: 89 days, 23 hours, 15 minutes, 28 seconds ago
transfer: 3.51 GiB received, 1.71 GiB sent
persistent keepalive: every 25 seconds
latest handshake: 89 days ago
demonstrate wg is done for a long time. At the same time mtr github.com
shows no output prove the bad situation.
STEP1: first try is to bring the wg-proxy up again
python register.py #自动生成warp-op.conf,warp.conf和warp-helper
mv warp-helper /etc/default
vim /etc/config/network #填写warp-op.conf内容,修改只用替换option private_key 和 ipv6 的 list addresses 即可
ifup warp #启动warp, 代替wg-quick up warp.conf
and test brainiac machine is back online
常见情形¶
大文件提交¶
Sometimes,it‘s the big log fault.
# find file
find . -type f -name "zsim.log.0" -size +10M
# find the most repeated lines
head -n 10000 your_file.txt | sort | uniq -c | sort -nr | head
# delete partten line in files
sed -i '/\[S 0\] WARN: \[6\] ContextChange, reason SIGRETURN, inSyscall 1/d' /staff/shaojiemike/github/PIA_huawei/log/zsim/chai-n/hsti/1000/cpu_tlb/zsim.log.0
# conbine two command
find . -type f -name "zsim.log.0" -size +10M -print0 | xargs -0 sed -i '/字符串模式/d'
# or just save the tail (sth wrong needed test)
find . -type f -name "zsim.log.0" -size +1M -exec bash -c 'tail -n 2000 "$1" > "$1"_back ' _ {} \;
请求被拦截¶
t00906153@A2305023964 MINGW64 ~/github
$ git clone https://github.com/jeremy-rifkin/cpptrace.git
Cloning into 'cpptrace'...
fatal: unable to access 'https://github.com/jeremy-rifkin/cpptrace.git/': SSL certificate problem: self-signed certificate in certificate chain
常见问题¶
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
出现于使用https协议,下载大仓库时,出现该错误。
- 首先使用retry脚本,多重试。
- 脚本中有http下载的限制修改。
- 使用
depth=1
参数,只下载最新提交。之后下好后能适应unshallow
复原 - 使用更快的https代理。 e.g., 华为xgate使用HK或者Auto
expecting SSH2_MSG_KEX_ECDH_REPLY
设置mtu解决:
STEP1:
eno0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 202.38.73.217 netmask 255.255.255.0 broadcast 202.38.73.255
inet6 fe80::ae1f:6bff:fe8a:e4ba prefixlen 64 scopeid 0x20<link>
inet6 2001:da8:d800:811:ae1f:6bff:fe8a:e4ba prefixlen 64 scopeid 0x0<global>
inet6 2001:da8:d800:730:ae1f:6bff:fe8a:e4ba prefixlen 64 scopeid 0x0<global>
ether ac:1f:6b:8a:e4:ba txqueuelen 1000 (以太网)
RX packets 12345942 bytes 2946978044 (2.9 GB)
RX errors 0 dropped 1438318 overruns 0 frame 0
TX packets 4582067 bytes 675384424 (675.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
STEP2:
STEP3: