Linuxnotes
Linuxnotes
Linuxnotes
======================================================
NETWORK CONFIGURATIONS
Question
-------------
• NETWORK CONFIGURATIONS. Configure the system using the following details.IP
address of machine : 172.25.250.10Subnet Mask : 255.255.255.0Gateway :
172.25.250.254Name Server : 172.25.250.254Host Name : servera.lab.example.com
========================================================
IP Setup
=======================================================
YUM Repository - Server A as repo
=======================================================
Question
-------------
:- Configure yum client by using the Yum baseurl paths
http://content.example.com/rhel8.0/x86_64/dvd/BaseOS and
http://content.example.com/rhel8.0/x86_64/dvd/AppStream
cd /etc/yum.repos.d/
vim server.repo
[server]
baseurl=http://content.example.com/rhel8.0/x86_64/dvd/BaseOS
NB--> if file path location where the CD/DVD contenets are copied to /rpms folder:-
"baseurl=file:///rpms/BaseOS"
enabled=1
gpgcheck=0
name=rhel8.0
[server1]
baseurl=http://content.example.com/rhel8.0/x86_64/dvd/AppStream
NB--> if file path location where the CD/DVD contenets are copied to /rpms folder:-
"baseurl=file:///rpms/AppStrem"
enabled=1
gpgcheck=0
name=rhel8.0.1
esc
:wq
=======================================================
CREATE USERS
Question
-------------
Create a group named "admingroup".Create a user natasha who have admingroup as
supplementary group.Create a user harry whoe have admingroup as supplementary
group.Create User sarah should not have access to interactive shell and she should
not be a member of "admingroup" group.Set the password of above three users as
'wakennym'.
=======================================================
useradd natasha
passwd wakennym
passwd natasha-->wakennym-wakennym
useradd harry
passwd harry-->wakennym-wakennym
useradd sarah
passwd sarah-->wakennym-wakennym
groupadd admingroup
=======================================================
COPY FILE.
-----------------
Copy the file /etc/fstab to /var/tmp/fstab and configure the ACL as mention
following..
The file is owned to the user root.
The file belongs to the group root.
The file should not be executable by anyone.
The user natasha sholud able to read and write to the file.
The user harry can neither read nor write to the file.
Other users(future or current) should be able to read the file.
=======================================================
cp /etc/fstab /var/tmp/fstab
setfacl -m u:natasha:rw- /var/tmp/fstab (Read and Write permission to natasha)
setfacl -m u:harry:--- /var/tmp/fstab (no permission to harry)
setfacl -m g:testgroup1:rwx /var/tmp/fstab (Read and Write Executable permission to
group testgroup1)
setfacl -m o:r-- /var/tmp/fstab (Others are having only read permission)
getfacl /var/tmp/fstab
=======================================================
COLLABRATIVE DIRECTORY.
-------------------------------------------
Create a directory "/home/admins" with the following characteristics.
Group ownership of "/home/admin" should go to "admingroup".
The directory should have read,write and access permission for all the members of
"admingroup" group but not to any other users.(It is noted that the "root" has full
access to all files present in the system).
Files created under "/home/admins" should get the same group ownership is set to
the "admingroup" group.
=======================================================
mkdir /home/admins
chown :admingroup /home/admins
setfacl -m g:admingroup:rwx /home/admins
setfacl -m u:root:--- /home/admins
setfacl -m o:--- /home/admins
chown -R :admingroup /home/admins/
chmod g+s /home/admins
=======================================================
CONFIGURE NTP.
--------------------
Configure your machine to be a NTP client of classroom.example.com
=======================================================
timedatectl
timedatectl
=======================================================
•CRON JOB.
-----------------
The user natasha must configure a cron job that runs at every 2 minutes and execute
the job "logger "EX200 EXAM IS ON PROGRESS".
=======================================================
note:- [a] – Minute [b] – Hour [c] – Day [d] – Month [e] – Day of the Week
crontab -e -u natasha
*/2 * * * * /usr/bin/logger "EXAM IS IN PROGRESS"
=======================================================
•Hard Link and Soft Link.
----------------------
Hard Link
ln logsfileSJ.txt /root/folder1/newhardlink.txt
=======================================================
=======================================================
•Main Paths for configuration
----------------------
/etc/passwd
/etc/shadow
/etc/group
/bin/bash
/dev/null
/bin/bash
/sbin/nologin
/etc/sudoers
/etc/profile & etc/bashrc --> umask value
cat /etc/bashrc--> for Umask default value setup
cat /etc/profile
/etc/selinux/config
=======================================================
Sudo Permission ( Wheel Group )
=======================================================
To enable full sudo access for the user user01, you could create
/etc/sudoers.d/user01
with the following content:
user01 ALL=(ALL) ALL
To enable full sudo access for the group group01, you could create
/etc/sudoers.d/group01
with the following content:
%group01 ALL=(ALL) ALL
example:-
echo "%admin ALL=(ALL) ALL" >> /etc/sudoers.d/admin
=========================================================
USER Removal
=========================================================
• The userdel username command removes the details of username from /etc/passwd,
but
leaves the user's home directory intact.
• The userdel -r username command removes the details of username from /etc/passwd
and also deletes the user's home directory.
=========================================================
Group Operations
=========================================================
groupmod -n group0022 group02 --->the -n option specifies a new name for the group
groupmod -g 20000 group0022 --> -g option specifies a new GID.
groupdel group0022 -->command removes groups group0022
usermod -g group01 user02 --> change user02 primary group to group01
usermod -aG group01 user03 --> command adds user03 to a supplementary group.
=======================================================
CHAGE Command
=====================================================
--> please get from note.
=======================================================
CHMOD Command
=====================================================
chmod WhoWhatWhich file|directory
• Who is u, g, o, a (for user, group, other, all)
• What is +, -, = (for add, remove, set exactly)
• Which is r, w, x (for read, write, execute)
chmod -R g+rwX demodir --> change permission of demo directory for group
recursively ( read write and execute)
chmod a+x file2 --> Setting executable permission for ( user & group&Other users)
chmod go-rw file1--> removes the read and write permission for the gropu and other
user permissions
1. Start with 0.
2. If the read permission should be present for this access level, add 4.
3. If the write permission should be present, add 2.
4. If the execute permission should be present, add 1.
=======================================================
CHOWN Command
=====================================================
chown student test_file --> ownership of the test_file file to the student
chown -R sijo softhardlink/ -->user ownership of the folder and the contents are
changed to user sijo
chown -R :ictsupport softhardlink/ --> group ownership of the folder and the
contents are changed to group ictsupport
chown visitor:guests test_dir --> changing the user and group ownership
accordingly
=======================================================
•Special Permission.
----------------------
=======================================================
u+s (suid) File executes as the user that owns the file, not the user that ran the
file. No effect.
g+s (sgid) File executes as the group that owns the file.
Files newly created in the directory have their group owner set to
match the group owner of the directory.
o+t (sticky) No effect. Users with write access to the directory can only remove
files that they own; they cannot remove or
force saves to files owned by other users.
umask
umask 007
vi ~/.bashrc
cat /etc/bashrc
cat /etc/profile
=======================================================
•SE Linux.
----------------------
Enforcing
Permissive
Disabled
semanage port -l
ps axZ
ps -ZC httpd
Question
Open a web browser on workstation and try to view http://servera/index.html.
You will get an error message that says you do not have permission to access the
file.
6. To permit access to the index.html file on servera, SELinux must be configured.
Define
an SELinux file context rule that sets the context type to httpd_sys_content_t for
the
/custom directory and all the files below it.
=======================================================
Tuning Profile
=======================================================
tuned-adm
tuned-adm profile <available profile from tuned-adm list command> --> sets that
profile.
renice -n 19 3521 --> 3521 (process ID) old priority 15, new priority 19
ps u $(pgrep sha1sum)
ps aux --sort=pcpu
=======================================================
YUM
=======================================================
List installed and available packages by name --- yum list [NAME-PATTERN]
List installed and available groups --- yum group list
Search for a package by keyword --- yum search KEYWORD
Show details of a package --- yum info PACKAGENAME
Install a package --- yum install PACKAGENAME
Install a package group --- yum group install GROUPNAME
Update all packages --- yum update
Remove a package --- yum remove PACKAGENAME
Display transaction history --- yum history
=======================================================
Mounting
=======================================================
lsblk -f ( Shows the UUID also)
Parted
parted /dev/sdb
mklabel ( msdos/gpt)
select the file systems --> parted /dev/vdb help mkpart --> commands shows the
available file systems can be parted.
quit
udevadm settle -->This command waits for the system to detect the new
partition and to create the associated device file under the /dev directory
fstab entry
=======================================================
SWAP space Creation with parted
=======================================================
parted /dev/sdb
mkpart ( crate partition)
quit
mkswap /dev/sdb2
fstab entry
UUID=ffde66ff-197f-47c8-87e9-2cd9168bfc0e swap swap defaults 0 0
swapon /dev/vdb2
swapon
=======================================================
•SYSTEMCTL
----------------------
systemctl list-units --type=service
systemctl status sshd.service
=======================================================
=======================================================
•
----------------------
=======================================================
=======================================================
•
----------------------
=======================================================
=======================================================
•
----------------------
=======================================================
=======================================================
•CREATE USER.
----------------------
Create a user "alex" with uid 3456 with password "wakennym".
=======================================================
Check whether User alex is available
--> cat /etc/passwd | grep alex
If groupid
--> groupadd -g 5465 support
*************************************
????
• SELINUX DEBUGGING The system consists of a web server which serves the contents
in /var/www/htmlThe webserver serves output using the port 82,not the default
oneMake necessary configurations in your system for serving the content using the
port 82
•SWAP CREATION. Add the swap space with "512"MiB on your system.Don't remove the
existing swap.Your new swap should be mounted at booting time also.
•LV CRREATION. Create the "LVM" with the name "database" by using 50PE's from the
volume group "datastore".Consider the PE size as "16MB".Mount it on /mnt/database
with file system ext3.
•STRATIS CREATION Create a stratis volume on the disk which is not used for
partition purpose.Create the stratis filesystem "stratisfs" in the pool
"stratispool"Mount the volume under the directory "/stratisvolume".Put a copy of
the file in "/stratisvolume" which got from the link Create snapshot of "stratisfs"
named as "stratisnap"
•AUTOFS. The home directory of LDAP users are shared via NFS.The
classroom.example.com (172.25.254.254)shares home directory of ldapusers via
NFS.Mount /home/guests/ldapuserX to your system, where x is your foundation
number.The ldapuserX's home directory is at
classroom.example.com:/home/guests/ldapuserx.The ldapuserX's home directory should
be automounted locally beneath /home/guests as /home/guests/ldapuserX.The home
directories must be writable by their users.For remote logging to the ldapuser
using the password 'kerberos'
•LOCATE FILES. Locate the files of owner "iris" and copy to the location
/root/findresult directory.
•SEARCH WORDS. Find the string "squid" from /usr/share/dict/words file and copy the
lines in /root/lists.txt file.
serverb.lab.example.com configurations
• CONFIGURE YUM. Configure yum client by using the Yum baseurl path Configure yum
client by using the Yum baseurl paths
http://content.example.com/rhel8.0/x86_64/dvd/BaseOS and
http://content.example.com/rhel8.0/x86_64/AppStream
• LVRESIZE. Resize the lvm size to 300MiB the location from "/dev/vg/vo" without
loosing any data.Size between 270MiB and 330MiB is permissible
•SWAP CREATION. Add the swap space with "512"MiB on your system.Don't remove the
existing swap.Your new swap should be mounted at booting time also.
============================================================================
•LV CRREATION.
Create the "LVM" with the name "database" by using 50PE's from the volume group
"datastore".Consider the PE size as "16MB".Mount it on /mnt/database with file
system ext3.
============================================================================
udevadm settle
pvcreate /dev/sdc1 /dev/sdc2
mkfs.xfs /dev/srv1vg1/srv1lv1
lsblk -f
vgdisplay srv1vg1
parted /dev/sdc
parted -s /dev/sdc mkpart primary 2148MiB 3218MiB
parted -s /dev/sdc set 3 lvm on
pvcreate /dev/sdc3
vgextend srv1vg1 /dev/sdc3
vgdisplay
vgdisplay srv1vg1
lvdisplay /dev/srv1vg1/srv1lv1
Notes
lvextend -l 128 --> Resize the logical volume to exactly 128 extents in size.
lvextend -l +128 --> Add 128 extents to the current size of the logical volume.
lvextend -L 128M --> Resize the logical volume to exactly 128 MiB.
lvextend -L +128M --> Add 128 MiB to the current size of the logical volume.
lvextend -l +50%FREE --> Add 50 percent of the current free space in the VG to the
LV.
xfs_growfs /root/lvmount
resize2fs /dev/vg01/lv01 also can be used
============================================================================
•VDO
============================================================================
# yum install vdo kmod-kvdo
mkfs.xfs -K /dev/mapper/vdo01
udevadm settle
mkdir /mnt/vdo01
mount /dev/mapper/vdo01 /mnt/vdo01/
Mount the volume labvdo on /labvdovol with the XFS file system so that it persists
across reboots. Don't forget to use the x-systemd.requires=vdo.service mount
option in /etc/fstab
x-systemd.requires=vdo.service
-->
The -K option in the preceding mkfs.xfs command prevents the unused blocks
in the file system from being discarded immediately which lets the command return
faster
•STRATIS CREATION Create a stratis volume on the disk which is not used for
partition purpose.Create the stratis filesystem "stratisfs" in the pool
"stratispool"Mount the volume under the directory "/stratisvolume".Put a copy of
the file in "/stratisvolume" which got from the link Create snapshot of "stratisfs"
named as "stratisnap"
lsblk
Deleting
# umount myfs1
# umount myfs1-experiment (if you created it)
# stratis fs destroy mypool myfs1
# stratis fs destroy mypool myfs1-experiment
# stratis pool destroy mypool
stratis pool add-data pool1 /dev/vdc --> add additional block devices to a pool.
•CONFIGURE TUNING Activate the tuning profile in your system which is recommended
by the system by default.
pass
network
QUESTIONS
CONFIGURE SELINUX.
Configure the selinux mode of your system as enforcing.
CONFIGURE YUM.
Configure your machine such that you are able to download exam softwares from
http://content.example.com/rhel7.0/x86_64/dvd/
CONFIGURE NTP.
Configure your machine to be a NTP client of classroom.example.com
CREATE USERS.
Create the following users:
Create a group sysadmin.
Create a user alice who has sysadmin as a supplementary group.
Create a user harry who also has sysadmin as his supplementary group.
Create a user joy who does not have an interactive shell.
LVM CRREATION.
Create a logical volume with 20 extents where one extend having the size of 16MiB.
The logical volume has the name of database and volume group have the name of
datastore.
The logical volume should be mounted under the directory /mnt/database with a file
system of ext3 and should be automatically available on reboot.
COPY FILE.
Copy the file /etc/passwd to /var/tmp/passwd.
The file should belong to the user root and group root.
The user alice should be able to read and write on the file.
The user harry should neither read nor write on the file.
All other users should have read permission on the file.
CREATE DIRECTORY.
Create a directory /mnt/data.
The user alice and harry should be able to collaberatively work on this directory.
The files and directories created within this directory should automatically belong
to the group sysadmin.
All members of the group should have read and write access.
All other users should not have any permissions.
Note: By default, root user will have read and write access on all files and
directories.
UPDATE KERNEL.
Update your kernel from http://content.example.com/rhel7.0/x86_64/errata/
CRON JOB.
Alice must set a job to run at 14:05 every day and the job is /bin/echo hi
CREATE USER.
Create a user ipsr with used id 3345.
SWAP PARTITION.
Create a swap partition of 256M and should be automatically available on reboot.
LOCATE FILES.
Find all files owned by the user root and group mail, copy the output files to
/root/findings.
SEARCH WORDS.
Display the matches for the words which begin with "ns" in the
/usr/share/dict/words and save the output to a file /home/student/locate.txt.
AUTOFS.
The home directory of LDAP users are shared via NFS.
The classroom.example.com (172.25.254.254)shares home directory of ldapusers via
NFS.
Mount /home/guests/ldapuserX to your system, where x is your foundation number.
The ldapuserx's home directory is at classroom.example.com:/home/guests/ldapuserx.
The ldapuserx's home directory should be automounted locally beneath /home/guests.
The home directories must be writable by their users.
mkdir /home/guests/ldapuserX
Firewall-CMD
firewall-cmd --get-zones
firewall-cmd --get-default-zone
firewall-cmd --set-default-zone public
firewall-cmd --permanent --zone=public --list-all
firewall-cmd --permanent --zone=public --add-port=80/tcp
reload firewall-cmd
LVRESIZE.
Resize the logical volume 'm7_storage' to 900M which belongs to the volume group
'vgroup'.
BACKUP FILES.
Create an bzip2 archive /root/today_backup.tar.bz2 which stores the backup of
/etc .