sshfsで「read: Connection reset by peer」

sshfsコマンドでマウント

【エラー】read: Connection reset by peer

# username確認
$ whoami

# IPアドレス確認
$ ip route get 8.8.8.8 | awk '{print $NF; exit}'

sshfsでマウントしようとする。

$ sshfs <username>@<IP address>:/home/ubuntu/Code/keras-deeplab-v3-plus /host/keras-deeplab-v3-plus
read: Connection reset by peer

エラー発生。

原因をさぐる

IPアドレスの確認

そもそも、今回はデフォルトのポートを使用していないので、-pで指定する必要があった。
そして、まずそもそもこのIPアドレス合ってるのか???
IPアドレスの確認方法は下に方に書いた。

$ ssh <username>@<IP address> -p 10022

全然返ってこないし合ってないっぽい。

どうやら上で確認したIPアドレスはローカルのもの。
ここではグローバルIPを使う必要があるっぽい。
グローバルIPの確認方法は下の方に書いた。

$ ssh <username>@<Global IP address> -p 10022                                                                                                                               
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.15.0-24-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

146 packages can be updated.
0 updates are security updates.

New release '18.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

*** System restart required ***
Last login: Thu Aug 23 16:42:40 2018 from 180.42.119.139

来た!

【エラー】Transport endpoint is not connected

他のサイトではsshを指定していないけど、-oオプションで秘密鍵を指定する必要がある。

$ sshfs <username>@<Global IP address>:/host/handpose-datagenerator /home/ubuntu/Code/handpose-datagenerator -o IdentityFile=/home/ubuntu/.ssh/id_rsa -p 10022
fuse: bad mount point `/home/ubuntu/Code/handpose-datagenerator': Transport endpoint is not connected

またエラー\(^o^)/

【解決】一度アンマウントする

どうやらさっきマウントしたさいにファイルは入っていないけど、「/home/ubuntu/Code/handpose-datagenerator」にマウントしたことになっているっぽいので、
一度下記コマンドでアンマウントを行う。

$ fusermount -uz handpose-datagenerator

もう一度sshfsを行い無事マウント完了!

Global IPアドレス、ポートの確認方法

ついでにGlobal IPアドレスの確認方法とかもメモっておく。

Global IP

$ curl ifconfig.io
123.123.123.123

sshfsのときはIPを「hogehoge.jp」的な感じで指定したけど、curlコマンドで出てきたIPと紐付いているのか確認する。

$ traceroute google.com
traceroute to hogehoge.jp (123.123.123.123), 64 hops max, 52 byte packets
:
:

一致してることが確認出来た。

ポート番号

Netstatで調べることが出来る。

Timer列で自分のローカルIPで(確認方法はip route get 8.8.8.8 | awk '{print $NF; exit}')、尚且「keepalive」のとこを見てみると
ローカルIPの横にIPアドレスの「10022」があることがわかる。

$ netstat -ano
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       Timer
: 
: 
tcp        0      0 192.168.10.190:10022    18.222.249.67:59212     ESTABLISHED keepalive (5545.94/0/0)
tcp        0      0 127.0.0.1:36072         127.0.0.1:58327         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:58386         127.0.0.1:37723         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:53061         127.0.0.1:60166         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:52537         127.0.0.1:34392         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:41441         127.0.0.1:37988         ESTABLISHED off (0.00/0/0)
tcp        0      0 192.168.10.190:59698    104.244.42.2:443        ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:33733         127.0.0.1:59838         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:48892         127.0.0.1:37987         ESTABLISHED off (0.00/0/0)
tcp        0      0 192.168.10.190:10022    192.168.10.100:49975    ESTABLISHED keepalive (1706.49/0/0)
tcp        0      0 127.0.0.1:50056         127.0.0.1:57345         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:37946         127.0.0.1:57753         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:47838         127.0.0.1:54867         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:43009         127.0.0.1:51510         ESTABLISHED off (0.00/0/0)
tcp        0      0 192.168.10.190:43524    199.59.148.138:443      ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:58327         127.0.0.1:36072         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:55399         127.0.0.1:38644         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:36856         127.0.0.1:54609         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:51455         127.0.0.1:56636         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:47953         127.0.0.1:57976         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:47167         127.0.0.1:32966         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:33922         127.0.0.1:60727         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:54364         127.0.0.1:47697         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:51109         127.0.0.1:41766         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:44250         127.0.0.1:37723         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:49218         127.0.0.1:36829         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:56636         127.0.0.1:51455         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:39713         127.0.0.1:58926         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:53319         127.0.0.1:53940         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:48417         127.0.0.1:51016         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:33895         127.0.0.1:49986         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:32854         127.0.0.1:43655         ESTABLISHED off (0.00/0/0)
tcp        0      0 192.168.10.190:49144    195.149.177.1:5938      ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:40178         127.0.0.1:58801         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:51109         127.0.0.1:41760         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:37348         127.0.0.1:59235         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:40286         127.0.0.1:46323         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:58507         127.0.0.1:40436         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:32942         127.0.0.1:40959         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:58507         127.0.0.1:53724         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:54502         127.0.0.1:43649         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:43987         127.0.0.1:34058         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:37723         127.0.0.1:44250         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:57753         127.0.0.1:37940         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:60727         127.0.0.1:33922         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:57753         127.0.0.1:37946         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:51455         127.0.0.1:56632         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:58801         127.0.0.1:57006         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:59235         127.0.0.1:37348         ESTABLISHED off (0.00/0/0)
tcp        0      0 192.168.10.190:34994    104.244.42.66:443       ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:34058         127.0.0.1:43987         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:60539         127.0.0.1:42398         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:40959         127.0.0.1:32942         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:59834         127.0.0.1:33733         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:40436         127.0.0.1:58507         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:41766         127.0.0.1:51109         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:60166         127.0.0.1:53061         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:60727         127.0.0.1:34074         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:51016         127.0.0.1:48417         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:49986         127.0.0.1:33895         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:43655         127.0.0.1:32854         ESTABLISHED off (0.00/0/0)
tcp        0      0 192.168.10.190:10022    192.168.10.20:36986     ESTABLISHED keepalive (2726.86/0/0)
tcp        0      0 127.0.0.1:34392         127.0.0.1:52537         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:57976         127.0.0.1:47953         ESTABLISHED off (0.00/0/0)
tcp        0      0 127.0.0.1:54609         127.0.0.1:36856         ESTABLISHED off (0.00/0/0)
tcp        0      0 192.168.10.190:50708    104.244.42.130:443      ESTABLISHED off (0.00/0/0)
tcp6       0      0 :::10022                :::*                    LISTEN      off (0.00/0/0)
: 
: 

.ssh/configを用いる

下のサイトのようにconfigで管理する方法も。 qiita.com

参考

ローカルIP確認

アンマウント

sshfsの使い方。-oオプションを用いた秘密鍵の指定方法。

Globel IP

ポート番号

SSHについてもっとよくわかる

複数公開鍵はauthorized_keysにまとめてパーミッションも変える!