Last active
April 1, 2025 17:37
-
-
Save luanlmd/073760fdc6612add76a98610f1af3ca1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Import your .ovpn file using Network Manager | |
# Mark the option:"Use this connection only for resources on its network" both on IPv4 and IPv6 tabs | |
# Set the next 3 variables | |
# Run the script to connect, you may disconnect using Network Manager's UI | |
VPNUSER="user.name" | |
VPNPASS="yourshamefulpassword" | |
VPNTOTP="base32token" | |
if ! command -v oathtool &> /dev/null; then | |
echo "Error: oathtool is not installed. Install it using: sudo apt install oathtool" | |
exit 1 | |
fi | |
TOTP_CODE=$(oathtool --totp --base32 "$VPNTOTP") | |
FINAL_PASSWORD="${VPNPASS}${TOTP_CODE}" | |
CONN=$(nmcli connection show | grep $VPNUSER | awk '{print $1}') | |
if [ -z "$CONN" ]; then | |
echo "Connection with '$VPNUSER' in the name not configured" | |
exit 1 | |
fi | |
nmcli connection down "$CONN" | |
nmcli connection modify "$CONN" vpn.user-name "$VPNUSER" | |
nmcli connection up "$CONN" --ask <<< "$FINAL_PASSWORD" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment