Server Essentials
SSH with Key Authentication
To secure your server, configure SSH to allow only key-based authentication and disable password logins. Also, create a non-root user for SSH access and disable root login:
-
Create a new user and add to sudo group:
1 2sudo adduser user sudo usermod -aG sudo userReplace
userwith your preferred username. -
Add your public key to the new user:
- Copy your public key from your PC to the server for the new user:
1ssh-copy-id user@your_server_ip - Or manually append your public key to
/home/user/.ssh/authorized_keys.
- Copy your public key from your PC to the server for the new user:
-
Edit the SSH daemon configuration:
- Open the SSH config file:
1sudo nvim /etc/ssh/sshd_config - Set or update these lines:
1 2 3 4 5PubkeyAuthentication yes PasswordAuthentication no PermitRootLogin no ChallengeResponseAuthentication no UsePAM no
- Open the SSH config file:
-
Restart SSH service:
1sudo systemctl restart ssh
Note:
- Before closing your root session, open a new terminal and test logging in as the new user.
- Disabling password authentication and root login increases security by preventing brute-force and privilege escalation attacks.
Important:
Keep your SSH private key secure. If you lose your key, you will lose access to the server. Always keep a backup in a safe place, such as another device you own or a secure storage location.
File Sharing with SMB
For network file sharing between Linux and other systems, I use Samba. Check my detailed Samba configuration guide for implementation details.
Security Monitoring
- fail2ban: Essential for protecting against brute force attacks by monitoring log files and banning suspicious IP addresses.
-
Install fail2ban:
1 2sudo apt update sudo apt install fail2ban -
Basic configuration:
- Copy the default config to create a local override:
1sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local - Edit
/etc/fail2ban/jail.localto adjust settings (e.g., ban time, findtime, maxretry).
- Copy the default config to create a local override:
-
Enable and start the service:
1sudo systemctl enable --now fail2ban -
Check status:
1 2sudo fail2ban-client status sudo fail2ban-client status sshd
fail2ban will now monitor for suspicious activity and ban offending IPs automatically. For more advanced configuration, refer to the official documentation or add custom jails as needed.
Docker Containers
I run several services in Docker containers for easy management:
- Homepage: A simple dashboard for my services
- VSCode Server: Cloud-based VS Code instance for remote development
- Immich: Self-hosted photo and video backup solution
- Calibre: E-book management and server
- FreshRSS: RSS feed aggregator
- Vikunja: Personal wiki and note-taking app
- Nextcloud: Self-hosted cloud storage and collaboration platform
- Paperless: Document management system
- Portainer: Web UI for Docker management
- \ Uptime Kuma: Service monitoring and uptime checker
- \ Grafana: Metrics visualization platform (works with Prometheus)
- Beszel: Simple, lightweight server monitoring
Note:
For home server monitoring, I now use Beszel instead of Uptime Kuma or Grafana. In the past, I used those tools, but found Beszel provides simple, lightweight status checks and metrics that are sufficient for most personal setups.
Securing Docker with userns-remap (Optional)
For enhanced security, you can enable Docker’s user namespace remapping feature (userns-remap). This isolates container processes from the host by mapping container users to non-root users on the host.
How to enable userns-remap:
-
Edit or create the Docker daemon config:
1 2sudo mkdir -p /etc/docker sudo nvim /etc/docker/daemon.jsonAdd:
1 2 3{ "userns-remap": "default" } -
Restart Docker:
1sudo systemctl restart docker
Docker will now run containers with remapped user IDs, reducing the risk of privilege escalation from containers to the host.
Important:
Enabling userns-remap will make all your existing Docker images and containers inaccessible. They will not be deleted, but Docker will not see them under the new user namespace. You can revert the change to regain access, or migrate images/containers as needed.
This is optional, but highly recommended for internet-exposed servers. Some images may require adjustments to work with userns-remap.
User Namespace Known Limitations:
- The following Docker features are incompatible with user namespaces:
- Sharing PID or NET namespaces with the host (
--pid=hostor--network=host) - External volume/storage drivers that do not support user mappings
- Using
--privilegedmode without also specifying--userns=host
- Sharing PID or NET namespaces with the host (
Disabling Namespace Remapping for a Container:
If user namespaces are enabled on the daemon, all containers use them by default. To disable user namespaces for a specific container (e.g., for privileged containers), add the --userns=host flag to your docker run or docker create command:
|
|
Note: The container filesystem will still be owned by the remapped user (e.g., 231072), which may cause issues for programs expecting root ownership (like
sudoor setuid binaries).
You can also check:
Docker Rootless Mode (docs.docker.com)
Running Docker in rootless mode is another way to improve security, especially in multi-user environments.
Laptop Server Specifics
Disabling Display on Boot
For headless laptop servers, I disable the display during boot:
-
Install required package:
1sudo apt install vbetool -
Turn display off:
1sudo vbetool dpms off -
To turn back on:
1sudo vbetool dpms on
To auto turn off screen I use crontab.
sudo crontab -e
|
|
Preventing Sleep When Lid Closed
To keep the server running when lid is closed:
-
Edit the login manager configuration:
1sudo nano /etc/systemd/logind.conf -
Change:
1#HandleLidSwitch=suspendTo:
1HandleLidSwitch=ignore -
Restart the service:
1sudo systemctl restart systemd-logind
Boot Optimization
Skipping GRUB Menu
To speed up boot time by skipping the GRUB menu:
-
Edit GRUB configuration:
1sudo vim /etc/default/grub -
Modify these lines:
1 2GRUB_TIMEOUT=0 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" -
Update GRUB:
1sudo update-grub
Oracle Cloud Free Tier Tips
To prevent Oracle from reclaiming your ARM instances due to inactivity:
Use NeverIdle - a simple tool that keeps your instance active by periodically utilizing resources.
I usually run this with screen. To keep running NeverIdle in the background.
|
|
This configuration:
- Uses 2 CPU cores every 2 hours (
-c 2h -m 2) - Performs network activity every 4 hours (
-n 4h)
Power Optimization with powertop & AutoASPM
To reduce power consumption, I use powertop and the AutoASPM script to automatically tune power settings.
Powertop
|
|
This command applies recommended power-saving settings:
|
|
To run this automatically at startup, add it to root’s crontab:
|
|
Add this line at the end:
|
|
AutoASPM
This is a script that enables PCIe ASPM (Active State Power Management) for better power savings.
See: AutoASPM GitHub
Install and run AutoASPM:
|
|
Note: Always test power-saving settings for stability, especially on servers. Some devices may not support all ASPM states.