Faculty of Mathematics and Physics CHARLES UNIVERSITY

NOFY077

Introduction to the OS

Peter Husz´ar KFA: Department of Atmospheric Physics

Pavel Rezn´ıˇcekˇ U´ CJF:ˇ Institute of particle and nuclear physics

October 23, 2019 Overview and Organization

Introduction to the Operation system Linux, focus on the command line, scripting, basic services and tools used in (not only) physics: tasks automation in data processing and modeling

Organization Graded Assessment (KZ): attendance to the lectures, worked out homeworks

Literature . Herborth: Unix a Linux - N´azorn´ypr˚uvodce, Press, Praha, 2006 D. J. Barrett: Linux - Kapesn´ıpˇrehled,Computer Press, Praha, 2006 M. Sobell: Mistrovstv´ıv RedHat a Fedora Linux, Computer Press, Praha, 2006 M. Sobell: Linux - praktick´ypr˚uvodce, Computer Press, Praha, 2002 E. Siever: Linux v kostce, Computer Press, Praha, 1999 Number of online sources...

Study materials and homeworks http://kfa.mff.cuni.cz/linux

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 2 / 138 Syllabus

1 UNIX systems, history, installation, basic applications 2 Structure of the Linux OS, file systems, hierarchy of the file system 3 Command line, shells, remote access (ssh, ftp) 4 Processes and their administration, basic system commands, packages, printing 5 Users, file and directory permissions 6 Work with files and directories, file compression, links, partition 7 Text-file processing commands, redirection, pipeline 8 Regular expressions 9 Command line based text editors 10 User and system variables, output processing 11 Scripts: basic construction, conditionals, loops, functions, automation 12 Networking, server-client services: http, (s)ftp, scp, ssh, sshfs, nfs 13 Programming in Linux (examples of Fortran, C/C++, Python), version control systems, documents in Latex

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 3 / 138 Motivation for Linux

Operating systems, two basic types: 1 Windows 2 UNIX (Mac and Android are also UNIX-based) Windows historically more focused on user-PCs UNIX systems used on servers (mail, web, computing, networking) Nowadays the abilities of both systems are close each to other

Why Linux ? Powerful command-line (cmd) Applications started from cmd System control via cmd Programs control, compilation, modifications and debugging via cmd Scripting / programming using shell Natural remote access (including graphic windows), remote administration Open source & free applications, support through wide-community

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 4 / 138 Linux - UNIX Based System

UNIX - trademark of created in Bell Laboratories of AT&T company in 1965 Path to UNIX 1964: Bell Telephone Laboratories, General Electric and MIT develops OS Multics (MULTIplexed Information and Computing System) Unfinished Kenn Thompson, Dennis Ritchie, Brian Kernighan 1969: Bell Labs. withdraws from Multics project, Thompson writes basic OS (kernel, shell), editor and assembler for the PDP-7 computer 1970: Kernighan suggests the name of the OS UNIX (firstly UNICS) 1971: Thompson asks for new PDP-11 computer for further development (rejected); Thompson pretends development of automatized office → computer assigned for text processing 1973: Thompson rewrites Fortran language - languages B, Richie rewrites UNIX into C language for better portability 1978: UNIX v7 released for Universities (Berkeley) - UNIX divided into two parts: AT&T (System III, System V) Berkeley (BSD 3.0)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 5 / 138 UNIX Systems

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 6 / 138 UNIX Systems

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 7 / 138 Present UNIX Systems

SUN: Sun OS, Solaris Silicon Graphics: Irix DEC: Ultrix, Digital Unix IBM: AIX HP: HP-UX Siemens Nixdorf: SINIX Novell: UNIXware SCO: SCO Unix FreeBSD, NetBSD, OpenBSD, ... Linux, Mac OS X Android OS

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 8 / 138 Licensing

Non-free source codes → release of open and free versions Development through free versions

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 9 / 138 Licensing

Non-free source codes → release of open and free versions Development through free versions

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 9 / 138 Linux System

Linux foundation 1984: Richard Stallman creating GNU (GNU’s not UNIX) Attempt to create free (license) system Creating General Public License (GPL) Freedom to run, study, share and modify the software 1991: Linus Torvalds trying to create freely available system Based on Minix Writing kernel of the system

GNU Linux - Linux kernel, tools and GNU libraries

Two SW development models: Bazaar Cathedral Heckert developed over Source code available with the Internet in view of the each software release, but public - Linus Torvalds code developed between releases is restricted to an exclusive group of software developers Tux

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 10 / 138 User View on Linux

Kernel of the system: drivers, processes, memory, filesystem management Filesystem: different from Windows Console: text-based interface Graphical interface: Management allowing remote transfer or graphics windows or even whole screen Terminal (cmd) Common applications: office, web-browsers, multimedia, file-browsers, coding editors, ... Software repositories Natural multi-user and multitasking

Based on free SW → Practically all parts of the system have number of variants → Number of Linux distributions: Various graphical interfaces Various choices of default applications Various program and library versions (stable vs. bleeding edge) Various SW repository types

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 11 / 138 Linux Distributions

List of components: kernel of the operating system GNU/Linux, libraries and other GNU tools Have its own installation image, packages and their repositories Historically 3 distributions: Debian, Red Hat and Slackware expanded into several hundreds, including , openSUSE, Fedora, Mandriva, Gentoo, ... Most distributions have their own Live versions: run from USB stick or CD/DVD

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 12 / 138 Linux Distributions Chart (2019)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 13 / 138 Debian

Debian is one of the most extensive distributions Fully developed by the community Supports 11 platforms: amd64, i386, Arm, PowerPC, mips, s390, ... More than 50000 packages Includes even non-Linux kernels (FreeBSD, NetBSD) Very specific development cycle: Deployment of stable release (getting only minor security updates) once per ∼ two years Very stable and secure Linux, often used for servers In the mean time new packages and package versions are tested in experimental, unstable and testing branches After certain time the testing release becomes stable For impatient users, there are also backports for the stable release Using testing distribution can serve as relatively stable ”rolling distribution” (continuously getting updates without and ”release” dates) Using unstable release as ”rolling” is not that comfortable as it can contain serious incompatibilities Debian (and most of its derivaties) uses package system based on *.deb packages and system apt Automatic resolution of package dependencies, conflicts, diversions, alternatives Pre/post-installation scripts Complex system to create or build own packages Widely considered as best packaging system

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 14 / 138 Ubuntu

Ubuntu is a system based on Debian Free, with both community and professional support Ubuntu community is based on principles described in the Ubuntu Manifesto: Should have the freedom to download, run, copy, distribute, study, share, change and improve their software for any purpose, without paying licensing fees. Should be able to use their software in the language of their choice. Should be able to use all software regardless of disability. Southern African philosophy of ubuntu (literally, ”human-ness”) Suitable both as user-PC as well as for servers Supports most common architectures: PC 32bit (i386), PC 64bit (amd64) and PowerPC (older Apple iBook, Powerbook, G4, G5) Half-year release, long-term supported release every 2 years Unity is the default GUI (Graphic User Interface) MAC-like, touchscreen friendly However, number of variants with different GUI exists (, Xubuntu, , ...), As well as specific-focus derivatives (Edubuntu, ...), or enhanced distributions (Linux Mint, ...)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 15 / 138 KNOPPIX

KNOPPIX is a primarily Live OS Already after installation contains wide range of SW, automatic HW detection and HW support (sound, graphics, peripherals) The CD contains up to 2 GB of compressed SW The DVD version up to 8 GB of compressed SW Can serve as ”rescue” Live system Can be installed as ordinary user-PC as well Derivatives: localized and enhanced system Danix

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 16 / 138 Red Hat

Red Hat is a commercial Linux Enterprise-level support Packages system uses *.rpm files (2nd widely-used package system) Number of free derivates with community-support only

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 17 / 138 Fedora

Fedora is a non-commercial Red Hat derivative Development (community) supported by the Red Hat company Serves as testing platform for the commercial Red Hat releases Progressive, implementing new features very soon Focused on user-PC, suitable for beginners Wide range of SW in the distribution Supports most common architectures: i386, amd64 and PowerPC Very strict in licensing, e.g. yet recently missing *.mp3 support

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 18 / 138 CentOS

CentOS is another Red Hat derivative Originally started as independent distribution, but transferred under Red Hat (developers from the Red Hat open-source team) Free and community supported Often used on servers Used in CERN (European Organization for Nuclear Research)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 19 / 138 Mandriva

Mandriva is originally based on Red Hat Started in 1998 started by Geld Welb, attempting to make more comfortable GUI experience The modified distribution, called Mandrake, was put on servers and Geld Welb left for holidays Strong response from users after return, offers to contribute from developers and testers Nowadays, Mandriva has number of developers in France and USA Focusing on office-PC and multimedia-PC Wide range of SW in the distribution Easy maintenance Strong involvement of users on the final shape of the distribution Beta-testers Suggestions for improvements and changes

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 20 / 138 Slackware

Slackware was the first widely used Linux distribution, created in 1992 by Patrick Volkerding, who remains its only official developer Although many contributors bring new packages, the existence of the only one developer makes the concept of the distribution unified and development trouble-free Slackware is known for simplicity and clarity: Using easy to understand text configuration files Transparency in every process Simple packaging system, able to only install and remove packages: No dependency resolutions No automatic updates → Very flexible in what is being installed on the system Still there are enhancements that overcomes the simplifications above

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 21 / 138 SUSE

SUSE was created in 1992 in Germany First release in 1994 2003/2004 bought by Novell Release of boxed version with manual first (together with Live DVD for preview only), online after serveral months Possibility to buy professional support Later project openSUSE: Community based program sponsored by Novell Easier and free access to SUSE Linux

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 22 / 138 Gentoo

Gentoo uses system similar to the BSD ports, called Portage Portage is a very flexible packaging system (flexible in the installation and maintenance of the SW) SW is being built from source at the time of installation The Portage system allows to set various installation configurations via use-flags Includes build-dependencies Safe installation and deinstallation of packages (via so called sandbox) Protection of config files etc. Very flexible installation, e.g. one can built system from source-code with selected optimization → Gentoo is often considered as metadistribution Active development, rapid fixes and updates Half-year releases

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 23 / 138 Cygwin

Cygwin is a Linux system that is compiled and runs natively on Windows No emulation as virtual machine Settings partly bound to windows (users) Possible to lanuch windows programs Nowadays owned by Red Hat

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 24 / 138 Windows Subsystem for Linux

Windows Subsystem for Linux (WSL) introduced in 2016 Windows update Shell on Windows / Ubuntu on Windows But not really limited to one distribution Enable in ”Windows Features” seetings Allows to run linux binaries (64bit) natively on Windows 10 Can also run graphical applications (after some tunning...) Superuser (root) privileges limited (can’t change Windows config - network etc.) Underlying principle: Linux system calls translated to Windows system calls Performance worse than on native Linux Special filesystem

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 25 / 138 VirtualBox, VMware

VirtualBox and VMware create virtual machine, in which another OS can run (Windows, Linux, MAC) Commercial SW, VirtualBox is open-source and free for personal or educational use Makes use of Intel/AMD hardware-assisted virtualization Can run several Linux installations on Windows in parallel (if enough resources on PC)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 26 / 138 Linux Installation Notes

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 27 / 138 Install Linux Inside Windows

Not genuine Linux experience: administration and hardware management may be limited by what Windows allows... No need for disk repartitioning Easy to uninstall

Cygwin Simply follow installation instructions, installs as an ordinary windows application

Windows Subsystem for Linux Enable in ”Windows Features” settings Install Ubuntu via Microsoft Store: search for ”Run Linux on Windows” and choose distribution

VirtualBox 1 Install VirtualBox 2 Create new virtual system: allocate part of RAM and disk space (VDI type) 3 Downloaded Ubuntu ISO image and install the system in VirtualBox via ”Start” button

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 28 / 138 Install Linux as Dual-Boot Machine

1 Free disk space in Windows May need to switch off (temporarily) disk encrypting, otherwise disk repartitioning won’t work Disk cleanup, including cleanup of system files (downloaded updates, old win versions, log files from upgrades, ...) Compress system files Disable hibernation (removes large hiberfile.sys file) Make small memory swap file (shrinks large pagefile.sys file) Make small space for restore points Make small shadow storage space Cleanup C:\SWSETUP which contains driver updates installation files Backup notebook recovery partition to USB stick and then delete the partition; not the ∼ (1 − 2) GB at disk beginning, but the (∼ (10 − 20) GB at the end ! → Can shrink Windows partition down to ∼ 30 GB (but will need USB for larger Windows updates) 2 Most distributions have (Live) CD/DVD/USB to start the installation Install the *.iso image on USB using Rufus program on Windows 3 No complications when following instructions... 4 However, it might be good to have partitioning of disk under control, instead of relying on the partitioning the Live Linux performs

⇓ ⇓ ⇓

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 29 / 138 Disk Repartitioning

1 Use Live Linux, e.g. specialized System Rescue CD using GParted program 2 Follow instruction to install on USB: With Rufus on Windows With dd if=name.iso of=/dev/sdX ; sync on Linux 3 May need to play with Boot/Startup sequence and with UEFI/SecureBoot in BIOS to allow boot from the USB stick 4 Most likely will have to create logical partition, since the default partition table does allow more than 4 primary partitions Windows, Windows recovery, Linux root, Linux home, swap

Partitions to create Root partition ’/’ of type ext4 and size ∼ (20 − 50) GB Home partition ’/home’ of type ext4 Swap partition of type swap > 2× RAM for small RAM systems (< 4 GB) > 1× RAM for middle-size RAM systems (< 8 GB) 0.5× RAM for large RAM systems (>√8 GB) and when hibernation-to-disk is not needed Ubuntu recommendations: SWAP = RAM when hibernation-to-disk is not needed, add 1 × RAM when it is needed

When touching (resizing) Windows partition, always make only one at a time and reboot to Windows for automatic check of the newly-repartitioned disk. Otherwise Windows may become unbootable ! (although there is a fix...)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 30 / 138 Troubleshooting

Dual-boot features May need to re-point WinRE (Windows Recovery Environment) to the correct partition on disk (usually is at the end of the disk) reagentc /info reagentc /setreimage /path \?\GLOBALROOT\device\harddisk0\partition2\Recovery\WindowsRE reagentc /enable Windows recovery to notebook factory settings may not work anymore Putting PC to hibernate on disk in both Windows and Linux at the same time may lead to loss of data if Windows disks are mounted in Linux

Linux boot recovery (Grub) May happen if / after reinstalling Windows Follow instructions at System Rescue CD

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 31 / 138 Linux Uninstall

1 Do not forget any data on your Linux disks :) 2 Set bootable flag (e.g. in GParted) program back to the Windows system partition 3 Install back the Windows Master Boot Record from within Linux (or Live Linux); several ways are possible, depending on what SW is available on your Linux (commands below to be run as root): A. dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/mbr.bin of=/dev/sdX (using syslinux package, mbr.bin may be located at different path) B. lilo -M /dev/sdX mbr (using lilo package) C. install-mbr -i n -p D -t 0 /dev/sdX (using mbr package) D. apt install boot-repair from ppa:yannubuntu/boot-repair repository 4 Boot to Live Linux (System Rescue CD) 5 Wipe data (rewrite with random contents) using schred / wipe commands shred -v -z -n 10 /dev/sdXY 6 Delete the Linux partitions and resize back the Windows one(s) Again, the deletion and resizing should be done in single steps, followed by reboots to Windows !

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 32 / 138 Linux Graphical User Interface and Software

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 33 / 138 Bootloader

Loader of the Linux kernel Most current Linux distributions use GRUB as the default bootloader It is loaded into the Master Boot Record of the disk Allows to load other systems too → dual-boot The installed systems are usually automatically recognized and added to the boot menu Allows to perform also memory tests Allows to add parameters to the kernel loading Allows rescue mode system load (e.g. when a disk fails to mount)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 34 / 138 Linux Kernel

Linux kernel is the core interface between a computer’s hardware and its processes Controls processes: create, stop, suspend, communicate, access to peripherals, ... Manages filesystems: allocation, freeing, protection, keeping consistency, ... Memory management: allocation, protection, swapping of unused memory to disk, ... Management of processes CPU time sharing: planning algorithm, assignment of time quantum, priorities, ... Can have installed several kernel versions for the same system; GRUB allows to choose the one to boot

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 35 / 138 Console and Virtual Terminals

Text-based interface to the system Provides a way for the kernel and other processes to output text-based messages to the user, and to receive text-based input from the user Works in parallel to the GUI Especially useful when GUI is not starting or not installed (servers) Limited support for localization, mouse and copy & paste; can be enhanced by SW packages as consolation or gpm

Switch between console and GUI (X-server) Virtual terminals: Ctrl+Alt+F1 (F1-F6) GUI: Ctrl+Alt+F7 (and above, if more X-sessions are running)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 36 / 138 Display Manager

X display manager is a graphical login manager which starts a login session on an X server from the same or another computer. Natural use of graphical applications on remote server Number of alternatives, distributions typically binds them with the used , resp. Some distributions prefer to use light Display Managers Choose user to login, Desktop Environment to start, switch to another user, reboot//sleep menu Analogy of the Windows login screen

Display Managers LightDM, SDDM, SLiM, LXDM, MDM (light display managers) Not all support remote logins KDM (KDE Display Manager) GDM (Gnome Display Manager)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 37 / 138 Window Manager and Desktop Enviroments

Window Manager (WM) is a system software that controls the placement and appearance of windows within a in a graphical user interface (GUI). It can be part of a Desktop Environment (DE) or be used standalone. One can install several Desktop Environments in parallel and test them. KDE and Gnome are the heaviest and most feature-full DEs Gnome3 / Unity - MAC like look Cinnamon - Gnome3 port with Windows-like look KDE - Windows-like look Mate - Gnome2 based Xfce4, LXDE/ - light environment, but still feature-full IceWM - extremely light Window Mananger

Native support for multiple desktops Applications can use different libraries for graphics decoration, typically unified for a given DE. However, the applications written for specific DE can still be used in other DE or WM.

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 38 / 138 GUI Features

Copy & paste in/from a clipboard Highlighting automatically copies highlighted text into clipboard Paste action is triggered by mouse middle button Most GUI applications support in addition Windows-like Ctrl+c & Ctrl+v Some applications (terminals, where Ctrl+c is reserved) support Ctrl+Shift+c & Ctrl+Shift+v Number of enhanced clipboard applications allowing to keep in memory multiple texts at one time

Drag & drop Drag and drop works for most graphical applications, but may not be available for the most simple Window Managers

Recycle bin The most complex Desktop Environments support Recycle Bin, but only for files deleted in their specific file-browser. Other file-browsers and especial deletion in terminal does not put files into the Recycle Bin → the files are instantly deleted. Moreover, the system may be configured from start not to use Recycle Bin at all

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 39 / 138 Quick list of Applications

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 40 / 138 Office Suites and Applications

Microsoft Office not available on Linux. However, there are number of alternatives: LibreOffice (former OpenOffice) fully included Gnome Office: Abiword, Gnumeric, Gnucash Suite (KDE focused office package) PDF viewers: : KDE PDF viewer, capable of adding annotations Evince: Gnome PDF viewer Old Adobe reader (needs special package repository) Foxit reader: not in package repositories, needs to be downloaded and installed manually Latex packages naturally included in all distributions, with number of graphical editors allowing to debug Latex compilation and preview generated PDFs. Texstudio Texmaker (KDE) Visual Studio Code + Latex plugin: free Microsoft product

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 41 / 138 Web-Browsers

The most common browsers are included: Firefox Chrome / Chromium Opera There are also DE specific ones: (KDE) Epiphany (Gnome) As well as terminal-based browsers (limited use only, no javascripts etc.): Lynx / Links / Elinks curl / wget Useful for scripts to extract information from web

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 42 / 138 File-Browsers

Number of file browsers, usually specific to DE: (KDE) Nautilus (Gnome) Thunar (XFce4) : KDE-based browser with Total Commander like look and features Midnight commander: terminal based 2-panel file browser (Norton/Total Commander like); very useful when working on remote machines as it does not need to transfer graphics

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 43 / 138 Terminal Emulators

Number of terminal emulators, usually specific to DE: : basic terminal emulator rxvt-unicode: basic terminal emulator with unicode support : KDE-based terminal emulator, support for tabs, complex configuration including predefined profiles etc. -terminal: Gnome-based terminal emulator, support for tabs, complex configuration including predefined profiles etc. xfce4-terminal: Xfce4-based terminal emulator, support for tabs, complex configuration

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 44 / 138 Editors

Editors for programmers with various level of IDE: : KDE based KDevelop: KDE based Geany: Gnome based Eclipse: heavy, Java based Gedit: light Visual Studio Code: Microsoft product, but open-source and free use (both home and commercial) Console editors (useful when working on remote machines): nano: simple jed: simple vim: very powerful, but difficult for beginners emacs: very powerful, but difficult for beginners

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 45 / 138 Multimedia

Figures: / Gthumb as picture viewers Gimp for bitmap drawings editing Inkscape for vector drawings editing Video: VLC SMplayer Xine Number of command-line programs for figures/audio/video conversions and processing convert for figures manipulations ffmpeg for audio/video manimulation

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 46 / 138 Emulators

Emulators of other (usually older) operating systems: Wine: emulator of Windows, many Windows applications able to run on that (not the complex ones as MS Office) DosBox / DosEMU: MS DOS emulators

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 47 / 138 Filesystems

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 48 / 138 Filesystem

System defining the way files and directories are stored on the physical disk

Command to show this file information: stat

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 49 / 138 Filesystems Overview

FAT: File Allocation Table The original MS-DOS filesystem, tree structure MS filesystems in Linux Limited depth of sub-directories, limited filename lenght Linux can work with all Follow-up systems: FAT8/16/32, VFAT, exFAT of them (R/W). VFAT and exFAT are nowadays used on external/flash USB disks MS formats are not NTFS: NT File System open =⇒ reverse First appeared on Windows NT engineering Current MS filesystem on Windows Support for the newest ISO9600: Read-only files system for CD/DVD exFAT is yet somewhat Limited subdirectory length, limited filenames experimental Enhanced systems: Joliet, ElTorito, Rock Ridge Journaling filesystems on Linux Keeps track of disk operations not yet performed / finished Minimizing loss of data

Swap Enhancing RAM of the system When RAM gets full, swap is used to store temporarily unused data No special structure Windows equivalent: pagefile.sys

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 50 / 138 Filesystems in Linux

Ext2, Ext3, Ext4: The most common on Linux Ext3 = Ext2 + journal Ext4 allows for larger files and for more files per dir (32000 vs 64000) XFS: Silicon Graphics for the OS IRIX Good performance for large data handling ReiserFS, Reiser4: Good performance for large number of small files Connecting advantages of filesystems and databases Developed by Hans Raiser (in 2008 convicted murderer)a JFS: IBM for the OS AIX and later for OS/2 and Linux First journaling system AFS: Andrew File System Distributed file system for large networks of servers and client workstations

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 51 / 138 Fragmentation

No defragmentation on Linux MS filesystems need occasional defragmentation: Files are placed to the next free sector on the physical disk =⇒ when a file is enlarged, the next sector of physical disk is usually already occupied by another file =⇒ file fragmentation Linux filesystems defragment on the fly: Files are placed on distant sections on the physical disk =⇒ space around existing file is usually free If there is a danger file would become fragmented, the system tries to find a continuous space on the physical disk and moves the file in there Fragmentation thus appears only when disk is close to full

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 52 / 138 Linux Files

Directory (d): container of files Plain file (-): ordinary file (collection of bytes) Symbolic link (l): analogy of hypertext link or shortcut in Windows Hard link: similar to ordinary file, just another name for one file Block and character device (b,c): representation of HW devices Name pipe (p): named pipes for communication between applications instead through RAM Socket (s): duplex communication between processes

List files using command ls -lah

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 53 / 138 Structure of Directories in Linux

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 54 / 138 Directories and files in Linux

Physical disks not visible in the structure (no C: and D:), disks are mounted to directories (admin can define what is mounted where) e.g. typically ”disk D:” is mounted to /home directory with users data Using ’/’ (slash) instead of Windows ’\’ (backslash) Linux filesystems (like ext4) features: Directory and file names are CaSe SeNsItIvE Native support of access control (user/group/all, read/write/execute) Links (a bit similar to shortcuts in Windows, but for applications behave as real files) Hidden dirs and files starting with dot (.*, e.g. .config), usually keeping configuration of applications Special files representing e.g. HW devices and their configurations Special directory names: Root directory ’/’ (top directory of the Linux system) Home directory of a user ’~/’ (representing typically /home/username) Current directory ’./’ Directory one level up ’../’ Absolute paths starting from root of the system / Relative paths from current directory (may or may not start with ’./’) Text files has different standard for end-of-line (EOF) code from Windows/DOS/Old MACs Conversion via commands dos2unix and unix2dos

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 55 / 138 Diagram of the Directories

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 56 / 138 Linux Root Directory

/ Snapshot of top directories in Linux and Windows 10: bin boot dev etc home lib* lost+found media mnt opt proc root run sbin snap srv sys tmp usr var

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 57 / 138 User Home Directory

/ bin /home boot Home directory of users in /home/$(USER) dev Place used by all ordinary users to store data, configurations, etc possibly also local applications home Other users can usually read files of other users, unless manually lib* disabled lost+found /home/$(USER)/Desktop: Any file/directory placed here will appear media on GUI desktop mnt /home/$(USER)/.*: User configuration files of various applications opt Especially in .config subdirectory proc Files associations, user shortcuts etc. in .local/share/ root (applications) subdirectory run Analogy of C:\Users, resp. C:\Documents and Settings in Windows sbin snap /root srv Home directory of administrator (superuser/root user) sys Same structure as for users in home/$(USER) directory tmp usr var

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 58 / 138 Application Installation

/ bin Ordinary application files boot Executable files in /usr/bin dev Data files in /usr/share etc Documentation, licence, examples etc. in /usr/share/doc home Manual pages (help) for executables in /usr/share/man lib* Libraries in /usr/lib* lost+found Header files of libraries in /usr/include media mnt System application files opt Executable files in /bin proc root Superuser executable files in /sbin and/or /usr/sbin run /etc: Configuration of the system (services) and applications, common for all users sbin etc/default: Most common default settings snap Analogy of Windows registry srv sys tmp usr var

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 59 / 138 Application Installation (Special, Local)

/ bin Local installations boot Usually not going through the ordinary package system, but directly dev copied to the system etc These programs and libraries placed in /usr/local home Contains similar sub-structure as the root / and/or /usr lib* directories lost+found I.e.: etc, bin, lib, share, ... media mnt 3rd party / commercial applications opt Whole application stored in /opt, with links to /usr/bin etc. proc /snap stores distribution-agnostic applications root All dependencies (libraries etc.) are included run sbin snap srv sys tmp usr var

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 60 / 138 Boot, Linux kernel, devices

/ bin Boot configuration in /boot boot Linux kernels to boot dev Configuration of the boot manager (GRUB) etc home Linux kernel modules and source lib* Linux kernels sit in /boot lost+found Linux kernel modules in /lib/modules media Linux kernel source code in /usr/src mnt opt Hardware devices and processes proc Connected HW devices represented by special files in /dev root Storage devices to mount run Dustbin /dev/null sbin Console, random generator device, ... snap Configuration of the HW devices in /sys, superuser can use the files srv to modify the configuration of the HW drivers sys /proc directory keeps information about running processes, HW tmp configuration (memory, cpu) usr Interface to the kernel internal data structures var Runtime information about processes in /run (e.g. connected WiFi)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 61 / 138 Storage devices

/ bin Lost files boot Lost and recovered files after OS crash dev etc Storage devices connected to the system home Removable devices usually appear in /media, lib* resp. /media/$(USER) lost+found Modern distributions connected them (mount) automatically media Windows partitions, network storages etc. are usually mounted to mnt /mnt opt Follow rules defined in /etc/fstab file proc And/or rules for auto-mounting in /etc/auto* files root run sbin snap srv sys tmp usr var

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 62 / 138 Boot, Linux kernel, devices

/ bin Temporary application settings in /var boot /var/cache: Temporary files of applications, e.g.: dev Downloaded installation packages of apt system in etc /var/cache/apt/archives home /var/lib: Variable system information, e.g.: lib* Network connections lost+found Installed packages info in /var/lib/dpkg/info media Content of package repositories in /var/lib/apt/lists mnt /var/spool: Data awaiting further processing, e.g.: opt E-mails proc Print jobs root /var/log: System log files: run Crucial for administrators Boot, kernel messages, logins, services (e.g. WWW servers) etc. sbin /var/www: WWW server data snap srv /var/lock: Application and system lockers sys Temporary files in /tmp tmp usr Temporary files of applications, e.g.: var Opened / downloaded files from web-browsers Archives unzipped in file-browsers

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 63 / 138 Users and Groups

Users and Groups: /etc/passwd: users configutation: home, shell, title, uid /etc/shadow: users password hash /etc/groups: groups Superusers: su / sudo (-i) su needs further config to run graphical applications visudo separate home dir in /root

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 64 / 138 Work with the Command Line in Terminals

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 65 / 138 Command Line

Very powerfull in Linux, allows to master the OS Commands are taken by a shell and given to the OS Allows complicated scripts including loops, macros, conditions, etc. Several shells exists: bash: most commont dash: minimalistic, for system scripts zsh: programmers focused ksh: csh: different syntax from bash-like shells above tcsh: enhances csh fish: friendly interactive shell chsh command to change user shell

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 66 / 138 Shortcut Keys

Left/Right/Home/End: navigate cursor through the command line Up/Down-Arrows: browsing through history of commands Tabulator: complements commands or file names Search for commands in the standard executable paths Shows all possibilities in case the completion is ambiguous Possibility to enhance completion for specific commands (ssh and remote host names etc.) Ctrl-r: search in history of commands backward Ctrl-s: search in history of commands forward Ctrl-g: end of search (not-only search) mode Ctrl-l: clear terminal window Ctrl-q: unblocks blocked terminal Some terminal emulators get blocked with the Ctrl-s command Ctrl+c: interrupt running process Ctrl+d: interrupt writing into file (e.g. in cat > filename)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 67 / 138 Shell Settings

Configuration / startup files: /.bash history: history of commands /.bashrc: startup script for non-login interactive shells /.bash profile: startup script for login shells (login in text console or from remote host) /.profile is read by bash too, to be backward-compatible with old sh /etc/profile: system-wide /etc/motd: message on login shells Other shells have similarly-named files Typical configurations in /.bashrc: Format of command prompt: PS1 (also PS2-PS4 for 2nd etc. level of prompts) PATH to executables PATH to 3rd party or local libraries (LD LIBRARY PATH) Enhanced completion and other plugins (e.g. list of commands in not-installed packages) Aliases (alias/unalias commands) Default limits (ulimit command) Environmental variables / program setups (export | less) History length

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 68 / 138 Commands in Linux

Programs available in shell or in the executable PATHs. General structure: [path/ ]command [options ][arguments ] List of options and arguments (e.g. for systemctl command): command --help, resp. command -h: basic syntax and options of the command man command: manual pages with more detailed info info command: interactive manual pages (jump to references etc.) command -v. resp. command --verbose: be verbose about what is being done Run in background, while continuing work in shell: command ... & fg: Put command already running in background back to foreground of the shell Ctrl+z: Suspend process / command (stops processing) bg: Put command into background (typically used to let suspended command running again in the background) When command / program ends, it usually returns a return code 0 ... usually means ”no error” non-zero is usually indication of premature exit of the command because of some problem Find full path to a command: which command (or search for it in aliases: command alias lists existing aliases)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 69 / 138 Scripts: Basics

Sequence of commands can be put into script files. # are used for comments Special header ”comment”: #!/usr/bin/zsh instructs the script to be run by the zsh shell. Not only for shells, but also for interpreters like python exit [number ] to quit script [and possibly return a return code ] Not needed at the very end of a script, it will end by itself set -x command inside a script instruct to show the commands being run by the script Two ways how to run a script: ./script.sh: starts a new shell and runs the script in it source ./script.sh (or also . ./script.sh: runs the commands from the script one by one in the current shell → i.e. as if one would write them manually in the current terminal PS: The ’./’ makes sure it runs script.sh in the current directory, and not somewhere from the $PATH paths

#!/bin/sh echo $SHELL sleep 0.5

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 70 / 138 Commands: User Information

login: Login user to the session, normally not directly invoked logout: Logout user from the session exit: Exit from the terminal/shell/script id [user]: User and group id information about myself groups [user]: List groups user is in whoami: Return user-name who: Show who is logged in w: Show who is logged in and what is he/she doing last: Show list of last logged-in users su/sudo: Become superuser su - to make sure superuser paths are set sudo -i to start superuser shell

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 71 / 138 Commands: File / Directories

ls [path/file]: List files/directories ls -1: List one file/dir per line ls -l: List full information:

-rw-r--r-- 1 reznicek reznicek 15360 Oct 14 19:40 osnova_Uvod_do_Linuxu.doc drwxr-xr-x 18 reznicek reznicek 4096 Jan 31 2019 skola

File type (file=’-’, dir=’d’, ...), access rights Number of links (copies) User name Group name Size in bytes Date and time of last modification File name ls -h: Human readable file size ls -a: List also hidden files and directories (.*) ls -d: Show information about directory instead of listing its content ls -R: List recursivelly also content of sub-directories ls -t: Sort by modification time ls -r: Reverse sort order (name, time) stat file: Disk-storage info about file Physical place on disk Creation, modification and access times

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 72 / 138 Commands: File / Directories

cd [path]: Change directory cd ../: Go one directory up cd ./: Go to (stay in) current directory cd /: Go to root (top filesystem) directory cd /, cd: Go to home directory cd -: Go to previous directory (back from last cd command) Change directory relativelly to the current dir or absolutelly specified path from the root dir relative path example: cd work/papers or cd ./work/papers absolute path example: cd /home/username/work/papers pwd: Print current directory readlink -f file: Print full path to the given file cat file: Dump content of file on the screen less file: Browse file content on the screen Enhanced more command (also on Windows) Search for content (’/’ key) touch file: Update modification time diff file1 file2: Show difference between two files, GUI versions exist too (meld, diffuse) File and directory manipulations (see later lectures in details): cp, mv, rm: copy, move/rename, remove files mkdir, rmdir: create directory, remove (empty!) directory Terminal-based file browser: mc

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 73 / 138 Work on Remote Machine via SSH

Secure Shell Connection, assuming the host PC is running sshd server (just install the ssh-server package...)

Client can: ssh -Y username@hostname Gains access to login shell on remote machine Can send graphical windows (e.g. xterm) -Y allows to transfer graphics With sudo/su commands can manage the computer (including reboots, poweroff etc.) Configure automatic options for ssh via $HOME/.ssh/config file:

Host lxplus user reznicek Hostname lxplus.cern.ch Host ipnp-stick User mlive Hostname 10.77.0.11

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 74 / 138 Manipulation with users and groups

Users: Users stored in /etc/passwd

student:x:1001:1001:Student linuxu,T11,1234,5678,Poznamka:/home/student:/bin/bash

adduser: add new user, copy /etc/skel content to the newly created home directory. Default options in /etc/adduser.conf deluser: remove user (home directory is kept by default) usermod: modifications to user settings (home dir, id, password-expiry, groups, shell, lock-password) chfn: changer user information (full name etc.) passwd: change user password chsh: change user shell Groups: Groups stored in /etc/group groupadd: add new group groupdel: delete group groupmod: name, id gpasswd: groups can have passwords, administrators

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 75 / 138 Change ownership of a file/dir

Users: chown username:groupname file: change user and group ownership of a file/dir chown -R: recursively for all sub-directories chown --dereference: for symbolic links ”jump” to the real file the link is pointing to chgrp groupname file: changer group ownership of a file/dir Username change mostly only for superuser, user cannot ”give” file to another user. But owner can modify group =¿ give file for r/w to other users via groups

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 76 / 138 Change read/write/execute/access rights to files/dir

Command chmod chown ugoa+/-rwxst file u: user rights g: group rights o: rights of others a: rights of all (user, group, others), not specifying who defaults to ”all” +: add rights -: remove rights r: read rights w: write/modify rights, for dirs only works when ’x’ is set too x: executable (file), directory enter and listing allowed (directories) s: setuid bit, allows to run command with file-owner privilegies (/etc/passwd) t: sticky bit for directory (o+t): everyone can create files, but files can be deleted only by the owners (Despite the ”xw” rights for all in the directory - e.g. /tmp)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 77 / 138 Change read/write/execute/access rights to files/dir

Command chmod chown 0644 file Rights can be also defined by octal numbers: 777 = (binary) 111 111 111 = rwx rwx rwx Default permissions driven by umask (022 = files ar 644, dirs are 755 =¿ i.e. it is subscracted from 666 and 777) Some filesystems support more advanced file-atributes (e.g. immutable, nodeletable, no copy, no write, ...) via commands chattr (and listing these attributes via lstattr)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 78 / 138 Processes in Linux

Running applications and system processes can be inspected, killed, ... (aka TaskManager in Windows) ps axuf | less: inspect currently running processes (one-time) top, htop: online inspection of processes Frequency of update Search Sort by memory usage instead of CPU Can kill or change priority of a process kill, killall, xkill: kill process or application nice, renice: change application priority (0 by default, only root can increase it) Priorities: -20 ... 19 nice -12 large-job: run large-job with priority 12 nice --12 large-job: run large-job with priority -12 renice 17 -p 1134: change priority of process with id 1134 to 17 cpulimit: limit cpu usage of a process ulimit, unlimit: limit resources for a process (resp. in active shell): e.g. memory, number of opened files, ... User can’t override defaults in /etc/security/limits.conf ulimit -a: see current limits unlimit: set limits to the system defaults (not further limits for user) ulimit -Sv: limit memory usage in kilobytes

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 79 / 138 GUI processes

xrestop: GUI processes xkill: GUI kill : Change GUI window position, size, etc. xev: Monitor / debug key press (special keys) xprop: Properties of GUI window xdotool: Properties of GUI window, including emulation of keyboard/mouse

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 80 / 138 Other resources monitoring

iotop: Disk usage per process jnettop: Network usage

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 81 / 138 Administration

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 82 / 138 Power and Services

In general: search for solutions of problems e.g. at stackoverflow.com, but be careful advices include modification of system files (configs are OK; reshufling binaries, libraries etc. NOT) shutdown, poweroff, halt, reboot, hibernate, hibernate-ram, hibernate-disk, s2disk, s2ram systemctl command: list-units: list running system services stop, start, restart: handle given service, only works till restart disable, enable: enable/disable service completely (even after restart) System configuration: in /etc directory most common default options in /etc/default directory Logging of system events: in /var/log directory syslog, daemon.log, messages, kern.log, debug: system messages auth.log: info about logging of users (including virtual ones) Xorg.0.log: log of the GUI system Log files are usually backuped per month and started freshly again (/etc/logrotate.conf, /etc/logrotate.d)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 83 / 138 Hardware

Handled by the Linux Kernel (includes HW drivers) Info about HW in pseudofiles: /dev/*, /sys/*, /proc Commands to list HW: lspci: HW connected to the PCI bus lshw: detailed info about all HW lsusb: USB devices lsblk: Block devices (disks) lsscsi: SCSI devices (CD/DVD) Adding removing driver (= kernel module): lsmod: list loaded kernel modules modinfo: detailed info about kernel module modprobe: add, or remove (-r) from kernel insmod, rmmod: simple add / remove module from kernel PS: Not all drivers are as separated modules, but can be builtin in the kernel =¿ the only way to disable them is via kernel option in GRUB boot loader Configuring kernel modules: /etc/modules: force load of kernel modules not picked up automatically (special HW, very new HW, ...) /etc/modprobe.d: add options to drivers, blacklist drivers

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 84 / 138 Network

Nowadays most systems use NetworkManager (NM) application to handle the net connection /sbin/ifconfig: Show info about network devices and connection (IP address, MAC address) NM allows complex configuration, including scripts NM recently generates random WiFi MAC address for security on public sites: might need to be disabled in corporate networks through /etc/NetworkManager settings Useful commands: ping: Check remote host is online traceroute: Show full communication path to remote host ssh: connect to remote host via Secure Shell ftp, sftp, scp, nfs: copy files from/to remote host (see later lectures) netstat: info about connections, opened ports etc. (netstat -natulp | less)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 85 / 138 Print

The linux system mostly rely on CUPS printing system: /etc/cups: configuration of the print client and server localhost:631 in web-browser: WEB-based configuration of CUPS However, recently some GUI applications can ignore CUPS settings and search for available printers by themselves...

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 86 / 138 Automatic tasks in background

CRON system: /etc/crontab: basic file to run tasks per hour/day/week/month /etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly /etc/cron.d: more complicated rules

# /etc/cron.d/renew_prak0x: crontab entries for reweval of the prak0x user home directories # Execute only during the period of the exercises (01.Oct - 20.Jan) # TODO ?: Add entry in between day in case of 2 excercises per single day SHELL=/bin/bash # m h dom mon dow user command 32 01 * OCT,NOV,DEC,JAN SUN root /home/prak_template/bin/reboot.cron.sh # NO!!! (studenti by po rebootu nenasli sva data !) #@reboot root /home/prak_template/bin/renew_prak0x.cron.sh 12 03 * OCT,NOV,DEC * root /home/prak_template/bin/renew_prak0x.cron.sh 12 03 1-20 JAN * root /home/prak_template/bin/renew_prak0x.cron.sh

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 87 / 138 Packages (Ubuntu/Debian based distibitions)

APT system to download and install packages from repositories apt-get, aptitude: commands to run the tasks (install, remove, update package list) /etc/apt: configuration of the packaging system Temporary files (package list, downloaded installation files) in /var/lib/apt/lists and /var/cache/apt files Dependencies are flagged as auto-installed (/var/lib/apt/extended states Simulate action (complicated upgrades): apt-get -s DPKG is used to handle already installed packages: -i: install local package -r/-P: remove/purge installed package (purge = remove also config files) Allows to install even conflicting packages (--force-depends, --force-conflicts): use with care ! Packages can ask for configuration options during installation process, reinvoke these questions by dpkg-reconfigure command Packages can provide ”alternatives” for similar tasks: update-alternatives command to handle these selections

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 88 / 138 Security

Linux on net is also target of attacks, especially through the ssh connection sshguard: service that stops ssh login after several failed attempts rkhunter: complex check of the most important system utilities chkrootkit: simple check of most known ”viruses” in the system utilities logcheck: scans log files and reports suspicious activities Many of these commands are set to run regularly and send reports by e-mail to the system admin (see /etc/aliases file)

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 89 / 138 Exercise 1

Write list of commands ala simple script, which will: List content of the /etc directory List file info of /etc/passwd (size, access rights etc.) Copy the file /etc/passwd to your home (hint: using cp /etc/passd /passwd.copy) Add new user named ”ukolvT11” Check by ls command that the file /etc/passwd has changed size etc. Use diff command to show difference between the /etc/passwd and /passwd.copy Change ”shell” of the new user from /bin/bash to /usr/bin/zsh (hint: chsh) Change access rights of the /passwd.copy file so that no-one can write into the file and only the owner can read it (nor group, nor others) Change the ownership of the file to the superuser root and group root Check by ls command that you can’t read this file now Remove the recently added user ”ukolvT11” Check by diff command that the /etc/passwd and /passwd.copy are same again Make sure the script has a header that to be run in shell /bin/bash. Use sudo on appropriate lines (not all operations above will be allowed to you as an ordinary user).

Husz´ar, Rezn´ıˇcekˇ Linux: Introduction NOFY077 October 23, 2019 90 / 138