大网数据广告活动
服务器运维问答

Create own ovpn file from using certificate and key

· 52CE 我爱测

Recently, i set up a raspberry such as a little server for doing some practise with networking and on it i installed OpenVPN. For sample certificates i used the command pivpn -a , as suggested by OpenVPN. But now i want to create…

问题原文

原帖链接 · Leonardo Bassi · CC BY-SA 4.0

Recently, i set up a raspberry such as a little server for doing some practise with networking and on it i installed OpenVPN. For sample certificates i used the command pivpn -a, as suggested by OpenVPN. But now i want to create my own certificates because i need to insert on them an expiration date for examples.

After many research on the internet, i didn't find anything which works, because the most of the examples provides from users are old version of OpenVPN, the only thing that i learned was that i need openssl for creating my certificates.

So i run the below commands for creating my certificates:

sudo openssl req -new -key ca.key > mycert.csr
sudo openssl x509 -req -days 1 -in ./mycert.csr /
-signkey /etc/openvpn/easy-rsa/pki/private/ca.key -out some.crt

ca.key is the key generated when i installed OpenVPN, at this point i tried to combine certificates and key such as many tutorial suggests:

client
dev tun
proto udp
remote <my_server_ip> 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
tls-version-min 1.2
verify-x509-name <server_name> name
cipher AES-256-CBC
auth SHA256
auth-nocache
verb 3
<ca>
-----BEGIN CERTIFICATE-----
#my ca.crt
-----END CERTIFICATE-----
</ca>
<cert>
-----BEGIN CERTIFICATE-----
#the some.crt file, which i created before
-----END CERTIFICATE-----
</cert>
<key>
-----BEGIN ENCRYPTED PRIVATE KEY-----
#No idea what i have to write there
-----END ENCRYPTED PRIVATE KEY-----
</key>
<tls-crypt>
#
# 2048 bit OpenVPN static key
#
-----BEGIN OpenVPN Static key V1-----
#my ta.key
-----END OpenVPN Static key V1-----
</tls-crypt>

I am stuck to this point, because in the section of encrypted private key someone says that there i have to put client.key, so the key which i used for sign my certificate, but it doesn't work.

I mess some steps or this is the wrog way to achive which i want?

已采纳解答

原帖链接 · Enno Gröper · CC BY-SA 4.0

For OpenVPN there are multiple certificates involved:

On the server side:

  • server certificate (and key)
  • ca certificate matching the private key, that signed the server certificate

On the client side (optional):

  • client certificate (and key) signed by the same or another ca

You have posted a client configuration. So the parameters need to be filled as follows:

  • ca: ca certificate to verify the server certificate (signed the server certificate)
  • cert: depending on server config, client certificate provided to the server for user authentication
  • key: key matching the cert

I suggest, you use easyrsa3. It should be explained in enough detail there.

Short summary for own OpenVPN server (and own, custom CA):

  • generate ca certificate (and key)
  • generate server certificate (and key)
  • generate client certificates (and keys)

For enhanced security, the keys are created locally (on the server/client) together with a CSR (certificate requests) and then the requests are signed on the node containing the ca (should be separated) resulting in the certificates.

EDIT: Having another look at your question, this looks suspicious:

sudo openssl req -new -key ca.key > mycert.csr
sudo openssl x509 -req -days 1 -in ./mycert.csr \
 -signkey /etc/openvpn/easy-rsa/pki/private/ca.key -out some.crt

What is the first ca.key? You should either seperately generate a new (client) key or simply let openssl req do this for you (-newkey). The "key" used by openssl req belongs to certificate you want to get a CSR for. At this point it has nothing to do with the CA.

Summary:

  • create a private key
  • create a CSR for the key
  • get the csr signed by a CA (resulting in a signed certificate matching the private key of the first step)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-04-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。