Link to this comparison view

Next revision
Previous revision
linux:mount_multiple_ssh_servers_using_fuse [2011/06/10 18:14]
Joel Dare created
linux:mount_multiple_ssh_servers_using_fuse [2020/06/01 22:53] (current)
Line 1: Line 1:
 +====== Mount Multiple SSH Servers Using Fuse ======
 +
 +I work on software on half a dozen servers and I work on these every day.  In order to work directly from my GUI using my favorite tools (like gedit) I need to mount them on the local file system. ​ I wrote the script below to automatically mount these drives. ​ If you're working on a laptop you may also want to look at my instructions on how to [[Unmount All Fuse Mount Points]].
 +
 +<code bash>
 +#!/bin/bash
 +
 +# Get a count of files on the foo server
 +dirCount=`ls /mnt/foo/ -a -1 | wc -l`
 +
 +# If unmount was specified
 +if [ "​$1"​ == "​-u"​ ] ; then
 +
 + # Check if there are more files than an empty directory
 + if [ $dirCount == 2 ]; then
 + echo Servers are not currently mounted.
 + exit
 + fi
 +
 + # Unmount the volumes
 + echo Unmounting servers
 + fusermount -u /mnt/foo
 + fusermount -u /mnt/bar
 +
 +else
 +
 + # Check if there are more files than an empty directory
 + if [ $dirCount != 2 ]; then
 + echo Servers are already mounted.
 + exit
 + fi
 +
 +  # Mount the systems
 + echo Mounting servers
 + echo
 + echo Connecting foo.example.com
 + echo foo_pass | sshfs joel@foo.example.com:/​ /mnt/foo -o password_stdin
 + echo Connecting bar.example.com
 + echo bar_pass | sshfs joel@bar.example.com:/​ /mnt/bar -o password_stdin
 +
 +fi
 +</​code>​
 +
 +You'll want to save any lines that contain //foo// or //bar// with your own server details, including the password, username, and server name.  You may also want to avoid using the //-o password_stdin//​ option that I used.  This is //​completely insecure// in that anyone who gets access to your computer can find your password in this plain text bash script. ​ If you exclude it you'll be prompted for your password each time you connect. ​ A better solution would be to setup public/​private keys on your local box and the server. ​ For some reason, the servers I connect to have broken (or odd) key setups and I don't have control of those boxes to correct it.
  
comments powered by Disqus
linux/mount_multiple_ssh_servers_using_fuse.txt · Last modified: 2020/06/01 22:53 (external edit)