Tuesday, April 30, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  12] [ 0]  / answers: 1 / hits: 2866  / 1 Year ago, fri, january 20, 2023, 9:08:48

Is it possible to auto-mount a remote FS using sshfs upon instantiating a proper VPN connection?



Allow me to explain the scenario, I'm working remotely, to do that it helps if I can mount my home dir from a server in the office. To do that I need to vpn in. So within network manager I select the relevant VPN and connect. It connects but now I have to drop to the command line and mount my home dir on several machines.



If I forget to do one machine my local dev environment isn't as efficient. I suppose I could write a quick bash script to do this but I'd rather get it running automatically when I connect.


More From » networking

 Answers
4

Find the UUID of your connection using



$ nmcli con


Note that this lists not just physical connections but also the Wireless connections defined (SSIDs).



Put some simple script like this in your /etc/NetworkManager/dispatcher.d/ directory:



#!/bin/bash

# Specify your connection UUID you like to trigger on below.
MYCON_UUID=397bdb70-2a89-415e-b3e9-09ca0b704fc1

if [ "$CONNECTION_UUID" == "$MYCON_UUID" ]
then
# do your scripting you need to do here:
mount -t sshfs ...
fi


Don't forget to set the right permissions to make it excutable (i.e. chmod +x trigger-sshfs-on-vpn.sh). It can be any type of script, a Bash script is probably sufficient for your purpose.



NetworkManager just executes all the scripts in this directory providing some environment variables you can use for scripting. In this case you probably just need CONNECTION_UUID.


[#35602] Saturday, January 21, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
feeous

Total Points: 102
Total Questions: 122
Total Answers: 119

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
;