虚拟专用网络 VPN-通过Easy-RSA自签发证书(服务端和客户端共用CA证书):操作步骤
操作步骤
- 根据Windows操作系统下载Easy-RSA安装包至“D:\”目录下。
- Windows 32位操作系统,可以下载EasyRSA-3.1.7-win32.zip。
- Windows 64位操作系统,可以下载EasyRSA-3.1.7-win64.zip。
此处以安装EasyRSA-3.1.7-win64为示例。
- 解压缩“EasyRSA-3.1.7-win64.zip”至指定目录,如“D:\EasyRSA-3.1.7”。
- 进入“D:\EasyRSA-3.1.7”目录。
- 在地址栏中输入cmd并按回车键,打开命令行窗口。
- 执行“.\EasyRSA-Start.bat”命令,运行Easy-RSA。
系统显示如下类似信息:
Welcome to the EasyRSA 3 Shell for Windows.Easy-RSA 3 is available under a GNU GPLv2 license.Invoke './easyrsa' to call the program. Without commands, help is displayed.EasyRSA Shell#
- 执行“./easyrsa init-pki”命令,初始化PKI环境。
系统显示如下类似信息:
Notice------'init-pki' complete; you may now create a CA or requests.Your newly created PKI dir is:* D:/EasyRSA-3.1.7/pkiUsing Easy-RSA configuration:* undefinedEasyRSA Shell#
执行命令后,在“D:\EasyRSA-3.1.7”的目录下自动生成了“pki”的文件夹。
- 配置变量参数。
- 将“D:\EasyRSA-3.1.7”目录下的“vars.example”文件复制到“D:\EasyRSA-3.1.7\pki”目录下。
- 将“D:\EasyRSA-3.1.7\pki”目录下的“vars.example”重命名为“vars”。
默认按“vars.example”中描述的参数值进行配置。如需自定义参数值,按需设置“vars”文件的参数值。
- 执行“ ./easyrsa build-ca nopass”命令,生成CA证书。
系统显示如下类似信息:
Using Easy-RSA 'vars' configuration:* D:/EasyRSA-3.1.7/pki/varsUsing SSL:* openssl OpenSSL 3.1.2 1 Aug 2023 (Library: OpenSSL 3.1.2 1 Aug 2023).....+..+.............+......+........+...+...+....+++++++++++++++++++++++++++++++++++++++*.+.+.....+..........+............+...+++++++++++++++++++++++++++++++++++++++*............+.....+......+...+....+..+..........+.....+....+...............+..+.........+.............+......+..+...+....+..+.+.........+.....+.........+....+............+...+...+.....+........................+...+.+.....+....+...+.........+...+...+...+.....+......+........................++++++.+++++++++++++++++++++++++++++++++++++++*.........+..........+++++++++++++++++++++++++++++++++++++++*.+......++++++-----You are about to be asked to enter information that will be incorporatedinto 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 blankFor 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]:p2cvpn.com //设置CA证书名称Notice------CA creation complete. Your new CA certificate is at:* D:/EasyRSA-3.1.7/pki/ca.crtEasyRSA Shell#
- 查看CA证书及其私钥。
- 执行 “./easyrsa build-server-full p2cserver.com nopass”命令,生成服务端证书及其私钥。
此命令中,“p2cserver.com”为服务端证书的CN,必须是 域名 格式,如“p2c-server.com”。否则无法正常托管到 云证书管理服务 ,请根据实际填写。
系统显示如下类似信息:
Using Easy-RSA 'vars' configuration:* D:/EasyRSA-3.1.7/pki/varsUsing SSL:* openssl OpenSSL 3.1.2 1 Aug 2023 (Library: OpenSSL 3.1.2 1 Aug 2023).+............+........+............+............+.+...............+.....+....+....................+............+.+..+......+............+....+.........+..+.........+.+.........+..............+.........+++++++++++++++++++++++++++++++++++++++*...+......+.....+......+...+++++++++++++++++++++++++++++++++++++++*..+...+..........+......+...........+....+......+.....+....+.....+....+........+...+.......+...+..+.......+..+......+.............+..+....+......+...+.....+................+......+..+.............+..+................+.....+......+....+...........+....+.....+.........+.+..+.............+...........+..........+......+........+............+...+....+..+......+......................+.....+......+.+...+..+...+.+......+........+...+....+.....+......+....+...+..+................+..+...+.......+..+......+..........+.........+...+..+.........+......+......++++++........+.+......+...+......+.....+...+.+.....+.+........+......+++++++++++++++++++++++++++++++++++++++*...+.....+...+.+.........+......+........+++++++++++++++++++++++++++++++++++++++*......+........+.+...+.....+.+..............+.+.....+.+...+...+.....+.......+.................+.+............+..+......+...+....+...+..+.+.....+.....................+.+..+.+...................................+....+........+.............+.....+....+.....+...+..........+........+.+.....+...+.............+........+....+......+.....+.......+..+............+.........+.+......+...+...............+......+...........+............+.......+...........+.......+...............+......+.................+...+.+...+..+...+.+..........................+.+.........+......+............+..+....+..+....+........+.......+........+...+...+.+...+...+..+...............+...+..........+..+.......+.........+.....+.........+................+......+...+......+.....+.......+...+..............+.+.....+.+...+...........+.+...+...+...+............+..+.......+...........+.......+...+...+...........+.....................+...+....+...........+............+...+......+..........+........+.+.....+....+.....+.+..+..........+..............+...+......+.+...+...........+.+......+...++++++-----Notice------Private-Key and Public-Certificate-Request files created.Your files are:* req: D:/EasyRSA-3.1.7/pki/reqs/p2cserver.com.req* key: D:/EasyRSA-3.1.7/pki/private/p2cserver.com.keyYou are about to sign the following certificate:Request subject, to be signed as a server certificatefor '825' days:subject= commonName = p2cserver.comType the word 'yes' to continue, or any other input to abort. Confirm request details: yes //输入“yes”以继续Using configuration from D:/EasyRSA-3.1.7/pki/openssl-easyrsa.cnfCheck that the request matches the signatureSignature okThe Subject's Distinguished Name is as followscommonName :ASN.1 12:'p2cserver.com'Certificate is to be certified until Sep 22 09:56:54 2026 GMT (825 days)Write out database with 1 new entriesDatabase updatedNotice------Certificate created at:* D:/EasyRSA-3.1.7/pki/issued/p2cserver.com.crtNotice------Inline file created:* D:/EasyRSA-3.1.7/pki/inline/p2cserver.com.inlineEasyRSA Shell#
- 查看服务端证书及其私钥。
- 执行“ ./easyrsa build-client-full p2cclient.com nopass”命令,生成客户端证书及其私钥。
此命令中,客户端证书的命名(如“p2cclient.com”)应与服务端证书的命名(如“p2cserver.com”)不一致。
系统显示如下类似信息:
Using Easy-RSA 'vars' configuration:* D:/EasyRSA-3.1.7/pki/varsUsing SSL:* openssl OpenSSL 3.1.2 1 Aug 2023 (Library: OpenSSL 3.1.2 1 Aug 2023).......+++++++++++++++++++++++++++++++++++++++*...+...+...+.....+...+....+......+......+........+.+.....+............+++++++++++++++++++++++++++++++++++++++*.+.....+.+.....+.........+.......+..+...+.......+...+..+......+.+......+........+....+...+...+..+.......+......+.....+..........+...........+....+......+.....+.........+......+.+..+...+..........+........+......+....+......+...........+.......+.....+.............+..+.+...........+..........+...+..+.........+......+.+........+.........+.+...............+..+..........+...+............+...+.....+.+...........+....+.....+.........+....+.......................+....+...+..+....+..+.......+...+............+.....+............+.+........+.......+.....+....+.........+..+............+..........+..+.............+...+...+..++++++..+.....+.......+.....+.........+....+++++++++++++++++++++++++++++++++++++++*.....+......+..+++++++++++++++++++++++++++++++++++++++*.......+.+.....+....+.........+...+.....+.........+...+...............+...+....+.....+.+...+......+......+...+.........+..+...+...+....+.........+..+...+...................+......+.....+.+...+...+.........+.....+..................+...+...+......+.+..+......+.+......+.....+...+..........+..+............+.......+.........+.....+......+.+..+............+................+..+...+....+......+.....+...+....+..+......+.........+.........++++++-----Notice------Private-Key and Public-Certificate-Request files created.Your files are:* req: D:/EasyRSA-3.1.7/pki/reqs/p2cclient.com.req* key: D:/EasyRSA-3.1.7/pki/private/p2cclient.com.keyYou are about to sign the following certificate:Request subject, to be signed as a client certificatefor '825' days:subject= commonName = p2cclient.comType the word 'yes' to continue, or any other input to abort. Confirm request details: yes //输入“yes”以继续Using configuration from D:/EasyRSA-3.1.7/pki/openssl-easyrsa.cnfCheck that the request matches the signatureSignature okThe Subject's Distinguished Name is as followscommonName :ASN.1 12:'p2cclient.com'Certificate is to be certified until Sep 22 09:58:26 2026 GMT (825 days)Write out database with 1 new entriesDatabase updatedNotice------Certificate created at:* D:/EasyRSA-3.1.7/pki/issued/p2cclient.com.crtNotice------Inline file created:* D:/EasyRSA-3.1.7/pki/inline/p2cclient.com.inlineEasyRSA Shell#
- 查看客户端证书及其私钥。