下面,我们就开始来生成证书了。保持当前目录为Open***根目录/easy-rsa/2.0。然后依次执行下列命令:
#初始化命令,用于设置后续命令所需的相关变量信息
. ./vars
#清除之前创建的所有证书和密钥
./clean-all #生成CA证书和密钥
./build-ca
[root@Open*** 2.0]# . ./vars
NOTE: If you run ./clean-all, I will be doing a rm -rf on /root/open***-2.3.3/easy-rsa/2.0/keys
[root@Open*** 2.0]# ./clean-all
[root@Open*** 2.0]# ./build-ca #生成ca证书和秘钥
Generating a 2048 bit RSA private key
............................+++
....................................................................................+++
writing new private key to 'ca.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) [US]:CN
State or Province Name (full name) [CA]:GD
Locality Name (eg, city) [SanFrancisco]:SZ
Organization Name (eg, company) [Fort-Funston]:softown
Organizational Unit Name (eg, section) [MyOrganizationalUnit]:softown_admin
Common Name (eg, your name or your server's hostname) [Fort-Funston CA]:Open***_CA
Name [EasyRSA]:
Email Address [me@myhost.mydomain]:admin@softown.cn
[root@Open*** 2.0]#
[root@Open*** 2.0]# ls keys/
ca.crt ca.key index.txt serial
[root@Open*** 2.0]# pwd
/root/open***-2.3.3/easy-rsa/2.0 生成服务端证书
[root@Open*** 2.0]# ./build-key-server ***S
Generating a 2048 bit RSA private key
.....+++
...............+++
writing new private key to '***S.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) [US]:CN
State or Province Name (full name) [CA]:GD
Locality Name (eg, city) [SanFrancisco]:SZ
Organization Name (eg, company) [Fort-Funston]:softown
Organizational Unit Name (eg, section) [MyOrganizationalUnit]:softown_admin
Common Name (eg, your name or your server's hostname) [***S]:***S
Name [EasyRSA]:
Email Address [me@myhost.mydomain]:admin@softown.cn
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:server_pwd
An optional company name []:softown
Using configuration from /root/open***-2.3.3/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'GD'
localityName :PRINTABLE:'SZ'
organizationName :PRINTABLE:'softown'
organizationalUnitName:T61STRING:'softown_admin'
commonName :PRINTABLE:'***S'
name :PRINTABLE:'EasyRSA'
emailAddress :IA5STRING:'admin@softown.cn'
Certificate is to be certified until Aug 29 08:00:20 2027 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 生成客户端证书
[root@Open*** 2.0]# ./build-key user1
Generating a 2048 bit RSA private key
..+++
.....................................+++
writing new private key to 'user1.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) [US]:CN
State or Province Name (full name) [CA]:GD
Locality Name (eg, city) [SanFrancisco]:SZ
Organization Name (eg, company) [Fort-Funston]:softown
Organizational Unit Name (eg, section) [MyOrganizationalUnit]:softown_admin
Common Name (eg, your name or your server's hostname) [user1]:user1
Name [EasyRSA]:
Email Address [me@myhost.mydomain]:admin@softown.cn
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:user1_pwd
An optional company name []:softown
Using configuration from /root/open***-2.3.3/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'GD'
localityName :PRINTABLE:'SZ'
organizationName :PRINTABLE:'softown'
organizationalUnitName:T61STRING:'softown_admin'
commonName :PRINTABLE:'user1'
name :PRINTABLE:'EasyRSA'
emailAddress :IA5STRING:'admin@softown.cn'
Certificate is to be certified until Aug 29 08:02:05 2027 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 生成迪菲·赫尔曼交换密钥
[root@Open*** 2.0]# ./build-dh
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
.......................................................................................................................................................................+........................................................................................................................................................................................................................+..........................................................................................................................................................................................................+..................................................................................................................................................+...............................................................+...........................................................................................................................................+...............................+.......................................................................................................+.............................................................................................................................................................................................+.....................................................................+....................................+.........................................+..........................................................................................................................................................................................................................................................................................................+..+.....................................................................................................+......................++*++* 生成TLS-auth密钥
[root@Open*** 2.0]# /usr/local/sbin/open*** --genkey --secret /root/open***-2.3.3/easy-rsa/2.0/keys/ta.key
编写配置文件
在这里,我们先在Open***主目录下创建一个config目录,并将其所需的证书和密钥文件拷贝到该目录中。
[root@Open*** 2.0]# mkdir /root/open***-2.3.3/config
[root@Open*** 2.0]# cp keys/ca.crt keys/ca.key keys/dh2048.pem keys/***S.crt keys/***S.key keys/ta.key /root/open***-2.3.3/config
此外,我们还需要为服务器和每个客户端的config目录分别编写一个配置文件,服务器端的配置文件为server.conf,客户端的配置文件为client.conf。
这两个配置文件该如何编写呢?Open***已经在sample/sample-config-files子目录中为我们提供了相关的示例文件server.conf和client.conf,并且配置文件中的每个配置选项均有详细的英文说明(配置文件中"#"或";"开头的均为注释内容)。
服务端配置文件server.conf
local 172.18.1.132 #指定监听的本机IP
port 3889
proto udp
dev tun
ca /root/open***-2.3.3/config/ca.crt
cert /root/open***-2.3.3/config/***S.crt
key /root/open***-2.3.3/config/***S.key # This file should be kept secret
dh /root/open***-2.3.3/config/dh2048.pem
server 10.8.0.0 255.255.255.0 #隧道分配的网段和掩码
ifconfig-pool-persist /root/open***-2.3.3/config/ipp.txt
push "route 192.168.40.0 255.255.255.0" #推送服务器的内网网段
;client-config-dir /root/open***-2.3.3/config/ccd #指定客户端网络配置
route 192.168.20.0 255.255.255.0 #服务器添加客户端的内网网段
client-to-client #允许客户端与客户端相连接,默认情况下客户端只能与服务器相连接
duplicate-cn
keepalive 10 120
tls-auth /root/open***-2.3.3/config/ta.key 0 #开启TLS-auth防御***服务器端的参数值为0,客户端的为1
cipher AES-128-CBC # AES 加密方式
comp-lzo #开启***连接压缩,如果服务器端开启,客户端也必须开启
max-clients 100
user nobody
group nobody
persist-key
persist-tun
verb 3 #指定日志文件的记录详细级别,可选0-9,等级越高日志内容越详细
mute 20
客户端配置文件client.conf
client
dev tun
proto udp
remote 172.18.1.132 3889 #服务器地址以及端口
resolv-retry infinite #断线自动重新连接
nobind
user nobody
group nobody
persist-key
persist-tun
ca ca.crt #指定CA证书的文件路径
cert user1.crt #指定当前客户端的证书文件路径
key user1.key #指定当前客户端的私钥文件路径
ns-cert-type server #指定采用服务器校验方式
tls-auth ta.key 1 #如果服务器设置了防御DoS等***的ta.key,则必须每个客户端开启
cipher AES-128-CBC #加密方式
comp-lzo #开启***连接压缩
verb 3 #指定日志文件的记录详细级别,可选0-9,等级越高日志内容越详细
mute 20
接着看下一篇:Open***路由模式