Categories

Friday, 27 July 2012

How to mount sshfs remote directory in fstab

Hello,

 Sshfs is used to mount  a remote directory on another server to our local server.This can be done by installing the sshfs package and a package named fuse.

The mounting is done as below.
sshfs USERNAME@HOSTNAME_OR_IP:/PATH LOCAL_MOUNT_POINT SSH_OPTIONS
 
Eg: sshfs sessy@mycomputer:/home/sessy /mnt/sessy -C -p 9876
 
To unmount the remote system: 
fusermount -u LOCAL_MOUNT_POINT
 
To mount it again 
fusermount -u LOCAL_MOUNT_POINT
 
We have to do ssh-keygen inorder to avoid asking the password upon mounting.
 
This can be done as below.
Create private and public keys using ssh-keygen commands
 
ssh-keygen
 
This will generate  private key in /root/.ssh/id_rsa and public key in /root/.ssh/id_rsa.pub
Then copy the content in id_rsa.pub to users /.ssh/authorized_keys file in remote server from which we are mounting.
 
 
You can use scp to copy the file.
 
then try to connect it using   sshuser2remotehost ,this time password will not be asked.
 
Then mount is on fstab using the following settings
sshfs REMOTEUSER@REMOTE:REMOTEMOUNTPOINT LOCALMOUNTPOINT -pREMOTEPORTNUMBER -o uid=LOCALUSERID -o gid=DESIREDGROUPID -o idmap=user -o IdentityFile=/root/.ssh/YOURKEYFILE -o allow_other
 
Eg:sshfs#user@remote.com:/home/user/audio /var/www/html/audio 
fuse 
IdentityFile=/root/.ssh/id_rsa,idmap=user,allow_other,port=10022,uid=0,gid=0,rw,nosuid,nodev
  0 0  
 
 
Please see the link 
http://ewald.tienkamp.nl/2010/01/19/mounting-a-remote-file-system-over-ssh-using-sshfs-and-non-standard-settings/
 for more details.
Regards
 


No comments:

Post a Comment

Ad