0% found this document useful (0 votes)
33 views51 pages

Linuxin 3 Hours

linuxin3hours
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views51 pages

Linuxin 3 Hours

linuxin3hours
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Learn

Click to edit Linux


Master in style
title 3 Hours

Agenda
Agenda
Click to edit Master title style
• Which Linux to use
• How to install
• Logging in to Linux
• Your first shell script
• Understanding where to find what
• Finding help about commands
• Accessing Linux Remotely
• Using storage devices
• Q&A
Learn
Click to edit Linux
Master in style
title 3 Hours

About the Instructor


About your instructor
Click to edit Master title style
• Linux user since 1992, Linux professional since 1996
• Linux author and instructor since 1996
• Many titles on this platform
• Live: Linux Fundamentals Bootcamp
• Linux Fundamentals - recorded video course
• RHCSA Crash Course
• Containers in 4 hours
• Kubernetes in 4 hours
• Ansible in 4 hours
• and many more, all on learning.oreilly.com
Learn
Click to edit Linux
Master in style
title 3 Hours

About you
PollClick
question 1
to edit Master title style
• How would you rate your own Linux knowledge on a
scale 1-5?
• 1
• 2
• 3
• 4
• 5
PollClick
question 2
to edit Master title style
• Do you have a favorite distribution?
• not yet
• Red Hat / CentOS / Fedora
• Ubuntu /Linux Mint
• Oracle
• SUSE
• Windows Subsystem for Linux
• Other
PollClick
question 3
to edit Master title style
• Which job title applies to you best?
• Systems administrator
• Developer
• Devops
• Manager
• Student
• Other
PollClick
Question 4
to edit Master title style
• Which statement best applies to you
• I want to learn how to work with WSL
• I want to learn how to access a remote Linux installation and work on
that
• I want to install Linux on a computer and work with it from there
PollClick
question 5
to edit Master title style
• Which part of the world are you from?
• North/Central America
• South America
• India
• Asia
• Europe
• Netherlands
• Africa
• Australia Pacific
Learn
Click to edit Linux
Master in style
title 3 Hours

Which Linux to Use:


Distributions
About Linux Distributions
Click to edit Master title style
• The Linux kernel is the heart of the operating system
• Other tools come from different open source projects
• Source code of these projects is freely available on Git
• Because collecting them individually to compile it into a working
computer is a lot of work, there are Linux distributions
• Or use https://linuxfromscratch.org if you want to do it yourself
(not recommended for beginners)
Most common Linux Distributions
Click to edit Master title style
• Red Hat and Family
• CentOS
• Fedora
• Oracle Linux
• Rocky Linux
• Ubuntu and Family
• Linux Mint
• Debian
• Kali
• WSL
• Cloud optimized
• Alpine
• Busybox
About the focus of Linux distributions
Click to edit Master title style
• Linux is the worldwide leading server platform
• Linux is used behind cloud to run applications in containers on top
of a Linux distribution
• Linux is in Windows as Windows Subsystem for Linux (WSL)
• Linux is in embedded devices
• Linux is in your Android phone
• The only platform where Linux is not leading is the end-user
desktop
• Fun fact: Most Linux professionals use MacOS because it runs all
applications and is closely related to Linux
Learn
Click to edit Linux
Master in style
title 3 Hours

How to Install Linux


HowClick
to work with Linux?
to edit Master title style
• To start working with Linux, you'll need to put it on your computer
• Instances in cloud are deployed, in all other cases you'll need to install
it
• Install on physical hardware or in a virtual machine
• Recommended Requirements
• 1GB of RAM
• 20GB disk space
• Connectivity to the Internet
• Alternatively, use Windows Subsystem for Linux (WSL)
Installing Linux for this class
Click to edit Master title style
• Use WSL
• Use the Rocky O'Reilly Sandbox
• Don't use the Linux Sandbox!
• Use a virtualization platform
• VirtualBox: free
• VMware Fusion/Workstation: $$ but superior
• Parallels
• HyperV
• Or look for "free tier Linux" in AWS, Google, Azure
Learn
Click to edit Linux
Master in style
title 3 Hours

Logging in to Linux
Connecting to Linux
Click to edit Master title style
• To log in, you should use a non-root user account
• There are multiple common ways to connect
• From the GDM Login Screen
• From the console
• Remotely (covered later)
To Root or not to Root
Click to edit Master title style
• Avoid logging in as root directly
• Root is a kernel level user and as such unrestricted!
• Use sudo to run commands with root privileges
• And if there really is no other option: use su - to open a root shell
sudo versus su
Click to edit Master title style
• sudo allows you to run commands with elevated privileges
• Requires authorization
• Password of the authorized user account is used
• su - allows you to open a root shell
• Requires the root password
• Does not work on Ubuntu (or WSL)
• Notice that some distributions don't set a root password by default
• sudo su - and sudo -i open a root shell for you
LabClick
1: Accessing Linux
to edit Master title style
• Determine how you want to access Linux in this class and access it.
• From the login prompt, if required, log in as a regular non-root user
• If your Linux environment doesn't require you to log in, type
whoami to see the actual username that is used
Learn
Click to edit Linux
Master in style
title 3 Hours

Your First Shell Script


Running a Shell Script
Click to edit Master title style
• The Linux Bash shell offers a powerful scripting language
• Bash scripting is easy to use and straightforward and will always
have a place besides Python and other languages
• To create a script, you need an editor: vim (vi) is the only editor
that really matters
• Use vimtutor to learn how to work with it
• BUT: vim is relatively complex, for a start use nano to edit text files
and worry about vim later
• To run the script, you need to make it executable
Permissions and Running Scripts
Click to edit Master title style
• Linux is the most secure operating system around
• Because files by default cannot be executed
• No virii
• No ransomwhere
• Use chmod +x to make your script file executable!
The $PATH and Other Environment Variables
Click to edit Master title style
• Linux runs commands from the $PATH
• The current directory is not in the $PATH
• Copy your script there where it belongs: /usr/local/bin
• sudo cp countdown /usr/local/bin
• Or rewrite the $PATH:
• export PATH=$PATH:/my/directory
Getting access to the script
Click to edit Master title style
• My example script is in my github repository
• Use the following to install the git client
• Ubuntu: sudo apt-get update; sudo apt install git
• CentOS: sudo dnf install git
• Use git clone https://github.com/sandervanvugt/linuxin3hours
• If prompted for a username / password, you've made a typo!
• The git clone command creates a directory "linuxin3hours" in your
current directory, containing this script
LabClick
2: Install the Git Client
to edit Master title style
• Open a terminal and type which git. If the output looks like
/usr/bin/git, you don't have to install anything.
• Use cat /etc/os-release. This will tell you on which Linux
distribution you are
• If you're on Ubuntu and you don't have Git installed, type sudo apt
install git
• If you're on Red hat and related and you don't have Git installed,
type sudo dnf install git
• Type git clone https://github.com/sandervanvugt/l3h to clone the
course Git repository
• Use ls ~/git to verify its content
Learn
Click to edit Linux
Master in style
title 3 Hours

Understanding where to find


what
Main Directory Structure
Click to edit Master title style
• Linux is file oriented, so knowing about files and directories is
essential
• /home/$USER is the user homedir
• /tmp is for temporary files
• Non-root users have write access to /tmp and /home/$USER only
• /usr/bin is for non-root binaries
• /usr/sbin is for system binaries
• /etc is for config files
• and many more
Finding Files
Click to edit Master title style
• Use find to find the exact location of any file
• find / -name "myfile"
• Use which to quickly find the exact location of an executable file
• which passwd
About Standardization
Click to edit Master title style
• The Linux Filesystem hierarchy is highly standardized
• This is because of Linux Foundation
• https://refspecs.linuxfoundation.org
• The File System Hierarchy is documented in man hier
LabClick
3: Finding Files
to edit Master title style
• Use the most efficient way to find the location of all files with the
name "passwd"
Learn
Click to edit Linux
Master in style
title 3 Hours

Finding Help about Linux


Commands
Using man
Click to edit Master title style
• Given differences between distributions, Google can be confusing
as well as outdated
• man is on-system documentation and always provides accurate
system-specific documentation
• Before using man, you need to know which man page to use
Finding the right man page
Click to edit Master title style
• man uses a database that contains names and descriptions of
commands
• Use sudo mandb to generate it if that hasn't been done yet
• Use man -k keyword to generate an overwhelming list of help
output
• Use man -k keyword | grep something to filter down the results
• Filtering on man sections is useful: see man man for an overview
Other options for getting help
Click to edit Master title style
• command --help provides command line option summary
• pinfo command provides additional information
• Use if man See also states that additional information is available via
info
LabClick
4: Using help
to edit Master title style
• Use the appropriate command to find detailed usage information
about the grep command. Which option do you need to use this
command in case-insenstive mode?
Learn
Click to edit Linux
Master in style
title 3 Hours

Accessing Linux Remotely


Understanding Remote Linux Access
Click to edit Master title style
• Most people don't sit directly behind the Linux console
• SSH is the most common way to access Linux
• To access SSH, you'll need the following
• If necessary: install the software package
• Start and enable the process
• Find the IP address
• Open a port in the firewall
• Remote graphical access to Linux is not commonly used
Checking and Installing Software Packages
Click to edit Master title style
• Before using SSH, you'll need to install it
• Use sudo apt install openssh-server on Ubuntu, and sudo dnf
install openssh-server on CentOS
• To install software, access to repositories is required
• On Ubuntu, use sudo apt update before installing packages
Managing Processes
Click to edit Master title style
• Use ps aux | grep ssh to see if the SSH service is currently running
• Or use top for an overview of most active processes
• If it's not running yet, use systemctl
• systemctl status sshd
• sudo systemctl start sshd
• sudo systemctl enable sshd
• On WSL, use the service command
• sudo service ssh status
• sudo service ssh start
Stopping Processes
Click to edit Master title style
• And if you don't want to have the process anymore
• sudo systemctl stop sshd
• sudo systemctl disable --now sshd
• sudo kill $(pidof sshd)
• On WSL, use the service command
• sudo service ssh stop
• And better don't use this
• sudo kill -9 $(pidof sshd)
Analyzing Network Information
Click to edit Master title style
• To remotely access a host, you need its IP address
• Use ip addr show to find it
• Do NOT use ifconfig, it is obsolete and often not even installed
anymore
Opening a Port in the Firewall
Click to edit Master title style
• Check if the firewall is running
• sudo firewall-cmd --list-all (CentOS)
• sudo ufw status (Ubuntu)
• WSL does not run the firewall by default
• Add the service to the firewall
• sudo firewall-cmd --add service sshd --permanent; firewall-cmd --
reload
• sudo ufw allow ssh
LabClick
5: enabling SSH
to edit Master title style
• Type sudo apt-get update to update the package indexes
• Use sudo apt install openssh-server to install the SSH server
• Type systemctl status ssh to verify the SSH server is running
• Use ip a to check your local IP address
• Type ssh localhost to open an SSH session to "localhost"
Learn
Click to edit Linux
Master in style
title 3 Hours

Using Storage Devices


Using Storage Devices
Click to edit Master title style
• To access disk devices, you need to find the device name
• Every disk device has a storage device file in /dev
• Plug in your USB thumb drive and use lsblk to find the device name
• Next, use sudo mount /dev/sdb /mnt to make your disk device
accessible on the directory /mnt
• May need to change mount point as well as device name
• On WSL, device mounts are handled by Windows, and mounted
devices occur in /mnt
Learn
Click to edit Linux
Master in style
title 3 Hours

Where to go from here


Where to go next
Click to edit Master title style
• Live: Linux Fundamentals Bootcamp (2x4 hours)
• Linux Fundamentals - recorded video course
• RHCSA Crash Course
• Containers in 4 hours
• Kubernetes in 4 hours
• Ansible in 4 hours
• and many more titles, all on learning.oreilly.com
Learn
Click to edit Linux
Master in style
title 3 Hours

Q&A

You might also like