Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 2Naam in de cursus: Accessing the Command Line

Log in and run commands in the shell

The command line is the main tool of a Linux admin. This chapter shows how to log in (on the console, in the desktop and over SSH), how a command is built, and the keys and tricks that make you fast: Tab, history and line editing.

  • 9 Lessen
  • 24 Commando's
  • 1 Labs

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

Vaardigheden in dit hoofdstuk

  • Inloggen en commando's uitvoeren in Bash

2.1

Log in on the console or in the desktop

You start a shell by logging in. On a server that is a text console, on a workstation the GNOME desktop with a terminal window.

  • Text console: the server shows server1 login:. Type the user name, press Enter, type the password (you see nothing while you type) and press Enter.
  • GNOME desktop: click your name, type the password. Open Activities, type terminal and start Terminal (or press Super, the Windows key).
  • Virtual consoles: a Linux machine has several text consoles. Switch with Ctrl+Alt+F1 … Ctrl+Alt+F6. On RHEL 10 the graphical login is on the first one.
Red Hat Enterprise Linux 10.0 (Coughlan)
Kernel 6.12.0-55.9.1.el10_0.x86_64 on x86_64
 
server1 login: student
Password:
[student@server1 ~]$

Op het werk

Servers in a data center usually have no desktop. You log in over SSH (next lesson) or with the console of the virtual machine or of the server's management card (iDRAC, iLO).

2.2

Log in to another machine with SSH

ssh user@host opens a secure shell on another computer over the network. Everything — also the password — is encrypted.

ssh student@server2
The authenticity of host 'server2 (192.168.122.20)' can't be established.
ED25519 key fingerprint is SHA256:Wp1tH3d2c0QhC8bXl9Zr5yJm6nK4aP7sT0uV2xY3zA8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
student@server2's password:
[student@server2 ~]$ hostname
server2.example.com
[student@server2 ~]$ exit
logout
Connection to server2 closed.
  • The first time, SSH shows the fingerprint of the server's host key. Type yes only when you trust it. SSH saves it in ~/.ssh/known_hosts.
  • ssh server2 without a user name uses your local user name.
  • ssh -i key.pem ec2-user@HOST logs in with a key file — normal in public clouds.

Let op

If SSH later shows WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED, stop. Either the server was reinstalled, or somebody is between you and the server. Check with the server owner before you remove the old key.

More about keys and the SSH server: Set up and secure SSH.

Commando's in deze les

2.3

Read the shell prompt

The prompt tells you who you are, where you are and how strong you are.

[student@server1 ~]$
[root@server1 /etc]#
PartMeaning
student / rootThe user name
server1The short host name
~ / /etcThe current folder (~ = your home folder)
$A normal user
#The superuser root: no limits, be careful
whoami
student
id
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)
pwd
/home/student

Onthoud

In these summaries, $ lines run as a normal user and # lines need root (or sudo).

2.4

Type a command the right way

A command line is command + options + arguments, with spaces between them. Linux is case-sensitive: ls works, LS does not.

ls
ls -l
ls -l -a /etc/ssh
ls -la /etc/ssh
ls --all --human-readable -l /var/log
  • Options change how the command works. Short options: one dash and a letter (-l), you can join them (-la). Long options: two dashes and a word (--all).
  • Arguments say what the command works on: files, folders, users, packages.
  • A file name with spaces needs quotes: ls -l "my report.txt".

Some simple commands to try:

date
Mon Oct 27 09:15:02 AM +03 2026
date +%F
2026-10-27
cal
file /etc/passwd /usr/bin/ls
/etc/passwd:  ASCII text
/usr/bin/ls:  ELF 64-bit LSB pie executable, x86-64
wc -l /etc/passwd
38 /etc/passwd
head -n 3 /etc/passwd
tail -n 3 /var/log/dnf.log

Let op

Before you press Enter on a command that deletes or changes things, read it again. The shell does not ask "are you sure?".

2.5

Run several commands on one line

; runs commands one after the other. && runs the next one only when the first one worked. || runs the next one only when the first one failed.

cd /tmp ; ls
mkdir -p /tmp/test && cd /tmp/test
ping -c 1 server2 > /dev/null || echo "server2 does not answer"
dnf check-update -q || echo "updates are waiting"

Every command ends with an exit status: 0 = OK, any other number = a problem. $? shows the status of the last command.

ls /etc/passwd
/etc/passwd
echo $?
0
ls /nothing
ls: cannot access '/nothing': No such file or directory
echo $?
2

Onthoud

&& = "and if OK", || = "or else", ; = "then, no matter what".

2.6

Let Tab type for you

Press Tab once to complete a command, a file name, an option or a service name. Press Tab twice to see all choices.

syst<Tab>
systemctl
systemctl sta<Tab><Tab>
start   status
ls /etc/sysco<Tab>
ls /etc/sysconfig/

Op het werk

Tab protects you from typing mistakes in long paths. If Tab does not complete, the name does not exist — you know at once that something is wrong.

2.7

Repeat commands from the history

Bash remembers the commands you typed. Repeat them instead of typing them again.

history 5
  41  ip -br a
  42  systemctl status sshd
  43  ss -tlpn
  44  df -h
  45  history 5
!42
!!
!ss
sudo !!
Keys / commandWhat it does
↑ / ↓Walk through the last commands
Ctrl+R, then typeSearch back in the history. Ctrl+R again: older match. Enter runs it.
!42Run line 42 again
!!Run the last command again
!ssRun the last command that started with ss
Esc . or Alt+.Paste the last argument of the previous command

The history is saved in ~/.bash_history when you log out. Details: the RHCSA lesson about history.

2.8

Edit the command line fast

You do not need the arrow keys to fix a long command. These keys move and delete fast.

KeysWhat they do
Ctrl+A / Ctrl+EGo to the start / end of the line
Alt+B / Alt+FGo one word back / forward
Ctrl+WDelete the word before the cursor
Ctrl+U / Ctrl+KDelete from the cursor to the start / to the end
Ctrl+YPaste back what you deleted last
Ctrl+LClear the screen (same as clear)
Ctrl+CStop the running command, or drop the line you are typing
Ctrl+DEnd of input; on an empty prompt it logs you out

A long command can go over several lines: end a line with \ and go on in the next line.

rsync -av --delete \
    /srv/www/ \
    backup@server2:/backup/www/

2.9

Log out and end the session

Always log out when you are done, also on a test server. An open root shell is an open door.

exit
logout
  • exit (or Ctrl+D) ends the shell. In an SSH session you are back on your own machine.
  • In GNOME, use the menu at the top right: Log Out or Power Off.
  • w and who show who else is logged in.
w
 09:31:10 up 2 days,  3:12,  2 users,  load average: 0.02, 0.05, 0.01
USER     TTY      LOGIN@   IDLE   JCPU   PCPU  WHAT
student  pts/0    09:02    0.00s  0.04s  0.00s w
anna     pts/1    08:47   20:11   0.01s  0.01s -bash

Oefenen

Alle commando's in dit hoofdstuk