|
1 | 1 | # 5. SSL Certficates
|
| 2 | + |
| 3 | +When we connect to a web server, we send packets of data to it. By default, with HTTP, those packets are readable (and sometimes editable) by people between you and the server. |
| 4 | + |
| 5 | +> 📖 Resources |
| 6 | +> |
| 7 | +> - https://en.wikipedia.org/wiki/Man-in-the-middle_attack |
| 8 | +
|
| 9 | +SSL certificates allow your browser to communicate with any server with no fear of someone being able to intercept your communications. |
| 10 | + |
| 11 | +Technically, a certificate is a document proving the ownership of an encryption key. |
| 12 | + |
| 13 | +> ⚠️ warning |
| 14 | +> |
| 15 | +> a frequent misconception with SSL certificates is they can prevent pirates from doing harm to you. SSL certificates is about **securing your communications** with a server, **it does not guarantee that the server has good intentions** |
| 16 | +
|
| 17 | +## 5.1 Certbot and nginx |
| 18 | + |
| 19 | +Setting up SSL certificates manually is extremely complicated to get right. Hopefully, amazing guys created tools allowing us to install certificates easily on servers. |
| 20 | + |
| 21 | +Also, SSL certificates used to be paid (and expensive), but thanks to services like [Let's Encrypt](https://letsencrypt.org/), we can get simple SSL certificates for free. Some advanced SSL certificates are still paid. |
| 22 | + |
| 23 | +Certbot (create by the EFF) automates SSL certificates installation on most operating systems and web servers. |
| 24 | + |
| 25 | +### 5.1.1 Installation |
| 26 | +Let's tell our server where to look for `certbox` |
| 27 | + |
| 28 | +```bash |
| 29 | +apt update |
| 30 | +apt install software-properties-common |
| 31 | +add-apt-repository universe |
| 32 | +add-apt-repository ppa:certbot/certbot |
| 33 | +apt update |
| 34 | +``` |
| 35 | + |
| 36 | +and let's install it: |
| 37 | + |
| 38 | +```bash |
| 39 | +apt install certbot python-certbot-nginx |
| 40 | +``` |
| 41 | + |
| 42 | +### 5.1.2 Setup |
| 43 | + |
| 44 | +Before everything, we should `nginx` to listen to a specific domain name: |
| 45 | + |
| 46 | +```bash |
| 47 | +nano /etc/sites-enabled/<something> |
| 48 | +``` |
| 49 | + |
| 50 | +and replace `server_name: _` by `server_name: <domain.tld>`. Then restart `nginx` (and check the domain name works). |
| 51 | + |
| 52 | +Then, let's run `certbot`: |
| 53 | + |
| 54 | +```bash |
| 55 | +sudo certbot --nginx |
| 56 | +``` |
| 57 | + |
| 58 | +> 🃏 hints |
| 59 | +> |
| 60 | +> - use the domain you have linked to this server's IP |
| 61 | +
|
| 62 | +### 5.1.3 Test |
| 63 | + |
| 64 | +Go to `https://<host>`, you should see a green lock on your browser. |
| 65 | + |
| 66 | +Let's also test that the auto-renewal works: |
| 67 | + |
| 68 | +```bash |
| 69 | +certbot renew --dry-run |
| 70 | +``` |
| 71 | + |
| 72 | +> ℹ️ information |
| 73 | +> |
| 74 | +> Let's Encrypt certificates are only valid 90 days and need to be renewed at this interval. Thanksfully, certbot automates it for us by creating a Cron job. |
| 75 | +
|
| 76 | +--- |
| 77 | + |
| 78 | +We got HTTPS working, [let's deploy something real](6.deployment.md) now! |
0 commit comments