Skip to content

Expert · Deployment and scaling · topic 47 of 54 · 30 min

Linux basics for backend developers

Explanation

Almost every server on the internet runs Linux, and you control it by typing commands in a terminal. A small set of commands lets you move around, read logs, check memory and disk, and restart your app. You log in safely with SSH keys, protect files with permissions like 644 and 755, and let systemd keep your app running.

Why servers run Linux

Linux is a free operating system (the base software that runs a computer, like Windows or Android). It is stable, light, safe and costs nothing per server, so most cloud servers, Docker images and hosting platforms use it. Ubuntu and Debian are common choices. A server usually has no screen or mouse: you control it through a terminal, a window where you type commands and read text answers.

Think of it like this: Using a terminal is like giving exact instructions to a helper on the phone instead of pointing at things in a shop. "Go to the second shelf, take the blue box, count the packets." You must say it precisely, but once you know the words, it is very fast, and you can write the instructions down and repeat them any time.

Moving around and handling files

bash
pwd                      # print working directory: where am I?
ls -la                   # list files, including hidden ones, with details
cd /srv/notes-api        # change directory
cd ..                    # go up one folder
mkdir logs               # make a new folder
cp .env.example .env     # copy a file
mv old.log archive.log   # move or rename a file
rm archive.log           # delete a file (there is no recycle bin!)
The everyday commands. Text after # is a comment and is not run.
Careful: rm deletes at once, with no recycle bin. rm -rf removes whole folders without asking. Read the command twice before pressing Enter, especially with sudo, and never run rm -rf with a path you are not sure about.

Reading files and logs

bash
cat .env.example                 # print a short file
less /var/log/syslog             # scroll a long file (q to quit, / to search)
tail -n 50 app.log               # show the last 50 lines
tail -f app.log                  # follow: keep showing new lines as they arrive
grep ERROR app.log               # show only lines that contain ERROR
grep -c ERROR app.log            # count those lines
tail -f app.log | grep ERROR     # follow only the errors
The | (pipe) sends the output of one command into the next one.

Checking the health of the server

bash
ps aux | grep node        # is my Node.js process running?
top                       # live list of processes using CPU and memory (htop is a nicer version)
df -h                     # disk space per drive, in human-readable sizes (G, M)
free -h                   # memory (RAM) used and free
curl -i http://localhost:3000/healthz   # call my own API from the server
When the app is slow or down, these five commands answer most first questions.

SSH: logging in safely with keys

SSH (Secure Shell) lets you open a terminal on a far-away server over an encrypted connection. Instead of a password, use an SSH key pair: a private key that stays on your laptop and a public key that you copy to the server. The server lets in only someone who holds the matching private key. Keys are much harder to guess or steal than passwords.

bash
ssh-keygen -t ed25519 -C "asha@laptop"     # make a key pair (once, on your laptop)
ssh-copy-id deploy@203.0.113.10            # copy the public key to the server
ssh deploy@203.0.113.10                    # log in, no password needed
# Then on the server, in /etc/ssh/sshd_config set: PasswordAuthentication no
Never share or upload the private key (the file without .pub).

File permissions: rwx, 644 and 755

Every file has three sets of permissions: for the owner, for the group, and for everyone else. Each set has r (read), w (write) and x (execute, or for a folder, enter it). ls -l shows them as 9 letters, like rw-r--r--. As numbers, r = 4, w = 2, x = 1, and you add them per set: rw- = 6, r-x = 5, rwx = 7. So rw-r--r-- is 644 and rwxr-xr-x is 755.

NumberLettersTypical use
644rw-r--r--Normal files: owner edits, others only read
755rwxr-xr-xFolders and scripts: owner edits, others can enter or run
600rw-------Secrets like .env or a private key: only the owner can read

Change them with chmod, for example chmod 600 .env. sudo runs one command as the administrator (called root). Use it only when needed, such as installing software or restarting a service, because root can change or delete anything.

Keeping your app running with systemd

bash
sudo systemctl status notes-api      # is it running? since when? last log lines
sudo systemctl restart notes-api     # restart after a deploy
sudo systemctl enable notes-api      # start it automatically after a reboot
journalctl -u notes-api -f           # follow this service's logs
journalctl -u notes-api --since "1 hour ago"
systemd starts services at boot and restarts them if they crash. journalctl reads their logs.
Tip: Keep a small text file of the commands you use on each server. When something breaks at night, you will not have to remember them under pressure.

Watch the lesson

Linux basics for backend developers · 1/7

Linux basics

Most servers run Linux, and you control them by typing commands in a terminal.

Prefer a video by a teacher? Find free videos on “linux command line basics for beginners server” on YouTube ↗

In real life: A food delivery API slows down at dinner time

At 8 pm the order API of a small food delivery startup becomes slow. The on-call developer runs ssh to log in, then free -h (memory is fine) and df -h: the disk is 99% full because old log files were never cleaned. tail -f app.log | grep ERROR shows "no space left on device" errors when saving orders. She deletes old logs carefully, runs sudo systemctl restart orders-api, and checks with curl that /healthz answers 200. Ten minutes, six commands. Later the team sets up log rotation so the disk never fills again.

Practice (0/3 done)

Task 1 · Code · Javascript

Write permissionsToOctal(perms) that turns 9 permission letters into the 3-digit number used by chmod. Each group of 3 letters is one digit: r = 4, w = 2, x = 1, and - = 0. Example: "rwxr-xr-x" gives "755". Return the number as a string, so "000" keeps its zeros.

Task 2 · Code · Javascript

Log lines look like "2026-10-19 20:15:02 ERROR Payment timeout for order 9051": date, time, level, then the message. Write countErrors(logText) that counts the lines whose level (the third word) is exactly "ERROR". Ignore blank lines. A line like "... INFO Showed error page" does NOT count, because its level is INFO. This is what grep does, but stricter.

Task 3 · Code · Javascript

Write diskWarnings(dfOutput, limit) for the text printed by df -h. Skip the first (header) line and any blank lines. For each other line, the 5th column is the use percent (like "88%") and the 6th is the mount point (like "/"). Return the mount points whose use is at or above limit, in order.

Quick quiz

Question 1

1.Which command keeps showing new lines of a log file as they are written?

Question 2

2.What does chmod 600 .env do?

Question 3

3.Which command shows how much disk space is left?

Question 4

4.With SSH keys, which key stays only on your laptop?

Question 5

5.Your app runs as a systemd service called notes-api. How do you read its recent logs?

Read more (free)

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

← Previous: Documenting your API with OpenAPI