<?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/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Hardening Ubuntu or Raspbian (Raspberry Pi or other Linux Servers) for 3D Printing - 3D Printing Support				            </title>
            <link>https://print3d.world/community/3d-printing-support/hardening-ubuntu-or-raspbian-raspberry-pi-or-other-linux-servers-for-3d-printing/</link>
            <description>Print 3D World Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Sat, 18 Apr 2026 08:15:47 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>Hardening Ubuntu or Raspbian (Raspberry Pi or other Linux Servers) for 3D Printing</title>
                        <link>https://print3d.world/community/3d-printing-support/hardening-ubuntu-or-raspbian-raspberry-pi-or-other-linux-servers-for-3d-printing/#post-261</link>
                        <pubDate>Mon, 04 Dec 2023 00:45:13 +0000</pubDate>
                        <description><![CDATA[Hello,
 
We are attaching a script you can use to harden your raspbian or Ubuntu server for running Mainsail or Octoprint and have a secure server that will not be hacked. I have seen clie...]]></description>
                        <content:encoded><![CDATA[<p style="text-align: left">Hello,</p>
<p> </p>
<p>We are attaching a script you can use to harden your raspbian or Ubuntu server for running Mainsail or Octoprint and have a secure server that will not be hacked. I have seen clients whom have had raspberry pi or other linux server hacked literally within the first 12 hours of attaching to their network; there are ALWAYS people hunting to hack your devices and add them to a botnet. I recommend using this hardening guide at the very minimum, and make sure to research for each operating system. Some stuff is manually done, some is done by my script.</p>
<p>Save the script in your server via ssh as "harden.sh" and then make sure to "chmod +x harden.sh"</p>
<pre contenteditable="false">#!/bin/bash

# Update the package list and upgrade installed packages
sudo apt update
sudo apt upgrade -y

# Enable Uncomplicated Firewall (UFW) and allow necessary ports
sudo ufw enable
sudo ufw allow 22  # Allow SSH
sudo ufw allow 80  # Allow HTTP (if applicable)
sudo ufw allow 443 # Allow HTTPS (if applicable)
sudo ufw allow 7125 # Allow moonraker
# sudo ufw allow 8080 # Allow crowsnest if you are using webcam, remove the #

# Disable root login and password authentication
sudo sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
sudo sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo systemctl restart ssh

# Set up fail2ban to protect against brute force attacks
sudo apt install fail2ban -y
sudo systemctl enable fail2ban
sudo systemctl start fail2ban

# Install and configure a firewall
sudo apt install -y iptables-persistent
# Add your firewall rules here
# Example: sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 7125 -j ACCEPT
# Save the rules: sudo service iptables-persistent save
sudo service iptables-persistent save
# Enable the rules to persist after a reboot: sudo service iptables-persistent start
sudo service iptables-persistent start

# Install and configure intrusion detection system (IDS)
sudo apt install -y rkhunter
sudo rkhunter --update
sudo rkhunter --propupd
sudo rkhunter -c --sk

# Regularly update and upgrade packages
echo "0 4 * * 1 root apt update &amp;&amp; apt upgrade -y" | sudo tee -a /etc/crontab

# Install and configure automatic security updates
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades

# Enable automatic updates for security patches
sudo sed -i 's,//\t"${distro_id}:${distro_codename}-security",\t"${distro_id}:${distro_codename}-security",g' /etc/apt/apt.conf.d/50unattended-upgrades
sudo sed -i 's,//\t"${distro_id}:${distro_codename}-updates",\t"${distro_id}:${distro_codename}-updates",g' /etc/apt/apt.conf.d/50unattended-upgrades

# Optional: Install and configure antivirus software
# sudo apt install -y clamav
# sudo freshclam

echo "Hardening script completed. Remember to review your firewall rules and adjust them according to your specific needs."
</pre>
<p> </p>
<p>Once you have completed that script, follow this list and ensure each option is applied.</p>
<ul>
<li>Make a sudo-enabled user and stop using root! (Automatically done on most distributions)<br />Lock the root account from user account -
<pre contenteditable="false">sudo passwd -l root</pre>
</li>
<li>Remove unneeded packages (Don't run this in a Qube, it may fuck up the utils for Qubes Tools) -
<pre contenteditable="false">sudo apt autoclean &amp;&amp; sudo apt autoremove &amp;&amp; sudo apt autopurge</pre>
</li>
<li>Install upgrades unattended for Debian -
<pre contenteditable="false">sudo apt install unattended-upgrades &amp;&amp; sudo apt install apt-config-auto-update &amp;&amp; sudo apt install powermgmt-base &amp;&amp; sudo systemctl enable unattended-upgrades &amp;&amp; sudo systemctl start unattended-upgrades</pre>
</li>
<li>Delete log history for the current session -
<pre contenteditable="false">sudo lastlog --clear --user &lt;USER&gt; &amp;&amp; sudo lastlog -C -u &lt;USER&gt;</pre>
</li>
<li>Disable history persistence for downloads -
<pre contenteditable="false">sudo ln -s -f /dev/null ~/.wget-hsts</pre>
</li>
<li>Disable shell history completely -
<pre contenteditable="false">echo 'set +o history' &gt;&gt; ~/.bashrc &amp;&amp; source ~/.bashrc &amp;&amp; rm -rf ~/.bash_history &amp;&amp; history -c</pre>
<br />*Alternatively you can just erase it after every session -
<pre contenteditable="false">sudo ln -s -f /dev/null ~/.bash_history*</pre>
</li>
<li>Disable shell history session persistence -
<pre contenteditable="false">sudo ln -s -f /dev/null ~/.bash_rc</pre>
</li>
<li>Disable history persistence for Python shells -
<pre contenteditable="false">sudo ln -s -f /dev/null ~/.python_history</pre>
</li>
<li>Limit SSH brute-force attacks - In this example, we drop connections from any IP address if it attempts to open more than 10 connections to the SSH port within 120 seconds.<br />
<pre contenteditable="false">sudo iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
sudo iptables -I INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 120 --hitcount 10 -j DROP
Limit HTTP/S requests - These rules continue to accept new connections as long as they don’t exceed the limit of 20 connections per minute from each IP address.
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW -m limit --limit 20/min --limit-burst 30 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -m conntrack --ctstate NEW -m limit --limit 20/min --limit-burst 30 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -m conntrack --ctstate NEW -j DROP
sudo iptables -A INPUT -p tcp --dport 443 -m conntrack --ctstate NEW -j DROP</pre>
</li>
</ul>
<p>This is just to get you started, and ensure you are following specific guides that fit your hardware and operating system/distro! Harden your installations to prevent being used by hackers.</p>]]></content:encoded>
						                            <category domain="https://print3d.world/community/3d-printing-support/">3D Printing Support</category>                        <dc:creator>Print3D</dc:creator>
                        <guid isPermaLink="true">https://print3d.world/community/3d-printing-support/hardening-ubuntu-or-raspbian-raspberry-pi-or-other-linux-servers-for-3d-printing/#post-261</guid>
                    </item>
							        </channel>
        </rss>
		