<\/span><\/h2>\r\n\r\n\r\n\r\nFirst, log in to your Debian 10 server via SSH as the root user:<\/p>\r\n\r\n\r\n\r\n
ssh root@IP_Address -p Port_number<\/pre>\r\n\r\n\r\n\r\nYou will need to replace ‘IP_Address’ and ‘Port_number’ with your server\u2019s respective IP address and SSH port number. Additionally, replace ‘root’ with the username of the admin account if necessary.<\/p>\r\n\r\n\r\n\r\n
Before starting, you have to make sure that all Debian OS packages installed on the server are up to date. You can do this by running the following commands:<\/p>\r\n\r\n\r\n\r\n
apt-get update -y\r\napt-get upgrade -y<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 2: Install OpenVPN and EasyRSA<\/span><\/h2>\r\n\r\n\r\n\r\nBy default, OpenVPN is included in the Debian default repository. You can install it with the following command:<\/p>\r\n\r\n\r\n\r\n
apt-get install openvpn -y<\/pre>\r\n\r\n\r\n\r\nOnce the OpenVPN package has been installed, you will need to download EasyRSA to your system.<\/p>\r\n\r\n\r\n\r\n
EasyRSA is a command-line utility to build and manage a PKI CA. It allows you to generate multiple types of certificates.
It is used to create a root certificate authority, and request and sign certificates for OpenVPN.<\/p>\r\n\r\n\r\n\r\n
You can download the latest version of EasyRSA from the Git repository using the following command:<\/p>\r\n\r\n\r\n\r\n
wget https:\/\/github.com\/OpenVPN\/easy-rsa\/releases\/download\/v3.0.8\/EasyRSA-3.0.8.tgz<\/pre>\r\n\r\n\r\n\r\nOnce the download is completed, extract the downloaded file using the following command:<\/p>\r\n\r\n\r\n\r\n
tar -xvzf EasyRSA-3.0.8.tgz<\/pre>\r\n\r\n\r\n\r\nNext, copy the extracted directory to the OpenVPN directory:<\/p>\r\n\r\n\r\n\r\n
cp -r EasyRSA-3.0.8 \/etc\/openvpn\/easy-rsa<\/pre>\r\n\r\n\r\n\r\nAt this point, OpenVPN and EasyRSA is installed in your server.<\/p>\r\n\r\n\r\n\r\n
<\/span>Step 3: Build the Certificate Authority<\/span><\/h2>\r\n\r\n\r\n\r\nNext, you will need to build the Certificate Authority (CA) for OpenVPN.<\/p>\r\n\r\n\r\n\r\n
First, change the directory to EasyRSA with the following command:<\/p>\r\n\r\n\r\n\r\n
cd \/etc\/openvpn\/easy-rsa<\/pre>\r\n\r\n\r\n\r\nNext, you will need to create a vars file inside this. A vars file is a simple file that Easy-RSA will source for configuration.<\/p>\r\n\r\n\r\n\r\n
You can create it with the following command:<\/p>\r\n\r\n\r\n\r\n
nano vars<\/pre>\r\n\r\n\r\n\r\nAdd the following lines as per your needs:<\/p>\r\n\r\n\r\n\r\n
set_var EASYRSA \"$PWD\"\r\nset_var EASYRSA_PKI \"$EASYRSA\/pki\"\r\nset_var EASYRSA_DN \"cn_only\"\r\nset_var EASYRSA_REQ_COUNTRY \"USA\"\r\nset_var EASYRSA_REQ_PROVINCE \"Newyork\"\r\nset_var EASYRSA_REQ_CITY \"Newyork\"\r\nset_var EASYRSA_REQ_ORG \"ROSE CERTIFICATE AUTHORITY\"\r\nset_var EASYRSA_REQ_EMAIL \"admin@example.com\"\r\nset_var EASYRSA_REQ_OU \"ROSE EASY CA\"\r\nset_var EASYRSA_KEY_SIZE 2048\r\nset_var EASYRSA_ALGO rsa\r\nset_var EASYRSA_CA_EXPIRE 7500\r\nset_var EASYRSA_CERT_EXPIRE 365\r\nset_var EASYRSA_NS_SUPPORT \"no\"\r\nset_var EASYRSA_NS_COMMENT \"ROSE CERTIFICATE AUTHORITY\"\r\nset_var EASYRSA_EXT_DIR \"$EASYRSA\/x509-types\"\r\nset_var EASYRSA_SSL_CONF \"$EASYRSA\/openssl-easyrsa.cnf\"\r\nset_var EASYRSA_DIGEST \"sha256\"\r\n<\/pre>\r\n\r\n\r\n\r\nSave and close the file when you are finished.<\/p>\r\n\r\n\r\n\r\n
Next, initiate the public key infrastructure with the following command:<\/p>\r\n\r\n\r\n\r\n
.\/easyrsa init-pki<\/pre>\r\n\r\n\r\n\r\nYou should get the following output:<\/p>\r\n\r\n\r\n\r\n
Note: using Easy-RSA configuration from: \/etc\/openvpn\/easy-rsa\/vars\r\n\r\ninit-pki complete; you may now create a CA or requests.\r\nYour newly created PKI dir is: \/etc\/openvpn\/easy-rsa\/pki\r\n<\/pre>\r\n\r\n\r\n\r\nNext, you will need to run build-ca command to create ca.crt and ca.key file. You can run it with the following command:<\/p>\r\n\r\n\r\n\r\n
.\/easyrsa build-ca nopass<\/pre>\r\n\r\n\r\n\r\nYou will be asked for several questions as shown below:<\/p>\r\n\r\n\r\n\r\n
Note: using Easy-RSA configuration from: \/etc\/openvpn\/easy-rsa\/vars\r\nUsing SSL: openssl OpenSSL 1.1.1f 31 Mar 2020\r\n\r\nEnter New CA Key Passphrase: \r\nRe-Enter New CA Key Passphrase: \r\nGenerating RSA private key, 2048 bit long modulus (2 primes)\r\n...+++++\r\n......................................................................+++++\r\ne is 65537 (0x010001)\r\nYou are about to be asked to enter information that will be incorporated\r\ninto your certificate request.\r\nWhat you are about to enter is what is called a Distinguished Name or a DN.\r\nThere are quite a few fields but you can leave some blank\r\nFor some fields there will be a default value,\r\nIf you enter '.', the field will be left blank.\r\n-----\r\nCommon Name (eg: your user, host, or server name) [Easy-RSA CA]:vpnserver\r\n\r\nCA creation complete and you may now import and sign cert requests.\r\nYour new CA certificate file for publishing is at:\r\n\/etc\/openvpn\/easy-rsa\/pki\/ca.crt\r\n<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 4: Generate Server Certificate and Key Files<\/span><\/h2>\r\n\r\n\r\n\r\nNext, you will need to use the gen-req command followed by common name to generate the server key.<\/p>\r\n\r\n\r\n\r\n
.\/easyrsa gen-req vpnserver nopass<\/pre>\r\n\r\n\r\n\r\nYou should see the following output:<\/p>\r\n\r\n\r\n\r\n
Note: using Easy-RSA configuration from: \/etc\/openvpn\/easy-rsa\/vars\r\nUsing SSL: openssl OpenSSL 1.1.1f 31 Mar 2020\r\nGenerating a RSA private key\r\n.......................................................+++++\r\n....+++++\r\nwriting new private key to '\/etc\/openvpn\/easy-rsa\/pki\/easy-rsa-1428.Angtmh\/tmp.C9prw4'\r\n-----\r\nYou are about to be asked to enter information that will be incorporated\r\ninto your certificate request.\r\nWhat you are about to enter is what is called a Distinguished Name or a DN.\r\nThere are quite a few fields but you can leave some blank\r\nFor some fields there will be a default value,\r\nIf you enter '.', the field will be left blank.\r\n-----\r\nCommon Name (eg: your user, host, or server name) [vpnserver]:\r\n\r\nKeypair and certificate request completed. Your files are:\r\nreq: \/etc\/openvpn\/easy-rsa\/pki\/reqs\/vpnserver.req\r\nkey: \/etc\/openvpn\/easy-rsa\/pki\/private\/vpnserver.key\r\n<\/pre>\r\n\r\n\r\n\r\nNext, you will need to sign the vpnserver key using your CA certificate. You can do it with the following command:<\/p>\r\n\r\n\r\n\r\n
.\/easyrsa sign-req server vpnserver<\/pre>\r\n\r\n\r\n\r\nYou should get the following output:<\/p>\r\n\r\n\r\n\r\n
Check that the request matches the signature\r\nSignature ok\r\nThe Subject's Distinguished Name is as follows\r\ncommonName :ASN.1 12:'vpnserver'\r\nCertificate is to be certified until Feb 6 14:38:52 2022 GMT (365 days)\r\n\r\nWrite out database with 1 new entries\r\nData Base Updated\r\n\r\nCertificate created at: \/etc\/openvpn\/easy-rsa\/pki\/issued\/vpnserver.crt\r\n<\/pre>\r\n\r\n\r\n\r\nNext, you will need to generate a strong Diffie-Hellman key to use for the key exchange. You can generate it with the following command:<\/p>\r\n\r\n\r\n\r\n
.\/easyrsa gen-dh<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 5: Copy All Certificate and Key File<\/span><\/h2>\r\n\r\n\r\n\r\nNext, you will need to copy all certificate and key file to the \/etc\/openvpn\/server\/ directory. You can copy the using the following command:<\/p>\r\n\r\n\r\n\r\n
cp pki\/ca.crt \/etc\/openvpn\/server\/\r\ncp pki\/dh.pem \/etc\/openvpn\/server\/\r\ncp pki\/private\/vpnserver.key \/etc\/openvpn\/server\/\r\ncp pki\/issued\/vpnserver.crt \/etc\/openvpn\/server\/<\/pre>\r\n\r\n\r\n\r\n<\/span>Step 6: Create Client Certificate and Key File<\/span><\/h2>\r\n\r\n\r\n\r\nNext, you will need to generate a certificate and key file for the client system.<\/p>\r\n\r\n\r\n\r\n
You can create it with the following command:<\/p>\r\n\r\n\r\n\r\n
.\/easyrsa gen-req vpnclient nopass<\/pre>\r\n\r\n\r\n\r\nYou should get the following output:<\/p>\r\n\r\n\r\n\r\n
Note: using Easy-RSA configuration from: \/etc\/openvpn\/easy-rsa\/vars\r\nUsing SSL: openssl OpenSSL 1.1.1f 31 Mar 2020\r\nGenerating a RSA private key\r\n....+++++\r\n.................................+++++\r\nwriting new private key to '\/etc\/openvpn\/easy-rsa\/pki\/easy-rsa-1563.TeOf5v\/tmp.i4YxLz'\r\n-----\r\nYou are about to be asked to enter information that will be incorporated\r\ninto your certificate request.\r\nWhat you are about to enter is what is called a Distinguished Name or a DN.\r\nThere are quite a few fields but you can leave some blank\r\nFor some fields there will be a default value,\r\nIf you enter '.', the field will be left blank.\r\n-----\r\nCommon Name (eg: your user, host, or server name) [vpnclient]:\r\n\r\nKeypair and certificate request completed. Your files are:\r\nreq: \/etc\/openvpn\/easy-rsa\/pki\/reqs\/vpnclient.req\r\nkey: \/etc\/openvpn\/easy-rsa\/pki\/private\/vpnclient.key\r\n<\/pre>\r\n\r\n\r\n\r\nNext, sign the client key with the following command:<\/p>\r\n\r\n\r\n\r\n
.\/easyrsa sign-req client vpnclient<\/pre>\r\n\r\n\r\n\r\nYou should get the following output:<\/p>\r\n\r\n\r\n\r\n
Signature ok\r\nThe Subject's Distinguished Name is as follows\r\ncommonName :ASN.1 12:'vpnclient'\r\nCertificate is to be certified until Feb 6 14:43:18 2022 GMT (365 days)\r\n\r\nWrite out database with 1 new entries\r\nData Base Updated\r\n\r\nCertificate created at: \/etc\/openvpn\/easy-rsa\/pki\/issued\/vpnclient.crt\r\n<\/pre>\r\n\r\n\r\n\r\nNext, copy all client certificate and key to the \/etc\/openvpn\/client\/ directory.<\/p>\r\n\r\n\r\n\r\n
cp pki\/ca.crt \/etc\/openvpn\/client\/\r\ncp pki\/issued\/vpnclient.crt \/etc\/openvpn\/client\/\r\ncp pki\/private\/vpnclient.key \/etc\/openvpn\/client\/<\/pre>\r\n\r\n\r\n\r\n