Unable to mount a directory on Google Compute Engine using sshfs
Asked Answered
C

3

6

I am trying to mount a remote filesystem on Google Container Engine. I am following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-use-sshfs-to-mount-remote-file-systems-over-ssh

Using following sshfs command:

sudo sshfs -o sshfs_debug,allow_other <instance-name>.<region>.<project_id>:/home/<user_name> /mnt/gce-container

I am getting error:

SSHFS version 2.5
read: Connection reset by peer

I referred this link https://cloud.google.com/sdk/gcloud/reference/compute/config-ssh and could login using ssh via following command:

$gcloud compute config-ssh
$ssh <instance-name>.<region>.<project_id>

Any ideas what might be going wrong here? I can't understand what keys and username should I use for sshfs login.

Update(11/5): I am using following command:

sshfs -o IdentityFile=~/.ssh/google_compute_engine <user>@<ip>:~/  /mnt/gce`

I have chowned /mnt/gce folder for my user. I checked the IP matches the entry in ~/.ssh/config file. However I still get the error read: Connection reset by peer

Cockeye answered 2/5, 2016 at 13:59 Comment(0)
C
8

The problem with command below is that

1) unless you have a static IP, it keeps changing on machine reboot

2) you need to use .pub file

sshfs -o IdentityFile=~/.ssh/google_compute_engine <user>@<ip>:~/  /mnt/gce

I finally got it working by following command:

sudo mkdir /mnt/gce
sudo chown <user> /mnt/gce

sshfs -o  IdentityFile=~/.ssh/google_compute_engine.pub <user_name>@<instance-name>.<region>.<project_id>:/home/<user_name> /mnt/gce
Cockeye answered 11/5, 2016 at 10:47 Comment(2)
running sudo chown <user> /mnt/gce made all the difference for me since running sshfs with sudo did not work, thanks!Formalin
If you use Identity Aware Proxy (IAP) to access your VMs, there's an extra step to first establish the tunnel: gcloud compute start-iap-tunnel <instance-name> 22 (assumes the project and region are already set via gcloud init). This will report back with the <local_port> number. Mounting the remote directory is then just sshfs -o IdentityFile=~/.ssh/google_compute_engine.pub,port=<local_port> <user_name>@localhost:. /mnt/gceMikesell
D
0

A few things that might be the cause of the problem:

  • Don't use sshfs as root. It's a FUSE filesystem and meant to be user mounted.
  • Don't specify a full path as the remote FS. It's SSH, so by default, the $PWD on the remote side is the login user's $HOME.

if ssh works, sshfs will work. The easiest way is to make sure that ~/.ssh/config has an entry for the remote host with the user, port, etc provided.

Douro answered 10/5, 2016 at 18:46 Comment(0)
V
0

If you get this from sshfs

read: Connection reset by peer

maybe help to set file to read only

chmod 400 /{{path_to_your_key}}/keypair.pem

and connect again.

Verduzco answered 12/5, 2016 at 0:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.