4

我正在尝试将 openvpn windows 客户端连接到在 ubuntu 上运行的 openvpn 服务器。使用“仅证书”身份验证时,VPN 工作正常,. 但是当尝试使用下面的脚本进行身份验证时,我在客户端上遇到以下错误:

Mon Jan 21 14:59:07 2013 SENT CONTROL [server]: 'PUSH_REQUEST' (status=1)
Mon Jan 21 14:59:07 2013 AUTH: Received AUTH_FAILED control message
Mon Jan 21 14:59:07 2013 TCP/UDP: Closing socket
Mon Jan 21 14:59:07 2013 SIGTERM[soft,auth-failure] received, process exiting

vpn_user.sh 是一个可执行文件,可由 server.conf 文件访问。

任何帮助表示赞赏。


这是身份验证脚本:

#!/bin/sh
#vpn_user.sh

ALLOWED_USER="user1"

ALLOWED_PASS="password1"
echo "$username"
echo "$password"

if ["$username"=="$ALLOWED_USER"] && ["$password"=="$ALLOWED_PASS"]
    then exit 0
fi

exit 1

服务器配置:

#server.conf
port 1194
proto udp
dev tap0

client-cert-not-required
auth-user-pass-verify vpn_user.sh via-env
script-security 3
username-as-common-name
tmp-dir /dev/shm

ca ca.crt
cert server.crt
key server.key  # This file should be kept secret
dh dh1024.pem
ifconfig-pool-persist ipp.txt
server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
client-to-client
duplicate-cn
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
log         openvpn.log
verb 3

客户端配置

client
dev tap
proto udp
remote 10.xx.xx.xx 1194
auth-user-pass
resolv-retry infinite
persist-key
persist-tun
ca ca.crt
dh dh1024.pem
comp-lzo
verb 3
4

2 回答 2

2

1.您输入的脚本行中缺少空格if,应该是:

if [ "$username" == "$ALLOWED_USER" ] && [ "$password" == "$ALLOWED_PASS" ]

执行脚本时会出现什么?以下是我的测试示例:

# username=user1 password=password1 ./vpn_user.sh && echo "authentication OK" || echo "Authentication failed"
user1
password1
authentication OK

# username=user1 password=wrong-pass ./vpn_user.sh && echo "authentication OK" || echo "Authentication failed"**
user1
wrong-pass
Authentication failed

2. 同时检查您的server.conf. 您可能需要将完整路径放入脚本

这是重要的部分:

auth-user-pass-verify /full/path/to/vpn_user.sh via-env
script-security 3

3. Chroot-ed 执行可能会造成困难。

如果您在 chroot 下运行 openvpn - 那么您的脚本需要在 chroot-ed 进程下可见,脚本的 shell 以及任何需要的库都需要可用。在这种情况下,您需要 chroot 并在 chroot 下测试脚本的执行。

这可能很棘手,对我来说,一个快速的解决方案是编写自己的小程序并编译(作为静态 - 不需要外部库)。

确切的指令、源代码、编译指令等 - 仍应在以下位置提供:

http://openbsdsupport.org/openvpn-on-openbsd.html

甚至更好 - 尝试直接转到相关部分:

http://openbsdsupport.org/openvpn-on-openbsd.html#AuthenticationVariant1simple

4. Openvpn 客户端也需要配置为使用密码认证。

验证客户端配置中的选项client-config.ovpn

password auth-user-pass
于 2017-10-27T18:56:52.947 回答
-1

root@myserver:/var/www# cat /tmp/quickAuth.sh

#!/bin/bash
#vpn_user.sh

ALLOWED_USER="user"
ALLOWED_PASS="password"

echo "$username"
echo "$password"
echo $ALLOWED_USER
echo $ALLOWED_PASS


if [[ "$username" == "$ALLOWED_USER"  && "$password"="$ALLOWED_PASS" ]]
then
 exit 0
else
  exit 1
fi

客户端配置

client
dev tun
proto udp
remote remote ip server 1194(server port)
resolv-retry infinite
nobind
user nobody
group nogroup
persist-key
persist-tun
mute-replay-warnings
ca ca.crt
cert client.crt
key client.key
ns-cert-type server
auth-user-pass
comp-lzo
route xxx.xxx.xxx.xxx  255.255.255.255 the ip that i want to route throw the openvpn(if default was not made)
verb 3

prb 带有 sh 脚本

于 2015-10-29T06:54:13.930 回答