bash linux:在命令行中传递用户名和密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38869427/
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
linux: passing username and password in command line
提问by JOhnlw009a
I am using IPVanish for using a proxy while surfing; like:
我正在使用 IPVanish 在冲浪时使用代理;喜欢:
sudo openvpn --config /home/ipv/conf/ipvanish-CA-Toronto-tor-a09.ovpn
Now, I have to enter my username, after that my password. How Can I pass those two params right as one command, so that I just use one command and the username/password are being passed automatically?
现在,我必须输入我的用户名,然后输入我的密码。如何将这两个参数作为一个命令直接传递,以便我只使用一个命令并且用户名/密码会自动传递?
回答by Fluffy
The previous answer didn't work for me (still asked for username and password), what did work was putting your credentials in a file (pass.txt), like this
以前的答案对我不起作用(仍然要求输入用户名和密码),起作用的是将您的凭据放入文件(pass.txt)中,如下所示
[email protected]
password
and calling openvpn with --auth-user-pass pass.txt
.
并使用--auth-user-pass pass.txt
.
回答by MrBr
Following @Fluffyanswer (unfortunately I don't have enough reputation to comment)
按照@Fluffy 的回答(不幸的是,我没有足够的声誉来评论)
There is a nice bash trick that can eliminate need for pass.txt file
有一个不错的 bash 技巧可以消除对 pass.txt 文件的需要
Insead of
代替
openvpn ... --auth-user-pass pass.txt
where pass.txt is
pass.txt 在哪里
opvn_user
ovpn_pass
one can use
一个可以使用
openvpn ... --auth-user-pass <(echo -e "opvn_user\novpn_pass")
回答by Franco Miguel Contreras
I'm not new here, but this is my first contribution
我不是新来的,但这是我的第一个贡献
This is what I did: (I'm a noob, advices are welcomed)
这就是我所做的:(我是菜鸟,欢迎提供建议)
Seems to me like you have a config file .ovpn with the configuration needed, you need to create a new file that contains the username and password, you can do it like this
在我看来,您有一个包含所需配置的配置文件 .ovpn,您需要创建一个包含用户名和密码的新文件,您可以这样做
vi pass.txt
Add this lines, save and exit
添加这一行,保存并退出
username
password
Now go the the .ovpn config file and edit, there should be a line that reads auth-user-pass
现在转到 .ovpn 配置文件并进行编辑,应该有一行显示 auth-user-pass
Add your username and password file
添加您的用户名和密码文件
auth-user-pass pass.txt
auth-user-pass pass.txt
Ok so now you should be able to authenticate to the VPN just by executing your .ovpn file
好的,现在您应该能够通过执行您的 .ovpn 文件来对 VPN 进行身份验证
If you need to do something like RDP there is also a way to authenticate without typing the password everytime using a #!/bin/bash script, let me know if you need help :)
如果您需要执行诸如 RDP 之类的操作,还有一种无需每次都使用 #!/bin/bash 脚本输入密码即可进行身份验证的方法,如果您需要帮助,请告诉我:)