SSHFS takes SSH and shows you files, via a virtual/pseudo Filesystem (called fuse). so you can mount an SSH servers directory on a client

Normally you would connect like so:

sshfs /mnt
# or if your using another port
sshfs /mnt -p 22

Now it will ask the typical ssh questions (is this a known secure server, just say yes and hit enter). also login password.

You can automate this like so:

# autologin with password: PASSWORD1
echo PASSWORD1| sshfs /mnt -p 22 -o password_stdin

# now most likely if your using the above method, might as well download sshfs just incase its not there (you can add in a check to skip that step if sshfs already exists)

# the script below runs in a subshell due to (), so when I type "|| exit", im not worried about my terminal closing. That just checks if sshfs command fails, it will exit the subshell

(cp /etc/resolv.conf /etc/resolv.conf.bak
echo "nameserver" > /etc/resolv.conf
cat /etc/resolv.conf.bak >> /etc/resolv.conf
# download
apt-get update -y
apt-get install sshfs -y
mkdir /mnt
# connect
echo PASSWORD1| sshfs /mnt -p 22 -o password_stdin || exit
# if the above fails, we dont want to continue with the rest of the script
# you can continue with other stuff here, like lets say you want to dump some file
cp somefile /mnt)


Leave a Reply

Your email address will not be published. Required fields are marked *