Auto-connect to SFTP?

So, I have an SFTP server on a Raspberry Pi, and I want to auto-connect to it and mount it at boot. Is it possible?

Xfce on X11 if that’s relevant.

Add an sshfs mount in /etc/fstab

could I get more resources on that topic, because this sounds like black magic?

Basically, it mounts any filesystem you can connect to via ssh into your local filesystem just like you would with an nfs or samba share.

1 Like

I provided some notes about creating the encryption keys for this here:

I’ve been using sftp \ sshfs to access my NAS shares for a long time, but I’ve opted to not have it auto-mount, rather I run a single bash script to mount them when I need them. I have this script perform a number of tasks, including confirming the NAS is online, and synchronising various items between NAS and my local system.

Here’s a snippet of that bash script, that tests the NAS (mynas) is responding, then mounts two of its sftp shares.

#!/bin/bash

timeout 5 bash -c "</dev/tcp/mynas/22"
if [ $? != 0 ];then
   # NAS unresponsive
   echo "NAS unresponsive."
   exit 1
fi

echo "NAS is responding."

# Mount shares
echo "Mounting shares..."
sshfs bink@mynas:/home /home/bink/myNAS/Home -o compression=no -o cache=yes -o kernel_cache
sshfs bink@mynas:/someshare /home/bink/myNAS/SomeShare -o compression=no -o cache=yes -o kernel_cache

I’d have mynas defined in my /etc/hosts file so that resolves correctly. I also have the local directories (eg: /home/bink/myNAS/Home) pre-created as mount points.

I guess you could have a script like that run automatically on startup if you want?

I have a RPi 4b 4GB device that I use as a LAN server. I have it set up so that anytime you login, it automatically uses FUSE/sshfs to mount my server to a mount point in my home directory on my Linux Client. It uses ssh and ssh keys.

Here are some Discover articles describing how to do this.

Scroll down to Homeserver 1, Homeserver 2, and Homeserver 3 for instrutions.

FYI The RPi server its self is configured during installation when installing this

Pudge

2 Likes

Thanks, this is exactly what I needed.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.