You are not logged in.
I wrote a script that runs as a network dispatcher script. The script runs sshfs and mounts a network location to a folder in my home directory. The script will run every time I connect to a wifi network, and it will verify that it is my home network before trying to mount.
The script seems to execute and mounts the ssh location, but I cannot for the life of me get this script to execute as my normal user. I copied my ssh keys to the /root/.ssh location and this works and allows the location to be mounted but then my normal user doesnt have access to the location. I only copied my ssh keys to the root location to see if it worked(it did), but this isnt what I want at all.
I simply want to automatically mount this location NOT as root, I just want access to this location during my normal computing. But it seems network dispatcher forces me down a path that I dont actually want at all. I dont think I should have to run this script as root, or at the very least, I should be able to switch to my normal user within the script.
Can anyone help me accomplish this? How do I make the script run as my normal user?
Last edited by blah123213 (2022-04-28 01:09:09)
Offline
Please post your script. It should be trivial to use sudo in it to run sshfs as the required user.
Offline
I had something like this (with four different mount points in four different VPNs - hence the "case") running for a while and wrote two scripts for the dispatcher events "vpn-up":
#!/bin/sh
if [ "$2" = "up-event-name" ]; then
case "$CONNECTION_UUID" in
connection_uuid_of_the_network)
su username -c "sshfs remoteuser@remoteip:/remotepath /local/mount/path -o IdentityFile=/home/username/.ssh/id_ed25519"
;;
esac
fi
and "pre-vpn-down":
#!/bin/sh
if [ "$2" = "down-event-name" ]; then
case "$CONNECTION_UUID" in
connection_uuid_of_the_network)
fusermount -u /local/mount/path
;;
esac
fi
Last edited by -thc (2022-04-28 06:31:18)
Offline
it appears that I got it working. I did something similar to -thc's script, but it wasn't working. I suspect it was due to a logging statement that I had inside the quotes that doesnt run as my normal user.
Anyway, -thc's script is essentially identical to mine, so that script should be see as the solution. Just dont include logging inside the quotes like I did
Offline