# 进入OpenVpn目录中的easy-rsa-server文件夹 cd /data/openvpn/easy-rsa-server # 初始化,执行此命令会生成pki目录 ./easyrsa init-pki # 创建CA机构,nopass代表不需要密码的意思 ./easyrsa build-ca nopass # 根据指引输入CA机构名,这里我用了rsa-xxin Common Name (eg: your user, host, or server name) [Easy-RSA CA]:rsa-xxin # 如果创建成功,在pki目录下会出现一个ca.crt文件,和一个private目录,目录中包含了一个ca.key文件
创建服务端证书
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# 进入OpenVpn目录中的easy-rsa-server文件夹 cd /data/openvpn/easy-rsa-server # 创建服务端证书,同时指定证书文件的文件名为openvpnserver ./easyrsa gen-req openvpnserver nopass # 当提示如下时,按回车继续 Common Name (eg: your user, host, or server name) [openvpnserver]: # 如果创建成功,将会提示如下 # Keypair and certificate request completed. Your files are: # req: /data/openvpn/easy-rsa-server/pki/reqs/openvpnserver.req # key: /data/openvpn/easy-rsa-server/pki/private/openvpnserver.key # 并且在对应的目录下生成了openvpnserver.req请求文件和openvpnserver.key私钥文件
签发服务端证书
1 2 3 4 5 6 7 8 9
# 这里的第一个server代表服务器,第二个openvpnserver则代表刚刚创建的服务端证书的名称 ./easyrsa sign server openvpnserver # 当出现如下提示时,输入yes Type the word 'yes' to continue, or any other input to abort. Confirm request details: # 出现如下提示时,说明得到服务端的证书文件 # Certificate created at: /data/openvpn/easy-rsa-server/pki/issued/openvpnserver.crt
创建交互密钥
1 2 3 4 5 6 7
./easyrsa gen-dh # 出现如下提示时,说明得到交互密钥文件 # DH parameters of size 2048 created at /data/openvpn/easy-rsa-server/pki/dh.pem # 启用安全增强配置 openvpn --genkey tls-auth ta.key
cd /data/openvpn/easy-rsa-server # 将客户端证书复制到CA工作目录,并指定证书名称为xxin,证书名称可以任意定义,复制到CA工作目录的客户端证书以指定的证书名称命名 ./easyrsa import-req /data/openvpn/easy-rsa-client/pki/reqs/xxin.req xxin # 当提示如下时,说明导入成功,客户端证书成功被复制到CA工作目录 # Note: using Easy-RSA configuration from: /data/openvpn/easy-rsa-server/vars # Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017 # # The request has been successfully imported with a short name of: xxin # You may now use this name to perform signing operations on this request. # # 若提示如下,说明导入失败,CA工作目录下已经存在该证书文件 # Note: using Easy-RSA configuration from: /data/openvpn/easy-rsa-server/vars # Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017 # # Easy-RSA error: # # The input file does not appear to be a certificate request. Aborting import. # File Path: /data/openvpn/easy-rsa-client/pki/reqs/xxin.req # 设置客户端证书有效期,这里设置的是90天 sed -i "s/set_var EASYRSA_CERT_EXPIRE.*$/set_var EASYRSA_CERT_EXPIRE\t90/g" ./vars # 签发名称为xxin的证书 ./easyrsa sign client xxin # 当提示如下时,输入yes # Type the word 'yes' to continue, or any other input to abort. # Confirm request details: # 证书签发成功 # Certificate created at: /data/openvpn/easy-rsa-server/pki/issued/xxin.crt
# 创建客户端申请证书,同时指定证书文件的文件名为xxin-test ./easyrsa gen-req xxin-test nopass # 将会提示如下内容,回车确定即可 # Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017 # Generating a 2048 bit RSA private key # .............+++ # ...+++ # writing new private key to '/data/openvpn/easy-rsa-client/pki/easy-rsa-27870.RaCSZg/tmp.0a2NSo' # ----- # 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) [xxin-test]: # 确定后提示如下内容说明申请成功 # Keypair and certificate request completed. Your files are: # req: /data/openvpn/easy-rsa-client/pki/reqs/xxin-test.req # key: /data/openvpn/easy-rsa-client/pki/private/xxin-test.key
签发证书
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# 进入到RSA服务端目录 cd /data/openvpn/easy-rsa-server # 导入一个证书签名请求文件 ./easyrsa import-req /data/openvpn/easy-rsa-client/pki/reqs/xxin-test.req xxin-test # 设置客户端证书有效期,这里设置的是90天 sed -i "s/set_var EASYRSA_CERT_EXPIRE.*$/set_var EASYRSA_CERT_EXPIRE\t90/g" ./vars # 签发证书 ./easyrsa sign client xxin-test # 当提示如下时,输入yes # Type the word 'yes' to continue, or any other input to abort. # Confirm request details: