LoginSignup
48
43

More than 5 years have passed since last update.

22番ポートが使えなくても、SSHでGitしたい!

Posted at

SSHでGit使ってると、ファイアーウォールやプロキシ環境でいらいらしますよね。
でも主要なサイト(GitHub,GitLab,Bitbucket)なら実は443ポートでSSHできちゃったりするんです。
でも、調べても正しい情報がなかなか出てこなかったりするので自分へのメモ用に残して残しておくことにしました。

使い方は簡単!以下のコンフィグを自分仕様に合わせて書くだけ!
(hoge.proxy.jpをプロキシサーバーのURLにして1080のとこはポート番号を入れてください)

Windowsの場合

Git Bash使っている場合(CMDは多分ダメ)

connectが入っているのでこれを使います。他の環境は調査してませんが似たような感じでいけると思います。

~/.ssh/config
Host github.com
    User git
    Hostname ssh.github.com
    IdentityFile ~/.ssh/id_rsa
    Port 443
    ProxyCommand connect.exe -H hoge.proxy.jp:1080 %h %p

Host bitbucket.org
    User git
    IdentityFile ~/.ssh/id_rsa
    HostName altssh.bitbucket.org
    Port 443
    ProxyCommand connect.exe -H hoge.proxy.jp:1080 %h %p

Host gitlab.com
    User git
    IdentityFile ~/.ssh/id_rsa
    HostName altssh.gitlab.com
    Port 443
    ProxyCommand connect.exe -H hoge.proxy.jp:1080 %h %p

macOS(OS X)/Linuxの場合

ncコマンドを使ってやります。ない場合はインストールしてください(方法は省略)

~/.ssh/config
Host github.com
    User git
    Hostname ssh.github.com
    IdentityFile ~/.ssh/id_rsa
    Port 443
    ProxyCommand nc -X connect -x hoge.proxy.jp:1080 %h %p

Host bitbucket.org
    User git
    IdentityFile ~/.ssh/id_rsa
    HostName altssh.bitbucket.org
    Port 443
    ProxyCommand nc -X connect -x hoge.proxy.jp:1080 %h %p

Host gitlab.com
    User git
    IdentityFile ~/.ssh/id_rsa
    HostName altssh.gitlab.com
    Port 443
    ProxyCommand nc -X connect -x hoge.proxy.jp:1080 %h %p

最後に

筆者はプロキシ使う環境と使わない環境の2つの環境でGit使っているので環境のたびにコメントをつけたり外したりするのがめんどくさいです。なにかいい方法はないでしょうか?(ホスト名proxy.github.comみたいな感じでリポジトリ切り替えとかすればいい?)

48
43
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
48
43