Skip to content

Secure a fresh VPS before you install Deployrr

A new VPS or dedicated server is on the public internet from the first minute. Bots try to log in to it right away. This page walks you through the basic steps to lock it down before you install Deployrr.

  • A VPS or dedicated server with a supported system. See Quick start for the list. The commands below are for Debian and Ubuntu.
  • The server’s public IP address and the root login details from your provider.
  • A way into your provider’s web console, also called the rescue or VNC console. If you lock yourself out, this is how you get back in. Find it in your provider’s panel now, before you change anything.
  • A second terminal window on your own computer. You use it to test each change.

If you start Deployrr as root, it stops with this message: “Do not run Deployrr as the root user. Run as a regular user with sudo privileges instead.” You need a regular user that can use sudo. For more on that message, see Deployrr install errors. To see these commands run, watch Docker on Proxmox LXC: creating a non-root user at 10:20.

  1. Log in to the server as root. Replace YOUR_SERVER_IP with your server’s address:

    Terminal window
    ssh root@YOUR_SERVER_IP
  2. Create the user. Replace NAME with the user name you want, here and in the later steps. Set a password when asked:

    Terminal window
    adduser NAME
  3. Add the user to the sudo group:

    Terminal window
    usermod -aG sudo NAME

    A minimal Debian install may not have sudo. If usermod or a later sudo -v fails, run these as root, then repeat this step:

    Terminal window
    apt update
    apt install sudo
  4. Keep this root session open. You need it in the next steps.

An SSH key is a pair of files. The private key stays on your computer. The public key goes on the server. You log in with the key instead of a password.

  1. On your own computer, not on the server, create a key. Press Enter to accept the default file name:

    Terminal window
    ssh-keygen -t ed25519

    Set a passphrase when asked. It protects the key if someone copies the file.

  2. Copy the public key to the server. Replace NAME and YOUR_SERVER_IP:

    Terminal window
    ssh-copy-id NAME@YOUR_SERVER_IP

    ssh-copy-id needs password login, which is still on at this point. It asks for the new user’s password.

    Windows does not include ssh-copy-id. Use the manual method in the next step instead.

  3. If you could not use ssh-copy-id, add the key by hand. On your computer, print the public key and copy the whole line:

    Terminal window
    cat ~/.ssh/id_ed25519.pub

    In PowerShell, use type $env:USERPROFILE\.ssh\id_ed25519.pub.

  4. In your root session on the server, create the folder and file for the key. Replace NAME:

    Terminal window
    mkdir -p /home/NAME/.ssh
    nano /home/NAME/.ssh/authorized_keys
  5. Paste the public key line, save, and exit nano.

  6. Set the owner and permissions. Replace NAME:

    Terminal window
    chown -R NAME:NAME /home/NAME/.ssh
    chmod 700 /home/NAME/.ssh
    chmod 600 /home/NAME/.ssh/authorized_keys
  7. Open a second terminal on your computer and log in as the new user:

    Terminal window
    ssh NAME@YOUR_SERVER_IP

    It should log you in with the key (or ask for your key passphrase), not the account password.

  8. Check that sudo works in this session:

    Terminal window
    sudo -v

Do not go on until steps 11 and 12 work.

For background on how SSH hardening fits into a home server build, see UDMS part 05: Secure SSH Access (manual setup, on a Proxmox LXC). Follow the steps on this page for a VPS.

  1. In the new user’s session, back up the SSH settings:

    Terminal window
    sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
  2. Look at what the server uses now:

    Terminal window
    sudo sshd -T | grep -E 'passwordauthentication|permitrootlogin|kbdinteractiveauthentication'

    Many cloud images ship a file such as /etc/ssh/sshd_config.d/50-cloud-init.conf that sets PasswordAuthentication yes. SSH uses the first value it finds, and files in that folder are read before the rest of sshd_config. Editing only sshd_config can have no effect.

  3. Create a settings file that is read before the others. The name starts with 00 so it comes first:

    Terminal window
    sudo nano /etc/ssh/sshd_config.d/00-hardening.conf
  4. Add these three lines, then save and exit:

    PasswordAuthentication no
    PermitRootLogin no
    KbdInteractiveAuthentication no
  5. Test the settings for mistakes. No output means no errors:

    Terminal window
    sudo sshd -t

    If it prints an error, fix the file before you go on. Do not restart SSH with an error.

  6. Restart SSH. On Debian and Ubuntu the service is called ssh:

    Terminal window
    sudo systemctl restart ssh

    On other systems it is called sshd: sudo systemctl restart sshd.

  7. Open a third terminal and log in again as NAME. It should still work.

  8. Check the new values:

    Terminal window
    sudo sshd -T | grep -E 'passwordauthentication|permitrootlogin|kbdinteractiveauthentication'

    You should see no on all three lines.

If something goes wrong, restore the backup in a session you kept open, remove the drop-in file, and restart SSH again:

Terminal window
sudo cp /etc/ssh/sshd_config.bak /etc/ssh/sshd_config
sudo rm /etc/ssh/sshd_config.d/00-hardening.conf
sudo systemctl restart ssh

A new port cuts down the log noise from bots. It does not stop a targeted attack, so treat it as a small extra. Skip this section if you want fewer things that can go wrong. To see the idea, watch Docker on Proxmox LXC: SSH configuration at 12:03. It edits sshd_config directly and does not cover the ssh.socket step below.

  1. Pick a port number between 1024 and 65535. This page uses 2222 as the example. Replace it with your number.

  2. Allow the new port in your provider’s firewall panel, and in UFW if you use it. See the next section and Set a basic UFW rule set.

  3. Back up the settings again:

    Terminal window
    sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
  4. Add the port to your settings file:

    Terminal window
    echo "Port 2222" | sudo tee -a /etc/ssh/sshd_config.d/00-hardening.conf
  5. Test the settings:

    Terminal window
    sudo sshd -t
  6. Restart SSH. On Ubuntu 24.04 and newer, SSH starts through a socket, so you also reload systemd and restart the socket:

    Terminal window
    sudo systemctl daemon-reload
    sudo systemctl restart ssh.socket
    sudo systemctl restart ssh

    Ubuntu 22.04 and Debian do not use ssh.socket. On those, the last command alone is enough.

  7. In a second terminal, log in on the new port. Replace 2222 with your port:

    Terminal window
    ssh -p 2222 NAME@YOUR_SERVER_IP
  8. When it works, remove the old port 22 rule from your firewalls.

If the new port does not work, restore the backup in a session you kept open and restart SSH. On Ubuntu 24.04 and newer, also reload systemd and restart the socket:

Terminal window
sudo cp /etc/ssh/sshd_config.bak /etc/ssh/sshd_config
sudo sed -i '/^Port 2222$/d' /etc/ssh/sshd_config.d/00-hardening.conf
sudo systemctl daemon-reload
sudo systemctl restart ssh.socket
sudo systemctl restart ssh

Ubuntu 22.04 and Debian do not use ssh.socket. On those, skip the two middle commands.

Your provider’s web panel often has a firewall page, sometimes called security groups. It filters traffic before it reaches your server. This matters because ports that Docker publishes bypass UFW. A rule in the provider panel still blocks them.

  1. Open the firewall page in your provider’s panel.
  2. Allow inbound TCP on your SSH port. This is 22 unless you changed it.
  3. Allow inbound TCP on 80.
  4. Allow inbound TCP on 443. Optionally allow UDP on 443 too, for HTTP/3. Browsers fall back to TCP if you skip it.
  5. Block all other inbound traffic. Apps reached through Traefik use port 443, so their own ports do not need to be open. Keep ports 81 and 444 blocked. Keep the Traefik dashboard port blocked too. It is 8080 by default, and Traefik Preparation prints “Port N assigned for Traefik dashboard” (or “Port N previously set for Traefik dashboard” when you run it again while Traefik is running). The dashboard has no login of its own on that port. To open it safely, see Open the Traefik dashboard without opening its port.
  6. Apply the rules to your server.
  7. Open a new SSH session to check that you can still log in.
  1. Ubuntu already has unattended-upgrades. On Debian, install it:

    Terminal window
    sudo apt update
    sudo apt install unattended-upgrades
  2. Turn it on and accept the default:

    Terminal window
    sudo dpkg-reconfigure unattended-upgrades

The system does not restart by itself unless you change that setting. Reboot when you can after kernel updates.

Optional: use Tailscale for private access

Section titled “Optional: use Tailscale for private access”

If you do not want an app reachable from the internet, reach it over Tailscale instead. See Set up Tailscale. To see the Linux client install, watch Tailscale tutorial: Tailscale setup on Linux at 7:12. You can then also limit SSH in the provider panel to your Tailscale network if you want.

  1. Log in as NAME, not root.

  2. Run the install command from Quick start with sudo, as it shows.

  3. Start Deployrr as your regular user. Type deployrr with no sudo.

  4. In Prerequisites > System Type, pick VPS (“Virtual Private Server in the cloud”).

  5. If Traefik Preparation stops with “Port N is occupied. This is needed for Traefik.”, another program is using one of the ports Traefik needs (80, 81, 443 or 444). Often it is a web server that came with your VPS image. Stop that web server, then run Traefik Preparation again.

  6. Go to Proxy > Traefik and look at the Traefik Mode line (“Toggle how apps are exposed”). If it says NOT SET or Simple, leave it. NOT SET works as Simple. If it says Advanced, select Traefik Mode once. Each press flips the mode.

    Use Simple on a VPS. A VPS has no router to forward port 80 to 81 and 443 to 444, which Advanced mode needs. See Simple vs Advanced Traefik mode.

Open the Traefik dashboard without opening its port

Section titled “Open the Traefik dashboard without opening its port”

Traefik Preparation publishes the Traefik dashboard on its own port, 8080 by default. If 8080 was taken, it picked the next free port and saved it as TRAEFIK_PORT in your .env file. The dashboard has no login on that port. Ports that Docker publishes skip UFW, so the provider firewall is what keeps this port off the internet. Keep it blocked there (step 33) and use one of these ways in:

  • The dashboard address. Open https://traefik.YOUR_DOMAIN. It asks for the username and password you set in Traefik Preparation (Basic HTTP Auth). For a stronger login, such as Authelia or TinyAuth, select TRAEFIK in Security > Manage Auth. It needs a Pro license and Traefik running in Production. See Choose a login method.

  • Tailscale. With Tailscale on the server, open http://TAILSCALE_IP:8080 from a device on your tailnet. Use your dashboard port if it isn’t 8080. Tailscale traffic arrives inside its own encrypted connection, so the blocked port in the provider panel doesn’t stop it.

  • An SSH tunnel. On your computer, run this and keep the session open. Add -p 2222 if you changed the SSH port:

    Terminal window
    ssh -L 8080:localhost:8080 NAME@YOUR_SERVER_IP

    Then open http://localhost:8080 in your browser. If your dashboard port isn’t 8080, put it in place of the second 8080.

To check that the port is closed, run this from your own computer, not the server. Replace 8080 with your dashboard port:

Terminal window
curl -m 5 http://YOUR_SERVER_IP:8080

It should time out. If it prints a page, fix the rule in the provider’s panel.

  1. Log in as NAME with your key from a new terminal. It works.

  2. Try to log in as root:

    Terminal window
    ssh root@YOUR_SERVER_IP

    It is refused.

  3. Try a password login:

    Terminal window
    ssh -o PubkeyAuthentication=no NAME@YOUR_SERVER_IP

    It is refused with Permission denied (publickey).

  4. Run sudo sshd -T | grep -E 'passwordauthentication|permitrootlogin|kbdinteractiveauthentication'. All three are no.

  5. From your computer, your apps open on https:// addresses. Other ports on the server do not answer.

If every SSH session is closed and you can’t log in, use your provider’s web console. It works like a screen and keyboard attached to the server, so the SSH settings and firewalls on this page don’t block it.

  1. Open the web console in your provider’s panel. It may be called console, VNC console or serial console.

  2. Log in as NAME with the account password you set with adduser. The SSH settings on this page only apply to SSH. The password still works at the console.

  3. Find out which port SSH listens on:

    Terminal window
    sudo ss -tlnp

    Look for your SSH port, for example :22 or :2222. On Ubuntu 24.04 and newer, the program on that line can be systemd instead of sshd. That is normal.

  4. Test the SSH settings for mistakes. No output means no errors:

    Terminal window
    sudo sshd -t

    If you changed the SSH settings, undo your change with the restore commands on this page: after turning off password login or after changing the port. On Ubuntu 24.04 and newer, include the daemon-reload and ssh.socket commands, or the port does not change.

  5. If UFW is on, check that it allows your SSH port:

    Terminal window
    sudo ufw status

    If the port is missing, allow it. Replace 22 with your SSH port:

    Terminal window
    sudo ufw allow 22/tcp
  6. If the provider’s firewall blocks the port, fix the rule in the provider’s panel. The console can’t change it.

  7. Log in over SSH from a second terminal before you close the console.

If you can’t log in at the console either, for example because you forgot the password, look in your provider’s panel for a password reset or a rescue mode. Each provider does this differently, so follow its guide.