Creating a server certificate | Linux know-how (2024)

Your requirement

You want to set up a server service on the Internet which provides encrypted SSL or TLS connections (e.g. HTTPS, POP3S, IMAPS, LDAPS, SMTP with TLS).

The difficulty

To offer a connection secured with SSL/TLS, you need a server certificate. This must be signed by a certification authority (CA).

An official server certificate, which is signed by an official authority, is unfortunately not free. In most cases, annual fees of several hundred euros will be incurred.

A possible solution

Under Linux, you can set up your own CA with on-board tools, and then create and sign your own certificates. This is a process of a few minutes. All details for the procedure are described in this article.

In this case, the only difference to a certificate signed by a recognised authority is that the client (email program, browser, etc.) will issue a warning that it does not recognise the CA. The user only needs to confirm this once, and can then accept the certificate despite such a warning.

Detailed procedure

1. Install OpenSSL

OpenSSL is almost always used under Linux for the administration of the certificates and for the encryption of the connections with SSL and TLS. This is probably why it is already installed on your system. If not, you will have to install the openssl package. You will need the openssl command-line command from this package.

2. Creating the CA

First create a directory in which you want to store the certificate. In our example we use /root/ca:

root@linux# mkdir /root/caroot@linux# cd /root/ca

We deliberately set the validity very high at 10 years. If the CA expires, all server certificates signed with it become invalid. The CA contains a secret key which is automatically generated and stored in the file cakey.pem. The CA certificate is written to cacert.pem. The following command generates a key with a length of 2048 bits for the certificate:

root@linux# openssl req -new -x509 -newkey rsa:2048 -keyout cakey.pem -out cacert.pem -days 3650Generating a 2048 bit RSA private key.....................................................................................................................................................................+++......................................+++writing new private key to 'cakey.pem'

Anyone who knows the secret key of the CA can use it to sign any server certificates. Therefore this key file is not stored in plain text on the hard disk, but encrypted with a passphrase. You will always require this passphrase if you want to issue new certificates with the CA:

Enter PEM pass phrase: wrzlprmpftVerifying - Enter PEM pass phrase: wrzlprmpft

You will now be asked to enter data that identifies the CA. This will be displayed to the client when they are asked to accept or reject the certificate. The code for Germany is DE. If you want to leave a field empty, enter a dot (period). Otherwise, the default value in square brackets is entered:

-----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.-----Country Name (2 letter code) [AU]: DEState or Province Name (full name) [Some-State]:.Locality Name (eg, city) []:MuenchenOrganization Name (eg, company) [Internet Widgits Pty Ltd]:Hinz und Kunz AGOrganizational Unit Name (eg, section) []:.

The Common Name (CN) field is the official name of the certification body. For your own CA you can simply enter your own name:

Common Name (eg, YOUR name) []: Adam HinzEmail Address []: [email protected]

Done. The following two files have been created:

root@linux# llinsgesamt 9drwxr-xr-x 2 root root 112 2006-04-30 12:08 .drwx------ 12 root root 600 2006-04-30 11:54 ..-rw-r--r-- 1 root root 1212 2006-04-30 12:08 cacert.pem-rw-r--r-- 1 root root 963 2006-04-30 12:08 cakey.pem

As a precaution you should set the rights so that only root can read the key file:

root@linux# chmod 600 cakey.pem

You can now try out whether you can open the key again using the passphrase:

root@linux# openssl rsa -in cakey.pem -noout -textEnter pass phrase for cakey.pem: wrzlprmpftPrivate-Key: (1024 bit)modulus: 00:d5:a5:37:51:e9:d9:fa:e3:97:e7:46:b2:88:1a: b5:46:80:47:76:14:ae:2b:8b:3e:35:5c:ab:15:84: 53:d9:63:2e:7f:08:4b:ec:77:db:02:45:f8:c7:46: 58:cd:2d:f9:29:4d:96:3d:d8:6c:5d:9f:79:8a:04: cf:b7:3a:89:da:a9:63:9f:44:b3:83:cf:0d:70:7d:

etc...

3. generate the key for the server certificate

Now that we have our own CA, it can finally issue a certificate for our server. First we generate a 2048 bit long RSA key, which is encrypted with AES 128 and stored on the disk (yes really, again an encrypted key). The passphrase does not have to be very secret this time, because we will remove it afterwards anyway. However, OpenSSL does not allow an empty phrase:

root@linux# openssl genrsa -out serverkey.pem -aes128 2048 -days 3650Generating RSA private key, 2048 bit long modulus....+++.......................................+++e is 65537 (0x10001)Enter pass phrase for serverkey.pem: jajaVerifying - Enter pass phrase for serverkey.pem: jaja

Like this. Now we remove the passphrase again. Why? After all, the server service (Apache, Cyrus, etc.) must be able to read the key without your intervention. Or do you want to have to enter a password every time the server boots?

root@linux# openssl rsa -in serverkey.pem -out serverkey.pemEnter pass phrase for serverkey.pem: jajawriting RSA key

4. Certificate Signing Request erzeugen

Der nächste Schritt zum eigenen Zertifikat ist ein CSR. Dies muss dann nur noch von der CA signiert werden. Hier sind wieder Angaben analog zum Erstellen der CA nötig, was oft Verwirrung stiftet. Die allgemeinen Daten kann man ggfl. gleich wie oben eingeben:

root@linux# openssl req -new -key serverkey.pem -out req.pem -nodesYou 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.-----Country Name (2 letter code) [AU]: DEState or Province Name (full name) [Some-State]:.Locality Name (eg, city) []:MuenchenOrganization Name (eg, company) [Internet Widgits Pty Ltd]:Hinz und Kunz AGOrganizational Unit Name (eg, section) []:.

ATTENTION – here comes the important part: With the server certificate, the Common Name is of crucial importance. It must contain the DNS name under which the client addresses the server! If the certificate is used for an HTTPS connection to www.hinzag.eu, the Common Name must be exactly www.hinzag.eu otherwise the browser will not accept the certificate, because it will assume that it has landed on the wrong server.

Common Name (eg, YOUR name) []: www.hinzag.euEmail Address []: [email protected]

Other options can simply be left blank:

A challenge password []:An optional company name []:

By now there will already be four files in our directory:

root@linux# llinsgesamt 17drwxr-xr-x 2 root root 168 2006-04-30 12:29 .drwx------ 12 root root 600 2006-04-30 11:54 ..-rw-r--r-- 1 root root 1212 2006-04-30 12:08 cacert.pem-rw------- 1 root root 963 2006-04-30 12:08 cakey.pem-rw-r--r-- 1 root root 1017 2006-04-30 12:29 req.pem-rw-r--r-- 1 root root 1679 2006-04-30 12:21 serverkey.pem

5. Customise the OpenSSL configuration

Unfortunately OpenSSL does not allow you to pass all data as command line arguments. Annoyingly, you need to change some settings in the file /etc/ssl/openssl.cnf before one can sign. Open this file and adjust the following lines in the [ CA_default ] section:

/etc/ssl/openssl.cnf:dir = . # Where everything is keptnew_certs_dir = $dir # default place for new certsprivate_key = $dir/cakey.pem # The private keyRANDFILE = $dir/.rand # private random number filedefault_days = 3650 # how long to certify for

The default_days field is preset to 365 days, and defines the validity of the certificate. Expired certificates are also a very common problem. When the time has been exceeded, nobody recognises the certificate anymore. For this reason you can increase the lifetime to 10 years, for example, as shown in the example.

If you have not specified a state in the server certificate, you need to make the following change in [ policy_match ]:

stateOrProvinceName = optional

Now you have to create some files:

root@linux# echo 01 > serialroot@linux# touch index.txt

6. Sign the Server Certificate
Let us come to the ceremonial conclusion – our CA now signs the certificate:

root@linux# openssl ca -in req.pem -notext -out servercert.pemEnter pass phrase for ./cakey.pem: wrzlprmpft...Certificate is to be certified until Apr 27 10:45:36 2016 GMT (3650 days)Sign the certificate? [y/n]: y1 out of 1 certificate requests certified, commit? [y/n] yWrite out database with 1 new entriesData Base Updated

7. Install the certificate

Where you install the certificates depends on the server service. What they all have in common: You only need the files cacert.pem, servercert.pem and serverkey.pem. The cakey.pem file is not required. It is best not to store it on the server but in a safe place on another computer.

Creating a server certificate | Linux know-how (2024)

FAQs

How to generate a certificate for a server? ›

Detailed procedure
  1. Install OpenSSL. ...
  2. Creating the CA. ...
  3. generate the key for the server certificate. ...
  4. Certificate Signing Request erzeugen. ...
  5. Customise the OpenSSL configuration. ...
  6. Sign the Server Certificate. ...
  7. Install the certificate.

How do I make my server certificate trusted? ›

Trusting an SSL Certificate on a Client Machine
  1. Step 1: Compare Host Names. Make sure that the host to which the certificate is issued is the same as the host name for your Secret Server website: ...
  2. Step 2: Transfer a copy from your server to the client computer. ...
  3. Step 3: Install the certificate on the client computer.

What is the purpose of a certificate on a server? ›

Server certificates enable encrypted connections, guaranteeing the confidentiality and integrity of data transferred between users and servers. Understanding the importance of server certificates is critical for both organizations and individuals since they are the cornerstone of trust in online interactions.

Can I create my own SSL certificate? ›

Technically, anyone can create their own SSL certificate by generating a public-private key pairing and including all the information mentioned above. Such certificates are called self-signed certificates because the digital signature used, instead of being from a CA, would be the website's own private key.

How do I add a new certificate to my server? ›

In the left pane of the console, double-click Certificates (Local Computer). Right-click Personal, point to All Tasks, and then select Import. On the Welcome to the Certificate Import Wizard page, select Next. On the File to Import page, select Browse, locate your certificate file, and then select Next.

How to create client server certificate? ›

Step 1: Manually Create a Client Certificate on the CA Server
  1. Access the CA Server: Log in to the CA server where you have the Certificate Authority role installed.
  2. Open Certification Authority MMC Snap-in: ...
  3. Request a New Certificate: ...
  4. Approve the Certificate Request: ...
  5. Retrieve the Issued Certificate:
Dec 26, 2023

How do I fix an untrusted server certificate? ›

Resolve Untrusted Certificate
  1. Procure and install a signed and trusted certificate. ...
  2. If the certificates are self-managed by your company's IT, then they will try to fix the error by editing the certificate attributes.
  3. They may ask you to click “Trust Anyway” and continue connecting to the application or website.

How do I fix server's certificate is not trusted? ›

How to Fix SSL Certificate Error
  1. Diagnose the problem with an online tool.
  2. Install an intermediate certificate on your web server.
  3. Generate a new Certificate Signing Request.
  4. Upgrade to a dedicated IP address.
  5. Get a wildcard SSL certificate.
  6. Change all URLS to HTTPS.
  7. Renew your SSL certificate.
Apr 3, 2024

How to create your own certificate authority? ›

Using OpenSSL to create our CA
  1. Step 1: Create a private key for the CA. ...
  2. Step 2: Create Certificate of the CA. ...
  3. Step 3: Add the CA certificate to the trusted root certificates. ...
  4. Step 4: Create a certificate for the webserver. ...
  5. Step 5: Sign the certificate. ...
  6. Step 6: Deploy the certificate.
Jan 29, 2022

Does every server need a certificate? ›

If you're asking yourself, “Do I need an SSL certificate?”, the fact is that every website should have an SSL certificate, even if they don't sell anything online. Let's go over why more in-depth below. SSL is a type of encryption protocol that secures data between browsers and servers so it can't be intercepted.

What is the difference between SSL certificate and server certificate? ›

Whereas server certificates are more commonly known as TLS/SSL certificates and are used to protect servers and web domains. Server Certificates perform a very similar role to Client Certificates, except the latter is used to identify the client/individual and the former authenticates the owner of the site.

What are the contents of a server certificate? ›

The issuer's information, which is typically a trusted Certificate Authority (CA) The validity period of the certificate, including the start and expiration dates. A public key associated with the server and the issuing CA's signature. Extensions containing additional information, such as Subject Alternative Names ( ...

How to create a trusted certificate? ›

Adding a self-signed certificate to the Server application
  1. Create a new file via a text editor and save it as cert. pem. ...
  2. Open the cert. pem file and add the contents of files created in step 1 to the cert. ...
  3. Stop the server application. ...
  4. Move the cert. ...
  5. Start the server application.
Feb 29, 2024

Can you have 2 SSL certificates on one server? ›

Of course, you can have them. There are no rules, whatsoever, to stop you from having 2 SSL certificates for one domain. There are a variety of reasons why you may want to use two SSL certificates for one domain or IP address.

How to get a server certificate? ›

Download the Trusted Root certificate from a CA

For example, a Gateway Server or Management Server. Open a web browser and connect to the certificate server web address. For example, https://<servername>/certsrv . On the Welcome page, select Download a CA Certificate, Certificate chain, or CRL.

How do I get a certificate file from a server? ›

Export using IIS
  1. Go to Start >> Administrative Tools >> Internet Information Services (IIS) Manager.
  2. Select the server on which the certificate is installed.
  3. Choose the Server Certificates option on the central menu:
  4. Right-click on the needed certificate and select Export.

How to create certificate for SMTP server? ›

Creating a certificate for an SMTP server
  1. Specify the private key file (one with the *. prk or *. pem extension).
  2. Specify the private key password.
  3. Specify the public key file (one with the *. cer extension).

How do I create a server certificate chain? ›

Then, begin by generating a self-signing certificate authority key:
  1. openssl genrsa -out cadb.key 4096. ...
  2. openssl req -x509 -new -nodes -key cadb.key -days 3650 -config db.cfg -out cadb.pem. ...
  3. openssl genrsa -out db.key 4096. ...
  4. openssl req -new -key db.key -out db.csr -config db.cfg.

How do I get a certificate from a web server? ›

Obtaining a certificate by using a web browser
  1. In the browser, enter the HTTPS address for the destination device.
  2. Click the Lock icon by the address bar. ...
  3. Click More information.
  4. Click View Certificate in the Website Identity section.
  5. Click the Details tab in the Certificate Viewerwindow.

Top Articles
WebD2: Common HTML Tags
10 New Crypto Coins You Should Buy Before December 2023!
What Did Bimbo Airhead Reply When Asked
Hotels
Brady Hughes Justified
Pga Scores Cbs
Erika Kullberg Wikipedia
Tj Nails Victoria Tx
Get train & bus departures - Android
DL1678 (DAL1678) Delta Historial y rastreo de vuelos - FlightAware
Gameplay Clarkston
Vanadium Conan Exiles
Hallowed Sepulchre Instances &amp; More
Free Robux Without Downloading Apps
Tamilblasters 2023
[PDF] INFORMATION BROCHURE - Free Download PDF
Audrey Boustani Age
Directions To O'reilly's Near Me
Bnsf.com/Workforce Hub
Ahrefs Koopje
The best firm mattress 2024, approved by sleep experts
Hewn New Bedford
Homeaccess.stopandshop
The Weather Channel Local Weather Forecast
Ou Class Nav
Haunted Mansion Showtimes Near Epic Theatres Of West Volusia
Inkwell, pen rests and nib boxes made of pewter, glass and porcelain.
Anonib Oviedo
Manuela Qm Only
EVO Entertainment | Cinema. Bowling. Games.
Planned re-opening of Interchange welcomed - but questions still remain
Emily Katherine Correro
Panchang 2022 Usa
Memberweb Bw
Nsu Occupational Therapy Prerequisites
Peter Vigilante Biography, Net Worth, Age, Height, Family, Girlfriend
Rise Meadville Reviews
Pitco Foods San Leandro
Aliciabibs
Avance Primary Care Morrisville
1v1.LOL Game [Unblocked] | Play Online
M Life Insider
2024-09-13 | Iveda Solutions, Inc. Announces Reverse Stock Split to be Effective September 17, 2024; Publicly Traded Warrant Adjustment | NDAQ:IVDA | Press Release
Nope 123Movies Full
Mit diesen geheimen Codes verständigen sich Crew-Mitglieder
Missed Connections Dayton Ohio
Definition of WMT
De Donde Es El Area +63
Subdomain Finer
ats: MODIFIED PETERBILT 389 [1.31.X] v update auf 1.48 Trucks Mod für American Truck Simulator
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 6136

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.