LoginSignup
0
2

More than 5 years have passed since last update.

autosshがハングした時の対処法

Last updated at Posted at 2018-02-27

接続を自動で維持してくれるはずのautosshがどうしても動かない時のチップです。どうしてハングアップするのか原因不明なので、たまたまうまくいってるだけかもしれません。。

以下のようなコマンドで接続が確立しているケースを想定します。

autossh -f -N -R 10022:localhost:22 user@example.com

example.comホスト上からは、以下のようなコマンドでautosshを実行しているホストに接続ができるはずです。が、時々どういうわけかポートは開いてるのに通信ができなくなります。

ssh -p 10022 user@localhost

lsof コマンドで該当のポートを使用しているプロセス番号を探してkillしてしばらく待つとうまくいくことがあるようです。

# lsof | grep 10022
sshd      1991          ubuntu    4u     IPv4              31886       0t0        TCP localhost10022 (LISTEN)
sshd      1991          ubuntu    9u     IPv4              44041       0t0        TCP localhost10022->localhost:53012 (CLOSE_WAIT)
# kill 1991
0
2
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
0
2