Remote Folders – Automatically Mount on Boot in Windows and Ubuntu

mountsshfsUbuntuwindows

I'm trying to mount a Windows folder on my Ubuntu machine on start up. I've tried following this page here, modifying /etc/fstab and appending sshfs#my_user@remote_host:/path/to/directory <local_mount_point> fuse user 0 0 to it, but it fails; on start up, I get an error saying that the mounting failed, and I can press S to skip or M to recover manually.

I also tried following this page here, appending /usr/bin/sshfs -o idmap=user my_user@remote_host:/path/to/directory <local_mount_point> to the /etc/rc.local file, but this doesn't help either; Ubuntu just boots up normally without mounting.

I have Cygwin installed on my Windows machine, and I can run everything smoothly, such as sshing without passwords, and mounting it manually. I've also tried to run the modified rc.local file $ /etc/rc.local, and it works perfectly, but I just can't seem to get the folder mounted on start up.

Can someone help me?

EDIT: by remote, I meant that the folder I'm trying to mount from my Windows machine (which has a public ip), is not on the same network. I am using sshfs, not nfs.

Best Answer

On my Ubuntu machine, I modified my /etc/fstab by adding this line:

 //192.168.xx.yy/Public /mnt/PUBNAS nfs rw,_netdev,credentials=/home/myname/.smbcredentials 0 0

The file .smbcredentials is very simple,

 username=myusername                                                                            
 password=mypassword

Edit:

After realizing that you use sshfs, I have tested the /etc/fstab entry suggested by the Arch Linux wiki page. For me, this entry worked:

USERNAME@HOSTNAME_OR_IP:/REMOTE/DIRECTORY  /LOCAL/MOUNTPOINT  fuse.sshfs  defaults,_netdev  0  0

It is important that you have passwordless access to the server (i.e., with cryptographic key). I hope this makes up for my initial blunder.

Edit 2:

If you want the remote folder to be mounted by you, not by root, which is admittedly a nuisance, you will have to change the /etc/fstab line to this:

 USERNAME@HOSTNAME_OR_IP:/REMOTE/DIRECTORY  /LOCAL/MOUNTPOINT  fuse.sshfs _netdev,user,idmap=user,transform_symlinks,identityfile=/home/USERNAME/.ssh/id_rsa,allow_other,default_permissions,uid=USER_ID_N,gid=USER_GID_N 0 0
Related Question