LoginSignup
5
6

More than 5 years have passed since last update.

GitでSSH接続がなかなか確立しない場合の対処法

Last updated at Posted at 2017-05-06

現象

GitでBitbucketにSSH接続しようとしてもなかなか接続が確立しない。
具体的には毎回pull/pushしようとする時に数十秒から数分待たされる。
環境は以下の通り。
OS: macOS Sierra 10.12.3
Git: git version 2.12.2
一方で、外部のLinuxサーバー
OS: CentOS release 6.8 (Final)
Git: git version 1.7.1
ではすぐに接続される。

対処法

常にIPv4で接続するようにする。
~/.ssh/configに以下の記述を追加。

.ssh/config
Host bitbucket.org
 AddressFamily inet

参考

sshの接続確立が遅い場合の対処方法
http://d.hatena.ne.jp/yuyarin/20090410/1239298235

追記

以下の同様の記事を見つけた。
http://qiita.com/devneko/items/5b4cbd89a66709f493ed
これってBitbucket固有の問題なんだろうか。

追記2

Bitbucket公式情報らしきものを発見。
https://confluence.atlassian.com/bbkb/recent-ipv6-changes-840796883.html
https://blog.bitbucket.org/2016/07/21/bitbucket-cloud-now-available-ipv6/

macOSで接続情報をチェック。

$ ssh -v git@bitbucket.org
OpenSSH_7.3p1, LibreSSL 2.4.1
中略。
debug1: Connecting to bitbucket.org [2401:1d80:1010::151] port 22.
debug1: connect to address 2401:1d80:1010::151 port 22: Operation timed out
中略。
debug1: Connecting to bitbucket.org [104.192.143.2] port 22.
debug1: Connection established.
以下省略。

どうやらIPv6で失敗してIPv4で接続し直している様子。
Linuxだと素直にIPv6で接続出来ていた。
対処するにはファイアウォールの設定をいじると良いらしい。
https://confluence.atlassian.com/bitbucket/what-are-the-bitbucket-cloud-ip-addresses-i-should-use-to-configure-my-corporate-firewall-343343385.html
暇な時に試してみよう。
IPv4も残っているらしいのでとりあえず最初の対処で良いことにする。

5
6
0

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
5
6