<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: David Dut</title>
    <description>The latest articles on DEV Community by David Dut (@david_dut_3abb1db64876b4a).</description>
    <link>https://dev.to/david_dut_3abb1db64876b4a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3669592%2F471c85ac-73cd-4dfb-a4fe-5591edddec96.png</url>
      <title>DEV Community: David Dut</title>
      <link>https://dev.to/david_dut_3abb1db64876b4a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/david_dut_3abb1db64876b4a"/>
    <language>en</language>
    <item>
      <title>Beafing up Your server For Production🐄</title>
      <dc:creator>David Dut</dc:creator>
      <pubDate>Thu, 18 Dec 2025 23:32:09 +0000</pubDate>
      <link>https://dev.to/david_dut_3abb1db64876b4a/beafing-up-your-server-for-production-1j0g</link>
      <guid>https://dev.to/david_dut_3abb1db64876b4a/beafing-up-your-server-for-production-1j0g</guid>
      <description>&lt;p&gt;Let's say you are ready for production. Now you want to host your services on the cloud. Are you production ready? &lt;br&gt;
I am going to give a step by step guide of how to beaf up your production server to prevent various attacks and make sure your server is safe. Let's start shall we.&lt;br&gt;
I am going to use linode. Since this is a small scale production server. I am going to set up a shared vps. I will use the 2GB linode for now. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F828ei54o4azk3csic0jx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F828ei54o4azk3csic0jx.png" alt=" " width="800" height="754"&gt;&lt;/a&gt;&lt;br&gt;
Make sure to set a very strong password then set up ssh. To set up the ssh key. On your local machine, then generate the keys if you don't have. I decided to go with ed25519 formart&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -t ed25519
cat ~/.ssh/id_ed25519.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once created. You'll need to add the .pub into your ssh section in linode when creating it.  You can choose to add a back up option but that will cost more. Wait for 1 to 2 minutes then log in to your server.Now Do the initial system setup that is the apt updrade and upgrade then reboot.&lt;br&gt;
Now your server is ready for beafing.&lt;br&gt;
Now le's create a non-root user then log in with the new credentials.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;adduser deploy
usermod -aG sudo deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's Secure our SSH to only allow use of public key:&lt;br&gt;
&lt;code&gt;vi /etc/ssh/sshd_config&lt;/code&gt;&lt;br&gt;
change the configurations to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
X11Forwarding no
UsePAM no
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also allow &lt;code&gt;AuthorizedKeysFile .ssh/authorized_keys&lt;/code&gt;&lt;br&gt;
Add the key to the new user you created&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir -p /home/deploy/.ssh
vi /home/deploy/.ssh/authorized_keys
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fix permission issues:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chown -R deploy:deploy /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
chmod 600 /home/deploy/.ssh/authorized_keys
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then restart SSH;&lt;br&gt;
&lt;code&gt;systemctl restart ssh&lt;/code&gt;&lt;br&gt;
Open another terminal and test first without closing the initial one.&lt;/p&gt;

&lt;p&gt;Now lets set up Firewall (UFW)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 80
sudo ufw allow 443
sudo ufw enable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we need a webserver, let's install nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test your webserver on the browser: &lt;br&gt;
&lt;code&gt;http://SERVER_IP&lt;/code&gt;&lt;br&gt;
Perfect, now our webserver is running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding your domain to cloudfalere&lt;/strong&gt;&lt;br&gt;
Now that your server is up and running. Let's add our domain to cloudflare. I am going to use the free tier.&lt;br&gt;
Log in to cloudflare, navigate to domains then add your new domain.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcuhg6aiqsvtc1pvzle94.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcuhg6aiqsvtc1pvzle94.png" alt=" " width="800" height="405"&gt;&lt;/a&gt;&lt;br&gt;
When you click continue, it is going to scan for any DNS records set up. In my case, I have my records set up on linode. If you had any records, cloudflare will import them. On your domain provider, in this instance where I am using godaddy, I am required to remove the NS records I set for linode and replace with the ones provided for you by cloudflare.&lt;/p&gt;

&lt;p&gt;Now let's create a cloudflare Origin Certificate.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxf8jrtfc8bigubnye7np.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxf8jrtfc8bigubnye7np.png" alt=" " width="800" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the Origin Certificate and Private key.&lt;br&gt;
Install the certificate on the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mkdir /etc/ssl/cloudflare
sudo vi /etc/ssl/cloudflare/origin.pem
sudo vi /etc/ssl/cloudflare/origin.key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set Permissions:&lt;br&gt;
&lt;code&gt;sudo chmod 600 /etc/ssl/cloudflare/origin.key&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's configure Nginx with SSL:&lt;br&gt;
&lt;code&gt;sudo vi /etc/nginx/sites-available/example.com&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add the following configurations and update accordingly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 443 ssl http2;
    server_name example.com www.example.com;

    ssl_certificate /etc/ssl/cloudflare/origin.pem;
    ssl_certificate_key /etc/ssl/cloudflare/origin.key;
    ssl_protocols TLSv1.2 TLSv1.3;

    root /var/www/example.com;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's enable our site:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mkdir /var/www/example.com
sudo chown -R deploy:deploy /var/www/example.com
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once that is done, let;s fix real client IP for cloudflare. This is to configure web server to see the actual visitors and not cloudflare's proxy IPs.&lt;br&gt;
Enter the nginx config and add the following:&lt;br&gt;
&lt;code&gt;sudo vi /etc/nginx/nginx.conf&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use Cloudflare real IP
real_ip_header CF-Connecting-IP;

# Trust Cloudflare IP ranges
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 131.0.72.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;

real_ip_recursive on;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then restart nginx.&lt;br&gt;
You can enable more features on cloudflare dashboard according to your preference.&lt;/p&gt;

&lt;p&gt;Now that our server is under a CDN. Let's set up go and react since this is what I use.&lt;br&gt;
First install the necessary packages.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>devops</category>
      <category>security</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
