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 5Naam in het boek: Connecting to Red Hat Enterprise Linux

Log in locally and remotely

You work on servers on the local console, in terminal windows and — most of the time — over SSH. This chapter shows how to switch consoles, reboot and shut down the right way, log in with SSH and keys, copy files safely between systems, and use the Cockpit web console.

  • 15 Lessen
  • 27 Commando's
  • 2 Labs

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

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

Examendoelen in dit hoofdstuk

  • Met SSH op systemen op afstand werken
  • Inloggen en van gebruiker wisselen in multi-user targets
  • Een systeem normaal opstarten, herstarten en afsluiten
  • Veilig bestanden tussen systemen verplaatsen

5.1

Log in on the local console

The console is the screen and keyboard of the machine itself (or the console window of a virtual machine). You log in there with a user name and password.

  • On a server without a graphical desktop you get a text login prompt: server1 login:.
  • On a server with a desktop you log in on the graphical login screen; a terminal window then gives you a shell.
  • The text in /etc/issue is shown before the login prompt.

After login, check who you are and where:

whoami
tty
/dev/tty3
hostname

Examentip

In the exam you work on virtual machines through a console in the browser. Keep it open: you need it when the network or SSH is broken.

5.2

Switch between terminals

Linux has several virtual terminals on the same screen. Ctrl+Alt+F1 … F6 switch between them.

KeysWhat you get (RHEL with desktop)
Ctrl+Alt+F1The graphical login screen
Ctrl+Alt+F2Your graphical session
Ctrl+Alt+F3 … F6Text consoles (tty3–tty6)

On a server without a desktop, Alt+F1 … Alt+F6 switch between text consoles. As root you can also use chvt N.

chvt 3

Op het werk

When the desktop hangs, switch to a text console (Ctrl+Alt+F3), log in and fix it (for example kill the hanging program).

Commando's in deze les

5.3

Understand pseudo terminals

Terminal windows and SSH sessions do not use a real console. They get a pseudo terminal: /dev/pts/0, /dev/pts/1 …

tty
/dev/pts/0
who
student  tty2         2026-10-25 08:10 (tty2)
student  pts/0        2026-10-25 09:02 (192.168.122.1)
w
  • tty shows your own terminal.
  • who lists who is logged in, on which terminal and from where.
  • w shows the same plus what each user is doing now and the load of the system.

Op het werk

who and w show active SSH sessions. An unknown user or IP address is a reason to investigate.

5.4

Reboot and shut down the right way

Always stop a system through systemd, so services can stop cleanly and file systems are written. Never just pull the power.

systemctl reboot
systemctl poweroff
shutdown -r +5 "Reboot for kernel update in 5 minutes"
shutdown -c
shutdown -h now

Let op

A hard reset (power button, echo b > /proc/sysrq-trigger) can damage open files. Use it only when the system does not react at all.

Examentip

Reboot your exam systems at the end and check that everything still works. Work that does not survive a reboot does not count.

5.5

Log in to another server with SSH

SSH (Secure Shell) gives you an encrypted shell on another system. Everything you type and see is protected.

ssh student@server2
ssh server2
ssh -p 2222 student@server2
ssh root@server2 'df -h /'
exit
  • ssh user@host logs in as that user. Without user@, your own user name is used.
  • The first time, SSH shows the fingerprint of the server and asks you to trust it. Answer yes only when you are sure it is the right server. It is then saved in ~/.ssh/known_hosts.
  • A command after the host runs on the remote system and SSH ends at once.
  • -X (or -Y) lets you start graphical programs from the remote server on your screen.

Let op

"REMOTE HOST IDENTIFICATION HAS CHANGED" means the server key is different. It can be a reinstall — or an attack. Check before you remove the old key with ssh-keygen -R server2.

5.6

Copy files securely with scp

scp copies files over SSH. The remote side is written as user@host:path.

scp /etc/hosts student@server2:/tmp/
scp student@server2:/var/log/messages ./server2-messages
scp -r ~/project server2:/home/student/
scp -P 2222 backup.tar.gz server2:/srv/
  • -r copies folders.
  • -P (capital) sets the port. (In ssh it is a small -p.)
  • -p (small) keeps times and permissions.

Onthoud

scp = cp over SSH: scp SOURCE TARGET, remote side = user@host:path.

Commando's in deze les

5.7

Transfer files with sftp

sftp opens an interactive file transfer session over SSH, like an FTP client but encrypted.

sftp student@server2
CommandWhat it does
ls / llsList remote / local files
cd / lcdChange remote / local folder
pwd / lpwdShow remote / local folder
get fileDownload a file
put fileUpload a file
mget *.log / mput *.txtDownload / upload many files
mkdir / rmMake a remote folder / remove a remote file
exitLeave

The l in front means "local". Everything else works on the remote side.

5.8

Synchronize folders with rsync

rsync copies only what is different. The second run of a big copy takes seconds. It works locally and over SSH.

rsync -av ~/project/ server2:/srv/project/
rsync -av --delete /var/www/html/ /backup/html/
rsync -avn --delete /var/www/html/ /backup/html/
rsync -avz -e "ssh -p 2222" /data/ server2:/data/
OptionMeaning
-aArchive: recursive, keep permissions, owners, times, links
-vShow what is copied
-zCompress during the transfer
--deleteRemove files in the target that are gone in the source
-nDry run: show what would happen, change nothing
-PShow progress and keep half-done files

Let op

A slash at the end of the source matters. src/ copies the content of src; src copies the folder itself into the target.

Op het werk

Always run rsync -avn --delete first. Read the list. Then run it without -n.

Commando's in deze les

5.9

Log in with SSH keys

A key pair replaces the password: the private key stays on your computer, the public key goes to the server in ~/.ssh/authorized_keys.

  1. Make a key pair on the client (your computer or server1).
    ssh-keygen -t ed25519
  2. Copy the public key to the server.
    ssh-copy-id student@server2
  3. Log in: no password is asked any more (only the passphrase of the key, if you set one).
    ssh student@server2

Controleer het

The permissions on the server must be tight, or SSH ignores the key.

ssh server2 'ls -ld ~/.ssh; ls -l ~/.ssh/authorized_keys'
FileWherePermissions
~/.ssh/id_ed25519Client600 — never share it
~/.ssh/id_ed25519.pubClient644 — this is the one you copy
~/.ssh/authorized_keysServer600
~/.ssh/Both700

Onthoud

private key stays home, public key travels.

Examentip

The exam objective "Configure key-based authentication for SSH" = ssh-keygen + ssh-copy-id + test the login. Chapter 20 adds the server settings.

5.10

Use a passphrase and ssh-agent

A passphrase encrypts the private key, so a stolen key file is useless. ssh-agent keeps the unlocked key in memory, so you type the passphrase only once per session.

ssh-keygen -t ed25519 -C "student@server1"
eval "$(ssh-agent)"
ssh-add
ssh-add -l
  • With a passphrase: safer, but you must unlock the key.
  • Without a passphrase: needed for automatic jobs (cron, scripts), but protect the key file well and limit what it can do on the server.

Op het werk

For automation, use a separate key without passphrase per job, and limit it in authorized_keys (for example from="10.0.0.5",command="/usr/local/bin/backup.sh").

5.11

Switch to another user in a session

You do not need to log out to work as another user. su - USER opens a login shell as that user; exit takes you back.

su - root
exit
sudo -i
exit

Chapter 6 explains su and sudo in detail.

5.12

Manage the server in a browser with Cockpit

Cockpit is a web console for RHEL: logs, services, storage, network, users and a terminal in the browser, on port 9090.

  1. Install it and start the socket.
    dnf install -y cockpit
    systemctl enable --now cockpit.socket
  2. Open the firewall (often already open on RHEL).
    firewall-cmd --add-service=cockpit --permanent
    firewall-cmd --reload
  3. Open https://server1:9090 in a browser and log in with a normal user. Choose "administrative access" to make changes.

Op het werk

Cockpit is great to show a junior colleague what is going on. In production, allow port 9090 only from the admin network.

5.13

Remember the main points

The most important facts of this chapter, in short.

  • Local logins use virtual consoles (Ctrl+Alt+F1…F6, or chvt); remote shells use pseudo terminals (/dev/pts/N).
  • Reboot with systemctl reboot and stop with systemctl poweroff; never just pull the power.
  • ssh user@host opens a remote shell; the first connection asks you to trust the host key (saved in ~/.ssh/known_hosts).
  • scp and sftp copy files over SSH; rsync copies only what changed and can keep permissions (-a).
  • Key-based login: ssh-keygen makes a key pair, ssh-copy-id puts the public key in ~/.ssh/authorized_keys on the server.
  • A passphrase protects the private key; ssh-agent and ssh-add keep it unlocked for a session.
  • su - switches to another user with a full login environment.
  • Cockpit is the web console (port 9090) for many admin tasks.

5.14

Learn the key terms

The words of this chapter in simple English.

TermMeaning
ConsoleThe screen and keyboard of the computer itself.
Virtual terminalOne of several text logins on the local console (tty1–tty6).
Pseudo terminalA terminal made by software, for example for SSH (/dev/pts/0).
SSHSecure Shell: encrypted remote login and file copy.
Host keyThe key that proves the identity of an SSH server.
Key pairA private key (secret) and a public key (shared) for login without a password.
authorized_keysThe file on the server with the public keys that may log in.
PassphraseThe password that protects a private key.
CockpitA web interface to manage a RHEL server.

5.15

Check what you learned

Think about the answer first, then open it.

1How do you switch to the third virtual console?

Ctrl+Alt+F3 (or chvt 3 as root).

2Which command shows who is logged in and on which terminal?

w or who.

3Where does SSH store the host keys of servers you trust?

In ~/.ssh/known_hosts.

4How do you set up login from server1 to server2 without a password?
5Which file permission must the private key have?

Only the owner may read it, for example 600 (chmod 600 ~/.ssh/id_ed25519).

6How do you copy only changed files from /data to server2, keeping permissions?
7What is the difference between su user and su - user?

su - starts a full login shell with the environment of that user; plain su keeps most of your old environment.

8Which port does the Cockpit web console use?

Oefenen

Alle commando's in dit hoofdstuk