Tuesday, October 7, 2008

Mounting a remote folder with ssh

Mounting a remote folder via ssh is not simple and clear as it should be, so I wrote down the main points to get work the whole thing.
- install sshfs ( with debian/ubuntu: apt-get install sshfs )
- add the user that will do the mount to the fuse group ( ex: 'fuse:x:106:simone' in /etc/group )
- create the folder where you want to mount (ex: mkdir /mnt/ssh_folder )
- remember to set correct permissions to the folder you've created
- mount the remote folder using sshfs ( ex: sshfs root@ /mnt/ssh_folder -o allow_other )

In order to have a permanent connection you can use fstab:
- Add the ssh key of your user to the remote machine, in order to remove password request during the connection. The key must be generated with ssh-keygen and the id_rsa.pub file (normally located in the ~/.ssh/ folder) must be copied to the remote machine and added under the home dir of the remote user used for the connection: ~/.ssh/authorized_keys ( ex: 'cat id_rsa.pub >> /home/john/.ssh/authorized_keys' if you connect to the remote machine with john@machine )
- Add a new line to fstab, for example:
sshfs#root@ /mnt/ssh_folder fuse defaults,allow_other 0 0

You can try fstab without restarting using 'mount -a'

That's all folks! ... maybe...