Linux Basics/Printable version


Linux Basics

The current, editable version of this book is available in Wikibooks, the open-content textbooks collection, at
https://en.wikibooks.org/wiki/Linux_Basics

Permission is granted to copy, distribute, and/or modify this document under the terms of the Creative Commons Attribution-ShareAlike 3.0 License.

Types of Operating Systems

What is an operating system?Edit

An Operating System (OS) is software that manages computer hardware and other software.

It's commonly portrayed as the bridge between hardware and software. For a more detailed definition see Operating system

What operating systems can beEdit

Different operating systems look, function, and are used differently. For example:

  • The interface can be graphical (GUI) or command-line (CLI)
  • It could be used as a server, desktop, internet route, appliance, etc.
  • It could support just a single-user, or multiple-users (Also known as multi-user)
  • It could support running just a single task at a time, or multiple tasks (multi-tasking).

Let's look at these different options in more detail:

  • Command-Line (CLI): Text based user interface
    • Present in almost every OS
    • Allows for flexible command input and automation (executing scripts)
    • Fast
      • Fast Computationally - Excels on computationally constrained hardware or when every bit of performance is needed.
      • Many tasks are faster when performed through a CLI compared to a GUI.
  • Graphical User Interface (GUI): Icon, Widget, and Audio-based user interface
    • More Intuitive for many
      • Generally more approachable for new users, less instruction is required to train a user to use a well designed GUI.
      • Literacy is not necessarily required to use a GUI, an important consideration in some educational environments.
    • Some operations are faster than in a CLI without a prior script being made.
      • Automation is still possible, though often requires a third party program.
      • Almost always more computationally expensive then a CLI in terms of computer resources.
  • Single task: 1 task/ program can be run at a time
  • Multi task: Multiple programs can be run at a time
    • Preemptive: the OS can take resources
    • Cooperative: it only works if every resource is available
  • Single-user: Only one user can be handled at a time.
    • Some single user operating systems allow for different user profiles, but lack the ability to run programs from multiple accounts at once.
  • Multi-user: Multiple user accounts can be created and used simultaneously.
    • Multiple users can use the system simultaneously. This can be through a user locking their session to allow another user to log in on a traditional desktop while their applications continue to run in the background, or have two users literally logged in and operating at the same time in the case of a multiheaded system.
    • Filesystem must support the convention of user separation (so FAT16 and FAT32 are excluded, but EXT2,3,4; NTFS and modern FS's support it).
    • A long time ago this was not the case, so users could exploit others on the computer. Nowadays it's near impossible to get access to other users' directories.

Types of OSes by CapabilitiesEdit

DOSEdit

MS-DOS, and Windows based on it (from 1.01 to ME):

  • CLI , with GUI as a bolt on add on with Windows
    • Vanilla MS-DOS is a pure CLI.
    • Early versions of Windows were simply graphical environments added on to MS-DOS, or later integrated with it. These versions included a program called MS-DOS Prompt to create CLI shells.
  • Single-user. Some versions allowed multiple user accounts, but were unable to allow them to be logged in simultaneously.
  • MS-DOS cost money back in the day, and is typically no longer sold in stores.
    • MS-DOS software is sometimes compatible with other DOS operating systems, some of which are still developed to this day.
  • Security issues, general obsolescence, and a lack of network focus make MS-DOS a terrible server or even networked operating system. MS-DOS can still work fine on offline machines.

Windows NTEdit

Windows NT (Windows NT 3.x – 11):

  • GUI with de-emphasized CLI.
    • Most tasks in Windows are performed using the GUI.
    • CLI environments such as the basic Run and Command Prompt applications are typically included.
    • More recent versions of Windows offer the more advanced and capable Power Shell application.
  • Multi-user (here the user folders are encrypted, so you can't get access to others' folders without proper right)
  • You typically have to pay for it, or be eligible for special promotions or offers.
  • There are server and desktop versions. There are further sub versions which target different market segments.

Unix and CompatiblesEdit

Linux:

  • CLI with optional GUI.
    • Some Distros are CLI only, especially those intended to be used on servers or embedded devices.
    • Most desktop distributions use a GUI by default with a de-emphasized CLI. Others try to strike a balance between the two.
  • Multi-user, so multiple user can be on the network, the folders can be encrypted, permissions can be set, widely customizable (both program- and interface-wise).
  • It's free as in freedom, and often free as in beer so you don't typically have to pay for it.
    • Most distributions are free.
    • For some enterprise distributions, such as Red Hat Enterprise Linux, you pay to get it directly from the company that makes it, and to get support.
  • There are server and desktop oriented distributions.

UNIX:

  • The BSD family includes a number of open source operating systems, as well as closed source operating systems.
  • There are a number of proprietary UNIX operating systems, such as Solaris (A direct UNIX descendent) and MacOS (Related to BSD).

Other: There are a few other UNIX-like operating systems you may read about while studying Linux

  • GNU Operating System - Many coreutils for Linux originated here.
  • MINIX - Important influence in the history of Linux, and still used in some applications.


Fundamental conceptions in Linux

DistributionsEdit

By itself Linux is a Kernel - the core component of an operating system. However other components are required to make a full operating system. A Linux Distribution, or Distro for short, includes all the components needed to form a full operating system. Because there are a number of different component options to choose from, each Linux distro offers a unique spin on Linux, and are often specialized for handling certain tasks.

Distribution componentsEdit

User Interface / ShellsEdit

Command Line InterfaceEdit
  • BASH
  • ZSH / Z Shell
Graphical User InterfacesEdit
Desktop EnvironmentsEdit
  • KDE, Gnome, MATE, Xfce, Cinnamon, LXDE, LXQt, Pantheon, Budgie stb.
Desktop ManagersEdit
  • Desktop Managers: SDDM, GDM, LightDM

Package ManagerEdit

RPM: Red Hat, Fedora, CentOS, openSUSE stb.

DEB: Debian, Ubuntu, Linux Mint, MX Linux stb.

repository: container; programs and drivers can be found for the distros

package manager: it solves the dependency tree if there is an compatibility issue.

Common distributionsEdit

Red Hat Enterprise LinuxEdit

Red Hat Enterprise Linux (RHEL) is one of the most successful Linux distributions which is developed by Red Hat for commercial usage.


Official support for RHEL is available, and while support costs money, it is generally well regarded.

Package Manager: RPM - RHEL is the original home of RPM, and remains heavily associated with it.

Default User Interface: GNOME

FedoraEdit

Fedora is a community distro associated with RHEL.

Unlike Red Hat Enterprise Linux, Fedora is gratis, costing no money.

Cutting edge features are often implemented in Fedora before they are added to RHEL.

Package Manager: DNF (RPM based), Flatpak

Default User Interface: GNOME (Wayland based)

SlackwareEdit

Slackware is the oldest Linux distribution under active development. The first version was released in 1993, based on the wide spread SLS Linux, and used floppy disks as an installation medium in the beginning.

Slackware pursues simple usability, stability and security as its main goals. It doesn't have automatic dependency handling. The aim since its release to become the most Unix-like Linux distribution.

Package Manager: slackpkg

Default User Interface: Bash

DebianEdit

Debian is one of the oldest Linux distros. It was announced on August 13, 1993 by Ian Murdock. The word Debian comes from Debora (Ian's wife) and Ian's name.

Debian is not commercially oriented. In contrast to RHEL, the distro is driven by volunteers.

Debian is a solid and reliable operating system. Because of this, it serves as the foundation of many distributions like Ubuntu and Knoppix.

Package Manager: APT (dpkg)

Default User Interface: GNOME or XFCE

UbuntuEdit

Ubuntu is one of the most popular distributions, which has been developed by Canonical Ltd. since 2004.

The first release was 4.10 and since then, in every 6 month a newer version and in every 4th month of even year a Long-Term Support releases.

Package Manager APT, Snap

Default User Interface GNOME

Arch LinuxEdit

Arch Linux is an independent distribution for advanced Linux users.

It has rolling-release model, which means that it updates continuously instead of bigger releases.

Package Manager Pacman - Arch's own package manager

Default User Interface Bash

OpenSUSEEdit

OpenSUSE is the sequel of SUSE Linux and it's a project which promotes of using Linux ensuring by this a free and complete distribution to the users.

Package Manager: ZYpp

User Interface: Selectable from major GUIs on install, including GNOME, KDE, and XFCE.

GentooEdit

Gentoo Linux is a flexible, fast distribution using Portage package manager.

In contrast to other distributions, you have to compile the whole system from source, so the installation process may take hours depending on hardware.

Package Manager: Portage

Default User Interface: Bash

Tux the PenguinEdit

The mascot of Linux is Tux, the penguin, which was planned by Alan Cox and Linus, and was drawn by Larry Ewing.[1]

HistoryEdit

Why Linux? Linus Torvalds showed that MINIX isn't available for x86(it was only available for education purposes), so he programmed a kernel for x86.[2]

In 1991 Linus Torvalds was sophomore student in University of Helsinki at the faculty of Computer Sciences. He was a self-educated hacker, and wanted to write his own operating system, so he decided to write one. Why? He wanted to explore the Intel 80386 CPU's protected mode, task-switching capabilities. That was around the summer of 1991.

GPL - The GNU General Public License is a widely used free software license, which was created by Richard Stallman for the GNU Project. The aim of GNU GPL is to grant the copying and distributing of free software ensuring the free use of the software for every user.

Linux is surrounded by shells - command prompts, and X Window System can be built on it.

What are Linux distributions/distros? Operating systems that has Linux kernel under the hood. Under the list there are some examples. You can find all the others on Distrowatch.com with ratings for each one.


SourcesEdit


Distributions for beginners

Which distributions are recommended for beginnersEdit

Because Linux isn't developed by companies but volunteers who distribute the code under GPL v2,[1] so there are many distributions (Operating Systems) based upon Linux kernel (so not only Ubuntu exists :) ) This chapter aims to help the beginners which distribution to choose. I shorten distribution as distro this time.

  1. Ubuntu Linux
    Ubuntu Linux is one of the most supported desktop Linux distributions. Its UI may be confusing for users coming from Windows, because by default the buttons in the titlebar are Mac-like. It comes with GNOME by default, but you can download it with XFCE, KDE Plasma, LXQt, MATE, Budge (and there is also Ubuntu Studio for professionals and Ubuntu Kylin for the Chinese). More info: Ubuntu flavours It comes with Debian's package manager (apt) but it's incompatible with Debian backwards.
  2. Linux Mint
    It's an Ubuntu fork, its aim is to grant an easy to use environment for those who come from Windows. The developers of Linux Mint develop the Cinnamon Desktop Environment and the programs associated with it. You can download Linux Mint with MATE and Xfce too. It relies only on Ubuntu LTS versions, so the software it uses remains on relatively stable versions.
  3. Manjaro
    It's based on Arch. If you want to get to know how does Linux work, and it's not a problem if the system breaks, and you need to fix it, then you should try it out hence you learn new things when you fix an update. Don't forget, you can ask help from the community anytime which is recommended, because you learn a lot from it. It uses pacman package manager, so problems can occur with the updates, so you may need manual intervention for installing the update, but you can learn by that too. The Arch User Repository (AUR) is a container where anyone can put packages, but you have to compile it from source. AUR packages have often problems but you can learn also by fixing them. It's a rolling release, which means it's enough to install it once and it updates to the latest version of every programs, so you don't have to reinstall at distro version update. The community is friendly and helpful.
  4. MX Linux
    MX Linux is on the first place of Distrowatch probably since 2018. The reason is that it's very easy to use, and there are so many programs in MX Tools which helps you a lot (like USB writer, desktop arrangement, MX Package installer which is very easy to use). It comes with Xfce only. It's compatible backwards with Debian, because it's a Debian stable fork.
  5. Solus
    It has a rolling release model (so it gets the updates continuously like Manjaro), but it's very stable. It has its own driver manager. Its drawback is the community, because it's not the friendliest, so you should ask for help in distro-independent communities if not Solus-specific is the problem.

GalleryEdit

ReferencesEdit


Installation, bootloader

InstallingEdit

There are a variety of ways to install Linux on a computer. Traditional installation methods for a desktop Linux environment can be either graphical or terminal based.

Installation media refers to the delivery method of the operating system. Common installation media includes USB storage devices or DVDs. Installation can also be done virtually, such as in the case of a network installation.

Linux distros can be installed directly on a computer as the sole operating system or installed alongside another operating system such as Windows or another installation of Linux.

Linux can even be run under a different operating system through the use of a virtual machine. By using software such as GNOME Boxes, Virtualbox, or VMware, a virtual machine can be created to install and run Linux on, while simultaneously running the original operating system, such as Windows, MacOS, or even another Linux distro. One can think of a virtual machine as a way to simply run Linux as one would run any other program, such as Firefox or LibreOffice.

Installers for Linux distributions come in a variety of forms. Below are two screenshots of installers, showing both a friendly graphical installer, and a powerful command line installer.

The BootloaderEdit

 
A simple GRUB configuration.

Bootloaders are programs that help the computer start up and prepare an operating system. Sometimes known as system loaders, one can compare bootloaders to the starter of a car or an usher at a theater showing you to your seat.

One of the most common bootloaders used on desktop Linux is GRUB. With GRUB you can give boot parameters to determine which operating system should boot up. GRUB also has additional features, including a memory test and hardware test, which checks if the computer hardware has any errors.

Bootloader can be installed on HDD in case of MBR, e.g. /dev/sda (first HDD), in case of GPT you can give which partition would be the "BIOS boot" one (e.g. /dev/sda3 - first hard disk's third partition), so the bootloader will be installed to the location which we picked.


Package management

What is Package Management?Edit

With package management, a special program called a Package manager is used to install, update, and remove applications. While it's still possible to install programs outside the package manager, the package manager can reduce the day to day work of the user, making it ideal for most software installations on a Linux based system.

One way to think about package management is to compare using an app store instead of downloading a program executable (Like a .exe) from a website. App stores can list installed applications, and update them from a centralized location, while individual programs typically only concern updates with themselves, if they even have an updater function. Unlike an app store, most package managers on Linux distros are completely free, and often predate their proprietary app store counterparts.

Using a package managerEdit

There are a number of package managers for Linux, but apt is among the most common, due to its use in Debian and most of its derivatives.

sudo apt update - updating package list under Ubuntu

  • repositories can be added to package list
  • we use apt mostly instead of dpkg under Debian-based Linux.

Program / package installation: apt install / dpkg -i <program>

dpkg won't indicate the dependency, so you have to install those that's not on the system. The dpkg, rpm, apt, apt-get etc. commands have man guides (man = manual)


The structure of Linux

  • Basically it's CLI
    • like DOS and Windows's command prompt
  • There are graphical user interfaces too (GUI)

FilesystemEdit

 
FAT structure
  • There are no letters at disks, like in DOS/Windows -> Everything is under /
  • It mounts (connects) the external storages
    • Nowadays Windows is also capable of it
    • The /etc/fstab file contains the automatical mount point of partitions and settings associated with them.
    • fdisk or fdisk -l commands, latter one lists the partitions.
    • Under /mnt we can find the mounted mediums (but that's not true mostly because in modern partitions the automatically mounted mediums like flash drives usually get mounted to /media, but that's true that /mnt is created to mount partitions there)
 
EXT structure

FAT-table contains entries for every cluster on a continuous area of the medium. Every entry contains the next cluster's number in a file or the EOF (end of file), unused disk space and the specially reserved space of the disk. It only can do soft-link.

EXT filesystem: It uses inode(Index node) table. In inode there are the files' description and the place of the data blocks, without filename. There is only one inode for each file. Files with bigger size may contain multiple catalog-entries, which contains the filename. Inode contains the name, description, creation date, permissions, owner(UID), group(GID), and how many links are attached to it. (so it can do much more than FAT) It can do soft-link and hard-link, which is one of the biggest advantage of EXT file system to FAT.

  • Soft-link: shortcut, if the original gets deleted, then it deletes itself, or it says error that it doesn't find the executable.
  • Hard-link: A copy of the file, but if we change the original one, then the content of the copy changes, but the file will only disappear eventually, if all the copies are deleted.

Properties of filesystemEdit

  • It attaches permissions separately to every file
  • It limits permission to the owner or groups
  • Read, write, execute permissions

File managersEdit

 
Midnight Commander under Fedora 29.

KernelEdit

Kernel = system core, the "soul" of the OS

Tasks of it: handling peripherals, handling filesystem, implementing directory structure, taking control of processor

Types of kernels:

  • Monolithic: The kernel consists of one unbreakable unit module. It's common for older Linuxes (older than 2.0) and UNIX systems.
  • Hybrid: like Windows – permissions can be set. Hybrid kernels are basically microkernels in which some "not important" code parts have been moved from user level (userspace) to kernel level (kernelspace) using fewer abstractions to run faster.
  • Microkernel: Kernel is in multiple small programs, not in one big module.
  • Modular: The modular kernel tries to fix the monolithic kernel's problems. Parts of the kernel - physical and logical - and modules created by this, which are mostly drivers can be loaded into memory. It saves the size of the kernel, but both together becomes bigger and bigger (its size is relative though, it depends how many drivers do you want to add, complete kernels are mostly around 100 MB or above, but if you are minimalist, it can be under 10 MB). We put modern Linux systems under the modular term (to be punctual, Linux kernel is monolithic modular). The kernel modules can be found in /lib/modules/kernel-version folder.

Place of kernel: It's in the /boot folder, and there are soft-links to vmlinuz and initrd in the root.

FilesystemsEdit

At filesystems arrays have huge role in Linux.

Virtual filesystems (for the system)

  • SMBFS, SSHFS, NFS, etc.

Supported filesystems:

  • ext2, ext3, ext4 (own filesystem of Linux)
  • ReiserFS, Btrfs, ZFS, XFS
  • FAT32, NTFS
  • stb.

Directory structureEdit

  • Hierarchical
    • directories (folders)
    • files

Single-level directory: Commodore floppy; magnetic tape

  • Path
    • Root: /
    • e.g.: /home/joe/myfile.txt
  • Connected (mounted) media
    • e.g. /mnt/usb
  • Mounting:
    • mount /dev/scd -t ISO9660 /mnt/cdrom (if we want to use CD-ROM)
    • mount /dev/sdb -ta /mnt/[name], where -ta indicates automatic detection of the media's type.
    • The sda,sdb, sdc… indicates the HDD,SSDs, and modern distros mount them to /media/[partition name].
  • Unmount / disconnect: umount /dev/sdb

Main foldersEdit

  • /bin, /sbin
    • executable, binary files (only admin can run sbin programs), no file extension needed
  • /boot
    • system startup files: GRUB, LILO, kernel (/boot/vmlinuz)
  • /cdrom, /media, /mnt
    • media mounting: USB, Floppy, CD/DVD
  • /dev
    • we can reach the devices through files e.g.: /dev/dsp (soundcard) /dev/cdrom (CD) /dev/sda2 (first HDD/SSD's 2nd partition)
  • /etc
    • configuration file
    • sysadmin has only access to it
    • global configuration folder
  • /home
    • users' folder
    • user's files
    • settings, configuration files, folders
    • for eg.: /home/peter /home/peter/documents
  • /lib
    • shared objects, libraries
    • like DLL files in Windows
    • kernel modules
  • /lost+found
    • damaged files
    • recoverables
  • /proc
    • currently running operations - numbered by files and information of the system(processor, memory etc)
    • example command (processor information): cat /proc/cpuinfo
  • /tmp
    • location of temporary files
    • both system and user level
  • /usr
    • location of user files
    • programok installed programs
    • libraries
    • sources (kernel): /usr/src
    • documentations: /usr/share/doc, /usr/doc
    • icons, and so on.
  • /var
    • collection of services
    • cache(temporary storage): /var/cache
    • log files: /var/log/maillog
    • email accounts (mailbox): /var/mail/root
    • www folder: the default webpage folder of apache (/var/www)

UsersEdit

  • system administrator: root
  • users: „root” user creates them basically
  • users can be grouped
  • permissions can be given in the filesystem
    • e.g.: /home/joe/myfile.txt 26 joe joe -rwxrwxrwx
  • The first user has also root permissions (which you set in the installation) - but this depends on distribution, e.g. Debian users have no root permission by default, and there is no sudo.


Basic commands

Root vs user permissionEdit

  • [root@ubuntu ~]# - root permission
  • [user@ubuntu ~]$ - user permission

User can execute things with root permission that the user wouldn't do with base permission likeapt install, but using sudo does the same job as if you were in root. Linux Basics/User management (System administrator) chapter dives deeply into this topic.

CommandsEdit

  • <command> --help: it will display all the switches for the command
  • cd: change directory (→ cd .. = it will go back by one folder/directory)
  • pwd: print working directory – it'll display which folder you're in right now
  • w: it shows who are logged in and what they are doing (w <username> displays the particular user's activity)
  • who: it displays only the tty interface, the date and ip address with the username
  • ls: listing files in a directory
    • ls -a: it lists all the hidden files aside the non-hidden ones
    • ls -A: same as previous, but it lacks . and .. (. means the current folder, .. means previous folder)
    • ls -l: detailed directory list
    • ls -al: based on the commands above: detailed directory list + hidden files with . and ..
  • exit: it'll quit the user from the shell and close the shell
  • sudo <command>: you can do commands as superuser
  • mv: move, moving from A to B: syntax: mv <source> <destination>. It can be used for renaming too.
  • mc: midnight commander's command (you have to install it, because most distros don't contain mc by default)
  • touch file: creating "file" named file
  • echo something: "something" will be directed to the echo's standard output.
  • nano file: editing "file" named file with nano (by default on some distros it's not installed, so you have to install it)
  • less file: outputting "file" named file to the terminal, but you can move in the word viewer, and you can quit from it by pressing q
  • rm: remove, delete
    • rm -r: recursive, so the rm command will delete everything that is given
    • rm -f: force, so without any arguments the folder will be deleted
    • rmdir: folder deletion, but rm -rf is simpler to delete a folder with files.
  • mount: connecting devices
  • umount: disconnecting devices
  • ln: creating link (hard-link)
  • df = disk free = it says how many free spaces are on each partition
  • du = disk usage; you have to give parameters, else it's gonna list all the directories
    • du /home: it's gonna list the content of /home and the usage of the folders
    • du -h it says which folder and file how many kB, MB, GB does it take, if we won't put this, it's gonna list everything in bytes
    • du -s summarizes (it takes every folder as one, and it'll write the sum of their size)
  • free = free memory and swap space
  • top (black and white) / htop (color) = it displays the currently running apps (like Task Manager in Windows)
  • uname = displays info about the system, -a switch tells everything about the kernel

Output in Manjaro:Linux manjaro 5.6.11-1-MANJARO #1 SMP PREEMPT Wed May 6 10:20:32 UTC 2020 x86_64 GNU/Linux

  • ntpdate <server> = it's gonna update your system's time based on the time server address you gave (like time.nist.gov => ntpdate time.nist.gov)
  • uptime = how long have your system been running, and how much it's loaded
  • netstat = network statistics
  • man = It opens the manual pages of the command, short and straightforward description
  • info = same as man, just it's more common in Red Hat systems

Network managemenentEdit

  • ifconfig = ip address, network settings, amount of sent and received packages
  • iwconfig = same as ifconfig, just this is for wireless settings
  • ping (pinging an IP address) : ping www.google.com ; ping -c 3 www.google.com (we can give after the -c switch how much packets do we want to send to a page)
  • ifup = interface up – it runs a script when it's enabled (e.g. ifup eth0 -> it enables eth0 interface)
  • ifdown = interface down – same as ifup, just here we disable the interface e.g. ifdown eth0
  • ifstatus - interface status
  • ifstat – it monitors the upload/download speed of the interfaces

User managementEdit

  • adduser/useradd – user creation
  • userdel – user deletion
  • chmod - change mode - we can set the permissions for the files and directories(Linux Basics/Filesystem, permissions has more information on this)
  • chown – change owner
  • usermod – modifying user

package management commands: dpkg, rpm, apt, yum, dnf, pacman, zypper stb.

Other commandsEdit

  • clear – clears terminal
  • chroot – changing root folder
  • kill – killing/terminating process based on PID (ps -A displays that)
    • kill -9 – kills every subthread
    • killall - kills the list's all elements but kill -9 @(...) is easier
  • halt - computer shuts down, but its PSU still goes(in case of ATX v2 PSUs)
  • shutdown / sudo init 0 – computer shuts down completely
  • reboot – computer reboots – sudo init 6
  • /bin/bash – bash command prompt
  • service – we can start/restart services running on the computer
  • systemctl – same as service
  • cron: computer does things without your input (in intervals, startups, shutdowns), cron daemon runs these (hourly, daily, weekly..)
  • crontab: user's own cron setting
    • crontab -e: editing crontab

/etc/skel folder: the content of this folder goes to the new user's home folder (skel = skeleton)

/etc/sudoers file: those users who can use sudo. (Linux Basics/Filesystem, permissions explains it in depth)


Graphical interfaces

X Window System does the job for graphical display under Linux. We also call X Window System as X or X11. Its GUI is very plain, but it's a graphical server, so it gives home to many desktop environments and window managers.[1]

 
GUI of X

Login can be on graphical interface:XDM(X Desktop Management), GDM, LightDM, SDDM etc.

 
Fedora 29's login screen

Every operating system has its own graphical package manager, like Synaptic under Debian-based systems, Fedora has dnfdragora, Arch has Pamac or Octopi, etc.

Important Desktop Environments and their logos:

 
dnfdragora under Fedora 29

There is also Cinnamon and MATE which can be mentioned, they're both Gnome-derivatives. (Arch wiki has all the Desktop Enviroments explained) You can choose which you want to install under Linux, customization has no limits.

Composite Window Managers e.g.: Compiz, Compton, Xfwm, Marco, KWin.

The Window Manager does the job for window operations (minimize, maximize, move etc), compositor does the effects, like at minimizing the window slowly vanishes etc.

You can change the Window Manager and Desktop Environment under operation (but when you install them, you may have to quit from the current DE and re-login to see the changes)

ReferencesEdit

  1. Wikipedia: X Window System


Terminals, command prompt, alias, history

What's a terminal?Edit

  • Terminal = command prompt → shell = command-line interpreter
  • Text-mode, DOS-like
  • There are several terminals
    • Gnome-terminal, Xfce4-terminal, xterm, etc.
  • There are many shells (e.g. bash, fish, ksh, zsh etc.)
  • commands can be executed
  • command list: https://ss64.com/bash/ (and also the Linux Basics/Basic commands chapter)
  • alias: we can shorten a complex command with an alias or we can create our own one.
  • Location of definition (in case of bash shell): ~/.bashrc
  • Global aliases: /etc/bashrc

HistoryEdit

  • It can be recalled by pressing up and down arrows on keyboard
  • you can switch tabs on terminal by pressing ctrl+page up or ctrl+page down
  • ~/.bash_history shows the commands before login

Environment variablesEdit

Environment variables: it stores information of the operating system or programs. Environment variables get set automatically after startup. For example, PATH environment variable tells the shell where to search the executable files.

  • Printing them to terminal: printenv, set
  • but particular environment variables can be displayed too: printenv PATH
  • to set up an environment variable: set VAR1=”something” where VAR1 is an arbitrary variable
  • to delete an environment variable: unset var1
  • displaying a particular one(same as printenv basically): echo $VAR1
  • to have the setting in the system permanently: export VAR1=”valami”
  • we can create an own command under /home/bin folder, but it works only if we added the folder to PATH environment variable:
  • export PATH=$PATH:~/bin, and to make it permanent in .bashrc:echo "export PATH=$PATH:~/bin" >> ~/.bashrc

Thottee explained it on his website in more detail that what we do exactly (his website is in hungarian so you may need to translate it with a translator program: http://linuxkezdoknek.hu/articles.php?article_id=33 (the article's second half)

HelpEdit

 
top in man help under Sparky Linux
  • help for using a command: help
  • command for the manual (detailed help): man, info
  • usage:
    • man <switches> <command>
    • info <switches> <command>


Archiving, mounting in depth

ArchivingEdit

  • Archiving, compression with tar program

Listing:

tar -tvf file.tar: shows content of file.tar

tar -tvfz file.tar.gz: shows content of mentes.tar.gz

tar -tvfj file.tar.bz2: shows content of mentes.tar.bz2

tar -tvvf file.tar: detailed listing, permissions, owner etc.

Compressing:

tar -cvf file.tar /to/path: compressing data to the given path in tar.

tar -cvfz file.tar.gz /to/path: compressing data to the given path in gzip.

tar -cvfj file.tar.bz2 /to/path: compressing data to the given path in bz2.

Uncompressing: tar -xvf file.tar: Uncompresses file.tar and it puts to a /file folder

tar -xvfz file.tar.gz:Uncompresses gz then tar and it puts to a /file folder

tar -xvfj file.bz2:Uncompresses file.bz2 and it puts to a /file folder

MountingEdit

Mounting – or connecting devices to the computer. Well, what happens of it doesn't work automatically, for example we didn't mount a hard drive under installation?

This is the base syntax of the mount command:

mount -t type device mount_folder - if we want to mount manually
mount -ta device mount_folder - if we want to detect the file system automatically
  • we mount by detection

type can be:

ext,ext2,ext3,ext4, fat, ISO9660, msdos, ntfs, udf, xfs etc.

if I want to mount a CD then the mounting would be like (from step to step):

mount -t ISO9660 /dev/sr0 /media/cd

Previously files were mounted to /mnt, but modern systems put them into /media folder.

In case of DVD it would be udf. You may ask, but DVD was in ISO too, yes, just in ISO there is a filesize limit, which is 2/4 GB, so in cas of DVD it's impossible to write a file bigger than the limit, even if the one layer - one sided DVD has a capacity of 4.7 GB.

We can give specific parameters at mounting with -o switch, separating them with commas (not all):

async – asynchronized I/O operations -> sync: synchronized I/O operations

atime – it updates the access time of inodes in the filesystem at every access, this is the kernel default.

noatime – it won't update the inode's access time in the filesystem

auto – automatically mounts the partition while booting (we have to do this in the case of non-root drives) and mount -a also does the same

noauto – it won't be mounted automatically, so we have to mount it manually

defaults: rw, suid, dev, exec, auto, nouser, async, and relatime

remount – Attempt to remount an already-mounted filesystem.

ro – read-only

rw – read/write

dev – Interpret character or block special devices on the filesystem.

nouser – Forbid an ordinary (i.e., non-root) user to mount the filesystem.

relatime – Update inode access times relative to modify or change time.

suid –Allow set-user-identifier or set-group-identifier bits to take effect.

other parameters: man mount command / https://linux.die.net/man/8/mount

So how does it work then?Edit

For e.g. we want to mount a device, that is writeable, can be mounted only by root, and we don't want to mount it automatically by boot, it has ext4 filesystem, we want to use the setuid, setgid bits, and it's in the first HDD's first partition, then i have to type this:

mount -t ext4 -o rw,noauto,nouser,suid /dev/sda1 /mnt/data

But first we need to create a folder for the partition we want to mount, else the command will alert that there's no such directory.

sudo mkdir /mnt/data

Then we edit the /etc/fstab file with e.g. nano, and we add the second line's content to the file:

# <file system>    <dir>    <type>   <options>            <dump> <pass>
/dev/sda1        /mnt/data  ext4    rw,noauto,nouser,suid  0     1

Explanation:

file system = this means the partition we want to mount

dir = this means the path we want to mount it

type = type of filesystem

options = options, that i mentioned above

dump = dump should make a copy of the file system or not, 0 means no, 1 means yes

pass = fsck decides by this that in what order it wants to check the filesystems, 1 is the root's, 2 is other file systems', in case of 0 the particular filesystem won't be checked

Unmounting is easier than mounting since just we have to give what we want to remove:

umount /dev/sda1 - we remove the first HDD/SSD's first partition.


User management

User management functionsEdit

  • Functions: adding, deleting user, setting password, modifying
  • Adding user: adduser(under Ubuntu), useradd
 
useradd's interactive guide in Ubuntu (adduser)

Adding userEdit

Syntax:

useradd [options] username

Options:

  • -u number: setting the user id (UID)
  • -c: note
  • -g group: setting group membership
  • -d /home/user: setting HOME folder to /home/user.
  • -s /bin/bash: default shell (here the user gets bash as default
  • -G group1, group2: separating them with commas, if the user is member of other groups
  • -m -k /home/existing <username>: it creates the home folder based on an existing user's home folder.
    • -m switch refers to create home directory, -k indicates where we want to copy the default files from (e.g. /etc/skel -> the skeleton folder of the home folder)

so the command looks like this:

useradd -c "test account" -u 1001 -g users -G info,sysadmin -d /home/test -s /bin/bash -m -k /etc/skel test

getentEdit

User information: getent

getent passwd <username>

If we want to get information about infotech group:

getent group infotech

/etc/passwd fileEdit

Location of user data: /etc/passwd

Content of /etc/passwd is like:

janos:x:1000:1000:Nagy János:/home/janos:/bin/bash

Passwd file's entries are separated with comma, and the explanation of the fields are the following:

  1. Username.
  2. Encrypted password.
  3. User ID(uid).
  4. Group ID (gid).
  5. Full name and other information
  6. Home folder
  7. Selected shell

/etc/shadow fileEdit

Content of /etc/shadow file is like:

smithj:Ep6mckrOLChF.:10063:0:99999:7:::

As with the passwd file, each field in the shadow file is also separated with ":" colon characters, and are as follows

  1. Username, up to 8 characters. Case-sensitive, usually all lowercase. A direct match to the username in the /etc/passwd file.
  2. Password, 13 character encrypted. A blank entry (eg. ::) indicates a password is not required to log in (usually a bad idea), and a ``*'' entry (eg. :*:) indicates the account has been disabled.
  3. The number of days (since January 1, 1970) since the password was last changed.
  4. The number of days before password may be changed (0 indicates it may be changed at any time)
  5. The number of days after which password must be changed (99999 indicates user can keep his or her password unchanged for many, many years)
  6. The number of days to warn user of an expiring password (7 for a full week)
  7. The number of days after password expires that account is disabled
  8. The number of days since January 1, 1970 that an account has been disabled
  9. A reserved field for possible future use

chageEdit

Changing user rules: chage

We can regulate with changing it when will the password of a user expires.

For example, output of chage -l joska will display the data for it:

   Last password change                                 : Feb 28, 2019
   Password expires 	                                : never
   Password inactive 	                                : never
   Account expires 	                                : never
   Minimum number of days between pasword change	: 0
   Maximum number of days between pasword change	: 99999
   Number of days of warning before password expires 	: 7

We want joska user's password to expire in 10 days:

chage -M 10 joska

When will we want joska's password to expire?

chage -E "2019-12-31" joska

Lockdown after inactive days

We lock joska's password after 10 inactive days.

chage -I 10 joska
chage --inactive 10 joska

User passwordEdit

User password: passwd

Changing own password:

# passwd

With superuser privilege we can change anybody's password:

# passwd username

Storing password encrypted: /etc/shadow

Generating password:

# makepasswd

chfnEdit

Modifying user data: chfn

We need finger package for it.

e.g.:

# chfn -f János janos
# chfn --full-name "Nagy János" janos

Kapcsolók:

  • -f, --full-name
  • -o, --office -- office room number
  • -p, --office-phone - office phone number
  • -h, --home-phone - home phone number

Deleting userEdit

Deleting user: deluser, userdel

It's recommended to regulate it with help of /etc/deluser.conf, We should look up deluser.conf(5) manual.

e.g.:

deluser --remove-home
deluser --remove-all-files
deluser --backup
deluser –backup-to

Handling user groupsEdit

Creating group: addgroup, groupadd

Location of group data: /etc/group

/etc/group file can be edited manually (text editor, mcedit, nano etc) by root.

A group is created with every user's name (like in case of kathy user a kathy group is created).

Adding to group:

gpasswd -a kathy infotech
  • We add kathy to infotech group

Csoportból kivétel:

gpasswd -d kathy infotech
  • We delete kathy from infotech group

Handling user groups (and user data)Edit

„usermod” command:

  • Changing user accounts.

Adding user mary to infotech group:

usermod -a -G infotech mary

(For -a the group name is appended, so the other group remains for that user. If we omit -a, then all the existing groups the user is assigned in gets deleted for that user.

Usermod command's other switches:

  • -u value user: it changes user ID (UID)
  • -g group user: it changes user group (e.g. usermod -g infotech mari)
  • -G group1,group2: it adds the user to the given groups (but without appending)
usermod -G human,economy,sysadmin mary
  • -L user: it locks the access of the user / bans the user (so you can't log in)
usermod -L -e 1970-01-01 mary (expiration date can be older than the current date) (--lock)
  • -e value: expire date (--expiredate)
  • -U user: unlocks the ban from the user
  • -d user: setting new home folder (--home)
  • -s user: setting shell (--shell)

id command:

Requesting information about the user.

group member:

id
id -nG

User accounts and handling "default"Edit

User account settingsEdit

In /etc/login.defs directory/file there can be set some properties for users. For example, where should the user emails be stored.

MAIL_DIR /var/mail

Logging failed logins into /var/log/faillog file:

FAILLOG_ENAB yes

Logging unknown usernames in case of failed logins:

LOG_UNKFAIL_ENAB no

Logging successful logins:

LOG_OK_LOGINS no

Controlling passwords. By default, when it's gonna expire, when the user can change it, what's the minimum length of the password, and when the warning should be:

PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7

User ID minimum and maximum ID's in case of useradd:

UID_MIN 1000
UID_MAX 60000

Minimum and maximum number group IDs:

GID_MIN 1000
GID_MAX 60000

Denying login after this number of fails:

LOGIN_RETRIES 5 

The length of lockdown after exceeding the number of unsuccessful logins:

LOGIN_TIMEOUT 60

User defaultsEdit

/etc/default folder contains it.

E.g. /etc/default/useradd

# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
  • /etc/skel folder contains the base home directory's content.


User management (System administrator)

The system administrator (superuser) and its functionsEdit

  • The most important user in Linux is: root
  • UID: 0, GID: 0
  • Root can access everything in the system!
  • The „su” command:
    • Changing user and executing command:
    • For example, we can become user mary:
      • su mary
    • If we use dash, then we get the whole environment of mary:
      • su - mary
    • We can add a group with the sg command. For example, we can add info:
      • sg info
  • Sudo command
    • With sudo command we can execute superuser commands. It asks the user's password, this is important because we don't want anybody to modify our system.
    • Ubuntu-based systems get root permissions only by sudo, root user doesn't get password.
    • We don't edit sudo's settings from directly the file. We use the following command instead: # visudo
    • Settings → in /etc/sudoers file
    • Syntax: <username> ALL=NOPASSWD: ALL Example: joska ALL=NOPASSWD: ALL
    • Without NOPASSWD it asks the given user's password.
    • Setting superuser permission: ALL=(ALL:ALL) ALL


Package management, process management

Package managementEdit

Function: Installing applications and its components.

There are two base formats:

  • RPM-based systems (RedHat, CentOS, Fedora, openSUSE) have rpm command for package management. One of its wrapper program is dnf. In openSUSE zypper is used for installation.
  • One of Debian GNU/Linux's wrapper program is in apt package. In the beginning apt-get was used, but since then an apt command appeared, which is the improved version of apt-get.
  • apt stands for Advanced Packaging Tool.
  • Package management was hard a lot because of the dependencies, so it had to be simplified.
  • There are console and graphical frontends for package management.

Process managementEdit

Process management:

  • The process is an existing copy of the started program.
  • The most important task of operating systems are the process management.
  • PID 0 is reserved, PID 1 is for the init. (Process IDentifier)
  • In a system there must not be two identical PIDs simultaneously.
  • Every process is created by an existing process except the first (init) process. We're gonna call the first process in the following as parent process (its identifier is usually called as PPID), and the freshly created one is called child process.
  • Of course the rules of the real life are also valid here, one process can be another process' child for the time, but it can be a parent process hence it can have many child processes.
  • Those processes which show 2 as PPID (this would be weird for other UNIX and UNIX-like system users because in other systems the system process's property is PPID=0), are parts of the kernel (and can't be found binary with this filename) and they can be only seen as a process for administration, scheduling reasons. Their name are kernel-level, kernel- or just system processes. For the system processes no permission managements are valid.
  • Processes in their lifetime use some CPU resources and memory and load the computer's I/O subsystem. The termination of a process has a phase when the process exists as "zombie" in the system..
  • We can get information about process directly via /proc filesystem or we can get it by ps command.
  • states:
    • R: running
    • S: interruptable sleep → The process waits for an event or resource and it can be interrupted by a signal. For example it waits for a counter (sleep) or any I/O operation.
    • D: uninterruptable sleep → The process waits for an event or resource and it cannot be interrupted by a signal. Usually this state is for waiting for some I/O device.
    • T: Stopped / Traced: Here goes a process if we press CTRL+Z from terminal when it's running and we drop it into the background
    • X: dead: this state can't be seen
    • Z: zombie process: terminated, it stayed in memory
    • see „man ps”
  • The first real process is init, and in the new systems systemd, which has an identifier of 1. The following started processes originate from that process, so the processes in relation create a tree-like structure → pstree
 
Pstree in Fedora 29
  • The „job” term: We can execute in the terminal with a command multiple operations / processes for e.g.:
$ cat something.txt | grep apple
  • Here the terminal starts 2 processes and between them it a pipeline, hence creating a need for a new term, which explains the started processes.
  • Command for following processes:
jobs
  • Processes can run in foreground and in background: FG, BG
  • We can terminate processes running in foreground by pressing CTRL+C in the terminal
  • We can terminate processes running in foreground by pressing CTRL+Z in the terminal
  • Processes we want to run in background is with & character, e.g.:
sudo apt update &
  • Running multiple command one after another automatically: with && characters, e.g.:
sudo apt update && sudo apt upgrade

Process management commandsEdit

ps: list and status of processes

pstree: process structure list

wait: [n] → it waits for an arbitrary number of jobs/processes and it will give the exit code of them

top, htop, atop: it lists the processes dynamically (like Task Manager in Windows)

nice: increasing or decreasing priority of a process, the lower number indicate higher priority, e.g.:

nice -n 3 program-name

We can modify the program's priority while it's running, by using renice:

renice -n 3 -p PID

Signals, terminating processEdit

  • A process can be suspended "from outside" via sending a signal. We can list all the signals by entering kill -l
  • For termination we need the PID, and the permission for the process from the user. Of course, we can terminate other's processes with superuser privilege.
  • Killall command kills every process which is associated with the main process, for example, killall conky will kill every process that is associated with conky.

List of signalsEdit

Name Number Description
SIGTSTP 20 Suspension, CTRL+Z
SIGINT 2 Instant halt, CTRL+C, but the program can ignore it
SIGQUIT 3 The process stops and clears its files
SIGKILL 9 Instant halt and the program cannot ignore the kill command
SIGABRT 6 Abort, the program initiates it
SIGHUP 1 Hang up and restart (most daemons reload their configs)
SIGTERM 15 Stops and frees up resources

PipelineEdit

  • it uses one program's output as an input for other program
  • For example:
ifconfig | grep eth0


Filesystem, permissions

FilesystemEdit

  • Linux system basically:
    • System partition
    • Swap partition which is useful when you run out of physical memory, the unused program files get to this partitions.
  • We can add swap space as file to the system on the go. The size of these files doesn't change, so there won't be any fragmentation.
  • We can install Linux on standalone file system, if we install it as a server. The reason is to increase security, for e.g. if the logfiles fill the system, and it's on separate partition, the system won't stop.
  • We usually put the following directories on separate partitions: /home /var /tmp /boot /usr
  • Partitions:
    • We divide the mediums (HDD, SSD) to partitions where we create the filesystem.
    • Partition table specifies the method of storing partitions. Linux uses "DOS" partition table by default because of compatibility reasons.
    • DOS partition table allows only 4 primary partitions, the others can be in an extended partition. The extended partition can be divided to more parts, we call these logical partitions.
    • GPT partition table allows unlimited partitions. This is used more common.

PermissionsEdit

  • The DAC word stands for Discretionary Access Control. This allows the identified users to access to objects based on their properties. The access can only be set for the owner and only for group.
  • We also call these as UNIX permissions.
  • MAC or Mandatory Access Control is also known. We create access rules for objects which applies to every user (even root).
  • The third one is Role-based Accesss Control or RBAC. The superuser creates several roles. With the given permissions, we can get access to particular objects.
  • We differentiate three permissions:
    • Read (r)
    • Write (w)
    • Execute (x)
  • Permissions can be given to three types of users:
    • Owner
    • User belonging into a group
    • Everyone else
  • With chmod command we can set the permissions, where sometimes we relate to the owners, groups and everyone else, based on this table:
user u
group g
other o
all a
  • Example: output of ls -l in HOME folder:

-rw-r--r-- 1 joska joska 3184 dec 13 18.37 .bashrc

Type Owner's permissions Group permissions Others
- rw- r-- r--

Type can be:

Content Meaning
- Simple file
d Directory
D Solaris gate(communication between processes)
c character device (tty or printer)
b block device (disk or CD-ROM)
l symbolic link (symlink)
s Socket
= or p FIFO (System V, Linux)

chown command:

  • We can use the command for assigning a file's or directory's owner and group.
chown joska.joska filename
chown joska:joska filename
chown joska. filename
chown joska: filename

chmod command:

  • It can be used for setting permissions.
  • We can add/take permissions by two methods. First one is with numbers, second one is with letters.
  • We give with the letters who we want to add or take permissions. Then +/- depending what we want to modify (+: add, -:remove). Then finally what we want to change. The user types are stackable, so we can write like ug or uo or ugo. the latter one is equal to "a". The permissions can be stacked too.
  • We want to give the user writing permission to forest.txt file: chmod u+w forest.txt
  • We want to give the group and owner every permission: chmod ug+rwx forest.txt
  • We can give it with numbers as well: chmod 770 forest.txt
  • Explanation of the "770":
owner / user (u) group (g) others (o)
421 421 000

4 means read, 2 means write, and 1 means execute.

The setuid, setgid, sticky bits:

  • SETUID: We can set which user's permission can the program run, but this has security risk, so we use only if the problem can be solved by this.
  • SETGID: Setting this the program can run with the group's permissions where the owner has the file, and we can set it in directories, so every file is in the particular group's ownership.
  • STICKY: Turning on sticky bit indicates to the operating system that it should keep the file in the memory after execution so it can start up faster later.
    • We can turn on sticky bit in the case of directories too. Anyone can add files in this folder marked with sticky bit (although their other permissions have to comply), but everyone can delete its own..


If you want to deal more with Linux

If you would like to to watch some Linux content on YouTube, I'd recommend DistroTube,Switched to Linux and ExplainingComputers. The last one it's not Linux oriented, but has some Linux content, I prefer Chris' channel.

It is also recommended to join some Telegram groups to get some help if you're stuck (most Linux distros have at least a few English language groups. Some local ones like there is an Ubuntu Hour community in Hungary which has its Telegram group), many Linuxers use this platform, although some like ArcoLinux's developer(Erik Dubois) use Discord as well.[1]

In Hungary, members from FSF use a matrix server (matrix.grin.hu), to communicate with each other, and there is the PenguinPit Discord server for those who use Discord a lot.

This article from itsfoss.com contains 25 free Linux books to learn more. I also prefer The Linux Command Line which contains lots of knowledge in 555 pages. However, on Wikibooks, there are some Linux books here too. Check them out, maybe those get your attention.

ReferencesEdit