Skip to content

Cookie settings

Choose which kinds of cookies you allow. You can change your choice at any time via Cookie settings at the bottom of every page. Privacy statement

Necessary

Always on

Needed to log in, keep your cart and remember your choices. These are always on.

Which cookies?
  • weboke_sessie, weboke_klant, weboke_remember: your session and staying logged in
  • weboke_basket: your cart
  • wkBtwIncl: showing prices with or without VAT
  • wok_cookies: your cookie choice, 12 months

Measures which ad leads to a visit or order, so we do not pay for ads that do nothing.

Which cookies?
  • Google Ads via Google Tag Manager (_gcl_au, _gcl_aw), up to 90 days
  • OpenAI Ads, ads in ChatGPT
  • wok_aff: which partner referred you to us (affiliate programme), 60 days

4.6

Country and language

Each country has its own site, with prices and VAT for that country.

View

Module 1 · 1.4

Finding your way around the command line

Module 1: Your first server · Reading time: 11 minutes

Learning objective: After this lesson you can find your way around a Linux server: move through directories, read and edit files, see how much disk space and memory is free, and look up help for a command yourself.

Key concepts: shell, prompt, directory and path, absolute and relative path, /etc, /var/log, /home, ls -l, cd, cat, less, nano, man, --help, tab completion, uname, df, free, uptime, pipe, grep

The shell and the prompt

After logging in, you are talking to the shell: the program that reads and runs your commands. On Debian and Ubuntu that is usually bash. To the left of the cursor is the prompt:

anna@web1:~$
root@web1:~#

It tells you three things: who you are (anna or root), which server you are on (web1) and which directory you are in (~ is your own home directory). The last character matters: $ means an ordinary user, # means root. If you see #, every command runs with full privileges. Type carefully there.

Directories and paths

Everything on Linux hangs from a single tree that starts at / (the root directory, not to be confused with the user root). You will come across a few directories again and again in this course:

DirectoryWhat it contains
/etcConfiguration: SSH (/etc/ssh), web server (/etc/nginx), users (/etc/passwd)
/var/logLog files (alongside the journal, lesson 6.2)
/var/libProgram data, for example databases and Docker
/homeHome directories of ordinary users, such as /home/anna
/rootHome directory of root
/usrInstalled programs and libraries
/tmpTemporary files, cleaned up automatically
/srv or /var/wwwUsual place for websites and services

An absolute path starts at /, for example /etc/ssh/sshd_config. A relative path starts where you are now: if you are in /etc, then ssh/sshd_config is the same file. .. is the directory above, . the current directory.

anna@web1:~$ pwd
/home/anna
anna@web1:~$ cd /etc/ssh
anna@web1:/etc/ssh$ ls
moduli  ssh_config  ssh_config.d  sshd_config  sshd_config.d  ssh_host_ed25519_key  ssh_host_ed25519_key.pub ...
anna@web1:/etc/ssh$ cd ..
anna@web1:/etc$ cd
anna@web1:~$

cd with nothing after it takes you back to your home directory.

Looking at files

ls -l shows more than just names:

anna@web1:/etc/ssh$ ls -l sshd_config ssh_host_ed25519_key ssh_host_ed25519_key.pub
-rw-r--r-- 1 root root 3248 Aug 12 10:01 sshd_config
-rw------- 1 root root  399 Nov  2 14:20 ssh_host_ed25519_key
-rw-r--r-- 1 root root   91 Nov  2 14:20 ssh_host_ed25519_key.pub

From left to right: the permissions, the number of links, owner, group, size in bytes, date and name. Notice the difference: only root may read the secret host key (-rw-------), while everyone may read the public one (-rw-r--r--). In lesson 3.1 you will learn to read these permissions exactly. ls -la also shows hidden files: names that start with a dot, such as .ssh.

To read the contents:

  • cat bestand: the whole file at once, handy for short files;
  • less bestand: scroll with the arrow keys and space, search with /woord, quit with q;
  • head -n 20 bestand and tail -n 20 bestand: the first or last lines; tail -f keeps watching as new lines are added.

Editing a file with nano

You change configuration in a text editor. nano is the simplest:

root@web1:~# nano /etc/hosts

The shortcuts are listed at the bottom; ^ means Ctrl. Save with Ctrl+O and Enter, exit with Ctrl+X, search with Ctrl+W. If you already work with vim, feel free to use it; on a minimal installation vim is not always fully available.

Three habits that will save you a lot of trouble later:

  1. Make a copy first: cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.
  2. Test the configuration before you restart a service. Many programs have their own command for this: sshd -t, nginx -t (lessons 2.2 and 7.2).
  3. Change one thing at a time, so you know what caused an error.

How is your server doing?

A few commands you will use in every situation:

anna@web1:~$ uname -a
Linux web1 6.12.0-... #1 SMP ... x86_64 GNU/Linux
anna@web1:~$ uptime
 10:12:44 up 3 days,  2:10,  1 user,  load average: 0.08, 0.05, 0.01
anna@web1:~$ df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        40G  3.1G   35G   9% /
anna@web1:~$ free -h
               total        used        free      shared  buff/cache   available
Mem:           3.8Gi       412Mi       2.9Gi       1.0Mi       720Mi       3.4Gi
Swap:             0B          0B          0B
  • uname -a: which kernel is running.
  • uptime: how long the server has been up and the load average over 1, 5 and 15 minutes. Roughly: a load that stays above the number of processor cores for a long time means things are waiting.
  • df -h: free disk space (-h means "human readable", with G and M). A full disk is one of the most common reasons a server "just" stops.
  • free -h: memory. Look at the available column, not free: Linux uses free memory as cache (buff/cache) and gives it back when a program needs it.

And your network, from lesson 1.2: ip -brief address.

Finding help

You don't need to memorise every option. You do need to know where to find them:

  • man ssh opens the manual page of a command. Scroll as in less, search with /. man sshd_config describes every setting you can use in that file.
  • ls --help gives a short list of options for most commands.
  • The Tab key completes names of commands and files. Pressing Tab twice shows the possibilities. That saves typos in long paths.
  • The up arrow brings back earlier commands; history shows them all.

Manual pages are sometimes missing on a minimal installation. On Debian and Ubuntu you install them with apt install man-db (module 4).

Pipes and grep

You can chain commands together with a pipe (|): the output of one becomes the input of the next. grep filters lines that contain a word:

anna@web1:~$ grep PasswordAuthentication /etc/ssh/sshd_config
#PasswordAuthentication yes
anna@web1:~$ ls -l /etc | less

Lines that start with # are comments: they do nothing and often show the default value. In lesson 2.2 you will see why that can be confusing with SSH.

Pitfalls

  • Pasting without reading. Commands from the internet do exactly what they say, even if that is different from what the article's title promises. Read every command before you run it, especially when you are root.
  • rm has no recycle bin. Gone is gone. Be extra careful with rm -r (a directory and everything in it) and with wildcards such as *.
  • Case matters. /etc/SSH does not exist; /etc/ssh does.
  • Spaces in paths need quotation marks: cat "/srv/mijn site/index.html". Better still: don't use spaces in names on a server.

Summary

  • The prompt tells you who you are, on which server and where; # means root.
  • Configuration lives in /etc, logs in /var/log, program data in /var/lib, home directories in /home.
  • Read with cat, less, head and tail; edit with nano, after making a copy, and test the configuration before you restart.
  • df -h, free -h, uptime and ip -brief address show how your server is doing.
  • Help is in man and --help; Tab completes; with | and grep you filter output.

Quiz

1. Your prompt is root@web1:/var/log#. What do you know now?



2. You are in /etc. Which path points to the same file as /etc/nginx/nginx.conf?



3. free -h shows free 120Mi and available 2.9Gi. Does the server have too little memory?



4. What is the wisest thing to do before you change /etc/ssh/sshd_config?



5. Where do you look up which settings sshd_config supports?



Exercise

Exercise O1.4: Getting to know your server. Run the commands from this lesson on your own server and fill in: distribution and version, kernel, free disk space, available memory, load, IPv4 and IPv6, and which files in /etc/ssh only root can read. Then answer two questions about what you saw.

Exercise O1.4: Getting to know your server

You do this exercise yourself; no one checks it. Tick off what you've done and mark the exercise as done.



Your ticks and notes only stay in this browser; we don't send them anywhere. If you're signed in, we only save in My courses that you've done the exercise.

Further reading

One moment…

Set up your domains

For each domain, arrange the nameservers, the link to your hosting and who becomes the owner.

Loading your domains…