How to Create a TLS/SSL certificate on CentsOS

Your web-server is only as secure as you make it but security isn’t only about protecting your server against attackers, it is also about protecting your clients from Man In The Middle(MITM) attacks. Securing your connections using the TLS protocol(successor of SSL) is strongly recommended if your website allows user registration, economic transactions or requests private information, otherwise plain text passwords, credit card numbers or confidential data could be easily stolen by MITM attackers.There are many cryptographic libraries to choose from. While NSS is recommended, OpenSSL is still dominant.

While OpenSSL uses x509 format and stores the certificates in files, NSS uses the PKCS12 format for certificates which it imports to a database. Genkey supports both, however it doesn’t allow to specify the cryptographic or the digest algorithm and the defaults can be considered weak as it uses SHA1 as a digest algorithm.

Create a Certificate using OpenSSL

1. Generate Private Keys

First generate the private key, in this example we will use a 2048 RSA key

# openssl genrsa -out 2048



2. Create SCR

Create a Certificate Signing Request(CSR). The Common Name field must be your server’s hostname

# openssl req -new -key -out -sha512

A message digest algorithm like SHA2 or stronger is recommended, but it’s more important for the certificate than for the request. However your CA decides which message digest they use for the certificate.

Now give your CSR to your Certificate Authority(CA) so they can sign your key and give you a certificate. Alternatively you can self-sign it, but bear in mind of the security issues that it poses and that browser will warn users about this:

# openssl x509 -req -days 365 -in -signkey -out -sha512

Once your CA has signed it they will give you the certificate(.crt file). Now move the private key and the certificate to their respective directories:

# cp /etc/pki/tls/certs/

# cp /etc/pki/tls/private/

The Certificate Signing Request(CSR) can be deleted as it becomes useless once you have obtained your certificate. Alternatively put it along your private key.

# cp /etc/pki/tls/private/


3. Context in SELinux

Set the correct context of these files for SELinux

# restorecon -RvF /etc/pki

The last step is to configure the webserver of your host for the TLS protocol using the key and the certificate files you have just created.


4. Create Postfix TSL

Once your TLS/SSL key generated then add these keys path into Postfix file, to build postfix with TLS support just add the following entry in the Postfix main file /etc/postfix/ directory and save the file

smtpd_use_tls = yes
smtpd_tls_key_file = /etc/pki/tls/private/
smtpd_tls_cert_file = /etc/pki/tls/certs/

smtpd_tls_loglevel = 3
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
smtp_use_tls = yes

5. Restart Services

Finally, restart Postfix and Httpd to take effect

# sudo systemctl restart postfix

# sudo systemctl restart httpd


Video Tutorial


In this post, I have covered how to create TLS / SSL certificate on CentOS 7 in a very easy way. Follow and share with your friends also ask by comment or from the contact section for your queries.


  1. This page really has all of the information and facts I wanted concerning this subject and didn’t know who to ask.

  2. These are truly fantastic ideas in regarding blogging. You have touched
    some good factors here. Any way keep up wrinting.

  3. Hello there! I know this is somewhat off topic but I
    was wondering if you knew where I could locate a captcha plugin for my comment form?

    I’m using the same blog platform as yours and I’m having trouble finding one?
    Thanks a lot!

Leave a Reply

Your email address will not be published. Required fields are marked *