Week 2 - Linux
Operator
• ; - user command more than two.
• & - execute 1st command after that execute 2nd command.
• && - if the 1st command is correct and execute, then execute the 2nd
command.
• | - only show last command.
• || - both command need to be correct
• Alias –p (list the alias)
• Alias ”hi=ping www.facebook.com”
• Unalias hi (remove the alias)
• History (list the shell history)
• History –c (clear the history)
Scheduling with Cron
Crontab Command
• crontab file
• crontab -l ( list your cronjobs)
• crontab -e ( edit your cron jobs)
• crontab -r ( remove all of your cron jobs)
• Systemctl restart crond
Root password recovery
1. Reboot
2. Press “e” key
3. console=tty1 rd.break
4. Ctrl+x
5. Mount –o remount,rw /sysroot/
6. chroot /sysroot/
7. sh shell
8. passwd root
9. Put new password
10. cd /
11. touch /.autorelabel
12. Exit
13. Login new root password
User management
• Create new account à useradd “user1”
• Create password à passwd “user1”
• Check account à cat /etc/passwd
• Check account ID à id username
• Change group à usermod –aG group username
• Remove username from Group à gpasswd –d username group
• Account delete à userdel username
Group Management
• Create new group à groupadd “groupname”
• Check the group à getent “groupname”
• less /etc/gshadow
• less /etc/group
• Delete the Group à groupdel “groupname”
Rename Username and ID
• Rename the user à usermod –l newname oldname
• Change user ID à usermod –u UID username
• Change user Directory à usermod –d /home/changed_name –m
username
• Change Group Name à groupmod –n newgroupname
oldgroupname
• usermod (username) –s /sbin/nologin
File Permission
• Chmod u+x filename << for user
• Chmod g+x filename << for gp
• Chmod o+x filename << for other
• Chmod +x filename << for all
• “-x “ for remove permission
Change Owner
• chown username:groupname filename
• e.g >> root user >> otheruser
• chown ksk:root filename/dir
Special Permission
• Special permissions make up a fourth access level in addition
to user, group, and other. Special permissions allow for additional
privileges over the standard permission sets (as the name suggests).
https://www.redhat.com/sysadmin/suid-sgid-sticky-bit
Special Permission
• Chmod u+s filename
• Chmod g+s filename
• Chmod o+t filename
• “t” >> sticky (full ေပးထားေပမယ့် ဖျက်မရေပာင်)
• “-t” for remove permission
• SUID = 4
• SGID = 2
• Sticky = 1
• chmod X### file | directory
File Level Access Control List in Linux
• setfacl -m u:username:rwx filename
• setfacl -m u:username: --- filename
• getfacl filename (show file permission)
• Check permission with ‘ls’, if there is ‘+’ confirm there is ACL.
NTP Server Setup
• yum -y install chrony
• timedatectl set-ntp true
• vi /etc/chrony.conf
• server 0.asia.pool.ntp.org iburst
• Systemctl restart chronyd
• Systemctl restart enable chronyd
• date
Physical Volume Management (LVM)
• Check Hard Disk Drive à lsblk (from /dev/ )
• Partitioning à fdisk /dev/name (eg: n,p,w)
• Create Physical Volume à pvcreate /dev/{sdb1, sdb2, sdb3}
• Remove Physical Volume à pvremove /dev/{sdb1, sdb2, sdb3}
• Show Physical Volume à pvs
• Create Volume Group à vgcreate (vg_name) /dev/{sdb1, sdb2, sdb3}
• Remove Volume Group à vgremove (vg_name)
• Show Volume Group à vgs
Logical Volume Managemnet
• Create Logical Volume à lvcreate /dev/vg/lv1
• Create Logical Volume altogether with group à lvcreate –n lv2 –L +2G
(PV group name)
• Remove Logical Volume à lvremove /dev/vg/lv1
• Show Logical Volume à lvs
Extend and Reduce Volume Group and Logical
Volume
• vgextend vg_name /dev/sdb à increases a volume group's capacity
by adding one or more free physical volumes
• vgreduce vg_name /dev/sdb à decreases a volume group's capacity
by adding one or more free physical volumes
• lvextend –L +1G /dev/lv1
• lvreduce –L -1G /dev/lv1
• vgrename (/dev/vg1) (/dev/vg_newname)
• lvrename (/dev/lv1) (/dev/lv_newname)
Thank you