天天看點

Git 多賬戶登入及代理配置

ssh 秘鑰别名登入

/etc/ssh/ssh_config

~/.ssh/config

中輸出以下行 (若檔案不存在,建立即可)

Host dev
    HostName www.ex.com
    User root
           

然後使用

ssh dev

即可登入至遠端伺服器

詳見ssh 秘鑰别名登入

git多賬戶

同上,在

/etc/ssh/ssh_config

~/.ssh/config

中配置git多賬戶登入

# 配置github.com
Host github.com                 
    HostName github.com
    IdentityFile C:\\Users\\god\\.ssh\\id_rsa_github
    PreferredAuthentications publickey
    User tillend

# 配置git.oschina.net 
Host git.oschina.net 
    HostName git.oschina.net
    IdentityFile C:\\Users\\god\\.ssh\\id_rsa_oschina
    PreferredAuthentications publickey
    User tillend
           

顯示對應賬戶

$ ssh -T [email protected]
Hi tillend! You've successfully authenticated, but GitHub does not provide shell access.
           
在使用時需要注意,不能設定全局的

username

email

# 取消全局 username, email
git config --global --unset user.name
git config --global --unset user.email
           

git代理

http代理

指令形式

git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
           

配置形式

Host github.com
    HostName github.com
    User root
    ProxyCommand connect -H 127.0.0.1:1080 %h %p 
    # ProxyCommand connect -S 127.0.0.1:1080 %h %p (socks5)
           

ssh代理

配置形式

Host github.com
    HostName github.com
    User root
    ProxyCommand nc -v -x 127.0.0.1:1080 %h %p
           

參考資料:

1.ssh 秘鑰别名登入

2.Windows Git多賬号配置