Server Config

Basic server set up guide

Basic server set up guide

Essentials

Basic workflow

  1. Configure SSH

  2. Configure fail2ban

  3. Configure UFW

Configure SSH

Basic workflow for configuring SSH

  1. Configure SSH public key authentication for the root user
  2. Disable SSH password authentication
  3. Verify that for the root user, SSH:
    • Does not work with password authentication
    • Works with public key authentication
  4. Add a new user
  5. Add the new user to the sudoers list
  6. switch to the new user
  7. Configure SSH public key authentication for the new user
  8. Disable SSH root login
  9. Verify that for the root user, SSH:
    • Does not work with password authentication
    • Does not work with public key authentication
  10. Verify that for the new user, SSH:
    • Does not work with password authentication
    • Works with public key authentication

Useful snippets for configuring SSH

Open the SSH config:

sudo nano /etc/ssh/sshd_config

Useful SSH config:

PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
ClientAliveInterval 120  # Keep alive ssh connections by sending a packet every 2 minutes.

Remember to also check /etc/ssh/sshd_config.d/*.conf and any other includes.

Restart the SSH service:

sudo systemctl restart ssh

Verify the status of the SSH service:

sudo systemctl status ssh

Useful snippets for adding a new user as the root user

Suppose that the username of the new user is user:

adduser user

Add the new user to the sudoers list:

visudo

Add this following line under # User privilege specification:

user ALL=(ALL) NOPASSWD: ALL

Useful snippets for configuring SSH public key authentication:

Create the .ssh directory:

mkdir ~/.ssh

Edit the authorized_keys file and add your public key:

nano ~/.ssh/authorized_keys

Configure fail2ban

Refer to Fail2Ban

Configure UFW

Refer to UFW

Optionals

Configure zram

Refer to zram

Configure swap file (unnecessary if zram is configured)

Refer to Swap

Configure zsh

Refer to Zsh

Disable XON/XOFF software flow control (prevent Ctrl+S from freezing the terminal)

Refer to IXON

Auto remove trash using trash-cli

Refer to trach-cli

Content Licensed under CC BY-SA 4.0. Code licensed under the MIT License.
Last updated on Feb 08, 2025 08:01 UTC