This guide covers the fundamental setup of a self-hosted server, from a fresh installation to a fully operational Docker service.
Definition
Self-Host: the practice of running and maintaining services on your own servers or VPS (cloud server).
This guide assumes you already have a Linux server (Debian/Ubuntu based) installed.
1. Automatic updates
The first step is to update the system.
sudo apt update && sudo apt upgrade -y
Then install the automatic update tool, unattended-upgrades:
sudo apt install unattended-upgrades -y
Set the apt update time with sudo systemctl edit apt-daily.timer:
# do apt update between 02:00 and 02:50
[Timer]
OnCalendar=*-*-* 02:00
RandomizedDelaySec=3000 # 50m delay
Persistent=false
And the upgrade time with sudo systemctl edit apt-daily-upgrade.timer:
# do upgrade between 03:00 and 03:50
[Timer]
OnCalendar=*-*-* 03:00
RandomizedDelaySec=3000 # 50m delay
Persistent=false
Reload systemd configuration with sudo systemctl daemon-reload and restart the timer:
sudo systemctl restart apt-daily.timer
sudo systemctl restart apt-daily-upgrade.timer
Finally, check that unattended-upgrades is active with systemctl status unattended-upgrades.
And the schedule configuration with systemctl list-timers apt-daily.timer apt-daily-upgrade.timer
2. Secure SSH connection
- Generate an SSH key with the name "ssh_key"
ssh-keygen -t ed25519 -f ~/.ssh/ssh_key
- automatic copy to the server
ssh-copy-id -i ~/.ssh/ssh_key.pub user@remote_ip
- Configure the SSH connection, where "myserver" is the server name you will use to connect.
Add it in sudo nano ~/.ssh/config on your local machine:
Host myserver
HostName <server-ip-or-hostname>
User <username>
IdentityFile ~/.ssh/ssh_key
IdentitiesOnly yes
-
Connect to the server with
ssh myserver. -
Disable password login and root SSH (optional). Open the SSH daemon config:
sudo nano /etc/ssh/sshd_config
Set these two lines (or uncomment them):
PasswordAuthentication no
PermitRootLogin prohibit-password
Restart SSH to apply, and keep this terminal session open until you've confirmed a new one works:
sudo systemctl restart ssh
Then open a second terminal and reconnect with ssh myserver. If it works, the hardened config is safe to keep.
3. Firewall
Using UFW :
# install UFW
sudo apt install ufw -y
# allow SSH (only use TCP)
sudo ufw allow 22/tcp
# good default
sudo ufw default allow outgoing
sudo ufw default deny incoming
# activate firewall
sudo ufw enable
4. Docker + Dockhand installation
Docker - install via the apt repository (or any other method you prefer): docker install instruction
Note: if you're not on Ubuntu, pick the installation guide matching your operating system from the same docs.
Dockhand - Install instruction
Dockhand is very good with build-in automatic update and security check. Portainer would be better if you need kubernetes.
Portainer - Install instruction
Run the docker run commands from that page for the quickest setup. It gives you a web-based GUI to manage your containers.
Source
-
Debian logo from Konpa : https://icon-sets.iconify.design/devicon-plain/debian/
-
Server logo from lucide : https://icon-sets.iconify.design/lucide/server-cog/
-
Docker logo from HeskeyBaozi : https://icon-sets.iconify.design/ant-design/docker-outlined/