尝试在启动时连接到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 

当我在我的机器上运行此脚本时,出现以下错误:

 $ /home/mythbuntu/VPN_start.sh Disconnected, trying to reconnect... Error: Connection activation failed: Not authorized to control networking. 

我认为这可能是一个权限问题,所以我尝试用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. 

如何在没有错误的情况下运行此脚本,以便我可以在启动或登录时运行它,以便我可以确保始终通过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 

另外,我只想补充一点,当我使用右上角的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:~$ 

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

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

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

资源

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

 password-flags=0 

并将以下行添加到文件中

  [vpn-secrets] password=YourPassword 

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

  sudo restart network-manager 

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

在启动时自动启动VPN

假设您的凭证文件正常工作,您应该能够使用像您最初启动VPN一样的dispatcher.d脚本。 我已经修改了你的脚本以使其能够使用2个连接(家中的无线路由器和工作时的有线连接)。 这样做的原因是,如果在我所需的任何互联网连接都处于活动状态时未启动,我希望它启动VPN。 在我的示例中,我使用默认名称对它们进行了配置,但您应该更改它们以匹配您自己的名称。

把它放在文件/etc/NetworkManager/dispatcher.d/vpn-up ,用chmod +x创建可执行文件

 #! /bin/bash REQUIRED_CONNECTION1_NAME="linksys" REQUIRED_CONNECTION2_NAME="Wired connection 1" VPN_CONNECTION_NAME="My VPN" activ_con=$(nmcli con status | grep "${REQUIRED_CONNECTION1_NAME}\|${REQUIRED_CONNECTION2_NAME}") activ_vpn=$(nmcli con status | grep "${VPN_CONNECTION_NAME}") if [ "${activ_con}" -a ! "${activ_vpn}" ]; then nmcli con up id "${VPN_CONNECTION_NAME}" fi 

在NetworkManager中配置客户端证书

如果您使用带密码的客户端证书对VPN进行身份validation,则它有点无证。

浏览NetworkManager 0.9设置规范后 ,我无法确定如何在配置文件中指定vpn cert pass。 我打开了seahorse ,找到了我的“ VPN秘密 ”(证书密码)。

它被列为“ 我的VPN / org.freedesktop.NetworkManager.openvpn / vpn ”的“ VPN cert-pass secret ”。 单击详细信息选项卡为我提供了setting-key名称的线索:

 setting-name: vpn setting-key: cert-pass connection-uuid: 0badcafe-f00d-dead-beef-feedfacef00d 

使用NetworkManager 0.9.4.0在Ubuntu 12.04(Precise Pangolin)上以root身份自动启动VPN:

打开/etc/NetworkManager/system-connections/My VPN并添加cert-pass VPN密码,使文件如下所示:

 [connection] id=My VPN uuid=0badcafe-f00d-dead-beef-feedfacef00d type=vpn timestamp=1234567890 [vpn] service-type=org.freedesktop.NetworkManager.openvpn key=/home//path/to/certs/your.secure.key ca=/home//path/to/certs/your.vpnca.crt connection-type=tls cert=/home//path/to/certs/your.crt remote=your.vpn-server.com cert-pass-flags=0 [vpn-secrets] cert-pass=your-vpn-pass [ipv4] method=auto never-default=true