Wednesday, January 9, 2013

mount remote directories over SSH using SSHFS


When you need to mount a remote directory securely
use SSHFS which is a much easier quicker option than trying to tunnel NFS over an ssh tunnel.

SSHS is quick , easy and secure.

yum install fuse-sshfs

If not done already you will wan't to create your private and public encryption keys and put your public key on the server who's directory you want to mount, so that you will have a password less connection
ssh-keygen to create the keys

leave passphrase blank

then to copy your public key to the server type
ssh-copy-id -i .ssh/id_rsa.pub user@remoteserver

Now, lets say there is some directory /mnt/dir/ on the remote system user@remoteserver and we want to mount it on our /localfolder directory. This is how we do it using sshfs.

type
sudo sshfs user@remoteserver:/mnt/dir /localfolder

Thats it. done.

and to unmount type

fusermount -u /localfolder/

If you want the directory to be available after a reboot

You could just put sudo sshfs user@remote:/mnt/dir /localfolder
in to your /etc/rc.local file

or if you prefer to use /etc/fstab then add the following line to your /etc/fstab file

sshfs#user@remoteserver:/mnt/dir /localfolder fuse    comment=sshfs,noauto,users,exec,uid=1000,gid=1000,allow_other,reconnect,transform_symlinks,BatchMode=yes








No comments: