Hi,
This is a script which to create an opvn user, I want which answer automatically to a certain part so, I try this, it works without the red part but I must type manually.. :
#!/bin/bash
## Environnement ##
LC_ALL=C
## Paths ##
rsa_dir="etc/openvpn/easy-rsa"
rsa_key_dir="etc/openvpn/easy-rsa/keys"
user_dir="etc/openvpn/users"
ccd_dir="etc/openvpn/ccd"
## Regex filter ##
regex_filter='[^a-zA-Z_0-9\s]'
## Position ##
cd /"$rsa_dir"/
## Loop ##
while
read -p "Please can you enter the vpn's username : " username
[[ -z "$username" ]] || [[ ${#username} -lt 2 ]] || [[ ${#username} -gt 15 ]] || [[ "$username" =~ $regex_filter ]]
do
echo "Your entry must not contain special characters and its length must do between 2-15 characters."
done
## Commands ##
. ./vars
./build-key "$username" << EOF
(14 empty lines feed)
y
y
EOF
cp -p /"$rsa_key_dir"/"$username".* /"$user_dir"/
cd /"$user_dir"/; cp template.ovpn "$username".ovpn
sed -i 's/name/'$username'/g' "$username".ovpn
tar -czvf "$username".tar.gz "$username".* ta.key ca.crt
touch ../ccd/"$username"
cp -a "$username".tar.gz /tmp/
scp "$username".* usersend@1.1.1.1:/tmp/.
Ouput :
$./user_ovpn.sh
Please can you enter the vpn's username : iki
NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/keys
Generating a 2048 bit RSA private key
........................................................................+++
....+++
writing new private key to 'iki.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [FR]:State or Province Name (full name) [FR]:Locality Name (eg, city) [hello]:
Organization Name (eg, company) [Hello]:Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) [iki]:Name [HELLO_VPN]:Email Address [hello@machin.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:An optional company name []:Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'FR'
stateOrProvinceName :PRINTABLE:'FR'
localityName :PRINTABLE:'Hello'
organizationName :PRINTABLE:'Hello'
commonName :PRINTABLE:'Hello'
name :T61STRING:'Hello'
emailAddress :IA5STRING:'Hello@machin.com'
Certificate is to be certified until Oct 13 06:01:44 2026 GMT (3650 days)
Sign the certificate? [y/n]:CERTIFICATE WILL NOT BE CERTIFIED: I/O error
iki.crt
iki.csr
iki.key
iki.ovpn
ta.key
ca.crt
Example of output with manually entries :
$./vpn_user.sh
Please can you enter the vpn's username : testuser2
NOTE: If you run ./clean-all, I will be doing a rm -rf on /etc/openvpn/easy-rsa/keys
Generating a 2048 bit RSA private key
............................................+++
............+++
writing new private key to 'testuser2.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [FR]:
State or Province Name (full name) [FR]:
Locality Name (eg, city) [Hello]:
Organization Name (eg, company) [hello]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) [testuser2]:
Name [HELLO_VPN]:
Email Address [hello@machin.com]:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'FR'
stateOrProvinceName :PRINTABLE:'FR'
localityName :PRINTABLE:'Hello'
organizationName :PRINTABLE:'Hello'
commonName :PRINTABLE:'testuser2'
name :T61STRING:'HELLO_VPN'
emailAddress :IA5STRING:'hello@machin.com'
Certificate is to be certified until Oct 13 05:45:45 2026 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
testuser2.crt
testuser2.csr
testuser2.key
testuser2.ovpn
ta.key
ca.crt
In red that represent the manually entries that I want which works automatically
Thanks in advance..