S
S
sasha-ld2021-10-20 19:40:24
linux
sasha-ld, 2021-10-20 19:40:24

How to disable connection by one login and password to Openvpn?

There is an Openvpn server on vps Centos 8

server config

duplicate-cn
auth-user-pass-verify /etc/openvpn/verify.sh via-file
username-as-common-name
script-security 2
client-cert-not-required
tmp-dir /etc/openvpn/tmp

client config
client
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
ignore-unknown-option block-outside-dns
block-outside-dns
auth-user-pass
explicit-exit-notify

On the Internet I found such a script for connecting by login and password
#!/bin/sh
## format: username:password username:password ...
## you can even have same usernames with different passwords
# USERS='user1:pass1 user2:pass2 user3:pass3'
## you could put username:password in
## a separate file and read it like this
USERS=`cat /etc/openvpn/user.pass`
vpn_verify() {
if [ ! $1 ] || [ ! $2 ]; then
#echo "No username or password: $*"
exit 1
fi
## it can also be done with grep or sed
for i in $USERS; do
if [ "$i" = "$1:$2" ]; then
## you can add here logging of users
## if you have enough space for log file
#echo `date` $1:$2 >> your_log_file
exit 0
fi
done
}
if [ ! $1 ] || [ ! -e $1 ]; then
#echo "No file"
exit 1
fi
## $1 is file name which contains
## passed username and password
vpn_verify `cat $1`
#echo "No user with this password found"
exit 1

Everything works, it connects, but you can somehow implement a connection using one certificate so that it is impossible to connect with one login and password to several clients at the same time.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Falaleev, 2021-10-20
@sasha-ld

https://4admin.info/setup-openvpn-deny-concurrent-...
And take a look at the comments below.

M
mureevms, 2021-10-21
@mureevms

If external authorization is used, and it is used, judging by the attached script, you just need to remove it duplicate-cnfrom the server config.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question