You are not logged in.

#1 2022-04-28 01:03:05

blah123213
Member
Registered: 2022-04-28
Posts: 19

Network dispatcher, run script as non-root user

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

#2 2022-04-28 05:03:04

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: Network dispatcher, run script as non-root user

Please post your script. It should be trivial to use sudo in it to run sshfs as the required user.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2022-04-28 05:37:06

-thc
Member
Registered: 2017-03-15
Posts: 498

Re: Network dispatcher, run script as non-root user

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)

Online

#4 2022-04-30 19:17:51

blah123213
Member
Registered: 2022-04-28
Posts: 19

Re: Network dispatcher, run script as non-root user

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

Board footer

Powered by FluxBB