How to permanently mount a remote share?

I’ve got an NAS file server on my local network, in my windows days I just mapped a drive to it and it was just there all the time. I’m having trouble doing the same in Ubuntu. I had done this successfully before using samba-cifs in fstab, but after reconfiguring the box that no longer works and it felt silly since the box itself runs Linux (Busybox I believe).

So at first I tried sshfs.
I can access it from the Places -> Connect to Server using ssh, and it’ll pull up in Nautilus.
I can also mount it via commandline: sshfs -o idmap=user $USER@<localip>:/mnt/HD_a2 /media/nas-files
and it works fine; however, it asks for a password so I can’t add that in rc.local to mount on login.
I’ve tried editing fstab, unsuccessfully, using this command:

sshfs#shazzner@<localip>:/mnt/HD_a2/files /media/nas-files/ fuse user 0 0

for some reason this turns the nas-files folder in a binary file, that appears to be garbage. When I unmount it, it comes back fine. No idea.

Second, someone in the chat mentioned, Autofs.
I edited auto.master with:

/media/auto /etc/auto.media

and in auto.media:

nfiles -fstype=fuse,rw,noperm,allow_other,reconnect sshfs\#//<localip>/mnt/HD_a2/files

then restarted autofs, it gives me no error message but the mount isn’t there.

Pulling my hair out with this one, any help?

Answer

You can try to do a

sudo su
ssh-copy-id username@nas

to enable certificate based auto login for the user root.

Now the user root should be able to login to the server viva ssh without a password and i think sshfs now also does not need a password.

So you have to write a little script executing sshfs and start the script on startup (checkout the update-rc.d command)

Attribution
Source : Link , Question Author : Shazzner , Answer Author : aatdark

Leave a Comment