How to mount remote SSHFS via SSH Tunneling!

sshfs is very handy for mounting remote directories on your local filesystem. Recently I needed to mount the / directory off a remote server so I can remotely work from home without complicating everything by ssh'ng then vim my code - Painful exercise.

All that is needed is to copy the code below to a file and chmod +x it.

    #!/bin/bash
      if [ -z "$*" ];
          then echo -e "Usage: $0 USERNAME HOST REMOTEHOST REMOTEPORT MOUNTPOINT \\n
          USERNAME: Default to local username
          HOST: Hostname or IP of server to connect to.
          REMOTEHOST: Host to tunnel via
          REMOTEPORT: Host port to tunnel via (Default: 2222)
          MOUNTPOINT: Local mounting point"
          exit 1;
      fi

      export PATH="${HOME}/bin:$PATH"
      USERNAME=$1
      HOST=$2
      REMOTEHOST=$3
      REMOTEPORT=$4
      MOUNTPOINT=$5
# Assumptions: ssh keys have been generated and successfully copied over to remotehost, vice versa # if necessary, openssh-client, openssh-server and sshfs packages installed # The first we need to pre-establish a forwarded port over SSH. ssh -v -f -N -L 1233:"${HOST}":22 -p "${REMOTEPORT}" "${REMOTEHOST}" sshfs -p 1233 "${USERNAME}"@localhost:/ "${MOUNTPOINT}" -o reconnect,ServerAliveInterval=15,ServerAliveCountMax=3