How to mount a remote directory using SSH to be available same as if it is a local directory?

share|improve this question
up vote 46 down vote accepted

First install the module:

sudo apt-get install sshfs

Load it to kernel

sudo modprobe fuse

Setting permissions

sudo adduser $USER fuse

sudo chown root:fuse /dev/fuse

sudo chmod +x /dev/fusermount

Now we’ll create a directory to mount the remote folder in.

I chose to create it in my home directory and call it remoteDir.

mkdir ~/remoteDir

Now I ran the command to mount it(mount on home).

sshfs maythux@192.168.xx.xx:/home/maythuxServ/Mounted ~/remoteDir

Now it should be mounted

cd ~/remoteDir
ls -l 

Enjoy

share|improve this answer
    
I'm a little confused... in the sshfs command, I think that the mountpoint local directory is named remoteDir, and when I'm on the ssh serever, there is a dir /home/maythuxServ/Mounted that is not mounted locally, and I can not tell, or care, whether it's mounted elsewhere? – Volker Siegel Nov 23 '14 at 0:56
1  
I skipped some of these steps under 14.04 when I used the following guide: help.ubuntu.com/community/SSHFS – Hemm Mar 9 '16 at 19:43
    
No fuse group needed (Ubuntu 16.04, Nov 2017): stackoverflow.com/questions/35635631/ubuntu-15-10-no-fuse-gr‌​oup – Matthew Kleinsmith Nov 30 '17 at 0:34
    
Are these commands running on the client or the server? – Jeff Dec 12 '17 at 19:35

Configure ssh key-based authentication

Generate key pair on the local host.

$ ssh-keygen -t rsa

Accept all sugestions with enter key.

Copy public key to the remote host:

$ ssh-copy-id -i .ssh/id_rsa.pub user@host

Install sshfs

$ sudo apt install sshfs

Mount remote directory

$ sshfs user@host:/remote_directory /local_directory

Don't try to add remote fs to /etc/fstab

Or don't try to mount shares via /etc/rc.local .

In both cases it won't work as the network is not available when init reads /etc/fstab.

Install AutoFS

$ sudo apt install autofs

Edit /etc/auto.master

Comment out the following lines

#+/etc/auto.master.d
#+/etc/auto.master

Add a new line

/- /etc/auto.sshfs --timeout=30

Save and quit

Edit /etc/auto.sshfs

Add a new line

/local_directory -fstype=fuse,allow_other,IdentityFile=/local_private_key :sshfs\#user@remote_host\:/remote_directory

Remote user name is obligatory.

Save and quit

Start autofs in debug mode

$ sudo service autofs stop
$ sudo automount -vf

Observe logs of the remote ssh server

$ ssh user@remote_server
$ sudo tailf /var/log/secure

Check content of the local directory

You should see contents of the remote directory

Start autofs in normal mode

Stop AutoFS running in debug mode with CTRL-C .

Start AutoFS in normal mode

$ sudo service autofs start

Enjoy

(Tested on Ubuntu 14.04)

share|improve this answer

Install sshfs

sudo apt-get install sshfs

Add to fstab:

<USER>@<SERVER_NAME>:<server_path> <local_path> fuse.sshfs delay_connect,_netdev,user,idmap=user,transform_symlinks,identityfile=/home/<YOUR_USER_NAME>/.ssh/id_rsa,allow_other,default_permissions,rw,nosuid,nodev,uid=1000,gid=1000,nonempty 0 0
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.