Installing SSHFS to Local Folder on Mac OS X to Edit Files on AWb Ubuntu Instance
I want to be able to edit files locally using a nice IDE and have the files on my local machine ( ~/Code/myproject
) go straight to my Ubuntu computer in the cloud ( /home/ubuntu/myproject
).
I have installed FUSE and SSHFS for my Mac OS X laptop (local).
I have an instance of Ubuntu 16.04 AWS 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 am using file .pem
for ssh in this flag box -i
(did not configure authorized_keys).
So here's what I am doing on my 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 \
ubuntu@ec2-xxxxxxxx.compute-1.amazonaws.com:/home/ubuntu/myproject \
/Users/me/Code/myproject
It asks me for the local computer password and then I see the following:
Password:
remote host has disconnected
Obviously something is mounted:
$ 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)
ubuntu@ec2-xxxxxxx.compute-1.amazonaws.com:/home/ubuntu/myproject on /Users/me/Code/myproject (osxfuse, synchronous)
and if I try to repeat the same command sshfs
as above (without unmoun
-ting) I get another error:
mount_osxfuse: mount point /Users/me/Code/myproject is itself on a OSXFUSE volume
I can disconnect and try again with sudo diskutil umount force /Users/me/Code/myproject/
, but when I try again I get the same original error.
I thought it was a problem with the remote SFTP server, so I found the entire location sftp-server
in the remote field:
$ 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 a line:
#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp /usr/lib/sftp-server
but none of the configuration after reboot seems to work.
I can use SFTP with the following command:
$ sftp -i ~/.ssh/aws.pem ubuntu@ec2-xxx.compute-1.amazonaws.com
Connected to ec2-xxx.compute-1.amazonaws.com.
sftp>
EDIT: debug3
Running loglevel gives relatively the same results:
$ sudo sshfs -o allow_other,defer_permissions,IdentityFile=~/.ssh/aws.pem,loglevel=debug3 ubuntu@ec2-xxxx.compute-1.amazonaws.com:/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 problem might be?
source to share
You are using sshfs
in a section sudo
that makes it impossible to use sftp
as a user because it root
cannot find your authentication keys:
IdentityFile=~/.ssh/aws.pem
expands to your home directory for your user ( /home/your-user/.ssh/aws.pem
), but for root
home for user sudo
( /root/.ssh/aws.pem
), where the file is clearly missing.
Use the full path to the PEM file, for example
IdentityFile=/home/your-user/.ssh/aws.pem`
source to share