Peter's Blog

Redefining the Impossible

Items filed under autofs


I have a number of pcs running linux now that I have hooked together. Copying files between them is a matter of uttering scp invocations along the lines of

scp me@there:/path/to/file ~/put/it/there

With ssh keys set up there is no need to enter a password but still this precludes the use of luxuries like file browsers. To cover this there is sshfs which invisibly turns an sftp login into a file system so the files on the remote box look like they are on the local hard disk. But then there is still the hassle of mounting them when you want to use them.

Along comes autofs and this is coolness, it means that the connection to the server is made automatically whenever one tries to access the file. The connection will disconnect automatically if it is not used so it is not permanently using resources like an fstab entry would.

Peter's notes:

  • switch to root
    sudo -i
    
  • enter
    ssh-keygen
    
    and keep pressing enter until it stops hassling you
  • enter
    ssh-copy-id user@server
    
    where user@server is the remote account you want to sftp to. ssh-copy-id is my BIG discovery today, it sticks your public key in the remote servers ~/.ssh/authorized_keys file saving much tedium.
  • run
    aptitude install autofs sshfs
    
    and press Y if it asks.
  • vim /etc/auto.master and add:
    /mnt/ssh /etc/auto.sshfs        uid=1000,gid=1000,--timeout=30,--ghost
    
    which maps anything in /mnt/ssh to an automatic file system. Your /mnt directory should already exist but /mnt/ssh will be created for you by autofs.
  • vim /etc/auto.sshfs and add your shares:
    desktop  -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#peter@desktop\:/
    
    this links /mnt/ssh/desktop to the root directory of my desktop pc.
  • run
    /etc/init.d/autofs restart
    
  • exit out of the sudo
  • run
    ls /mnt/ssh/desktop
    
    and relish how cool all this is.
Autofs plus Sshfs

Autofs plus Sshfs

On the left, my desktop as viewed from the Mythical Convergence Box, on the right Peter's Blog on Slicehost.

An important thing to underline is that since the connection is made as root it is necessary for root to have an ssh key to the ssh account that is sharing the files, NOT from your own user account.

Since this uses sftp it is secure and easy to pass through firewalls etc. I copied 9G of photos over the link from desktop to convergence box in maybe ten minutes so the performance is reasonable.

Thanks to this guy who figured out the incantations.


Add a comment