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:
- Basic knowledge on Linux (
sudo apt update/upgrade,chmod/chown, etc.). - You can exit
vim🤭. Otherwise usenanoinstead.
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
- Identify the network interface:
nmcli d. - Create the
/etc/netplan/50-static-ip.yamlwith permissions600 / 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] # CheckFor 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 sudo neptplan applyip aorifconfigto 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_configwhich keeps system-wide SSH client configuration (think when you performssh another-serverfrom your server).sshd_configwhich controls the behavior of SSH server (think when you callssh your-serverfrom the outer world).
Security tips (modify the sshd_config):
PasswordAuthentication noPermitRootLogin no
Set up SSH access
- Generate the SSH key pair.
Check out where the files are stored (by default in📂 ~/.ssh/). - On the Server:
- Create the
/home/YOUR_USER/.ssh/authorized_keyswith permissions600 / rw-------. - Place the public key (
.pubfile content) into that file:ssh-ed25519 AAAA..... my-key-description
- Create the
- On the Client:
- Place the private key into
📂 ~/.ssh/; ensure the permissions are600 / rw-------. - Create or update the
~/.ssh/config: (similar permissions:600 / rw-------):
⚠️ Watch out: doing this on Windows requiresHost HUMAN_FRIENDLY_SERVER_NAME HostName SERVER_ADDRESS User SERVER_USERNAME IdentityFile /home/YOUR_USER/.ssh/PRIVATE_KEY_FILE_NAMEC:\Users\YOUR_USER\.ssh\...path to theIdentityFile.
- Place the private key into
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!