Jump to content

Instalando o SSL da Let's Encrypt


msaulohenrique

Recommended Posts

Vamos lá

  • Execute (CentOS/CloudLinux 6.X)
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -ivh https://rhel6.iuscommunity.org/ius-release.rpm
yum -y install git python27 python27-devel python27-pip python27-setuptools python27-virtualenv --enablerepo=ius
cd /root
git clone https://github.com/letsencrypt/letsencrypt
cd /root/letsencrypt
sed -i "s|--python python2|--python python2.7|" letsencrypt-auto
./letsencrypt-auto --verbose
  • (CentOS 7.X)

 

yum -y install git
cd /root
git clone https://github.com/letsencrypt/letsencrypt
cd /root/letsencrypt
./letsencrypt-auto --verbose

Pronto, temos o Let's Encrypt instalado no nosso servidor.

  • Vamos criar agora os certificados para os domínios que queremos.

Estarei ensinando a criar o SSL com renovação automática. A cada novo SSL que queira, precisará realizar esse passo novamente.

Execute, lembre-se de alterar o domínio e por o usuário do cPanel respectiva a hospedagem e o e-mail do dono da hospedagem.

cd /root/letsencrypt
./letsencrypt-auto --text --agree-tos --email [email protected] certonly --renew-by-default --webroot --webroot-path /home/cPanelUser/public_html/ -d domain.com -d www.domain.com

Caso vc queira instalar o certificado em subdomínio terá que fazer assim. Ex.: Quero instalar no subdomínio central.domain.com farei assim:

cd /root/letsencrypt
./letsencrypt-auto --text --agree-tos --email [email protected] certonly --renew-by-default --webroot --webroot-path /home/cPanelUser/public_html/central -d central.domain.com -d www.central.domain.com

Veja que tive que especificar o diretório tbm. Algo que vale ressaltar que cada certificado SSL é válido por domínio, sempre que precisa de usar em subdomínio, tem que especificar o diretório.

Prosseguindo...

Precisamos configurar uma atividade CRON para que a cada 60 dias o certificado seja renovado, pois é o tempo de validade de cada certificado. Para isso execulte:

crontab -e

E acrescente a seguinte linha (para cada dominio configurado para o SSL), lembre-se de por o usuário e domínio igual a que foi usado para configurar anteriormente.

0 0 */60 * * /root/.local/share/letsencrypt/bin/letsencrypt --text certonly --renew-by-default --webroot --webroot-path /home/cPanelUser/public_html/ -d domain.com -d www.domain.com; /root/installssl.pl domain.com
  • Configurando script universal para renovação de todos os SSL's configurados

Execulte, lembre-se de altera domain.com pelo que vc está configurou o certificado 

vim /etc/letsencrypt/live/domain.com/fullchain.pm

Adicione:

#!/usr/local/cpanel/3rdparty/bin/perl

use strict;
use LWP::UserAgent;
use LWP::Protocol::https;
use MIME::Base64;
use IO::Socket::SSL;
use URI::Escape;

my $user = "root";
my $pass = "rootpass";

my $auth = "Basic " . MIME::Base64::encode( $user . ":" . $pass );

my $ua = LWP::UserAgent->new(
    ssl_opts   => { verify_hostname => 0, SSL_verify_mode => 'SSL_VERIFY_NONE', SSL_use_cert => 0 },
);

my $dom = $ARGV[0];

my $certfile = "/etc/letsencrypt/live/$dom/cert.pem";
my $keyfile = "/etc/letsencrypt/live/$dom/privkey.pem";
my $cafile =  "/etc/letsencrypt/live/bundle.txt";

my $certdata;
my $keydata;
my $cadata;

open(my $certfh, '<', $certfile) or die "cannot open file $certfile";
    {
        local $/;
        $certdata = <$certfh>;
    }
    close($certfh);

open(my $keyfh, '<', $keyfile) or die "cannot open file $keyfile";
    {
        local $/;
        $keydata = <$keyfh>;
    }
    close($keyfh);

open(my $cafh, '<', $cafile) or die "cannot open file $cafile";
    {
        local $/;
        $cadata = <$cafh>;
    }
    close($cafh);

my $cert = uri_escape($certdata);
my $key = uri_escape($keydata);
my $ca = uri_escape($cadata);

my $request = HTTP::Request->new( POST => "https://127.0.0.1:2087/json-api/installssl?api.version=1&domain=$dom&crt=$cert&key=$key&cab=$ca" );
$request->header( Authorization => $auth );
my $response = $ua->request($request);
print $response->content;

Em my $pass = "rootpass"; vc precisa alterar e colocar a senha do seu acesso root.

Agora execute: 

vi /etc/letsencrypt/live/bundle.txt

Adicione ao seu interior:

-----BEGIN CERTIFICATE-----
MIIEqDCCA5CgAwIBAgIRAJgT9HUT5XULQ+dDHpceRL0wDQYJKoZIhvcNAQELBQAw
PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1c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VgzQ1JM
LmNybDATBgNVHR4EDDAKoQgwBoIELm1pbDAdBgNVHQ4EFgQUqEpqYwR93brm0Tm3
pkVl7/Oo7KEwDQYJKoZIhvcNAQELBQADggEBANHIIkus7+MJiZZQsY14cCoBG1hd
v0J20/FyWo5ppnfjL78S2k4s2GLRJ7iD9ZDKErndvbNFGcsW+9kKK/TnY21hp4Dd
ITv8S9ZYQ7oaoqs7HwhEMY9sibED4aXw09xrJZTC9zK1uIfW6t5dHQjuOWv+HHoW
ZnupyxpsEUlEaFb+/SCI4KCSBdAsYxAcsHYI5xxEI4LutHp6s3OT2FuO90WfdsIk
6q78OMSdn875bNjdBYAqxUp2/LEIHfDBkLoQz0hFJmwAbYahqKaLn73PAAm1X2kj
f1w8DdnkabOLGeOVcj9LQ+s67vBykx4anTjURkbqZslUEUsn2k5xeua2zUk=
-----END CERTIFICATE-----
  • Validando o SSL

Execute e lembre-se de alterar o dominio pelo que vc configurou o SSL.

chmod +x installssl.pl
./installssl.pl domain.com

Enfim!

De fato é algo complicado, os passos em azul, são os que vc deve prosseguir a cada certificado novo que queira instalar. Espero ter ajudado.

Link to comment
Share on other sites

19 minutes ago, AnderS2Aline said:

uma dúvida, esse certificado é anual ? porque agora ele esta aparecendo no cpanel e se tu fazer por la automático só vem 3 meses grátis ou depois ele se renova automaticamente 

Eles só emitem por 3 meses, exatamente para forçar automação do seu lado... 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

Do you agree with our terms?