Rhcsa7 Study Guide 1520876655

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 22

Study Guide
Linux
Academy
RHCSA 7 Prep
Contents
Basic Commands 1
Input-Output Redirection 1
File System Hierarchy Standard 2
Grep and Regular Expressions 2
Access Remote Systems Using SSH 3
Log In and Switch Users in Multi-User Targets 3
Archive and Compress Using tar, star, gzip and bzip2 4
Create and Edit Files 5
Create, Delete, Copy and Move Files and Directories 5
Create Hard and Soft Links 6
List, Set and Change Standard Permissions 6
Locate, Read and Use System Documentation 7
Boot, Reboot and Shut Down a System 8
Boot Into Different Targets Manually 8
Interrupt Boot Process to Access System 9
Identify CPU/Memory Intensive Processes, Adjust Priority, Kill
Processes 10
Locate and Interpret System Log Files and Journals 12
List, Create and Delete Partitions 12
Create and Remove Physical Volumes, Logical Volumes 13
LVM Set Up 13
Congure System to Mount File System at Boot 13
Schedule Tasks Using at and cron 14
Congure System to Use Time Services 15
Install and Update Software Packages 15
Enable Third-Party Repositories 16
RPM 17
Create, Delete and Modify Local User Accounts 17
Change Password and Password Aging 18
Create, Delete and Modify Groups 18
Create, Mount, Unmount and Use VFAT, EXT4 and XFS File Systems
18
RHCSA 7 Prep Linux Academy
- 1 -
Basic Commands
pwd • Show current working directory path
cd • Change directory
ls • List contents of directory
sudo • Allows a super user to run a command with root priviledges
mkdir • Create new directory
»-p • Create parent directories, if do not already exist
rmdir • Remove directory
rm -rf • Force remove a directory, recursively (includes all les inside)
touch • Create new, empty les
Input-Output Redirection
> • Redirect standard output to le
»echo "test" > le.txt
»Replaces le, if already exists
>> • Redirects and appends standard output
»echo "test" >> le.txt
»Adds text to bottom of le
| • Chain scripts, les and commands together by the STDOUT as STDIN for the next command
»cat /etc/passwd | grep root
2> • Redirect standard error
2>> • Redirect and append standard error
/dev/null • Data sent to /dev/null is lost
2>&1 • Redirect STDERR to STDOUT
< • Accept input from le
»mysql < ledump.sql
less • File viewing application and STDOUT can often piped into for ease of reading
RHCSA 7 Prep Linux Academy
- 2 -
head • Show rst ten lines of le
»-n • Dene number of lines
tail • Show last ten lines of le
»-n • Dene number of lines
File System Hierarchy Standard
/etc • Contains conguration les for programs and packages
/var • Variable data specic to system. This data should not be removed or changed when the
system reboots. Logs les tend to be stored within the /var directory
/run • Runtime data for processes since last boot
/home • Location of home directories; used for storing personal documents and information on
the system
/root • root user home directory
/tmp • Files are removed after ten days; universal read/write permissions
/boot • Files needed to start the system boot process
/dev • Contains information on essential devices
Grep and Regular Expressions
grep • Prints lines that match dened pattern
»grep pattern le.txt
»-i • Case insensative
»-v • Shows lines not containing pattern
Examples including regex:
»grep linuxacademy lename • Search for linuxacademy in lename
»grep "^linuxacademy" lename • Search for lines starting with linuxacademy
»grep "linuxacademy$" lename • Search for lines ending with linuxacademy
»grep "^[abd]" lename • Search for characters not contained in brackets
»grep [lL]inuxacademy lename • Search for pattern starting with either capital or
lowercase L
RHCSA 7 Prep Linux Academy
- 3 -
»grep "^$" lename • Search for empty lines
»grep -v ^# lename • Search for uncommented lines
egrep • Same as grep, but using extended regular expressions
fgrep • Interpret pattern as list of xed strings
Access Remote Systems Using SSH
Password authenticationAllows user to log in with only a password; considered to be less
secure than using key-based authentication
ssh user@server • Connect to remote host
ssh server command • Issue command on remote host without connecting
scp lename user@server:~/ • Secure copy le to server
sftp user@server • Secure File Transfer Protocol
»? • Display all options
»ls • List les
»cd • Mode directories
»get • Download
»quit • Exit sftp
Log In and Switch Users in Multi-User Targets
TargetSystemd conguration les used for grouping resources
Interactive shellAny shell that has a prompt for user interaction
su • Log in as another user
»su user • Log in to an interactive, non-login shell
»su - user • Log in to a login shell
GNU Bourne-Again ShellBash
»Interactive shell uses either $ (user) or # (root) prompt
»Takes commands, which run programs
- Made up of three parts:
RHCSA 7 Prep Linux Academy
- 4 -
Command name
Options or ags to pass into the command
Arguments
Archive and Compress Using tar, star, gzip and
bzip2
tar • Archive les; does not handle compression
»-c • Create new archive
»-t • List contents of archive
»-x • Extract les from archive
»-z • Compress or uncompress le in gzip
»-v • Verbose
»-j • Compress or uncompress le in bzip2
»-f • Read archive from or to le
»Examples
- tar -cf helloworld.tar hello world • Archive hello and world les into
helloworld.tar archive
- tar -tvf helloworld.tar • List all les in helloworld.tar archive
- tar -xf helloworld.tar • Extract les in archive
- tar -czvf helloworld.tar.gz hello world • Archive and compress (using
gzip) hello and world les into helloworld.tar.gz archive
- tar -zxvf helloworld.tar.gz • Uncompress (in gzip) and extract les from
archive
star • Archiving utility generally used to archive large sets of data; includes pattern-matching
and searching
»-c • Create archive le
»-v • Verbose output
»-n • Show results of running command, without executing the actions
»-t • List contents of le
RHCSA 7 Prep Linux Academy
- 5 -
»-x • Extract le
»--di • Show difference between les
»-C • Change to specied directory
»-f • Specify le name
»Examples”
- star -c f=archive.tar le1 le2 • Archive le1 and le2 into archive.tar
archive
- star -c -C /home/user/ -f=archive.tar le1 le2 • Move to
/home/user and archive le1 and le2 from that directory into archive.tar
- star -x -f=archive.tar • Extract archive.tar
- star -t -f=archive.tar • List contents of archive.tar
gzip • Compression utility used to reduce le sized; les are unavailable until unpacked;
generally used with tar
»-d • Decompress les
»-l • List compression information
»Examples:
- gzip le1 • Compress le1 into le1.gz
- gzip -d le1.gz • Unpack le1
- gunzip lename • Unpack lename
Create and Edit Files
vi • Text editor that is always installed and useable; replaced vim
vim • Vi iMproved; full-featured version of vi
nano • Simple text editor
touch • Create empty le
Create, Delete, Copy and Move Files and
Directories
mkdir • Make directory
RHCSA 7 Prep Linux Academy
- 6 -
»-p • Create parent directories, if not already created
cp • Copy les and directories
»-R • Copy directory recursively
mv • Move les and directories
rm • Remove les and directories
»-r/-R • Remove recursively
»-f • Force remove
»-i • Prompt before removal
Create Hard and Soft Links
ln • Create links between les
»Without the -s ag, creates a hard link
»-s • Symlink les
symlinksSoft links that connects one le to another, symbolically; if the target le moves to
changes, the symlink continues to try use the previous location and must be updated
Hard linkLinks directly to an inode to create a new entry referencing an existing le on the
system
List, Set and Change Standard Permissions
Two ways to dene permissions on a standard Linux system:
»Using symbolic characters, such as u, g, o, r, w and x
»Using octal bits
»The RHCSA only requires knowledge of the symbolic
chmod • Change mode; set the permissions for a le or directory
»u • User
»g • Group
»o • Other
»a • All
»r • Read
RHCSA 7 Prep Linux Academy
- 7 -
»w • Write
»x • Execute
»s • Set UID or GID
»t • Set sticky bit
»-X • Indicate the execute permissions should only affect directories and not regular les
»Octal bits:
- 1Execute
- 2Write
- 4Read
chown • Change owner and group permissions
»chown user:group lename
»-R • Set ownership recursively
chgrp • Change group ownership
setuid • Set user ID permissions on executable le
setgid • Set group ID permissions on executable le
umask • Set default permissions for new directories and les
Locate, Read and Use System Documentation
command --help
info • Read information les; provides more information than man
which • Show full path of command; useful for scripting
whatis • Display manual page descriptions
locate • Locate les on system by name
updatedb • Update locate command databases
man • Documentation
»Nine sections:
- 1Executable programs and shell commands
- 2System calls
RHCSA 7 Prep Linux Academy
- 8 -
- 3Library calls
- 4Special les
- 5File formats
- 6Games
- 7Miscellaneous
- 8root user commands
- 9Kernel routines
apropos • Search man pages and descriptions for text
Boot, Reboot and Shut Down a System
Reboot:
»reboot
»systemctl reboot
»shutdown -r now
Shutdown:
»No power off
»systemctl halt
»halt
»shutdown -h now
»init 0
Power off:
»systemctl powero
»powero
»shutdown -P
Boot Into Different Targets Manually
A target is a Systemd unit of conguration that denes a grouping of services and conguration
les the must be started when the system moves into the dened target.
»A grouping of dependencies starts when a target is called
RHCSA 7 Prep Linux Academy
- 9 -
systemctl list-units --type=target • View all targets on system
systemctl list-units --type=target --all • View all targets on disk
Common targets:
»emergency.targetsu login; mounts only the root lesystem, which is read-only
»multi-user.targetSupport concurrent log ins of multiple users
»rescue.targetsu login; basic Systemd init
»graphical.targetSupport concurrent log ins of multiple users on a graphical interface
systemctl get-default • Show default target
systemctl set-default • Set default target
Conguration les:
»/usr/lib/systemd/system
»/etc/systemd/system
systemctl -t help • View unit conguration types
systemctl status service • Find status of service
systemctl --type=service • List conguration les of active services
systemctl enable service • Enable service conguration to start at boot
systemctl --failed • List failed services
Select a different target at boot:
»Reboot system
»At Grub menu, press E to edit entry
»Go to linux16 kernel and press CTRL+E
»Add systemd.unit=target.target
»CTRL+X
Interrupt Boot Process to Access System
Start or reboot system
Stop Grub autoselection
Ensure the appropriate kernel is highlighted and press E to edit
RHCSA 7 Prep Linux Academy
- 10 -
Navigate to the linux16 line, press E
Add line rd.break
CTRL+X
System boots into emergency mode
Mount /sysroot with read and write permissions
»mount -oremount, rw /sysroot
Switch into chroot jail:
»chroot /sysroot
Reset root password
Clean up
»touch /.autorelabel
exit
exit
Identify CPU/Memory Intensive Processes,
Adjust Priority, Kill Processes
top
»k • Kill process
»q • Quit
»r • Renice
»s • Change update rate
»P • Sort by CPU usage
»M • Sort by memory usage
»l • Toggle load average
»t • Toggle task display
»m • Toggle memory display
»B • Bold display
»u • Filter by username
RHCSA 7 Prep Linux Academy
- 11 -
»-b • Start in batch mode
»-n • Number of updates before exiting
»Columns:
- PIDProcess ID
- USER
- PRPriority
- RESNon-swap memory
- SHRShared memory size
- %CPUTask’s share of elapsed CPU time
- %MEMCurrent amount of used memory
- TIME+CPU time minus the total CPU time the task has used since starting
Nice priority:
»-20Highest priority
»19Lowest priority
»Any user can make a task lower priority
pgrep • Search processes
»-u • Username
»-l • Display process name
»-t • Dene tty ID
»-n • Sort by newest
pkill • Kill process
»-u • Kill process for dened user
»-t • Kill process for dened terminal
Kill signals:
»1SIGHUPCongure reload without termination; also used to report termination of
controlling process
»2SIGINTCause program to terminate
»3SIGQUITWhen user requests to quit a process
RHCSA 7 Prep Linux Academy
- 12 -
»9SIGKILLImmediately terminate process
»15SIGTERMSend request to terminate process; request can be interpreted or ignored
»18SIGCONTRestart previously stopped process
»19SIGSTOPStop a process for later resumption
»20SIGTSTPSend by terminal to request a temporary stop
ps • Process status
Locate and Interpret System Log Files and
Journals
journald • Responsible for event logging; records events from log les, kernel messages, etc.
»Data does not persist after reboot
»Can be congured for persistence in /etc/journald.conf
»Temporary log location: /run/log/journal
»Persistent log location: /var/log/journal
journalctl
»-n • Set number of lines to show
»-x • Provide explanation text, if available
»-f • Show last ten events; continues listening
»-b • Show messages from current boot only
»-p • Show message priority type
»_SYSTEM_UNIT=service • Get events related to service
»--since=yesterday • Get events since dened time
»--until=00:00:00 • Get event from before dened time
Find information about system boot:
»systemd-analyze
»systemd-analyze blame
List, Create and Delete Partitions
RHCSA 7 Prep Linux Academy
- 13 -
fdisk • Used to create master boot record-based partitions
gdisk • Used to create GPT-based partitions
Create and Remove Physical Volumes, Logical
Volumes
Physical volumeThe physical disk or disks; can be a partition or whole volume
Volume groupA combination of physical volumes that work as a logical volume, with pooled
space
LVM Set Up
pvcreate • Create physical volume
pvdisplay • Show available physical volumes
vgcreate name /dev/disks • Create volume group
vgdisplay • Show available volume groups
lvcreate • Create logical volume
»-n • Volume
»-L • Size in bytes
lvremove /dev/vg/volume • Remove volume
pvremove /dev/disk • Remove physical volume
Congure System to Mount File System at Boot
mkfs -t xfs /dev/xvdf1 • Make le system
blkid • List available block devices on system
lsblk • List all attached block devices
mount /dev/disk /mnt/mountlocation • Non-persistent mount
»Mounting with the UUID ensures the appropriate mount is used
»Add to /etc/fstab to mount persistently
tune2fs -L labelname /dev/disk • Mount with le system label (ext)
e2label /dev/disk labelname • Mount with le system label (ext)
RHCSA 7 Prep Linux Academy
- 14 -
xfs_admin -L labelname /dev/disk • Mount with le system label (XFS)
mount LABEL=labelname /mnt/mountlocation defaults 1 1 • Mount with label,
non-persistent; edit /etc/fstab for persistence
mount -a • Mount all le systems in /etc/fstab
umount -a • Unmount all le systems in /etc/fstab
Schedule Tasks Using at and cron
at • Execute command at a later time
»/etc/at.allowCongure users permitted to use at command
»/etc/at.denyCongure users not permitted to use at command
»Accepts following time/date formats:
- hh:mm
- midnight
- noon
- teatime (16:00)
- am/pm
- Full dates
- now + time
atrm • Remove pending at task
anacron • Execute commands periodically
»-f • Force execution, ignoring timestamps
»-u • Upload timestamps of all jobs; does not run jobs
»-n • Run jobs immediately, ignoring delays
»-t • Use specied conguration le, instead of default
»-h • Show help
»/etc/anacrontabConguration le
»/var/spool/anacronShows all timestamps for jobs
»Only root and superusers can use acacron
RHCSA 7 Prep Linux Academy
- 15 -
»Syntax:
- period in daysFrequency of execution
- delay in minutesNumber of minutes to wait before job execution
- job-identierUnique name of job used in log les
- commandCommand to execute
- start_hours_rangeTime frame when jobs can be run
- random_dayStagger job starts at random times
Configure System to Use Time Services
timedatectl list-timezones • List all available time zones
tzselect • Select appropriate time zone
timedatectl set-timezone zone/location • Set time zone
timedatectl set-time YYYY-MM-DD hh:mm:ss • Set time and date
timedatectl set-ntp true • Use Network Time Protocol
NTP can be managed by either ntpd or chronyd
»Generally, ntpd is for servers, and chronyd is for systems with frequent restarts
»chronyd is the default for RHEL7
Install and Update Software Packages
yum • Package management tool
»install packagename • Install package
»search string • Search packages
»search all string • Searches name, description and summary
»list • List installed packages
»list all • Listed installed and available packages
»list installed • List installed and available packages
»check-update • Lists packages with available updates
»update packagename • Update dened package
RHCSA 7 Prep Linux Academy
- 16 -
»update • Update all packages with available updates
»info package • Provide information about package
»provides /some/directory • Displays packages that match path
»list kernel • List installed and available kernels
»remove packagename • Removes dened package
»history • Display summary of installations and removes
»history undo idnumber • Reverse a transaction
»Working with groups (packages of software):
- yum grouplist • Show available groups to install
- grouplist hidden • Show all available groups
- groupinstall groupname • Install dened group
- groupinfo groupname • Display all packages to be installed with the group
- • Package is not installed and will not be installed
= • Package is installed as part of group
+ • Package is not installed, but will be installed at next update
No symbol means that the package is installed, but was not installed as part of the
group
»/var/log/yumLog le
Enable Third-Party Repositories
yum repolist • List repository ID, name and number of packages available
»-v • List more information about repos
»all • Show all repos
yum repoinfo • Show information about both enabled and disabled repos
/etc/yum.repos.d/reponame.repoLocation of repositories
yum-cong-manager • Set repositories
»--enable reponame • Enable repo
»--disable reponame • Disable repo
»--add-repo repourl • Add repository from dened URL
RHCSA 7 Prep Linux Academy
- 17 -
RPM
RPM Package Manager
Always use yum when possible
rpm
»-i • Install
»-v • Verbose
»-e • Remove package
»-h • Use hashmarks for progress
»-U • Upgrade to install package
»-F • Upgrade already-installed package
»-q • Query for a package
»-a • Display all packages
»-qa • Display installed les
»-ql • List les in installed package
»-qd • List documentation for package
»-qpl • List les in RPM package
Create, Delete and Modify Local User Accounts
id • Print user and group IDs
UID ranges:
»0root
»1-200System users for Red Hat processes
»201-999System users for processed that do not own les
»1000+Regular users
/etc/passwdUser login and password information
/etc/shadowUser login and password hash information
Primary groupThe main group for a user; all les created by a user are set under this group
RHCSA 7 Prep Linux Academy
- 18 -
/etc/groupsGroup member information
getent group username • Show all groups for a user
useradd • Create user
usermod • Modify user
userdel • Delete user
Change Password and Password Aging
chage • Modify amount of days between password changes
»-d • Number of days since 1970-01-01 to dene password change
»-E • Set password expiration date
»-I • Number of days of inactivity before password expiration
»-l • Show account aging information
»-m • Minimum number of days between password changes
»-M • Maximum number of days between password changes
»-W • Days of warning before password change
Create, Delete and Modify Groups
groupadd • Add a group
»-g • Group ID
»-r • Create system group
groupmod • Modify group
»-g • New group ID
»-n • New group name
groupdel • Delete group
chmod g+s directoryname • Set group permissions for directory, and all les created in that
directory have the same permissions
Create, Mount, Unmount and Use VFAT, EXT4
and XFS File Systems
RHCSA 7 Prep Linux Academy
- 19 -
VFATExtension of FAT le system, allowing log le names; often used in SAMBA shares or
when sharing les between Linux and Windows computers
»mkfs.ext /dev/xvdf1 • Create VFAT le system at location
»mount /dev/xvdf1 /mnt/location • Mount le system
»fsck.vfat /dev/xvdf1 • Check for le system consistency
EXT4Common among Linux systems; journaling-based le system that can support up to
16TBs on Red Hat and up to 50TB in le system size
»mkfs.ext4 /dev/xvdf1 • Create EXT4 le system on device
»mount /dev/xvdf1 /mnt/location • Mount the le system at location
»fsck /dev/xvdf1 • Check for le system consistency
»dumpe2fs /dev/xvdf1 • Get details of le system
»tune2fs /L labelname /dev/xvdf1 • Label the device
XFSKnown for parallel processing and high I/O throughput; journaled le system that supports
up to 500TB le size on Red Hat 7 with 500TB in le system size
»mkfs.xfs /dev/xvdf1 • Create XFS le system on device
»mount /dev/xvdf1 /mnt/location • Mount le system at location
»xfs_repair /dev/xvdf1 • Check for le system consistency
»xfs_info /dev/xvdf1 • Get details of le system
»xfs_admin /L labelname /dev/xdf1 • Label the device

Navigation menu