直接在Ubuntu 10.10中将私钥密码传递给openvpn命令

时间:2012-06-28 07:45:13

标签: linux shell command openvpn

我尝试了使用不同参数的方法

我有密码 以下密码为 mypassword

1)

root$ echo mypassword || openvpn client.conf.ovpn 

结果显示:

mypassword

2)

root$ openvpn client.warriors.conf.ovpn || echo mypassword

结果显示:

Thu Jun 28 00:00:00 2012 us=757575 NOTE: OpenVPN 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables  
Enter Private Key Password:  

(仍然需要手动输入密码)

我不想手动输入密码。我怎样才能做到这一点?

3) DUDE

运行脚本后,它会退出:

Fri Jun 29 11:56:59 2012 us=707916   cf_max = 0
Fri Jun 29 11:56:59 2012 us=707925   cf_per = 0
Fri Jun 29 11:56:59 2012 us=707934   max_clients = 1024
Fri Jun 29 11:56:59 2012 us=707944   max_routes_per_client = 256
Fri Jun 29 11:56:59 2012 us=707953   auth_user_pass_verify_script = '[UNDEF]'
Fri Jun 29 11:56:59 2012 us=707963   auth_user_pass_verify_script_via_file = DISABLED
Fri Jun 29 11:56:59 2012 us=707973   ssl_flags = 0
Fri Jun 29 11:56:59 2012 us=707982   port_share_host = '[UNDEF]'
Fri Jun 29 11:56:59 2012 us=707992   port_share_port = 0
Fri Jun 29 11:56:59 2012 us=708001   client = ENABLED
Fri Jun 29 11:56:59 2012 us=708010   pull = ENABLED
Fri Jun 29 11:56:59 2012 us=708020   auth_user_pass_file = '[UNDEF]'
Fri Jun 29 11:56:59 2012 us=708032 OpenVPN 2.1.0 i686-pc-linux-gnu [SSL] [LZO2] [EPOLL] [PKCS11] [MH] [PF_INET6] [eurephia] built on Jul 12 2010
Fri Jun 29 11:56:59 2012 us=708131 NOTE: OpenVPN 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables
Enter Private Key Password:
Fri Jun 29 11:56:59 2012 us=726649 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this
Fri Jun 29 11:56:59 2012 us=726805 WARNING: file 'client-team-20110222.key' is group or others accessible
Fri Jun 29 11:56:59 2012 us=727136 /usr/bin/openssl-vulnkey -q -b 1024 -m <modulus omitted>
Fri Jun 29 11:56:59 2012 us=875611 Control Channel MTU parms [ L:1543 D:140 EF:40 EB:0 ET:0 EL:0 ]
Fri Jun 29 11:56:59 2012 us=876742 Data Channel MTU parms [ L:1543 D:1450 EF:43 EB:4 ET:0 EL:0 ]
Fri Jun 29 11:56:59 2012 us=876777 Local Options String: 'V4,dev-type tun,link-mtu 1543,tun-mtu 1500,proto TCPv4_CLIENT,cipher BF-CBC,auth SHA1,keysize 128,key-method 2,tls-client'
Fri Jun 29 11:56:59 2012 us=876788 Expected Remote Options String: 'V4,dev-type tun,link-mtu 1543,tun-mtu 1500,proto TCPv4_SERVER,cipher BF-CBC,auth SHA1,keysize 128,key-method 2,tls-server'
Fri Jun 29 11:56:59 2012 us=876810 Local Options hash (VER=V4): 'd902a8f8'
Fri Jun 29 11:56:59 2012 us=876825 Expected Remote Options hash (VER=V4): '7e078940'
Fri Jun 29 11:56:59 2012 us=877124 NOTE: UID/GID downgrade will be delayed because of --client, --pull, or --up-delay
Fri Jun 29 11:56:59 2012 us=877145 Attempting to establish TCP connection with [AF_INET]89.105.130.193:444 [nonblock]
Fri Jun 29 11:57:00 2012 us=877280 TCP connection established with [AF_INET]89.105.130.193:444
Fri Jun 29 11:57:00 2012 us=877337 Socket Buffers: R=[87380->131072] S=[16384->131072]
Fri Jun 29 11:57:00 2012 us=877353 TCPv4_CLIENT link local: [undef]
Fri Jun 29 11:57:00 2012 us=877364 TCPv4_CLIENT link remote: [AF_INET]89.105.130.193:444
Fri Jun 29 11:57:00 2012 us=877568 TLS: Initial packet from [AF_INET]89.105.130.193:444, sid=c5d843bc e9f3e6ab
Fri Jun 29 11:57:04 2012 us=105788 VERIFY OK: depth=1, /C=IE/ST=NA/L=DUB/O=ABC.OpenVPN/OU=server-terminus/CN=terminus/emailAddress=ops@abc.com
Fri Jun 29 11:57:04 2012 us=106189 VERIFY OK: nsCertType=SERVER
Fri Jun 29 11:57:04 2012 us=106202 VERIFY OK: depth=0, /C=IE/ST=NA/O=abc.OpenVPN/OU=server-terminus/CN=terminus/emailAddress=ops@abc.com
root@bond$

以这种方式退出是正常的。

4 个答案:

答案 0 :(得分:53)

在我的openvpn.conf

...
askpass /etc/openvpn/jdoe.pass   <<< new line here
ca /etc/openvpn/jdoe_ca.crt
cert /etc/openvpn/jdoe.crt
key /etc/openvpn/jdoe.key
...

文件/etc/openvpn/jdoe.pass只包含密码。 您可以chmod将此文件600发送至Ubuntu 12.04.4 LTS OpenVPN 2.2.1 x86_64-linux-gnu [SSL] [LZO2] [EPOLL] [PKCS11] [eurephia] [MH] [PF_INET6] [IPv6 payload 20110424-2 (2.2RC2)] built on Mar 13 2014 。 这种方法挽救了我的生命...; - )

{{1}}

答案 1 :(得分:7)

尝试使用shell脚本,例如:

#!/usr/bin/expect -f
spawn openvpn client.warriors.conf.open
match_max 100000
expect "*?assword:*"
send -- "mypassword"
send -- "\r"
expect eof

您需要chmod + x this,您也可以将其设置为环境变量,这样您就不必输入目录。

看起来他们让这个脚本工作了:https://unix.stackexchange.com/questions/9055/establish-openvpn-tunnel-in-bash-script

答案 2 :(得分:6)

如何将其存储到文件中并使用--askpass /your/file?在OpenVPN版本2.0-beta20中添加了--askpass选项,Maverick的版本为2.1.0-3ubuntu1

答案 3 :(得分:0)

我认为您只需轻扫|||运营商。

|将上一个命令的标准输出插入下一个命令的标准输入。

||仅在第一个命令失败时才启动第二个命令(退出代码!= 0)。

此命令应该有效。

root$ echo mypassword | openvpn client.conf.ovpn