尝试在启动时连接到 VPN 时出错

Que*_*ner 14 vpn

此问题已更新。请看这篇文章的结尾。

我正在尝试将 Mythbuntu 计算机设置为在启动时连接到 VPN 服务。我希望 Mythbuntu 计算机将始终使用 VPN 进行所有互联网连接。

找到了一个据说可以做到这一点的脚本,它看起来像这样:

#!/bin/bash
while [ "true" ]
do
    VPNCON=$(nmcli con status)
    if [[ $VPNCON != "*MyVPNConnectionName*" ]]; then
        echo "Disconnected, trying to reconnect..."
        (sleep 1s && nmcli con up uuid df648abc-d8f7-4ce4-bdd6-3e12cdf0f494)
    else
        echo "Already connected !"
    fi
    sleep 30
done
Run Code Online (Sandbox Code Playgroud)

当我在我的机器上运行这个脚本时,我收到以下错误:

$ /home/mythbuntu/VPN_start.sh
Disconnected, trying to reconnect...
Error: Connection activation failed: Not authorized to control networking.
Run Code Online (Sandbox Code Playgroud)

我认为这可能是权限问题,所以我尝试使用 sudo 运行它:

$ sudo /home/mythbuntu/VPN_start.sh
[sudo] password for mythbuntu: 
Disconnected, trying to reconnect...
Active connection state: unknown
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/1
state: VPN connecting (need authentication) (2)
Error: Connection activation failed: no valid VPN secrets.
Run Code Online (Sandbox Code Playgroud)

如何让此脚本无错误地运行,以便我可以在启动或登录时运行它,从而确保我始终通过 VPN 进行连接。

如果有人有更好的脚本或方法,那也足以作为答案。


这些是我的 /etc/NetworkManager/system-connections/MyVPN 文件的内容(一些细节用 x 字符替换以保护隐私):

[connection]
id=MyVPN
uuid=xxxxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxxxxx
type=vpn

[vpn]
service-type=org.xxxxxxxxxxxxxx.xxxxxxxxxxxxxxx.openvpn
username=xxxxxxxxxx
comp-lzo=yes
remote=us-xxxxxx.xxxxxxx.com
connection-type=password
password-flags=0
ca=/etc/openvpn/xxxxxxx.crt

[vpn-secrets]
password=xxxxxxxxxxx

[ipv4]
method=auto
never-default=true
Run Code Online (Sandbox Code Playgroud)

另外,我只想补充一点,当我使用 Xfce 面板右上角的小程序打开 VPN 时,它连接没有问题。因此,在我看来,问题不是授权不正确,而是尝试从命令行执行此操作时的配置问题。

更新:

我不完全确定发生了什么变化——可能是升级到 12.10 时发生的变化——但我现在可以从命令行启动我的 VPN 服务。但是,此命令仅在我第一次启动计算机时有效一次,并且还需要使用sudo.

mythbuntu@mythbuntu:~$ nmcli con up id "Private Internet Access SSL"
Error: Connection activation failed: Not authorized to control networking.
mythbuntu@mythbuntu:~$ sudo nmcli con up id "Private Internet Access SSL"
[sudo] password for mythbuntu: 
mythbuntu@mythbuntu:~$
Run Code Online (Sandbox Code Playgroud)

由于我需要使用它sudo来运行它,所以我无法在启动时自动运行它。

如何获得它以便我可以在没有超级用户权限的情况下启动我的 VPN?

dev*_*av2 8

问题似乎是,您在密钥环中的密码无法访问。

来源

提到的解决方案是打开文件/etc/NetworkManager/system-connections/ConnectionName并设置

password-flags=0
Run Code Online (Sandbox Code Playgroud)

并将以下几行添加到文件中

 [vpn-secrets]
 password=YourPassword
Run Code Online (Sandbox Code Playgroud)

然后重新启动网络管理器以获取更改:

 sudo restart network-manager
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅来源