Openvpn密码认证

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
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进程下可见,脚本所需的shell也需要在其中,还需要任何必要的库。在这种情况下,您需要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

-1

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

根@我的服务器:/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

问题出在 sh 脚本上。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接