C# Windows 上的 OpenVPN --auth-user-pass FILE 选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1203343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenVPN --auth-user-pass FILE option on Windows
提问by jonathanpeppers
If you try to pass the username/password to OpenVPN from a file via the --auth-user-pass switch, you get the following error:
如果您尝试通过 --auth-user-pass 开关将用户名/密码从文件传递给 OpenVPN,则会出现以下错误:
"Sorry, 'Auth' password cannot be read from a file."
At least they're polite.
至少他们很有礼貌。
So our workaround was to programmatically write to "standard in" when we get the Auth Username: and Auth Password: prompts (this is in C#).
因此,我们的解决方法是在获得 Auth Username: 和 Auth Password: 提示(这是在 C# 中)时以编程方式写入“标准输入”。
Something with the timing isn't 100% reliable, so I was looking for a way to pass the credentials to OpenVPN in a different way and came across this post: OpenVPN Post
时间上的东西不是 100% 可靠的,所以我正在寻找一种方法以不同的方式将凭据传递给 OpenVPN 并遇到了这篇文章:OpenVPN Post
It says you can recompile the source with a --enable-password-save option. Has anyone been able to do this?
它说您可以使用 --enable-password-save 选项重新编译源代码。有没有人能够做到这一点?
My final question is: How can I pass an auth username/password to openvpn.exe on the client side? And does OpenVPNGUI somehow do this (maybe we can copy what they do)?
我的最后一个问题是:如何在客户端将身份验证用户名/密码传递给 openvpn.exe?OpenVPNGUI 是否以某种方式做到了这一点(也许我们可以复制他们所做的)?
采纳答案by jonathanpeppers
It turns out the problem wasn't with standard in.
事实证明,问题不在于标准输入。
I was using some locking where if the process exited in the middle of writing to standard in, there could be a deadlock.
我正在使用一些锁定,如果进程在写入标准输入的过程中退出,则可能会出现死锁。
There is no issue sending the password in this manner.
以这种方式发送密码没有问题。
回答by Mark Starmer
It's possible to open a VPN connection via a script by using the following DOS command (however this is not recommended since the password is not encrypted)
可以使用以下 DOS 命令通过脚本打开 VPN 连接(但不建议这样做,因为密码未加密)
$openvpn.exe config.ovpn < username < password
回答by user2363047
For automatic authentication to Openvpn you have to modify the config.ovpn file.
对于 Openvpn 的自动身份验证,您必须修改 config.ovpn 文件。
-Go to OpenVPN\config directory and edit the .ovpn file
-转到 OpenVPN\config 目录并编辑 .ovpn 文件
-Add this line to the config file -> auth-user-pass password.txt
- 将此行添加到配置文件 -> auth-user-pass password.txt
-Then create the password.txt file and write in it:
-然后创建password.txt文件并写入:
yourusername
yourpassword
-After these steps your openvpn will connect automatically.
- 完成这些步骤后,您的 openvpn 将自动连接。
回答by Timofey
NOTE! param auth-user-passnot work if start by GUI "C:\Program Files\OpenVPN\config\name.ovpn"
笔记!如果通过 GUI "C:\Program Files\OpenVPN\config\name.ovpn" 启动参数auth-user-pass不起作用
Made start file start_openvpv.cmd (+ link to with "run as admin") with content:
使用以下内容制作启动文件 start_openvpv.cmd(+ 链接到“以管理员身份运行”):
cd C:\Users\Name\Documents\VPN
"C:\Program Files\OpenVPN\bin\openvpn.exe" --config C:\Users\Name\Documents\VPN\myvpnconfig.ovpn --auth-user-pass "C:\Users\Name\Documents\VPN\pass.txt"
pass.txt:
通过.txt:
yourusername
yourpassword
OR put line to name.ovpn, as in upper messege:
或将行放入 name.ovpn,如上层消息:
auth-user-pass pass.txt
+start_openvpv.cmd:
+start_openvpv.cmd:
cd C:\Users\Name\Documents\VPN
"C:\Program Files\OpenVPN\bin\openvpn.exe" --config C:\Users\Name\Documents\VPN\myvpnconfig.ovpn