DEV Community

Chan sokngoun
Chan sokngoun

Posted on

Generate a SSL with certbot on digitalocean droplet

Install Certbot for SSL


# Install python3 virtual environment
apt install python3-venv

# Create a virtual environment
sudo python3 -m venv /opt/certbot/

Enter fullscreen mode Exit fullscreen mode

# Upgrade pip
sudo /opt/certbot/bin/pip install --upgrade pip

# Using pip to install certbot & certbot-nginx
sudo /opt/certbot/bin/pip install certbot certbot-nginx

# Copy the newly install certbot package
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot

# Instructs Certbot to use the Nginx plugin to automatically configure SSL/TLS for Nginx web servers.
sudo certbot --nginx

Enter fullscreen mode Exit fullscreen mode

Add an auto certificate renew script

# Run once every 2 days
echo "0 0 */2 * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && sudo certbot renew -q" | sudo tee -a /etc/crontab > /dev/null
Enter fullscreen mode Exit fullscreen mode

Top comments (0)