I have a remote file server that I would like to access via SSHFS. For authentication I have disabled passwords and use key based authentication with ssh-agent. To automatically mount the share on my Linux system (KDE Neon, Ubuntu based) when I log in, I wrote myself a .sh script (visible below) that should actually perform the task. The script is located in /home/username/.scripts/mount_sshfs.sh and has execute permission (711). I added it as a login script in the KDE system settings, whereupon KDE created a .desktop file in the /home/username/.config/autostart folder that starts the script. When running the script manually, the shares are also mounted without any problem, it just doesn't work automatically. Another script that I also want to start through the KDE autostart works fine. Actually the script should mount six shares from the same server, but since they differ only in the folder locations I have specified only one target for the actual mount for the sake of simplicity:
#!/bin/bash
# Start ssh-agent
eval $(ssh-agent)
# Add private key to ssh-agent
ssh-add /home/username/.ssh/privateSSHKey
# Set up sshfs connection
sshfs -o IdentityFile=/home/username/.ssh/privateSSHKey username@<ServerIP>:/path/on/server /home/username/local/mount/folder
I ran the script manually on the console to get possible error messages - there are none, only Agent pid 4500 Identity added: /home/username/.ssh/privateSSHKey (username@MyPCsHostname). I checked the shebang line, on which I could not see any errors either. I also made sure to run the script as my normal user and not superuser/root to avoid permission issues.
I also tried to mount it with /etc/fstab as I did with the NFS shares I used before SSHFS. I also tried to create a systemd service to run the script on startup (after the network connection is established), but that didn`t work either. There seems to be some problem with the script itself that prevents it from running automatically.