# Task Solution ------------------------------------------------ ### Part 1: LVM create volume group on the second disk **/dev/sdb** To list all disks on device run ```bash= fdisk -l ``` <center> ![](https://i.imgur.com/XzagTsS.png) **we will create LVM on partion /dev/sdb1 and /dev/sdb2** </center> ### 1. Initializes PhysicalVolume by **pvcreate** command ```bash= pvcreate /dev/sdb1 /dev/sdb2 ``` ![](https://i.imgur.com/L1gBsh7.png) ### 2. Create a new volume group called vg1 using **vgcteate** command with 16M physical extent size. ```bash= vgcreate -s 16M vg1 /dev/sdb1 /dev/sdb2 ``` ![](https://i.imgur.com/TEzmlcA.png) // check vgs ### 3. Create a new logical volume in a volume group(vg1) called lvm02 with 50 extents size by **lvcreate** command ```bash= lvcreate -l 50 -n lvm02 vg1 ``` ![](https://i.imgur.com/j0xj5r0.png) ### 4. Create an ext4 filesystem in the logical volume (lvm02) ```bash= mkfs.ext4 /dev/vg1/lvm02 ``` ![](https://i.imgur.com/XAtpWU7.png) ### 5. Print logical volume attributes ```bash= blkid /dev/vg1/lvm02 ``` ![](https://i.imgur.com/inbTx0E.png) ### 6. make /mnt/data to mount it later ```bash= mkdir -p /mnt/data ``` ### 7. Copy the UUID of /dev/vg1/lvm02 in the /etc/fstab file ```bash= vim /etc/fstab ``` ![](https://i.imgur.com/gNqR8Ei.png) ### 8. Mount it under /mnt/data by **mount** command ```bash= mount -a ``` <center > All filesystems mentioned in fstab to be mounted as we do above . </center> #### To verfiry the mounting run : ```bash= mount ``` ![](https://i.imgur.com/XINoAqI.png) ### 9. Run fdisk again to see LVM :) ```bash= fdisk -l ``` ![](https://i.imgur.com/eyWjM0S.png) ------------------------------------------------------ ### Part 2: users, groups and permissions #### 1.Add user1 with id=601 and with nologin to shell (non-interactive shell) ant type password by passwd command . ```bash= useradd -m -u 601 -s /sbin/nologin user1 passwd user1 ``` ![](https://i.imgur.com/O1IHf6Z.png) #### To check the login open ssh from user1 ![](https://i.imgur.com/sPYkwhD.png) #### 2. Add user to TrainingGroup * First add TrainingGroup to groups * Second modfiy in the user1 attribites to add it to TrainingGroup * open /etc/passwd to see users ```bash= groupadd TrainingGroup usermod -a -g TrainingGroup user1 id user1 ``` ![](https://i.imgur.com/Jlf0q5N.png) #### 3. * First add AdminGroup to groups * Second Add user2 , user3 with Admin group and password * open /etc/passwd to see users ```bash= groupadd AdminGroup useradd -m user2 useradd -m user3 passwd user2 passwd user3 usermod -a -G AdminGroup user2 usermod -a -G AdminGroup user2 cat /etc/passwd | tail ``` ![](https://i.imgur.com/r1iLZL7.png) * add user3 permisions ```bash= usermod -a -G wheel user3 id user3 ``` ![](https://i.imgur.com/DE6tAL3.png) ------------------------------------------------- ### Part 3: SSH **Connect ssh with another ip (like ubuntu vm)** ```bash= ssh nisreen@192.168.56.101 ``` ![](https://i.imgur.com/wi5sGbi.png) * To generate ssh Key : ```bash= ssh-keygen -t rsa ``` ![](https://i.imgur.com/K515GPQ.png) Note: the public key by defult will be stored in username/.ssh * Copy public key to the server: In the server device: ```bash= ssh-copy-id -i ~/.ssh/id_rsa nisreen@192.168.56.101 ``` ![](https://i.imgur.com/B1dRxR9.png) * exit the session and log it again without password: ```bash= exit ssh nisreen@192.168.56.101 ``` ![](https://i.imgur.com/IdgH42W.png) ------------------------------------------------ ### Part 4: permissions * Copy files ```bash= cp ../etc/fstab ../var/tmp/admin ``` <center> Note : this is root directoy </center> * Open tmp directoy and list the files to see admin file ```bash= cd ../var/tmp ls -la ``` ![](https://i.imgur.com/hlHupll.png) * Set permissions for specific users, without changing the ownership of the directory by setfacl command. ```bash= setfacl -R -m u:user1:rwx admin ``` Note : others permision is 0 ![](https://i.imgur.com/xSn1r9E.png) ------------------------------------- ### Part 5: permissions **Enforcing mode is enabled by default when the system was initially installed with SELinux** * Open /etc/selinux/config ```bash= vi /etc/selinux/config ``` * Configure the SELINUX=enforcing option: ![](https://i.imgur.com/vtXP9fi.png) * Save the chang and reboot the system ```bash= reboot ``` * Confirm that the getenforce command returns Enforcing: ```bash= getenforce ``` ![](https://i.imgur.com/o0AhJNU.png) ---------------------------------------- ### Part 6: bash script and processes 1. Create process in t he background to sleep for 10 m ```bash= sleep 10m & ``` 2. Display the process ```bash= ps ``` 3. Kill the process by ID ```bash= kill 2409 ``` 4. Display the process again ```bash= ps ``` ![](https://i.imgur.com/bZOtEI8.png) ----------------------------------------------- ### Part 8: Network management * Open port 80,443 with firewall commands: ```bash= sudo firewall-cmd --permanent --zone=public --add-port=80/tcp sudo firewall-cmd --permanent --zone=public --add-port=443/tcp sudo firewall-cmd --reload sudo firewall-cmd --permanent --zone=public --list-ports ``` ![](https://i.imgur.com/DiW1Ntf.png) * To block ssh connction from colleague ip (like ubutnu): ```bash= sudo firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='192.168.56.101' reject" sudo firewall-cmd --reload ``` #### IF we try to connect ssh from ubuntu ![](https://i.imgur.com/j4UmXyy.png) ----------------------------------------------- ### Part 9: Cronjob 1. create bashscript file to collect current user login and store it in login.txt file ```bash= echo -e -n $(date +"%D %T" ) "\t" >> login.txt for user in $(who | awk '{print $1}' | sort | uniq ); do echo -n -e "$user \t " >> login.txt done echo -e "\n" >> login.txt ``` who : display users and login information awk '{print $1}: get the users sort : sort name to be able remove duplicate uniq : remove duplicate usernames 2. create crontab at 1:30 AM to run script ```bash= crontab -e ``` Add a cronjob: 30 1 * * * /home/nisreenmaher/getuserlogin.sh ### Test the cronjob: ##### edit on crontab to add near time to me to see the result : ![](https://i.imgur.com/ylXPA6N.png)