Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to allow my laptop (Ubuntu 13.04) to access my PC (Lubuntu 13.04) hard drive through SSHFS. I'm using RSA keys to connect.

It works perfectly fine if I type this in the terminal:

sshfs my-PC:/a_folder /media/a_folder

But I would like it to be mounted automatically when I boot my laptop. So I added myself to the fuse group:

sudo adduser mynickname fuse

And I added the following line to my fstab file:

sshfs#mynickname@my-PC:/a_folder /media/a_folder fuse defaults,idmap=user,_netdev 0 0

When I boot the laptop, a_folder appears in the list of devices, but is not mounted. When I try to access it through Nautilus, it displays the following error:

mount: only root can mount sshfs#mynickname@my-PC:/a_folder on /media/a_folder

I get the same error if I try

mount /media/a_folder

in a terminal.

If I try

sudo mount /media/a_folder

I get

read: Connection reset by peer

I tried to add "allow_other" as an option in the fstab entry, and uncommented the related line in /etc/fuse.conf, but it didn't change anything.

The user "mynickname" is the owner of the folder /media/a_folder and has rwx permissions.

I looked at many threads on the internet about people with quite similar issues, but nothing worked so far. Usually, people can't even do

sshfs my-PC:/a_folder /media/a_folder

without getting an error, whereas this works fine on my laptop.

Any insight and tips will be greatly appreciated! Thanks.

EDIT: I solved this issue a while ago, but I forgot to update this post. So here is what is in my fstab:

sshfs#mynickname@my-PC:/a_folder /media/a_folder fuse noauto,_netdev,idmap=user,user,default_permissions 0 0

The key option to add was default_permissions if I recall. I had to add mynickname to the group to which belongs /a_folder/ on my-PC.

share|improve this question

4 Answers 4

The problem you are experiencing is that your normal user has a correct setup for your identity file, while the root user has no idea what ssh key to use.

You can fix this by telling fstab what identity file/ssh key to use while trying to connect:

sshfs#user@host:/mnt/whatever/ /mnt/whatever/        fuse    user,_netdev,reconnect,uid=1000,gid=1000,IdentityFile=/home/USER/.ssh/KEYFILE,idmap=user,allow_other  0   2
share|improve this answer
    
Thanks for your answer. I already tried with the IdentityFile option, but I didn't specify the uid and gid options, so I will try that! –  Radoslaw Jurga Jun 30 '13 at 17:04
    
Technically, you shouldn't need to use sudo if everything is set up correctly for a FUSE mount. Also, the uid/gid settings should only affect which user has rights to the files on your system. –  earthmeLon Jun 30 '13 at 17:06
    
So I just tried with uid, gid, IdentityFile, allow_other, all those options at the same time, and unfortunately it still doesn't work. Still the same error. –  Radoslaw Jurga Jun 30 '13 at 17:16
    
Would you mind posting a sample of how you've gotten it written? You should be pointing to your private key, and not your public key. –  earthmeLon Jun 30 '13 at 21:28
    
You also must put your user in the fuse group and restart your machine in order for the allow_other to work. –  earthmeLon Jun 30 '13 at 21:29

This problem can also occur when the host key of ssh changes.

Try to connect to the server via ssh (e.g. ssh username@hostIP). If the following error appears:

 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!    @
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Follow the instructions in the error message to delete the old key and try to connect again via ssh. If the error does not appear any more, the sshfs connection should work.

share|improve this answer

To get real debug output you need to add both sshfs_debug and debug options to the mount:

sshfs#mynickname@my-PC:/a_folder /media/a_folder fuse defaults,idmap=user,_netdev,debug,sshfs_debug 0 0

With this you will get a lot of debug info to help you:

$ sudo mount -a
SSHFS version 2.5
FUSE library version: 2.9.2
nullpath_ok: 0
nopath: 0
utime_omit_ok: 0
executing <ssh> <-x> <-a> <-oClearAllForwardings=yes> <-2> <user@box> <-s> <sftp>
user@box's password: 
Server version: 3
Extension: posix-rename@openssh.com <1>
Extension: statvfs@openssh.com <2>
Extension: fstatvfs@openssh.com <2>
Extension: hardlink@openssh.com <1>
Extension: fsync@openssh.com <1>
unique: 1, opcode: INIT (26), nodeid: 0, insize: 56, pid: 0
INIT: 7.22
flags=0x0000f7fb
max_readahead=0x00020000
remote_uid = 1001
   INIT: 7.19
   flags=0x00000011
   max_readahead=0x00020000
   max_write=0x00020000
   max_background=0
   congestion_threshold=0
   unique: 1, success, outsize: 40
unique: 2, opcode: STATFS (17), nodeid: 1, insize: 40, pid: 2771
unique: 3, opcode: LOOKUP (1), nodeid: 1, insize: 47, pid: 3371

In my case I discovered that my machine was only listed in .ssh/config, so it was unresolvable for root.

And BTW, you need to set uid and gid, since idmap=user only seems to work for the current user, which is root in this case.

share|improve this answer

Full disclosure: old-school geek, but brand spanking new to the linux/open source world

First off, I'm still using password authentication because I haven't yet become savvy enough with RSA keys. That's nearing the top of the list though.

Relevant set-up info: Using a MacBook Pro with VMWare Fusion installed, on which I have Ubuntu server 10.04 LTS. Relying on Mac's terminal and SSH for almost all my server interaction

After botching a Drupal install, I rolled back to a prior snapshot and was suddenly unable to execute a command that I had just used moments previously: sshfs -o idmap=user -o allow_other user@mac.home:/Users/<username>/Documents ~/mountpoint

The issue is that the keys got out of sync. I don't know if I actually needed to do this on both my host and server, but I cleared out all of the local keys on each by first making a back-up of the known_hosts file, then editing the known_hosts file to remove entries.
On Mac, this file was located at: /Users/<username>/.ssh/known_hosts
On Ubuntu, this file is located at: /home/<username>/.ssh/known_hosts

So, to summarize, all performed from my Mac terminal, after starting up Ubuntu server:

cp /Users/<username>/.ssh/known_hosts /Users/<username>/.ssh/known_hosts.old
nano  /Users/<username>/.ssh/known_hosts
  # remove extra entries, save file
ssh <username>@ubuntu_server
cp /home/<username>/.ssh/known_hosts, /home/<username>/.ssh/known_hosts.old
nano /home/<username>/.ssh/known_hosts
  # remove extra entries, save file

Upon first SSH into each system, SSH prompts me to allow RSA keys to be added and all works thereafter.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.