Skip to content

Instantly share code, notes, and snippets.

@stephenjude
Forked from Shourai/namecheap SSL.md
Created October 7, 2018 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenjude/edccbea9d5fb0ae1d0408991bc259669 to your computer and use it in GitHub Desktop.
Save stephenjude/edccbea9d5fb0ae1d0408991bc259669 to your computer and use it in GitHub Desktop.
Letsencrypt SSL certificate with namecheap hosting

source: https://savedlog.com/uncategorized/letsencrypt-ssl-certificate-namecheap-hosting/

The “Positive SSL” certificate I bought along with my domain is invalid with any of my subdomains and cannot be used with wildcards. One annoying thing is that namecheap doesn’t offer auto installation of free let’s encrypt certificates, even though, they are saying “Namecheap is dedicated to data security and privacy for all internet users. We believe the movement to encrypt nearly all web traffic is a positive direction. As more sites embrace HTTPS and use of security products, providers of free SSL are beginning to come online.”

Let me show you what it needs to be done in order to “encrypt nearly all web traffic”.

First, not required but it’s helpful to enable ssh access, it is not enabled by default on the base hosting plans, just go an start a live chat and request ssh access.

Letsencrypt nosudo

SSH to your hosting server, visit diafygi/letsencrypt-nosudo and “git clone” the project. You can also follow the tutorial on the project site.

mkdir tools && cd tools
git clone https://github.com/diafygi/letsencrypt-nosudo.git 
cd letsencrypt-nosudo/

Generate an user account key for Let’s Encrypt.

openssl genrsa 4096 > user.key
openssl rsa -in user.key -pubout > user.pub

Generate the domain key and a certificate request. Replace “example.com” with the domain you own

For single subdomain.example.com use:

openssl genrsa 4096 > domain.key
openssl req -new -sha256 -key domain.key -subj "/CN=example.com" > domain.csr

If you want the certificate to be valid for multiple subdomains create a file name openssl-san.cfg and paste the following (Replace the alt_names “mail.example.com” with the domain and subdomain you own):

[req]
default_bits = 2048
default_md   = sha256
distinguished_name = req_distinguished_name
req_extensions     = req_ext

[ req_distinguished_name ]
countryName          = Country Name (2 letter code)
stateOrProvinceName  = State or Province Name (full name)
localityName         = Locality Name (eg, city)
organizationName     = Organization Name (eg, company)
commonName           = Common Name (e.g. server FQDN or YOUR name)

[ req_ext ]

subjectAltName = @alt_names

[alt_names]
DNS.1        = test.example.com
DNS.2        = www.example.com
DNS.3        = mail.example.com
DNS.4        = ftp.example.com

and run:

openssl req -new -sha256 -key domain.key -subj "/O=My Company Name LTD./C=US" -config openssl-san.cfg > domain.csr

Create and install new certificate

Next, you run the script using python and passing in the path to your user account public key and the domain CSR.

python sign_csr.py -f --public-key user.pub domain.csr > signed.crt

When you run the script, it will ask you do do some manual commands. It has to ask you to do these because it doesn’t know your private key or have access to your server. You can edit the manual commands to fit your situation (e.g. if your sudo user is different or private key is in a different location).

When you run the script, it will ask you do do some manual commands, open another terminal and follow the instructions.

At the final step the script will ask you to serve a file on each of your subdomains and you need to create the folders and requseted file in the subdomain root folder.

For example if you have the subdomain test.example.com with root folder in /home/cpanel_user/test.example.com and the script ask you to serve for example:

STEP 4: Please update your server to serve the following file at this URL:
--------------
URL: http://test.example.com/.well-known/acme-challenge/_bpFRhpfEVHktwEVdjmdCtVcF5MZ7qRvcn--uZwPKzM
File contents: "_bpFRhpfEVHktwEVdjmdCtVcF5MZ7qRvcn--uZwPKzM.Nh8mz3FnS03KxkGXN4_Cj9j9vcw4wXcZm0Z25CW6Ttw"
--------------

Notes:
- Do not include the quotes in the file.
- The file should be one line without any spaces.

Press Enter when you've got the file hosted on your server...

you need to create in .well-known/acme-challenge/ in /home/cpanel_user/test.example.com and paste the file content in _bpFRhpfEVHktwEVdjmdCtVcF5MZ7qRvcn–uZwPKzM

mkdir -p /home/cpanel_user/test.example.com/.well-known/acme-challenge/


echo "_bpFRhpfEVHktwEVdjmdCtVcF5MZ7qRvcn--uZwPKzM.Nh8mz3FnS03KxkGXN4_Cj9j9vcw4wXcZm0Z25CW6Ttw" > /home/cpanel_user/test.example.com/.well-known/acme-challenge/_bpFRhpfEVHktwEVdjmdCtVcF5MZ7qRvcn--uZwPKzM

After you done it for all your subdomains you can go and install it your namecheap hosting cpanel. You can use this link for help.

  • Go to cpanel > Security > SSL/TLS and press on Manage SSL sites.
  • Select the domain you want to install the certificate, for example test.example.com
  • In Certificate: (CRT) paste the content of the recently created signed.crt
  • In Private Key (KEY) paste the content of domain.key
  • Press Autofill by Domain button, next to the domain selection drop-down.
  • Press Install certificate.

Congrats you are now using free let’s encrypt certificate on namecheap basic hosting server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment