1. Install autofs
Ubuntu/Debian: sudo apt-get install autofs Red Hat/Fedora based: sudo yum install autofs
2. Edit /etc/auto.master and add a line:
/media/sshfs /etc/auto.sshfs uid=1000,gid=1000,--timeout=30,--ghost
3. Edit /etc/auto.sshfs
mountpoint -fstype=fuse,rw,nodev,nonempty,allow_other,reconnect,uid=1000 ,gid=1000,max_read=65536,compression=yes,auto_cache,no_check_root, kernel_cache :sshfs\#user@server\:/remotedir
4. Make the autofs mount point
mkdir -p /media/sshfs
5. SSH Access using Keys – for root
To make efficient use of sshfs access and a prequisite for autofs you need to set up host based key authentication. It is required that you can ssh from the root user to the target user on the remote filesystem using keys.
ssh-keygen -t rsa scp .ssh/id_rsa.pub user@server: ssh user@server mkdir --mode=0700 -p .ssh cat id_rsa.pub >> .ssh/authorized_keys chmod 0600 .ssh/authorized_keys
Now test you can log in to user@remote from the root user without it prompting for a password
6. Start Autofs
Ubuntu/Debian: sudo autofs start RedHat/Fedora: sudo service autofs start
7. Access your remote filesystem by going to /media/sshfs/mountpoint
cd /media/sshfs/mountpoint
You should now be access the remote machine as if it was part of your local filesystem
Advertisements
Pingback: Automount ssh “shares” | adventuresinlinuxland
Pingback: Automount ssh “shares” | adventuresinlinuxland
Pingback: Configuring autofs and sshfs on Ubuntu | Mostly Linux