Score:0

Force separate Mullvad VPN settings per user?

us flag

I would prefer that I was able to autoconnect to a different server for each of two users with Mullvad VPN.

What I have tried:

With crontab -u <username> -e for each user I added a single line from the following unique to each:

@reboot mullvad relay set location ie dub
@reboot mullvad relay set location uk lon

but both users, even with different crontabs, still connected to the same VPN.

Next I created this script:

#!/bin/bash

if [ "$(logname)" = "<username>" ]; then
        mullvad relay set location gb lon
else
        mullvad relay set location ie dub
fi

and made it executable with:

chmod u+x /usr/localbin/mullvadrelay.sh

The script itself works when run manually.

I tried getting this to run on login by creating /etc/rc.local and setting it to read:

/usr/localbin/mullvadrelay.sh

but this did not work.

I next edited /etc/bash.barshrc to include the code from the body of the script but discovered this only runs when I open a terminal.

Best solution so far:

Currently I have the following added to the end of /etc/profile:

if [ "$(logname)" = "<username>" ]; then
        mullvad disconnect && mullvad relay set location gb uk && mullvad connect
else
        mullvad disconnect && mullvad relay set location ie dub && mullvad connect
fi

The disconnect and connect were initially outside of the if block but did not function properly. They are not entirely necessary but using this connect instead of the Mullvad program's autoconnect prevents duplicate notifications, and it seems cleaner and a good precaution to put a disconnect in place before changing servers.

This works unless I switch to one user and then back to the first, rather than logging out and in, so with dconf-editor to prevent switching I have set:

disable-user-switching true
user-switch-enabled false

If there was an option to keep the VPN settings isolated to each user I would prefer to keep the switch functionality but only if I could be certain one account would not leak the connection from to the other before being resumed, e.g a website on user1 is connected to a website with VPN1 but while switched to another user, or at some point when later resuming user1 before the script can run, requests are sent using VPN2.

This setup works but I think I must have something wrong as now sometimes when I login my gnome extensions are disabled and I have to turn the parent extension switch on in settings manually. Is there a fix to my solution for the extension issue, or a better way to use a different VPN on each user?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.