Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
What the course covers
This course is a first step into Linux. You do not need any past experience.
- It uses Red Hat Enterprise Linux (RHEL) in the lab.
- You learn to move around the command line with
bash. - You work with files: create, copy, move, look inside, and delete them.
- You learn users, groups, passwords, and file permissions.
- You look at processes, services, boot targets, logs, and SSH.
- You set up the network with
nmclianddnfpackages. - You finish with LVM storage: physical volumes, volume groups, and logical volumes.
Prefix Chapters
Four short lessons before the real work starts. They cover the poll, the coach, and the live class.
- VIRGIL is the lab coach. It sits in the lab and helps you when you get stuck.
tmuxkeeps many shells in one window. PressCtrl+B, let go, then press the next key.- In tmux:
%splits left and right,"splits top and bottom, arrows move,zzooms,[scrolls back. - To paste in the lab terminal: right-click Paste, or
Shift+Insert, orCtrl+Shift+V.
Get Started with Red Hat Enterprise Linux
Linux is an open-source operating system. It runs on servers and on many other devices.
- RHEL is the Red Hat build of Linux. It is common in companies.
- This course works in a RHEL lab. Each lesson names the RHCSA skill it covers.
- After the install, set the root password with
passwd. - Check the network with
nmcli device status, then bring a link up withnmcli connection up. - Set a static address with
nmcli connection modify ... ipv4.addresses,ipv4.gateway,ipv4.dns, andipv4.method manual. - Set the machine name with
hostnamectl set-hostname myserver.example.com.
Fundamentals of Command Line Operations
bash reads what you type and runs it. The prompt shows user@host:~$.
~is your home folder.$means a normal user. Root sees#.pwdshows where you are.lslists files.ls -ashows hidden files.ls -lshows details.cdchanges folder.cd ..goes up one level.cd ~goes home.historyshows your past commands.touchmakes an empty file.echo "text" > filewrites a file.cpcopies,mvmoves or renames,rmdeletes.cp -rcopies a whole folder.rm -rdeletes a folder.- Linux has one tree. Everything starts at
/(root). Common folders:/home,/etc,/var,/usr,/tmp. - An absolute path starts with
/. A relative path starts from where you are now. catprints a file.lesspages through it.headshows the top.tailshows the end.- Redirection:
>writes,>>adds,2>sends errors,&>sends both.|sends output into the next command. - Example:
ls > directory_list.txtsaves the list.ls | grep "log"filters it.
Help Systems in Red Hat Enterprise Linux
man ls opens the manual page for ls. Press q to leave.
- Man pages are split into sections.
man 1 passwdpicks section 1 (commands). man -k networkorapropos networksearches by keyword.command --helpgives a short list of options.- Files in
/usr/share/docgive more detail.
Text File Management
vim is a modal editor. i starts typing. Esc stops typing.
:wqsaves and quits.:q!quits and drops changes.Gjumps to the end of the file.Ajumps to the end of the line and starts typing.grep "root" /etc/passwdfinds a word in a file.- Useful
grepflags:-iignore case,-nline numbers,-rsearch folders,-ccount,-vinvert,-wwhole word. diff file1 file2shows what changed.diff -ugives a unified view.cmpsays if two files differ.- Regex:
^start,$end,.one character,[aeiou]a set,[^0-9]not a digit,*repeat.
User and Group Management
Every file has an owner and a group. root is the superuser.
useradd -m johnmakes a user with a home folder.-ssets the shell,-Gadds a group.usermod -aG wheel johnadds a group.-Llocks the account.-Uunlocks it.userdel -r johnremoves the user and home.groupadd,groupmod -n, andgroupdelmanage groups.gpasswd -dremoves one member.passwd johnsets a password.passwd -eforces a change at next login.chage -l johnshows the password age.-M 90sets the most days a password can stay.
File Permissions and Security
ls -l shows -rw-r--r--. The first - is the file type. Then come user, group, and other rights.
ris read (4),wis write (2),xis execute (1).chmod u+x script.shadds execute for the owner.chmod g-w fileremoves write from the group.chown alice:developers filesets owner and group. Add-Rfor a whole folder.chgrpchanges only the group.- ACLs give rights to more than one user or group.
getfacl fileshows them andsetfaclsets them. - Check ACL support with
mount | grep acl. Add it withmount -o remount,acl /mountpoint.
Process Management
A process is a running program. Every process has a PID.
ps auxlists all processes.ps aux | grep httpdfinds one program.topshows live CPU and memory use.htopis a friendlier version.nice -n 10 ./backup.shstarts a job at lower priority.renice 10 -p 1234changes a running job. Only root can lower the number (raise priority).kill PIDstops one process.killallorpkill -fstops many at once.
Managing Services and Daemons
A daemon is a background program. A service is a daemon that systemd controls.
systemctl start httpdstarts it.stop,restart, andstatusdo the other jobs.systemctl enable httpdmakes it start at boot.disableturns that off.journalctl -u httpdshows the logs of one service. Add-fto follow live.- Boot targets:
systemctl get-defaultshows the current one. systemctl set-default multi-user.targetchanges the default.systemctl isolate rescue.targetswitches now.
SSH Configuration and Security
SSH lets you log in to a remote machine over an encrypted link.
- Install with
dnf install openssh-server, thensystemctl enable --now sshd. - In
/etc/ssh/sshd_configyou can setPort 2222,PermitRootLogin no,AllowUsers, andPubkeyAuthentication yes. - Restart the service after a config change:
systemctl restart sshd. ssh-keygen -t rsa -b 4096makes a key pair. The private key stays on your machine.ssh-copy-id user@serversends the public key to the server.- Fix the key file rights:
chmod 700 ~/.sshandchmod 600 ~/.ssh/authorized_keys.
Log Management
Logs live in /var/log. There you find messages, secure, and the journal folder.
journalctlreads thesystemdjournal.-bshows this boot.-b -1shows the last boot.journalctl --since todayand--since "1 hour ago"filter by time.journalctl -u sshd -bshows one service for this boot.logrotatestops logs from filling the disk. Main config:/etc/logrotate.conf. Extra files:/etc/logrotate.d/.- Common rules:
daily,rotate 7,compress, andnotifempty.
Networking in Red Hat Enterprise Linux
Every host needs an IP address, a gateway, and a DNS server.
ip addrshows addresses.ip link set enp0s4 upturns a link on.ip route add default via 192.168.1.1adds a default route.- Old style config files sit in
/etc/sysconfig/network-scripts/ifcfg-<interface>. nmcliis the modern tool.nmcli device statuslists links.nmcli con addmakes a new profile.- DNS servers go in
/etc/resolv.confor in thenmcliprofile. - Local names live in
/etc/hosts.hostnamectl statusshows the host name.
Package Management
dnf installs, updates, and removes software on RHEL.
dnf install httpdinstalls a package. You can list several packages in one call.dnf remove httpdremoves it.dnf updateupdates all packages.dnf search apachefinds packages.dnf info httpdshows details.dnf repolistshows the repos.dnf list installedshows what you have.dnf autoremovecleans packages nobody needs now.
File System Management
LVM puts a flexible layer between the disk and the file system.
- Three parts: physical volume (PV), volume group (VG), and logical volume (LV).
pvcreate /dev/sdbmarks a disk for LVM.pvdisplayshows it.vgcreate my_vg /dev/sdbmakes a group.vgextend my_vg /dev/sddadds a disk.lvcreate -L 10G -n my_lv my_vgmakes a volume.mkfs.ext4 /dev/my_vg/my_lvputs a file system on it.mountattaches it to a folder.lvextend -L +5G /dev/my_vg/my_lvmakes the volume bigger.- Then grow the file system:
resize2fsfor ext4,xfs_growfs /mntfor XFS. df -hshows free space.
Key commands and tools
- Where am I:
pwd,ls -la,cd,history,whoami,groups. - Files:
touch,cp -r,mv,rm -r,mkdir -p,cat,less,head,tail. - Text:
grep -in,grep -r,diff -u,cmp. - Edit:
vim,i,Esc,:wq,:q!,G,A. - Help:
man,man -k,apropos,--help. - Users:
useradd -m,usermod -aG,userdel -r,passwd,chage,groupadd,groups. - Rights:
chmod,chown,chgrp,getfacl,setfacl. - Processes:
ps aux,top,htop,nice,renice,kill,killall. - Services:
systemctl start|stop|restart|status|enable|disable,journalctl -u,systemctl get-default. - Remote:
ssh,sshd,ssh-keygen,ssh-copy-id. - Logs:
journalctl -b,journalctl --since,/var/log/messages,logrotate. - Network:
ip addr,ip route,nmcli,nmtui,hostnamectl,ss -tln,/etc/hosts,/etc/resolv.conf. - Packages:
dnf install,dnf remove,dnf update,dnf search,dnf repolist. - Storage:
lsblk,df -h,pvcreate,vgcreate,lvcreate,lvextend,mkfs.ext4,mount,resize2fs,xfs_growfs.
Key terms
The words of this course in one table. Learn them before the quiz or exam.
| Term | Meaning |
|---|---|
| Absolute path | A full path that starts with /. |
| ACL | Access Control List. Extra permissions for more users or groups. |
| Bash | The shell that reads what you type and runs the command. |
| Boot target | The state the system boots into, such as multi-user or graphical. |
| Daemon | A program that runs in the background. |
| DNS | The service that turns a name into an IP address. |
| Group | A set of users. A group makes it easy to share files. |
| Home directory | Your own folder, usually /home/yourname. The ~ sign means home. |
| Journal | The systemd log. Read it with journalctl. |
| Linux | An open-source operating system. The course uses it on servers. |
| LVM | Logical Volume Management. It puts a flexible layer over disks. |
| man page | The built-in manual of a command. Open it with man command. |
| NetworkManager | The service that manages network links. nmcli and nmtui control it. |
| Permissions | The read (r), write (w), and execute (x) rights on a file. |
| PID | The number that names a process. |
| Pipeline | A / between two commands. The first output becomes the second input. |
| Process | A running program. |
| Prompt | The text before your cursor. It shows user@host and the current folder. |
| Redirection | Sending output or errors to a file with >, >>, 2>, or &>. |
| Regular expression | A text pattern. ^ is the line start, $ is the line end. |
| Relative path | A path that starts from the folder you are in now. |
| RHEL | Red Hat Enterprise Linux. The Linux version in the lab. |
| Service | A daemon that systemd starts, stops, and watches. |
| SSH | Secure Shell. It gives you an encrypted login on a remote machine. |
| User | A named account on the system. |
Useful links
Official documentation and pages for this course.
Oefenen
Alle commando's in dit hoofdstuk
bashnmclidnftmuxtestpasswdhostnamectlpwdlscdhistorytouchechocpmvrmcatlessheadtailmanaproposgrepuseraddusermoduserdelgroupaddgpasswdchagewchmodchownchgrpgetfaclsetfaclmountpstopnicerenicekillkillallpkillsystemctljournalctlssh-keygenssh-copy-idlogrotateippvcreatepvsvgcreatevgextendlvcreatemkfs.ext4lvextendresize2fsxfs_growfsdfwhoamigroupsmkdirvimsshsshdnmtuisslsblk