lollercoaster
lollercoaster

Reputation: 16533

Mounting SSHFS for local folder on Mac OS X to edit files on Ubuntu AWS instance

I want to be able to edit files locally using a nice IDE and have the files on my local machine (~/Code/myproject) get immediately pushed to the Ubuntu machine in the cloud (/home/ubuntu/myproject).

I installed FUSE and SSHFS for my Mac OS X laptop (local) machine.

I have an Ubuntu 16.04 AWS instance on EC2:

ubuntu@ip-xxxxxx:~$ uname -a
Linux ip-xxxxxx 4.4.0-1017-aws #26-Ubuntu SMP Fri Apr 28 19:48:19 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
ubuntu@ip-xxxxxxx:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:   xenial

I use a .pem file to SSH into that box with the -i flag (haven't set up authorized_keys).

So here's what I do on local machine:

$ mount  # check for mounted
/dev/disk1 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)

$ sudo sshfs -o allow_other,defer_permissions,IdentityFile=~/.ssh/aws.pem,loglevel=debug \
    [email protected]:/home/ubuntu/myproject \
    /Users/me/Code/myproject

It prompts me for local machine password and then I see the following:

Password:
remote host has disconnected

Clearly, something has mounted though:

$ mount
/dev/disk1 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
[email protected]:/home/ubuntu/myproject on /Users/me/Code/myproject (osxfuse, synchronous)

and if I try the same sshfs command as above again (without unmoun-ting) I get a different error:

mount_osxfuse: mount point /Users/me/Code/myproject is itself on a OSXFUSE volume

I can unmount and try again with sudo diskutil umount force /Users/me/Code/myproject/ but I get the same original error when I try again.

I thought perhaps it was a problem with my remote server's SFTP so I located all the sftp-server location on the remote box:

$ sudo find / | grep sftp-server
...
/usr/lib/sftp-server
/usr/lib/openssh/sftp-server

And then I tried with both in my /etc/ssh/sshd_config file with the line:

#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp /usr/lib/sftp-server

but neither configuration after a reboot seems to work.

I can SFTP in with the following command:

$ sftp -i ~/.ssh/aws.pem [email protected]
Connected to ec2-xxx.compute-1.amazonaws.com.
sftp>

EDIT: running the debug3 loglevel gives relatively the same results:

$ sudo sshfs -o allow_other,defer_permissions,IdentityFile=~/.ssh/aws.pem,loglevel=debug3 [email protected]:/home/ubuntu/myproject /Users/me/Code/myproject
sudo: cannot get working directory
The authenticity of host 'ec2-xxx.compute-1.amazonaws.com (xx.xx.xx.xx)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
remote host has disconnected

Any ideas on what to fix / where the issue could be?

Upvotes: 5

Views: 6982

Answers (1)

Jakuje
Jakuje

Reputation: 26016

You are running the sshfs under sudo, which makes the difference from running the sftp as your user, becuause the root can not find your authentication keys:

IdentityFile=~/.ssh/aws.pem

expands to your home directory for your user (/home/your-user/.ssh/aws.pem), but to root home for sudo user (/root/.ssh/aws.pem), where the file obviously is not.

Use the full path to the PEM file, such as

IdentityFile=/home/your-user/.ssh/aws.pem`

Upvotes: 3

Related Questions