This is a generic Linux operations baseline, not a Laravel deployment guide. The baseline: a named sudo user with an SSH key, UFW with two open ports, systemd units, persistent journals and a tested restore.
Establish access before hardening
Create a named sudo user and install an Ed25519 public key. Verify that a second terminal can log in, then disable root and password login. Keep an out-of-band console until you are done with SSH. Allow only the required ports through UFW and check the active rules from another host.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verbose
Fail2ban only reacts to attacks; it doesn't replace patched software or closed ports. Make sure its jail reads the log source SSH actually writes to, and trigger a failed login to see that it bans.
systemd owns long-running processes
Don't run a service from nohup, tmux or an SSH session. A unit sets the user, working directory and restart policy.
[Unit]
Description=Example worker
After=network.target
[Service]
User=deploy
WorkingDirectory=/srv/example
ExecStart=/usr/local/bin/example-worker
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
Put secrets in an environment file, not in the unit. After editing a unit, run systemctl daemon-reload, then enable --now and a restart. This variant adds EnvironmentFile and sandboxing options:
[Service]
User=deploy
WorkingDirectory=/srv/example
EnvironmentFile=/etc/example/worker.env
ExecStart=/usr/local/bin/example-worker
Restart=on-failure
RestartSec=5
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
Make SSH and logs recoverable
In /etc/ssh/sshd_config set PermitRootLogin no, PasswordAuthentication no and AllowUsers deploy, and run sshd -t before reloading. Files in /etc/ssh/sshd_config.d/ (for example a cloud-init drop-in) are included first, and the first value wins, so confirm the effective settings with sshd -T | grep -Ei 'permitrootlogin|passwordauthentication|allowusers'. Test the key from a second terminal first, and keep the provider console available.
A persistent journal with a size cap survives a reboot without filling the volume:
# /etc/systemd/journald.conf.d/retention.conf
[Journal]
Storage=persistent
SystemMaxUse=1G
MaxRetentionSec=14day
sudo systemctl restart systemd-journald
journalctl -u example-worker --since '1 hour ago'
sudo fail2ban-client status sshd
Patch, monitor and rehearse recovery
Enable unattended security upgrades, alert on the reboot-required marker and schedule kernel restarts. Monitor disk and inode usage, CPU/RAM pressure, service state (systemctl status example-worker, journalctl -u example-worker -f), certificate expiry and backup age.
Patch, back up and rehearse recovery
A backup counts as evidence only once an encrypted off-host copy has been restored into an isolated environment. Keep retention and alerting on the off-host storage, and write down the hostname, service owner, dependencies, secret rotation, rollback and restore runbook.
When not to use this baseline
Don't apply these commands to immutable images, managed Kubernetes nodes or provider-managed appliances; use the platform's control plane. Don't open ports “temporarily” without an expiry. Laravel's PHP-FPM, queue and Nginx settings belong in the deployment guides, where they can be tested together.