DIRECTORY STATUS (commands would take effect on these locations) EASYRSA: /etc/openvpn/easy-rsa-server PKI: /etc/openvpn/easy-rsa-server/pki vars-file: /etc/openvpn/easy-rsa-server/vars x509-types: /etc/openvpn/easy-rsa-server/x509-types CA status: CA has not been built
IMPORTANT: The preferred location for 'vars' is within the PKI folder. To silence this message move your 'vars' file to your PKI or declare your 'vars' file with option: --vars=<FILE> ## 初始化PKI ,在当前目录下生成PKI目录及相关文件 [root@rocky9 easy-rsa-server]# ./easyrsa init-pki
Notice ------ 'init-pki' complete; you may now create a CA or requests.
Your newly created PKI dir is: * /etc/openvpn/easy-rsa-server/pki
Using Easy-RSA configuration: * /etc/openvpn/easy-rsa-server/vars
IMPORTANT: The preferred location for 'vars' is within the PKI folder. To silence this message move your 'vars' file to your PKI or declare your 'vars' file with option: --vars=<FILE>
## 生成的PKI [root@rocky9 easy-rsa-server]# tree . ├── easyrsa ├── openssl-easyrsa.cnf ├── pki │ ├── inline │ ├── openssl-easyrsa.cnf │ ├── private │ ├── reqs │ └── vars.example ├── vars └── x509-types ├── COMMON ├── ca ├── client ├── code-signing ├── email ├── kdc ├── server └── serverClient
[root@rocky9 easy-rsa-server]# ./easyrsa build-ca Using Easy-RSA 'vars' configuration: * /etc/openvpn/easy-rsa-server/vars
IMPORTANT: The preferred location for 'vars' is within the PKI folder. To silence this message move your 'vars' file to your PKI or declare your 'vars' file with option: --vars=<FILE>
Using SSL: * openssl OpenSSL 3.0.7 1 Nov 2022 (Library: OpenSSL 3.0.7 1 Nov 2022)
## (在此处设置CA密码) Enter New CA Key Passphrase:
Confirm New CA Key Passphrase: ....+.+..............+.+...+..+....+.....+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...........+.+..............+...+................+..+...+.+.........+......+.....+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+.....+......+.......+...+.....+.+........+......+....+...........+.+...+..+................+...+......+.....+.........................+......+..+................+..+.........+............................+...+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .+.+.....+.........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.........+...+..+.+.........+..+....+..+....+...+......+...........+....+......+......+..+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..+...+...+...+.......+...+.....+...................+..+...+......+.+...........+....+......+...+...........+...+.+..............+...+.......+........+...............+.......+...............+.....+......+....+..+....+...........+.+..+.+............+........+.+...+..+................+............+..+......+...+.+........+.+......+..........................+....+...+.....+.......+...+..+.+...+...........+.+.........+...+..+................+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ----- 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. ----- ## (在此外回车接受默认值) Common Name (eg: your user, host, or server name) [Easy-RSA CA]:
Notice ------ CA creation complete. Your new CA certificate is at: * /etc/openvpn/easy-rsa-server/pki/ca.crt
[root@rocky9 easy-rsa-server]# ./easyrsa gen-req server nopass Using Easy-RSA 'vars' configuration: * /etc/openvpn/easy-rsa-server/vars
IMPORTANT: The preferred location for 'vars' is within the PKI folder. To silence this message move your 'vars' file to your PKI or declare your 'vars' file with option: --vars=<FILE>
Using SSL: * openssl OpenSSL 3.0.7 1 Nov 2022 (Library: OpenSSL 3.0.7 1 Nov 2022) ......+.+......+........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*....+....+...+......+....................+.+.....+.+........+.+...+...............+..+.+........+....+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.....+.+...+..+........................+......+..........+.....+....+..............+....+.....+...+....+...+...+........+......+......+.......+...+............+..+....+.....+......+.+.........+.....+...+...+.......+.....+.+...............+......+.....+.+.........+...+..+.+........+.+.....+......+.........+.............+..+...+...+..........+........+.+...+.....+.+...........+.+...+..............+......+.....................+.+..+...+....+........+..................+....+.....+....+......+........+.......+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ .....+......+...+.+......+.........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...+..............+.............+.....+....+.....+.+.....+...+.......+..+.+......+.........+.....+.........+.............+...+..............+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+...+..+......+...+....+..+.+............+.....+.+...............+..+.......+...+..+.+..+...+...............+.......+....................+..........+...............+..............+....+......+......+...+..+............+.......+.....+....+...........+......+....+..............+............+....+...+..+......+...+.......+..+.......+...+.....+............+...+...+....+.....+..........+.........+............+..+..........+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ----- 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. ----- Common Name (eg: your user, host, or server name) [server]: ## 回车确认 Notice ------ Private-Key and Public-Certificate-Request files created. Your files are: * req: /etc/openvpn/easy-rsa-server/pki/reqs/server.req * key: /etc/openvpn/easy-rsa-server/pki/private/server.key
[root@rocky9 easy-rsa-server]# ./easyrsa sign server server Using Easy-RSA 'vars' configuration: * /etc/openvpn/easy-rsa-server/vars
IMPORTANT: The preferred location for 'vars' is within the PKI folder. To silence this message move your 'vars' file to your PKI or declare your 'vars' file with option: --vars=<FILE>
Using SSL: * openssl OpenSSL 3.0.7 1 Nov 2022 (Library: OpenSSL 3.0.7 1 Nov 2022) You are about to sign the following certificate: Please check over the details shown below for accuracy. Note that this request has not been cryptographically verified. Please be sure it came from a trusted source or that you have verified the request checksum with the sender. Request subject, to be signed as a server certificate for '18250' days:
subject= commonName = server
Type the word 'yes' to continue, or any other input to abort. Confirm request details: yes ## 输入yes确认 Using configuration from /etc/openvpn/easy-rsa-server/pki/openssl-easyrsa.cnf Enter pass phrase for /etc/openvpn/easy-rsa-server/pki/private/ca.key: ## 输入设置的CA密码 Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows commonName :ASN.1 12:'server' Certificate is to be certified until Apr 18 05:24:37 2074 GMT (18250 days)
Write out database with 1 new entries Data Base Updated
Notice ------ Certificate created at: * /etc/openvpn/easy-rsa-server/pki/issued/server.crt
[root@rocky9 easy-rsa-server]# ./easyrsa gen-dh Using Easy-RSA 'vars' configuration: * /etc/openvpn/easy-rsa-server/vars
IMPORTANT: The preferred location for 'vars' is within the PKI folder. To silence this message move your 'vars' file to your PKI or declare your 'vars' file with option: --vars=<FILE>
Using SSL: * openssl OpenSSL 3.0.7 1 Nov 2022 (Library: OpenSSL 3.0.7 1 Nov 2022) Generating DH parameters, 2048 bit long safe prime ......................................................+..................................+...........................................................................................................................+...............................................................................................................................................................................+....................................................................................+........................+.............+..................................+.......+......+.........................................................................................................................................................................+.............................+........................................+.......................................................+..........................................................................................................................................................+.............................................+......................................................................................................................................................................+........................................................................................................................................................................................................................+...........................................................................................................................................................................................................................+.........................+......................+....................................................................+..........................................................................................................+......................................................................................................................................................................+...........................................................................................................................................................................................................................................................................................................................................................+....+............................................................................................................................................+.................................................................................+..........+.....................................................................................................................................................................................................................+............++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++* DH parameters appear to be ok.
Notice ------
DH parameters of size 2048 created at: * /etc/openvpn/easy-rsa-server/pki/dh.pem
创建客户端证书和私钥
1 2 3 4
## 修改客户端证书的有效期设置
[root@rocky9 easy-rsa-server]# vim vars set_var EASYRSA_CERT_EXPIRE 180
IMPORTANT: The preferred location for 'vars' is within the PKI folder. To silence this message move your 'vars' file to your PKI or declare your 'vars' file with option: --vars=<FILE>
Using SSL: * openssl OpenSSL 3.0.7 1 Nov 2022 (Library: OpenSSL 3.0.7 1 Nov 2022) .+.........+..+.......+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*...+........+...+.+.....+.+...+...........+....+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+..................+...+....+...+...+..+..........+..+.......+.........+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ..+.+...+...+..+...+.............+..............+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.....+.....+.......+.....+.......+..+....+.....+....+..+...+.+...........+.........+.+......+........................+......+...+..+...+.+...+.....+.......+......+.....+...+......+..........+...+......+..+....+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*..............+...+............+....+...+........+.............+.........+......+...........+...+..........+...+..+.......+...........+.........+...+...+....+...+.....+......+.+...........+....+.........+......+........+......+.......+..+..........+...+.....+.........+.+.....+............+.+.....+....+...+...+......+...+......+......+........+............+.+..+................+..+...+.......+............+.....+................+......+...+...+..+.+......+.....+....+..+.......+..+......+.......+...+...+.....+.......+...+..+......................+.....+...+...+......+..........+...........+...+.......+..+.......+.........+.........+.....+............+...................+.............................+.+..+....+.....+.+..+.......+...+..+.+.....+..............................+...+.......+.....+...+.+...+...+...+...........+...+.+...........+..........+...+...+.....+.........+...+.......+........+.+...............+......+.....+..........+...............+......+..+...+...+....+...+............+......+...............+..+...+....+...+.....+.......+..+...+......+.......+..............+................+.....+..........+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ----- 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. ----- Common Name (eg: your user, host, or server name) [xcjyc]:
Notice ------ Private-Key and Public-Certificate-Request files created. Your files are: * req: /etc/openvpn/easy-rsa-server/pki/reqs/xcjyc.req * key: /etc/openvpn/easy-rsa-server/pki/private/xcjyc.key
IMPORTANT: The preferred location for 'vars' is within the PKI folder. To silence this message move your 'vars' file to your PKI or declare your 'vars' file with option: --vars=<FILE>
Using SSL: * openssl OpenSSL 3.0.7 1 Nov 2022 (Library: OpenSSL 3.0.7 1 Nov 2022) You are about to sign the following certificate: Please check over the details shown below for accuracy. Note that this request has not been cryptographically verified. Please be sure it came from a trusted source or that you have verified the request checksum with the sender. Request subject, to be signed as a client certificate for '180' days:
subject= commonName = xcjyc
Type the word 'yes' to continue, or any other input to abort. Confirm request details: yes ## 输入yes确认 Using configuration from /etc/openvpn/easy-rsa-server/pki/openssl-easyrsa.cnf Enter pass phrase for /etc/openvpn/easy-rsa-server/pki/private/ca.key: ## 输入CA的密码 Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows commonName :ASN.1 12:'xcjyc' Certificate is to be certified until Oct 27 05:43:16 2024 GMT (180 days)
Write out database with 1 new entries Data Base Updated
Notice ------ Certificate created at: * /etc/openvpn/easy-rsa-server/pki/issued/xcjyc.crt
## 检查服务状态及1194端口 [root@rocky9 ~]# systemctl status openvpn@server ● openvpn@server.service - OpenVPN Robust And Highly Flexible Tunneling Application On server Loaded: loaded (/usr/lib/systemd/system/openvpn@.service; enabled; preset: disabled) Active: active (running) since Tue 2024-04-30 15:28:49 CST; 3min 4s ago Main PID: 3331 (openvpn) Status: "Initialization Sequence Completed" Tasks: 1 (limit: 24718) Memory: 1.5M CPU: 12ms CGroup: /system.slice/system-openvpn.slice/openvpn@server.service └─3331 /usr/sbin/openvpn --cd /etc/openvpn/ --config server.conf
Apr 30 15:28:49 rocky9 systemd[1]: Starting OpenVPN Robust And Highly Flexible Tunneling Application On server... Apr 30 15:28:49 rocky9 openvpn[3331]: 2024-04-30 15:28:49 WARNING: Compression for receiving enabled. Compression has been used in the past to bre> Apr 30 15:28:49 rocky9 systemd[1]: Started OpenVPN Robust And Highly Flexible Tunneling Application On server. lines 1-14/14 (END)
[root@rocky9 ~]# ss -ntl State Recv-Q Send-Q Local Address:Port Peer Address:Port Process LISTEN 0 128 0.0.0.0:22 0.0.0.0:* LISTEN 0 4096 0.0.0.0:111 0.0.0.0:* LISTEN 0 32 0.0.0.0:1194 0.0.0.0:* LISTEN 0 128 [::]:22 [::]:* LISTEN 0 4096 [::]:111 [::]:*