Server Setup Guide

Add Non-Root User

Creating a non-root user enhances security by limiting privileged access. This user can perform administrative tasks using sudo when needed, reducing the risk of accidental system changes.

  1. Create new user with home directory and bash shell:
    useradd -m -s /bin/bash userName
    
  2. Set user password:
    passwd userName
    
  3. Add user to sudo group:
    usermod -aG sudo userName
    
  4. Verify sudo group members:
    getent group sudo
    
  5. If you want to remove user from sudo group:
    gpasswd --delete userName sudo
    

Configure User SSH Key

SSH keys provide stronger security than passwords. Using ed25519 keys with a passphrase adds two layers of protection: the key file itself and the passphrase.

  1. Switch to new user account:
    su - userName
    
  2. Generate SSH key:
    ssh-keygen -t ed25519 -C "your_email@example.com"
    
  3. Add passphrase when prompted
  4. Add key to authorized_keys:
    cat ~/.ssh/ed25519.pub >> ~/.ssh/authorized_keys
    

Setup Application Group

Creating a dedicated group for applications helps manage permissions and access control for application-specific files and directories.

  1. Switch to new user:
    su - userName
    
  2. Create apps group:
    sudo groupadd apps
    

Secure SSH Configuration

These settings strengthen SSH security by disabling root login, changing the default port, and enforcing key-based authentication only.

  1. Open SSH config file:
    sudo nano /etc/ssh/sshd_config
    
  2. Update these settings, you can change the port if you want to:
    PermitRootLogin no
    Port 1122
    PasswordAuthentication no
    UsePAM no
    PubkeyAuthentication yes
    
  3. Apply changes:
    sudo systemctl reload ssh
    
  4. Update firewall rules:
    sudo ufw status numbered
    sudo ufw delete {number}  # Delete port 22 rule
    sudo ufw allow 1122      # Add new SSH port
    
✨ Well done!