All posts

Ubuntu Server Essentials

📅 Created 4 hours ago 👁️ 10

🏷️ #ubuntu #linux #git

Here are some useful approaches for setting up a Linux server. As example, the Ubuntu 24.04 LTS was taken. Same commands were tested on 20.24 and 22.04 (both LTS as per November-2025 according to Ubuntu release cycle ).

Prerequisites:

  1. Basic knowledge on Linux (sudo apt update/upgrade, chmod/chown, etc.).
  2. You can exit vim 🤭. Otherwise use nano instead.

Useful commands

grep
  -i             ignore case
  -E             extended RegExp support
  -n             print line number
  -H             print file name (useful with `find`)
  -v             invert search
  --color=never  useful for scripting
Purpose Command
Check the public IP address curl ipinfo.io/$(curl ifconfig.me)
Disk usage df -H (human-friendly units)
Memory free -h (human-friendly units)
Watching the process watch -n 5 <ANOTHER COMMAND>
Shuffle shuf pipe; the -n NUM limits output.
E.g., ls | shuf -n 1 to return a random file.

OS essentials

sudo apt update
sudo apt upgrade

# Set the hostname
sudo vim /etc/hostname

# Timezone setup
timedatectl list-timezones | grep -i YOUR_CITY_OR_COUNTY
sudo timedatectl set-timezone Your/Timezone

# User management
sudo adduser USERNAME
# Add user to the `sudo` group
sudo usermod -aG sudo USERNAME

Static IP config

  1. Identify the network interface: nmcli d.
  2. Create the /etc/netplan/50-static-ip.yaml with permissions 600 / rw-------.
    For Ethernets:
    network:
      version: 2
      ethernets:
        enp0s3:                                 # ❗ Replace
          dhcp4: false
          addresses:
            - 192.192.92.100/24                 # ❗ Replace
          routes:
            - to: default
              via: 192.192.92.1                 # ❗ Replace
          nameservers:
            addresses: [8.8.8.8, 8.8.4.4]       # Check
    
    For WiFi networks:
    network:
     version: 2
     wifis:
       wlp3s0:
         dhcp4: false
         addresses:
           - 192.192.92.100/24                 # ❗ Replace
         routes:
           - to: default
             via: 192.192.92.1                 # ❗ Replace
         nameservers:
           addresses: [8.8.8.8, 8.8.4.4]       # Check
         access-points:
           "YOUR_WIFI_NETWORK":                # ❗ Replace
             auth:
               key-management: "psk"
               password: "PASSWORD"            # ❗ Replace
    
  3. sudo neptplan apply
  4. ip a or ifconfig to verify.

The ufw Firewall

sudo ufw enable|disable
sudo ufw status
sudo ufw status numbered
sudo ufw allow|deny 8080/tcp
sudo ufw allow ssh|http|https|samba

To delete the rule:

sudo ufw status numbered
sudo ufw delete <number>

SSH

The 📂 /etc/ssh/ contains 2 config files:

  • ssh_config which keeps system-wide SSH client configuration (think when you perform ssh another-server from your server).
  • sshd_config which controls the behavior of SSH server (think when you call ssh your-server from the outer world).

Security tips (modify the sshd_config):

  1. PasswordAuthentication no
  2. PermitRootLogin no

Set up SSH access

  1. Generate the SSH key pair.
    Check out where the files are stored (by default in 📂 ~/.ssh/).
  2. On the Server:
    1. Create the /home/YOUR_USER/.ssh/authorized_keys with permissions 600 / rw-------.
    2. Place the public key (.pub file content) into that file:
      ssh-ed25519 AAAA..... my-key-description
      
  3. On the Client:
    1. Place the private key into 📂 ~/.ssh/; ensure the permissions are 600 / rw-------.
    2. Create or update the ~/.ssh/config: (similar permissions: 600 / rw-------):
      Host HUMAN_FRIENDLY_SERVER_NAME
        HostName SERVER_ADDRESS
        User SERVER_USERNAME
        IdentityFile /home/YOUR_USER/.ssh/PRIVATE_KEY_FILE_NAME
      
      ⚠️ Watch out: doing this on Windows requires C:\Users\YOUR_USER\.ssh\... path to the IdentityFile.

This allows accessing the server via convenient HUMAN_FRIENDLY_SERVER_NAME instead of using the IP/hostname. It comes handy when managing several remote servers from one machine. E.g., I’m using ssh site-server and ssh home-server; the Ubuntu terminal autocomplete picks these names up automatically.


Happy hacking!

Three roles in Project Management