關(guān)于 Git 使用 Proxy , 網(wǎng)上很多教程講的都是 如何設(shè)置 Http 下 Git 使用 Proxy , 但是并沒有提到 SSH 下如何使用 Proxy . 即便有些文章講到了, 也有不少是 Windows 平臺(tái)下的, Linux 平臺(tái)下的很少提及, 所以這里就記錄一下, 如何在 Ubuntu 中, 使用 Git 在 SSH 協(xié)議下應(yīng)用代理.
# 如何設(shè)置 git http proxy
$ git config --global http.proxy http://127.0.0.1:1080
$ git config --global https.proxy http://127.0.0.1:1080
$ cat ~/.gitconfig
[http]
proxy = http://127.0.0.1:1080
[https]
proxy = http://127.0.0.1:1080
Ncat
首先你需要 安裝一個(gè) Ncat 工具, 在 Ubuntu 下這樣安裝即可,
$ sudo apt install ncat -y
ncat 和 nc 類似, 都是用于在兩臺(tái)電腦之間建立連接并返回?cái)?shù)據(jù), nc 是 netcat 的 OpenBSD 實(shí)現(xiàn), 而 ncat 是從 nmap 項(xiàng)目抽離出來的 netcat 實(shí)現(xiàn).
如果想看更加詳細(xì)的介紹, 可以點(diǎn)擊下面的鏈接 或者 在 Google 查詢
10 個(gè)例子教你學(xué)會(huì) ncat (nc) 命令
What are the differences between ncat, nc and netcat?
Linux每天一個(gè)命令:nc/ncat
為 SSH 設(shè)置代理,
為 Git 以 ssh 的方式拉取項(xiàng)目設(shè)置代理的實(shí)質(zhì), 其實(shí)就是為 ssh config 中的 github.com
設(shè)置代理, 那么說到為ssh設(shè)置代理, 自然繞不開 ~/.ssh/config,
我們需要在 ~/.ssh/config 中加入如下內(nèi)容:
Host github.com
User git
Hostname github.com
ProxyCommand /usr/bin/ncat --proxy 127.0.0.1:1080 --proxy-type http %h %p
# 如果你的代理使用的協(xié)議是 socks4/5 , 修改 --proxy-type 后面的協(xié)議即可, 例如
# --proxy-type socks4
# --proxy-type socks5
接著嘗試用 git 用戶 SSH 連接 Github.com
$ ssh -T git@github.com
# 如果輸出以下內(nèi)容則代表成功.
Hi Kuri-su! You've successfully authenticated, but GitHub does not provide shell access.
Success !!
Part of the content reference from
https://blog.systemctl.top/2017/2017-09-28_set-proxy-for-git-and-ssh-with-socks5/文章來源:http://www.zghlxwxcb.cn/news/detail-812929.html
https://kuricat.com/gist/git-use-ssh-protocal-with-proxy-in-ubuntu-6cv0p/文章來源地址http://www.zghlxwxcb.cn/news/detail-812929.html
到了這里,關(guān)于Git 在 SSH 協(xié)議下使用代理的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!