Add ssl certificate to linux

Installing a root CA certificate in the trust store

Enterprise environments sometimes have a local Certificate Authority (CA) that issues certificates for use within the organization. For an Ubuntu server to be functional and trust the hosts in this environment this CA must be installed in Ubuntu’s trust store.

How to recognize the form (PEM or DER)?

To install a certificate in the trust store it must be in PEM form. A PEM-formatted certificate is human-readable in base64 format, and starts with the lines —-BEGIN CERTIFICATE—- . If you see these lines, you’re ready to install. If not, it is most likely a DER certificate and needs to be converted.

Installing a certificate in PEM form

Assuming a PEM-formatted root CA certificate is in local-ca.crt , follow the steps below to install it.

Note: It is important to have the .crt extension on the file, otherwise it will not be processed.

$ sudo apt-get install -y ca-certificates $ sudo cp local-ca.crt /usr/local/share/ca-certificates $ sudo update-ca-certificates 

After this point you can use Ubuntu’s tools like curl and wget to connect to local sites.

Converting from DER-form to PEM-form

Convert a DER-formatted certificate called local-ca.der to PEM form like this:
$ sudo openssl x509 -inform der -outform pem -in local-ca.der -out local-ca.crt

The CA trust store location

The CA trust store as generated by update-ca-certificates is available at the following locations:

  • As a single file (PEM bundle) in /etc/ssl/certs/ca-certificates.crt
  • As an OpenSSL compatible certificate directory in /etc/ssl/certs

Источник

Добавляем корневой доверенный сертификат в Linux

date

28.09.2022

user

itpro

directory

CentOS, Linux, Ubuntu

comments

комментария 4

В этой статье мы покажем, как добавить (установить) новый сертификат в список доверенных корневых сертификатов в Linux.

Например, вы используете на своем сайте самоподписанный SSL/TLS сертификат и не хотите, чтобы на клиентах при открытии сайта появлялась ошибка SEC_ERROR_UNKNOWN_ISSUER.

недоверенные сертификат в браузере на linux

В данном примере мы установим в Linux корневой сертификат Минцифры (Russian Trusted Sub CA), на базе которого сейчас выпускаются сертификаты для сайтов многих компаний и гос-органов РФ.

Или это может быть самоподписанный сертификат с сайта IIS на Windows.

Читайте также:  Steam gaming on linux

Чтобы проверить, что ваш хост Linux не может проверить (и соответственно не доверяет) SSL сертификату на определенном сайте, выполните команду:

$ curl –I https://www.sberbank.ru

curl: (60) SSL certificate problem: unable to get local issuer certificate. More details here: https://curl.haxx.se/docs/sslcerts.html curl failed to verify the legitimacy of the server and therefore could not establish a secure connection to it. To learn more about this situation and how to fix it, please visit the web page mentioned above.

curl - не могу проверить сертификат

В данном случае нам нужно добавить корневой центр сертификации этого сайта в список доверенных корневых сертификатов Linux.

Установка корневого сертификата в Linux

Для обновления хранилища доверенных сертификатов в Linux вам нужен файл сертификата в формате PEM с расширением файла .crt. PEM сертификат представляет собой текстовый файл в формате base64, который содержит в начале файла строку —-BEGIN CERTIFICATE—- и в конце ——END CERTIFICATE——.

PEM формат сертификата

Если ваш файл сертификата в формате DER, вы можете конвертировать его в PEM формат с помощью утилиты openssl:

$ openssl x509 -in my_trusted_sub_ca.der -inform der -out my_trusted_sub_ca.cer

Сначала рассмотрим, как добавит корневой сертификат вашего CA в доверенные в дистрибутивах Linux на базе DEB (Ubuntu, Debian, Mint, Kali Linux).

Скопируйте файлы ваших сертификаты в хранилище сертификатов в каталог usr/local/share/ca-certificates/:

$ sudo cp my_trusted_sub_ca.crt /usr/local/share/ca-certificates/
$ sudo cp my_trusted_root_ca.crt /usr/local/share/ca-certificates/

Обновите хранилище сертификатов командой:

$ sudo update-ca-certificates -v

$ sudo apt-get install -y ca-certificates

обновить хранилище сертфикатов в linux

Если сертификаты успешно добавлены, появится сообщение о том, что сертфикат скопирован в /etc/ssl/certs/:

Updating certificates in /etc/ssl/certs… 2 added, 9 removed; done. Running hooks in /etc/ca-certificates/update.d

$ sudo dpkg-reconfigure ca-certificates

Выберите из списка сертификаты, которые нужно добавить в доверенные.

добавить сертификаты в доверенные CA в Linux

В Linux список доверенных сертификатов содержится в файле /etc/ssl/certs/ca-certificates.crt. Обе рассмотренные выше команды обновят этот файл и добавят в информацию о новых сертификатах.

Вы можете проверить, что ваши сертификаты были добавлены в доверенные с помощью команды:

Укажите часть Common Name вашего сертификата вместо YourCASubj для поиска в хранилище по subject.

awk вывести доверенные сертификаты

Вы можете убедиться, что ваша ОС доверяет сертификату с помощью команду:

$ openssl verify my_trusted_sub_ca.crt

openssl verify - проверить доверяет ли linux сертификату

error 20 at 0 depth lookup: unable to get local issuer certificate error my_trusted_sub_ca.crt: verification failed

Теперь проверьте, что на сайте используется доверенный SSL сертификат с помощью curl:

$ curl –I https://www.sberbank.ru

Все ок, сертификат доверенные < HTTPOnly: secure >.

curl проверка ssl сертификата secure

$ sudo mkdir /usr/share/ca-certificates/extra

Чтобы удалить сертификат, удалите ваш crt файл:

$ sudo rm /usr/local/share/ca-certificates/yourcert.crt

$ sudo update-ca-certificates —fresh

В дистрибутивах Linux на базе RPM (CentOS, Oracle, RHEL, Rocky Linux, Fedora) для добавления сертификата в доверенные:

  1. Установите пакет ca-certificates: # yum install ca-certificates
  2. Скопируйте файл сертификата в каталог /etc/pki/ca-trust/source/anchors/: # cp mycert.crt /etc/pki/ca-trust/source/anchors/
  3. Обновите хранилище:
    # update-ca-trust force-enable
    # update-ca-trust extract
Читайте также:  Установить линукс с телефона

Добавить корневой доверенный сертификат для браузеров Mozilla, Chrome

Теперь все системные утилиты будут доверять сайтам, использующим данный CA. Но это не повлияет на веб браузеры Mozilla Firefox или Google Chrome. Они по-прежнему будут показывать предупреждение о недоверенном сертификате.

Дело в том, что браузеры Firefox, Chromium, Google Chrome, Vivaldi и даже почтовый клиент Mozilla Thunderbird не используют системное хранилище сертификатов Linux. Хранилище сертификатов для этих программ находится в директории пользователя в файле cert8.db (для Mozilla) или cert9.db (для Chromium и Chrome). Для обновления этих хранилищ сертификатов используется утилита certutil из пакета libnss3-tools.

$ sudo apt install libnss3-tools

установка libnss3-tools

Теперь выполните следующие скрипты для добавления ваших сертификатов в хранилище через NSS:

#!/bin/bash
certfile=»my_rusted_root_ca.crt»
certname=»My Root CA1″
for certDB in $(find ~/ -name «cert8.db»)
do
certdir=$(dirname $);
certutil -A -n «$» -t «TCu,Cu,Tu» -i $ -d dbm:$
done
for certDB in $(find ~/ -name «cert9.db»)
do
certdir=$(dirname $);
certutil -A -n «$» -t «TCu,Cu,Tu» -i $ -d sql:$
done

После запуска скрипта, сайтам с данным CA будут доверять все браузеры.

Предыдущая статьяПредыдущая статья Следующая статья Следующая статья

Источник

Classic SysAdmin: How to Install an SSL Certificate on Linux Server

With Security being the top most priority in the e-commerce world, the importance of SSL Certificates has skyrocketed. Installing an SSL Certificate on an online portal has become the basic foundation of a company’s business structure.

But the question is ‘How to install an SSL Certificate on a server?’

It is not necessary that everyone who is into e-commerce has a technical background. E-commerce is all about business and the owners are mostly businessmen. So also the core team of an e-commerce industry is not fully technical. In such a situation it becomes very difficult for people with minimal technical knowledge to grasp concepts even as basic like SSL Certificates or its installation for that matter.

This article aims at giving a sneak peek into the process of installing an SSL Certificate on Linux server in lay man’s words. This would help the non-technical people also to get a grasp of what it is all about. Of course, every e-commerce company has a core technical team, so they can easily take over from here. But it is always good to have a know-how of the process.

The installation of SSL Certificates on a Linux server is very easy. It can be done using a Plesk control panel and also without it.

What is Plesk?

It is a web hosting platform that has a very simple configuration. This simple configuration helps all web hosting providers to manage a lot of virtual hosts easily and on a single server. Ever since its conception, Plesk has been coming up as a preferred choice for all the web hosting companies.

Читайте также:  Kali linux persistence не сохраняет

How to install an SSL certificate on a Linux Server that has Plesk

1. First Log into the control panel of Plesk.

3. The third step implies choosing the domain to be updated.

4. In the next step click on the ‘Add New Certificate’ icon.

5. Save the certificate name in the ‘Certificate Name’ box.

One would have the certificate and key files saved on the local computer. These certificate and key files are provided by the certificate authority and are important for the installation.

6. The next step is to find these files. Open these in a Notepad or in other similar text formats from where one can copy the text.

7. Copy the entire text of the files.

8. Paste them in the correct boxes. Reading through the content and the box name in Plesk will give one an idea where to paste it.

9. Next, click on the ‘Send Text’ button.

10. Go to the ‘Hosting Section’. It is on the domain screen.

11. Click ‘Set-up’ from this section. A drop down list will follow.

12. The next step is to click on the ‘new certificate’ from the drop down list.

How to install SSL Certificate on Linux servers that do not have Plesk

1. The first and foremost step is to upload the certificate and important key files. One can upload the files to the server using – S/FTP.

2. Login to Server. It is important to log in via SSH. Logging in via SSH will help the user to become the root user.

4. One can see /etc/httpd/conf/ssl.crt in the following step. Move the certificate file here

5. Next move key file also to /etc/httpd/conf/ssl.crt

It is important to ensure the security of the files that has been moved. One can keep the files secure by restricting permission. Using ‘chmod 0400’ will help users to securely restrict permission to the key.

6. Next Go to etc/httpd/conf.d/ssl.conf. Here the user will find Virtual Host Configuration set up for the domain.

7. Edit Virtual Host Configuration.

The technicality of installing an SSL certificate may baffle many non-technical people, but once one gets a hang of it, it becomes easy.

Ready to continue your Linux journey? Check out our free intro to Linux course!

Источник

Оцените статью
Adblock
detector