Index of /software/autofs_sshfs
      Name                        Last modified       Size  Description

[DIR] Parent Directory 09-Oct-2007 15:19 - [   ] Changelog 10-Jan-2008 20:29 1k [   ] TODO 10-Jan-2008 23:59 1k [TXT] auto.ssh.txt 26-Dec-2007 08:35 1k [TXT] sudo_ssh_user.sh.txt 22-Dec-2007 03:59 1k [TXT] sudo_ssh_workarounds.sh.txt 10-Jan-2008 20:16 1k

Here we have scripts to allow transparent access to remote files over ssh using autofs and sshfs-fuse.

Motivation

You have two cows^H^H^H^H linux boxes

Chances are good that if you use one linux machine, you use more than one. If you use more than one, you probably find yourself wanting to do things with files on one while you're sitting in front of another. So maybe you get some much needed exercise, and walk over to the other machine. But that doesn't work so well when the other machine is at home and you are at the office, or when you're at home and the other machine is a web server in a datacenter somewhere.

You're one bad nfs'ing, ftp'ing, scp'ing, rsync'ing mofo

So no problem. You've got all kinds of tools for moving files around. You bang out an scp command, or use something really slick like lftp. But wouldn't it be nice if you could just access all those remote files like they were local files? If you could just run something like
vi myhomemachine/home/drevil/plan_to_takeover_world.txt

Your mad schemes get in the way of your mad schemes

You'd like to edit that file like it was local without revealing your ingenious scheme to the world, so you put together a plan involving VPNs, firewalls, nfs, and a lot of pvc pipe. Now you're never going to get that text file edited.

Salvation

So let's look at how we can setup quick and secure access to your remote files. This method will: to get all of these, you must follow the 2nd set of instructions below

Installation

The slightly easier way

  1. Install autofs and sshfs-fuse
    (Debian / Ubuntu)
    apt-get install autofs sshfs
    (Gentoo)
    emerge -av autofs sshfs-fuse
  2. Place auto.ssh in /etc (or /etc/autofs if your distribution puts auto.master there)
  3. Make auto.ssh executable:
    chmod +x /etc/auto.ssh
  4. mkdir -p /ssh; echo "/ssh /etc/auto.ssh" >> /etc/auto.master
  5. Set up your root account to have passwordless ssh access to the remote servers you want to use, possibly by using my script, setup_sshkey.sh.txt
  6. Set autofs to start by default, start it. Debian and Ubuntu do this automatically.
  7. Go look in the a directory named after the remote server, such as
    ls /ssh/user@example.com/
    Or
    /ssh/user@example.com:4000
    (if sshd is listening on port 4000 of the server)

The totally secure, super sexy way, with benefits

  1. Install autofs and sshfs-fuse as above, but also install keychain and x11-ssh-askpass
    (Debian / Ubuntu)
    apt-get install autofs sshfs keychain ssh-askpass
    (Gentoo)
    emerge -av autofs sshfs-fuse keychain x11-ssh-askpass sudo
  2. Add this to your .bashrc file:
    source ~/.keychain/`hostname`-sh
  3. If you haven't already, generate an ssh key by running
    ssh-keygen -t dsa
    Be sure to give it a password
  4. If you already have one but it's not encrypted, encrypt it with a password by running
    ssh-keygen -p -f ~/.ssh/id_dsa
  5. Copy your public key to some accounts on remote machines. My script, setup_sshkey.sh.txt can make this easy. Of course, you can add more later.
  6. Copy sudo_ssh_user to /user/local/bin, rename it for your username, and edit it to use your username
  7. Also copy sudo_ssh_workarounds to /usr/local/bin and (optionally) edit it
  8. Create an auto.ssh_username in /etc/ (or /etc/autofs if your distribution puts auto.master there)
  9. Edit auto.ssh_username to use your username
  10. Make this new auto.ssh_username executable:
    chmod +x /etc/auto.ssh_username
  11. Add an entry such as
    /home/username/ssh auto.ssh_username
    to auto.master
  12. Set autofs to start by default, start it. Debian and Ubuntu do this automatically.

Ubuntu Specific Steps

  1. In System->Preferences->Indexing Preferences->Ignored Files, you should add entries for your /home/yourusername/ssh directory so Tracker won't attempt to index all files on the machines to which you connect
  2. On Ubuntu, X starts an ssh-agent, which isn't ideal for us. Delete the contents of /etc/X11/Xsession.d/90x11-common_ssh-agent, and replace them with
    eval `keychain -q --eval`
    Then run:
    killall ssh-agent
    log out, and log back in

Notes

Continuation

Now that you have keychain, x11-ssh-askpass, and ssh-under-sudo all working together nicely, let's set up backups.

Backups? We don't need no stinking backups!

No really, I know you're not backing up your files because it's a pain in the arse, and requires all sorts of setup and configuration on the server. So do us both a favor and install rsnapshot. It's easy, and they've got a howto. A lot of the same features will apply; you don't need to setup anything on the remote machine being backed up except ssh access. Once you've got it installed, edit your rsnapshot.conf with this line:
cmd_ssh /usr/local/bin/sudo_ssh_YOURUSERNAMEHERE
That's it! Now your backup program can run as root so it can preserve file ownership, but you don't have to have a seperate ssh key setup for your root account.