Red Hat 55
Red Hat 55
rmdir >> delete directories (only if empty directory), if not empty: rm -r >> delete
find . -user root >> search within the current working directory for a file with a specific user
If you want to save the output of the command to a file (this is called a redirection):
standard output:
error:
Note: change permissions (chmod) will change "existing" permission for files & directories.
Note: if I want to change the default permission that is being granted with file creation: umask (the
opposite > 0 > is on):
0: read, write, and execute, 1: read and write, 2: read and execute, 3: read only, 4: write and execute, 5:
write only, 6: execute only, 7: no permissions [umask 000 >> grant all permissions]
tar command
“-“ >> can be omitted, “c” >> for archive, “v” >> list the processed fils, “f” >> specify the files
Example of archiving newFile & oldFile: tar cvf cmp.tar newFile oldFile
To view the file "ls" won't work and I need to use tar again with "tf" to view, for example:
tar tf cmp.tar
Directory archive:
tar cvf /mnt/etc.tar /etc >> Creating archive file for etc dir within the mnt dir and name it etc.tar
Compression:
Q1: give the user owner all permissions: chmod 7whatever Dir
Q2: compressed archive of /etc name as /root/com.gz: tar cvfz /root/com.gz /etc
Note: if you don't remember the symbol of the archive type just use "a" and it will convert it as per the
specified file extension (gz) >> gzip, example: tar cvfa /root/com.gz /etc
Q3: find lines containing the word root & copy them into a file named /mnt/pass:
Usage of “yum”:
1. Install packages >> yum install packagename, example: yum install httpd
1. You need to create entries within the below file for both of them:
/etc/yum.repos.d/local.repo
name=baseOS
baseurl=http://xyz.server.com/baseos
gpgcheck=0
enabled=1
Tuned: a profile-based system for static and dynamic tuning of system settings.
By default, tuned will not dynamically adjust system settings, to modify manually use tuned-adm
command-line tool.
In the exam, they can give us a profile to set up or ask to set up a recommended profile so I will need to
check the recommended one and then set it:
tuned-adm recommend
tuned-adm profile
NTP (network time protocol): sync my system with any time server and it uses "chrony" service and
"chronyd" daemon to sync the system with the required server.
2. nano /etc/chrony.conf :
3. any change will require restarting the service to take effect so to restart:
4. chrony sources -v
timedatectl set-ntp true (enable or disable NTP syn for automatic time adjustment)
systemctl: whenever we download any package we need to start or enable that particular service in
which systemctl gives us control.
Checking:
Note: enable means the automatic start-up upon system boot up (make sure it is always enabled in the
exam).
Q1: create user harsh & make a new group as the secondary group:
groupadd newgroup
check: cat /etc/group
useradd harsh -G newgroup
check: cat /etc/passwd, cat /etc/group
Q2: create user nitin, do not add to newgroup, nitin should have no login shell:
ACL
check owner: ls -l
change owner: chown root /var/fstab
Q3: User natasha should have read & write access to that file:
Note: check if a file has ACL: there will be (+) next to the permission when using ls -l command
Sticky Bit , SetGID and SetUID
(s): whenever a new file or subdir is created, it will "inherit" the group (g) ownership of the parent
directory if the "setGID" bit is set
The SetUID bit enforces user ownership of an executable file. When it is set, the file will execute with the
file owner's user ID, not the person running it (chmod u+s)
The SetGID bit enforces group ownership of files and directories. When it is set, any file or directory
created in a directory will get the directory's group ownership, not the user's. When it is set on a file, the
file will always be executed as its owning group rather than as the user (chmod g+s)
The sticky bit, also referred to as the "restricted deletion flag," can be set on a directory to prevent
anyone except the directory's owner from deleting a file in that directory (chmod o+t)
The sticky bit can be set in numerical mode by adding its value to those of the other permissions. If you
have an object with a value of 755 and you want to set the sticky bit, add 1000 (chmod 1755)
mkdir /linux
ls -ld /linux
chgrp Mac /linux
Q2: All existing files within linux the group owner is Mac: (user recursive)
Note: The chown command allows you to change the user and/or group ownership of a given file,
directory, or symbolic link.
Q4: Ensure that no user other than the user owner can delete the content within directory:
chmod +t /linux
Extras
-R: recursive
Disk Partitioning
Q1: Add a swap partition of size 750Mb, do not delete the existing swap.
2. Creating partition:
fdisk /dev/vda
"n"
then the "Last Sector": "+750M"
4. format it:
mkswap /dev/vda5
nano /etc/fstab
/dev/vda5 [TAB] swap [TAB] swap [TAB] defaults [TAB] 0 [TAB] 0
5. Then use "swapon -a" command to verify (if no errors > all good):
"free -m" to check
Convert physical devices (disk partitions, fulldisk, raid) >> Into physical volumes (PV) >> Convert all of
them into a one volume group (VG) >> Create logical volume (LV)
pvcreate /dev/vda1
pvcreate /dev/vda2
pvcreate /dev/vda3
use the command "pvs" to check PV
2. PV to VG
3. VG to LV
4. mount it:
mkdir /mountpoint
nano /etc/fstab
/dev/VG1/LV1 [TAB] /mountpoint [TAB] xfs [TAB] defaults [TAB] 0 [TAB] 0
5. format it:
mkfs.xfs /dev/VG1/LV1
"mount -a" to check
Q3: create LV named LV2 with 10 extents where the size of each extent is 8MB.
blockdev: block devices, partitions that we use for storage (minimum size required must be 1Gb)
pool: (one or more block devices) size of pool = sum of block devices.
filesystem: thin provisioned layer (no fix size, grows as the details added)
VDO provides inline data reduction for linux in the form of deduplication, compression & thin
provisioning. (remove duplicate copies of data and keep 1 copy)
Note: you can use "man vdo" to check the syntax on the manual page
corntab -e (edit)
corntab -l (list content of cron tab file)
corntab -r (delete command in cron tab file)
1. ensure the service is running on the system "service cron status" if not use the command "yum install
cron" to install it or "cron service start" to start it
2. corntab -e (edit)
3. syntax: Minutes (00-59), Hours(00-23), Day of Month (01-31), Month (01-12), Day of Week (0-7 : both
0 & 7 mean Sunday), Command
this will take backup of /etc directory every minute on 14 Jan every year
this will take backup of /etc directory every minute between 5AM to 3PM on the 14th of Jan
this will take backup of /etc directory every minute between 5AMP to 3PM on every Monday and Friday
Forth: */x (interval of x), example:
Fifth: when "Day of Month" and "Day of Week" don't match with each other, example:
(15 is not Tuesday) so this will execute when either of the two field matches (on every 15th of every
month and every tuesday)
Q: send email with the word "linux" to the owner of the job every 3 minutes between 9AM and 4PM on
every Friday in June: */3 9-15 * 6 5 echo "Linux"
1. once the system runs use the arrow keys to select the default bootloader entry
3. go to the line starts with "Linux" and press [END] button on your keyboard to go to the end of line
after the word quiet then write "rd.break" then press "ctrl+x"
chroot /sysroot
6. touch /.autorelabel
then "enter" and "exit" twice and wait till the system reboot and login again.
Network Configuration
1. To view network info "ip addr show" then check the interface status to be up and you can check
the IPV4 address
2. "ping" >> check if the system can connect with the destination address or not
3. "nmcli" command:
Create new connection: "nmcli con add"
Modify Existing Connection: "nmcli con mod"
nmcli con add con-name Default type ethernet ifname eth0 ip4 192.168.1.2/24 gw4 192.168.1.1
After creation you can use "nmcli con show Default" to show the parameters and after that you can edit,
example:
Note: for some info like the ones can't be added while creation.
Note: you can add multiple IP addresses: nmcli con mod Default +ipv4.addresses 192.168.1.6/24
connection.autoconnect yes
now to activate it:
nmcli con up Default
Changing Hostname
Q: create a new connection named Net of Type Ethernet having interface named eth0, ip address:
200.0.0.12 mask 255.255.0.0, gateway 20.0.0.1, DNS 8.8.8.8 and activate it
nmcli con add con-name Net type ethernet ifname eth0 ip4 200.0.0.12/16 gw 20.0.0.1
nmcli con mod Net ipv4.dns 8.8.8.8
nmcli con up Net
SELinux: which process can access what file
nano /etc/sysconfig/selinux
next to SELINUX= write "disabled"
restart the system
2. SELinux Booleans
we will need to change boolean value from off to on (we need to know what boolean to enable)
3. SELinux port
Q: the system is not able to connect to httpd service at port 82, it should be accessible at port 82 and
should start at boot time
4. SELinux Context
by default the httpd service or the "apache web server" is able to host the files within "/var/www/html"
curl localhost/index.html (will display the content of file because server is able to access it)
Question: ensure that the httpd service is able to access the host files from the /test directory:
1. mkdir /test
2. touch index2.html
then we need to change the context of the test directory and its content, we can show context
using "ls -lZ /test" and we need it the same as "ls -lZ /var/www/html"
5. nano /etc/httpd/conf/httpd.com
scrol down to DocumentRoot and change its value to "/test" and the directory below it as well to
<Directory "/test">
Containers
The use of postman to Pull a container, Run a container, Map the container to a local directory, Run the
container as a service
Note: In case you want to delete image use command "podman rmi <imagename>"
Note: to stop an image use command "podman stop <container name>" and to remove the container
use "podman rm <container name>"
Note: you can also run it interactively using the below command and you will be in the apache server:
Note: if you want to change the web page you gotta find the "index.html" file so "find / -name
index.html" and then cat, nano whatever.
systemctl daemon-reload
systemctl start web5-container
systemctl enable web5-container
useradd test
passwd test
ssh test@localhost
2.
now you downloaded the httpd image for this particular user
3.
mkdir -p ~/.config/systemd/user
nano ~/.config/systemd/user/New-container.service
Edit the "WantedBy=" value to: WantedBy=default.service
now all options are the same but you will need to add "--user":
writing a bash script > write a file, make it executable, run the file.
nano script1.sh
add the script
chmod u+x script1
./script1
Note: you can use bash command to run the script without adding the execute permission "bash script1"
She - bang (can be written on top of the script file to tell the system which interpreter to use by default
to execute the script), for example:
#!/bin/sh
#!/bin/bash
#!usr/bin/perl
#!usr/bin/env python
Note: whenever I want to use the value of the variable I need "$"
variable types:
2. environmental variables: affect the behavior of the shell and user interface.
3. Global Variable.
Environmental variables example:
nano file
echo "Enter name of file"
read name
touch $name
echo "File Created"
Example:
nano shell.sh
touch $1 $2
echo "files $* was created"
echo "total arguments passed: $#"
./file file1 file2
if [ condition ]
then
statement1
statement2
else
statement1
fi
Comparison Expression:
if strings are equal: string = string (if you don't give space on either side of the equal to; this will
become assign to)
if strings are not equal: string != string
if string is null: -n string
if string is not null: -z string
check a file:
if [ condition ]
then
statement1
elif [ condition2 ]
then
statement1
else
statement1
fi
OR: ||
AND: &&
do
statement1
statement2
done
Notes: values will be assigned to the variable
Examples:
do
touch $x
done
for((i=0;i<10;i++))
do
date
sleep1
done
for x in $*
do
touch $x
done
using a counter:
count=0
for x in $*
do
if [ -f $x ]
then
count=$(($count+1))
fi
done