我需要从 Windows 上的 powershell 脚本在 linux 路由器上启动 openconnect VPN。
我在 linux 路由器上有一个工作脚本:
echo PASSWORD | sudo openconnect -b --no-dtls --interface=sslvpn host.isp.com --authgroup=SharedVPN --user=username --passwd-on-stdin
当我在路由器本地运行脚本时,vpn 完美启动。这是我在 Windows 机器上的 powershell 脚本:
Import-Module SSH-Sessions
New-SshSession -ComputerName "10.1.43.11" -Username "ubuntu" -KeyFile "C:\keys.pem"
Invoke-SshCommand -ComputerName "10.1.43.11" -Command '/usr/local/sbin/InitializeVPN'
Remove-SshSession -computername "10.1.43.11"
当我运行 powershell 脚本时,它会启动 VPN,但会冻结在那里,等待 VPN 结束。我可以终止路由器上的进程,然后 powershell 脚本完成。我需要 VPN 在后台运行。所以我修改了路由器上的脚本,如下所示:
echo PASSWORD | sudo openconnect -b --no-dtls --interface=sslvpn host.isp.com --authgroup=SharedVPN --user=username --passwd-on-stdin &
现在,当我运行 powershell 脚本时,它似乎确实将其发送到后台,但 VPN 并没有保持正常运行,我只得到部分输出到屏幕:
Key file specified. Will override password. Trying to read key file...
Successfully connected to 10.1.43.11
10.1.43.11: POST https://host.isp.com/
Connected to ip_addr:443
SSL negotiation with host.isp.com
Connected to HTTPS on host.isp.com
XML POST enabled
POST https://host.isp.com/
Connected to ip_addr:443
SSL negotiation with host.isp.com
Connected to HTTPS on host.isp.com
XML POST enabled
10.1.43.11 should now be disconnected and disposed.
当我直接在路由器上运行它时,在最后一个“启用 XML POST”之后还有更多:
Please enter your username and password.
POST https://host.isp.com/
Got CONNECT response: HTTP/1.1 200 OK
CSTP connected. DPD 30, Keepalive 20
Connected as 10.251.0.29, using SSL
Continuing in background; pid 11049
Connect Banner:
| Access to this system is restricted to authorized users. Unauthorized use is strictly prohibited. Information on this system may be intercepted, recorded, read, copied, and disclosed by and to authorized personnel for official purposes, including criminal investigations. Access or use of this system whether authorized or unauthorized, constitutes your awareness and consent to these terms. DISCONNECT IMMEDIATELY if you do not agree to the conditions stated in this warning.
|
如何让 VPN 在后台启动?
我正在使用 ubuntu 16.04、openconnect 7.08、powershell 5.1、windows server 2016,从http://www.powershelladmin.com/wiki/SSH_from_PowerShell_using_the_SSH.NET_library#Downloads下载了 SSH-Sessions