Ubuntu – Toggleable system-wide Tor

networkingPROXYtorvpn

I've set up Tor on my system with torsocks by adding 127.0.0.1:9050 to Ubuntu's network proxy settings (set to manual). I can confirm this works as intended by comparing IP addresses and using https://check.torproject.org/

However, while I wish to use a system-wide Tor connection at certain times, I also want to be able to run a normal connection for when security and privacy are not crucial.

In the Android variant (OrBot), you are able to connect to the Tor network, and maintain that connection, but you also have a "VPN Mode" toggle, which is what determines whether a standard or a Tor connection is being made.

This is essentially the functionality I am looking for; a way to quickly and conveniently toggle between Tor and standard connections with a single click or by setting a hotkey.

Best Answer

  • Digging around, I've found one possible solution. This involves setting two hotkeys, and the usage of gsettings.

    After configuring your proxy settings, you will need to go to Settings > Devices > Keyboard and create one custom hotkey that initiates the following command:

    gsettings set org.gnome.system.proxy mode manual
    

    Then create a second one for:

    gsettings set org.gnome.system.proxy mode none
    

    As the proxy settings remain saved whether enabled or not, you can then assign an 'enable' key for the first command, and a 'disable' key for the second.

    Confirm the change by pressing your first hotkey and navigating to Settings > Network, then navigating away, pressing your second hotkey, and returning to the network settings. Assuming Tor is set up correctly, and passes https://check.torproject.org, this should be all that's needed.

    Perhaps not the most ideal solution, but it will do for now, unless someone comes up with a toggle on the activity bar or something.

    EDIT:

    A slight improvement on the above, is to use one hotkey that checks the current state of the proxy mode, then sets it to the opposite. Grab your text editor and create a new file with the following contents:

    case "$(gsettings get org.gnome.system.proxy mode)" in
    "'none'") gsettings set org.gnome.system.proxy mode "'manual'" 
    notify-send "Tor Enabled";;
    "'manual'") gsettings set org.gnome.system.proxy mode  "'none'"
    notify-send "Tor Disabled" ;;
    esac
    

    This will also display a message showing the current state of your proxy settings.

    Save the script somewhere, then reference the file location when creating a custom hotkey.

  • Related Question