<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Aadarsha Khadka</title><link>https://aadarshakhadka.com.np/</link><description>Recent content on Aadarsha Khadka</description><generator>Hugo</generator><language>en</language><lastBuildDate>Fri, 07 Aug 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://aadarshakhadka.com.np/index.xml" rel="self" type="application/rss+xml"/><item><title>PL - 019 — SELinux Security Management &amp; Policy Control</title><link>https://aadarshakhadka.com.np/practice-log/linux/pl-019-selinux/</link><pubDate>Fri, 07 Aug 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/pl-019-selinux/</guid><description>&lt;h4 id="terminal-session"&gt;Terminal Session&lt;/h4&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt; # SELinux ( Security Enhanced Linux )

 # Modes of SELinux
 # - Enforcing
 # - Permission
 # - Disabled
 
| Mode | Policy Enforced | Violations Logged | Use Case | 
|----------------|-----------------|-------------------|-----------------------------------------|
| Enforcing | Yes | Yes | Normal/production systems | 
| Permissive | No | Yes | Testing and troubleshooting | 
| Disabled | No | No | SELinux is turned off (not recommended) | 

aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.2
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Thu Aug 6 05:14:23 2026 from 192.168.254.32

[aadarsha@lab ~]$ whoami
aadarsha

[aadarsha@lab ~]$ date
Thu Aug 6 05:18:47 AM +0545 2026

[aadarsha@lab ~]$ getenforce
Enforcing
 
 # Changing SELinux modes

 # Temporary

[aadarsha@lab ~]$ getenforce
Enforcing

[aadarsha@lab ~]$ setenforce 0
setenforce: security_setenforce() failed: Permission denied

[aadarsha@lab ~]$ su - root
Password: 
Last login: Thu Aug 6 05:14:54 +0545 2026 on pts/0

[root@lab ~]# getenforce
Enforcing

[root@lab ~]# setenforce 0

[root@lab ~]# getenforce
Permissive
 
[root@lab ~]# setenforce 1
 
[root@lab ~]# getenforce
Enforcing
 
 # Permanently
 
[root@lab ~]# cat /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
# See also:
# https://docs.fedoraproject.org/en-US/quick-docs/getting-started-with-selinux/#getting-started-with-selinux-selinux-states-and-modes
#
# NOTE: In earlier Fedora kernel builds, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
# grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
# grubby --update-kernel ALL --remove-args selinux
#
SELINUX=enforcing
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@lab ~]# 

[root@lab ~]# vi /etc/selinux/config

[root@lab ~]# cat /etc/selinux/config 
...
SELINUX=permissive
...
[root@lab ~]# 

[root@lab ~]# getenforce
Enforcing

 # After modifying SELINUX, to implement and persist the change, reboot the system (Need to do reboot to reload)
 # the policy of SELinux is applied during boot time
 
[root@lab ~]# reboot
[root@lab ~]# Connection to 192.168.254.2 closed by remote host.
Connection to 192.168.254.2 closed.
 
aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.2
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Thu Aug 6 05:18:39 2026 from 192.168.254.32

[aadarsha@lab ~]$ su - root
Password: 
Last login: Thu Aug 6 05:23:35 +0545 2026 on pts/0

[root@lab ~]# getenforce 
Permissive

[root@lab ~]# cat /.autorelabel
cat: /.autorelabel: No such file or directory
[root@lab ~]# 

[root@lab ~]# vi /etc/selinux/config 

[root@lab ~]# cat /etc/selinux/config 
...
SELINUX=permissive
...
[root@lab ~]# 

 # changing SELINUX to enforcing
 
[root@lab ~]# vi /etc/selinux/config 

[root@lab ~]# cat /etc/selinux/config 
...
#
SELINUX=enforcing
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@lab ~]# 

[root@lab ~]# getenfoce

[root@lab ~]# getenforce
Permissive

[root@lab ~]# touch /.autorelabel

[root@lab ~]# cat /.autorelabel 

[root@lab ~]# reboot
[root@lab ~]# Connection to 192.168.254.2 closed by remote host.
Connection to 192.168.254.2 closed.
aadarkdk@pop-os:~$ 

aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.2
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Thu Aug 6 05:29:27 2026 from 192.168.254.32
[aadarsha@lab ~]$ 

 # Note: while changing to enforcing mode must create /.autorelabel unlike permissive mode

[aadarsha@lab ~]$ getenforce
Enforcing
[aadarsha@lab ~]$ 

 # Security context of SELinux

[root@lab ~]# touch file1

[root@lab ~]# mkdir dir1
[root@lab ~]# 
 
[root@lab ~]# ls -Z
 system_u:object_r:admin_home_t:s0 anaconda-ks.cfg
unconfined_u:object_r:admin_home_t:s0 dir1
unconfined_u:object_r:admin_home_t:s0 file1
[root@lab ~]# 

[root@lab ~]# ls -Z file1 
unconfined_u:object_r:admin_home_t:s0 file1

 # Format of SELinux Security Context

 # User:Role:Type:Sensitivity

 # Type

 # Effects of Create, Copy &amp;amp; Move Operations on SELinux

 # - Create: When a file is created inside a directory then the file inherits the SELinux security context of the parent directory

 # - Copy: When a file is copied from one directory to another directory then file takes SELinux security context of the destination.

 # - Move: When a file is moved from one directory to another directory then the file still retains its original SELinux Security context

 # - Copy: When a file is copied from one directory to another directory then file takes SELinux security context of the destination directory


 # To show the effect of SELinux context, we need the service
 # Let&amp;#39;s use httpd

[root@lab ~]# rpm -q httpd
package httpd is not installed

[root@lab ~]# yum -y install httpd
...
Installed:
 apr-1.7.5-3.el10.x86_64 apr-util-1.6.3-23.el10.x86_64 
 apr-util-lmdb-1.6.3-23.el10.x86_64 apr-util-openssl-1.6.3-23.el10.x86_64 
 centos-logos-httpd-100.5-1.el10.noarch httpd-2.4.63-14.el10.x86_64 
 httpd-core-2.4.63-14.el10.x86_64 httpd-filesystem-2.4.63-14.el10.noarch 
 httpd-tools-2.4.63-14.el10.x86_64 mailcap-2.1.54-8.el10.noarch 
 mod_http2-2.0.29-4.el10.x86_64 mod_lua-2.4.63-14.el10.x86_64 

Complete!
[root@lab ~]# 
 
[root@lab ~]# systemctl status httpd
○ httpd.service - The Apache HTTP Server
 Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
 Active: inactive (dead)
 Docs: man:httpd.service(8)
[root@lab ~]# 

[root@lab ~]# systemctl start httpd

[root@lab ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
 Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
 Active: active (running) since Thu 2026-08-06 05:45:04 +0545; 5s ago
...
[root@lab ~]# systemctl enable httpd
Created symlink &amp;#39;/etc/systemd/system/multi-user.target.wants/httpd.service&amp;#39; → &amp;#39;/usr/lib/systemd/system/httpd.service&amp;#39;.
[root@lab ~]# 

[root@lab ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
 Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: disabled)
 Active: active (running) since Thu 2026-08-06 05:45:04 +0545; 17s ago
...
[root@lab ~]# 

[root@lab ~]# cd /var/www/html/
[root@lab html]# ls
[root@lab html]# 
[root@lab html]# vi index.html

[root@lab html]# ls
index.html
[root@lab html]# cat index.html 
&amp;lt;h1&amp;gt; Httpd Service is running &amp;lt;/h1&amp;gt;
[root@lab html]# 

[root@lab html]# ls -dZ /var/www/html/
system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
[root@lab html]# 

[root@lab html]# ls -Z index.html 
unconfined_u:object_r:httpd_sys_content_t:s0 index.html
[root@lab html]# 

 # the created file index.html has the security context same as that of it&amp;#39;s parent directory /var/www/html
 
[root@lab html]# systemctl is-enabled httpd
enabled

[root@lab html]# systemctl reload httpd

[root@lab html]# firewall-cmd --list-all | grep http
[root@lab html]# 
[root@lab html]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client ssh
 ports: 5050/tcp
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
[root@lab html]# 

[root@lab html]# firewall-cmd --permanent --add-service=http
success

[root@lab html]# firewall-cmd --reload
success

[root@lab html]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client http ssh
 ports: 5050/tcp
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
[root@lab html]#
 
[root@lab html]# ls
index.html
[root@lab html]# 

[root@lab html]# curl http://localhost
&amp;lt;h1&amp;gt; Httpd Service is running &amp;lt;/h1&amp;gt;
[root@lab html]# 

[root@lab html]# curl 0
&amp;lt;h1&amp;gt; Httpd Service is running &amp;lt;/h1&amp;gt;
[root@lab html]# 

[root@lab html]# curl 127.0.0.1
&amp;lt;h1&amp;gt; Httpd Service is running &amp;lt;/h1&amp;gt;
[root@lab html]# 

[root@lab html]# hostname -I
192.168.254.2 
 
[root@lab html]# vi index.html 

[root@lab html]# curl 127.0.0.1
&amp;lt;h1&amp;gt; Httpd Service is running &amp;lt;/h1&amp;gt;
&amp;lt;h3&amp;gt; Testing the Security context of SELinux &amp;lt;/h3&amp;gt;
[root@lab html]# 

[root@lab html]# cd
[root@lab ~]# pwd
/root

[root@lab ~]# vi index.html

[root@lab ~]# cat index.html 
&amp;lt;h1&amp;gt; this is the file created on /root &amp;lt;/h1&amp;gt;

&amp;lt;p&amp;gt; it&amp;#39;s security context will be according to it&amp;#39;s parent home directory &amp;lt;/p&amp;gt;

[root@lab ~]# 

[root@lab ~]# ls -dZ /root/
system_u:object_r:admin_home_t:s0 /root/
 
[root@lab ~]# ls -Z index.html 
unconfined_u:object_r:admin_home_t:s0 index.html

[root@lab ~]# cp /root/index.html /var/www/html/
cp: overwrite &amp;#39;/var/www/html/index.html&amp;#39;? y
[root@lab ~]# 

[root@lab ~]# ls -Z /var/www/html/index.html 
unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html
[root@lab ~]# 
 # In above, security context is according to destination&amp;#39;s parent directory

[root@lab ~]# ls -dZ /var/www/html/
system_u:object_r:httpd_sys_content_t:s0 /var/www/html/
[root@lab ~]# 

[root@lab ~]# curl 0
&amp;lt;h1&amp;gt; this is the file created on /root &amp;lt;/h1&amp;gt;

&amp;lt;p&amp;gt; it&amp;#39;s security context will be according to it&amp;#39;s parent home directory &amp;lt;/p&amp;gt;

[root@lab ~]# 

 # For the context of move:

[root@lab ~]# history

 1067 pwd
 1068 vi index.html 
 1069 ls -Z index.html 
 1070 ls -dZ . 
 1071 mv index.html /var/www/html/
 1072 curl 0
 1073 # This is the error page because of SELinux Security context.
 1074 clear
 1075 history
[root@lab ~]# 

[root@lab ~]# setenforce 0

[root@lab ~]# getenforce 
Permissive

[root@lab ~]# curl 0
&amp;lt;h1&amp;gt; this is the file created on /root &amp;lt;/h1&amp;gt;

&amp;lt;p&amp;gt; it&amp;#39;s security context will be according to it&amp;#39;s parent home directory &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt; While moving: security context is carried on &amp;lt;/p&amp;gt;
[root@lab ~]# 

 # while removing the SELinux to permissive from enforcing ---&amp;gt; bad practice in prod env

[root@lab ~]# cd /var/www/html/

[root@lab html]# ls
index.html

[root@lab html]# ls -dZ .
system_u:object_r:httpd_sys_content_t:s0 .

[root@lab html]# ls -Z index.html 
unconfined_u:object_r:admin_home_t:s0 index.html

 # different security context

 # Chaning SELinux Security Context of a File/Dir

 # chcon -t &amp;lt;Security Context Type&amp;gt; &amp;lt;file/dir&amp;gt;
 
[root@lab html]# pwd
/var/www/html

[root@lab html]# ls -dZ .
system_u:object_r:httpd_sys_content_t:s0 .

[root@lab html]# chcon -t httpd_sys_content_t index.html 

[root@lab html]# ls -Z index.html 
unconfined_u:object_r:httpd_sys_content_t:s0 index.html

[root@lab html]# chcon --reference=/var/www/html index.html 
 
 # OR

[root@lab html]# chcon --reference=/var/www/html index.html 

[root@lab html]# curl 0
&amp;lt;h1&amp;gt; this is the file created on /root &amp;lt;/h1&amp;gt;

&amp;lt;p&amp;gt; it&amp;#39;s security context will be according to it&amp;#39;s parent home directory &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt; While moving: security context is carried on &amp;lt;/p&amp;gt;
[root@lab html]# 

[root@lab html]# getenforce 
Permissive

[root@lab html]# setenforce 1

[root@lab html]# getenforce 
Enforcing
 
[root@lab html]# curl 0
&amp;lt;h1&amp;gt; this is the file created on /root &amp;lt;/h1&amp;gt;

&amp;lt;p&amp;gt; it&amp;#39;s security context will be according to it&amp;#39;s parent home directory &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt; While moving: security context is carried on &amp;lt;/p&amp;gt;
[root@lab html]# 

[root@lab html]# cd
[root@lab ~]# 
[root@lab ~]# cd -
/var/www/html
[root@lab html]# 
[root@lab html]# curl 0:80
&amp;lt;h1&amp;gt; this is the file created on /root &amp;lt;/h1&amp;gt;

&amp;lt;p&amp;gt; it&amp;#39;s security context will be according to it&amp;#39;s parent home directory &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt; While moving: security context is carried on &amp;lt;/p&amp;gt;
[root@lab html]# 

[root@lab html]# vi /etc/httpd/conf/httpd.conf 

[root@lab html]# grep Listen /etc/httpd/conf/httpd.conf 
# Listen: Allows you to bind Apache to specific IP addresses and/or
# Change this to Listen on a specific IP address, but note that if
#Listen 12.34.56.78:80
Listen 80
[root@lab html]# 

[root@lab html]# vi /etc/httpd/conf/httpd.conf # Modified port to 8080

[root@lab html]# grep Listen /etc/httpd/conf/httpd.conf 
# Listen: Allows you to bind Apache to specific IP addresses and/or
# Change this to Listen on a specific IP address, but note that if
#Listen 12.34.56.78:80
# Listen 80
Listen 8080
[root@lab html]# 

[root@lab html]# systemctl restart httpd
 
[root@lab html]# ls /var/log/httpd/
access_log error_log
[root@lab html]# 

[root@lab html]# curl 0:80
curl: (7) Failed to connect to 0.0.0.0 port 80 after 0 ms: Could not connect to server
[root@lab html]# 

[root@lab html]# curl 0:8080
&amp;lt;h1&amp;gt; this is the file created on /root &amp;lt;/h1&amp;gt;

&amp;lt;p&amp;gt; it&amp;#39;s security context will be according to it&amp;#39;s parent home directory &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt; While moving: security context is carried on &amp;lt;/p&amp;gt;
[root@lab html]# 

[root@lab html]# getenforce 
Enforcing
[root@lab html]# 

 # semanage port -a -t http_port_t -p 8080 tcp
 
[root@lab html]# # semanage port -a -t http_port_t -p tcp 8080

[root@lab html]# firewall-cmd --permanent --add-port=8080
Error: INVALID_PORT: bad port (most likely missing protocol), correct syntax is portid[-portid]/protocol
[root@lab html]# 

[root@lab html]# firewall-cmd --permanent --add-port=8080/tcp
success

[root@lab html]# firewall-cmd --reload
success

[root@lab html]# firewall-cmd --list-ports
5050/tcp 8080/tcp

[root@lab html]# semanage port -a -t http_port_t -p tcp 8080
Port tcp/8080 already defined, modifying instead
[root@lab html]# 

[root@lab html]# curl http://localhost:8080
&amp;lt;h1&amp;gt; this is the file created on /root &amp;lt;/h1&amp;gt;

&amp;lt;p&amp;gt; it&amp;#39;s security context will be according to it&amp;#39;s parent home directory &amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt; While moving: security context is carried on &amp;lt;/p&amp;gt;
[root@lab html]# 
 
[aadarsha@lab ~]$ whoami
aadarsha

[aadarsha@lab ~]$ su - root
Password: 
Last login: Fri Aug 7 05:13:01 +0545 2026 on pts/0

 # SELinux Booleans

[root@lab ~]# getenforce
Enforcing

[root@lab ~]# getsebool -a # list all boolean parameters
abrt_anon_write --&amp;gt; off
abrt_handle_event --&amp;gt; on
abrt_upload_watch_anon_write --&amp;gt; on
auditadm_exec_content --&amp;gt; on
authlogin_nsswitch_use_ldap --&amp;gt; off
authlogin_radius --&amp;gt; off
authlogin_yubikey --&amp;gt; off
cdrecord_read_content --&amp;gt; off
cluster_can_network_connect --&amp;gt; off
cluster_manage_all_files --&amp;gt; off
cluster_use_execmem --&amp;gt; off
colord_use_nfs --&amp;gt; off
condor_tcp_network_connect --&amp;gt; off
corecmd_bin_sys_resource --&amp;gt; off
cron_can_relabel --&amp;gt; off
cron_system_cronjob_use_shares --&amp;gt; off
cron_userdomain_transition --&amp;gt; on
cups_execmem --&amp;gt; off
daemons_dontaudit_scheduling --&amp;gt; on
daemons_dump_core --&amp;gt; off
daemons_enable_cluster_mode --&amp;gt; off
daemons_use_tcp_wrapper --&amp;gt; off
daemons_use_tty --&amp;gt; off
dbadm_exec_content --&amp;gt; on
dbadm_manage_user_files --&amp;gt; off
dbadm_read_user_files --&amp;gt; off
deny_bluetooth --&amp;gt; off
deny_execmem --&amp;gt; off
deny_ptrace --&amp;gt; off
dhcpc_exec_iptables --&amp;gt; off
dhcpd_use_ldap --&amp;gt; off
dnsmasq_use_ipset --&amp;gt; off
domain_can_mmap_files --&amp;gt; off
domain_can_write_kmsg --&amp;gt; off
domain_fd_use --&amp;gt; on
domain_kernel_load_modules --&amp;gt; on
fcron_crond --&amp;gt; off
fenced_can_network_connect --&amp;gt; off
fenced_can_ssh --&amp;gt; off
fips_mode --&amp;gt; on
ftpd_anon_write --&amp;gt; off
ftpd_connect_all_unreserved --&amp;gt; off
ftpd_connect_db --&amp;gt; off
ftpd_full_access --&amp;gt; off
ftpd_use_cifs --&amp;gt; off
ftpd_use_fusefs --&amp;gt; off
ftpd_use_nfs --&amp;gt; off
ftpd_use_passive_mode --&amp;gt; off
git_cgi_enable_homedirs --&amp;gt; off
git_cgi_use_cifs --&amp;gt; off
git_cgi_use_nfs --&amp;gt; off
git_session_bind_all_unreserved_ports --&amp;gt; off
git_session_users --&amp;gt; off
git_system_enable_homedirs --&amp;gt; off
git_system_use_cifs --&amp;gt; off
git_system_use_nfs --&amp;gt; off
gitosis_can_sendmail --&amp;gt; off
glance_api_can_network --&amp;gt; off
glance_use_execmem --&amp;gt; off
glance_use_fusefs --&amp;gt; off
global_ssp --&amp;gt; off
gluster_anon_write --&amp;gt; off
gluster_export_all_ro --&amp;gt; off
gluster_export_all_rw --&amp;gt; on
gluster_use_execmem --&amp;gt; off
gpg_web_anon_write --&amp;gt; off
gssd_read_tmp --&amp;gt; on
guest_exec_content --&amp;gt; on
haproxy_connect_any --&amp;gt; off
httpd_anon_write --&amp;gt; off
httpd_builtin_scripting --&amp;gt; on
httpd_can_check_spam --&amp;gt; off
httpd_can_connect_ftp --&amp;gt; off
httpd_can_connect_ldap --&amp;gt; off
httpd_can_connect_mythtv --&amp;gt; off
httpd_can_connect_zabbix --&amp;gt; off
httpd_can_manage_courier_spool --&amp;gt; off
httpd_can_network_connect --&amp;gt; off
httpd_can_network_connect_cobbler --&amp;gt; off
httpd_can_network_connect_db --&amp;gt; off
httpd_can_network_memcache --&amp;gt; off
httpd_can_network_redis --&amp;gt; off
httpd_can_network_relay --&amp;gt; off
httpd_can_sendmail --&amp;gt; off
httpd_dbus_avahi --&amp;gt; off
httpd_dbus_sssd --&amp;gt; off
httpd_dontaudit_search_dirs --&amp;gt; off
httpd_enable_cgi --&amp;gt; on
httpd_enable_ftp_server --&amp;gt; off
httpd_enable_homedirs --&amp;gt; off
httpd_execmem --&amp;gt; off
httpd_graceful_shutdown --&amp;gt; off
httpd_manage_ipa --&amp;gt; off
httpd_mod_auth_ntlm_winbind --&amp;gt; off
httpd_mod_auth_pam --&amp;gt; off
httpd_read_user_content --&amp;gt; off
httpd_run_ipa --&amp;gt; off
httpd_run_preupgrade --&amp;gt; off
httpd_run_stickshift --&amp;gt; off
httpd_serve_cobbler_files --&amp;gt; off
httpd_setrlimit --&amp;gt; off
httpd_ssi_exec --&amp;gt; off
httpd_sys_script_anon_write --&amp;gt; off
httpd_tmp_exec --&amp;gt; off
httpd_tty_comm --&amp;gt; off
httpd_unified --&amp;gt; off
httpd_use_cifs --&amp;gt; off
httpd_use_fusefs --&amp;gt; off
httpd_use_gpg --&amp;gt; off
httpd_use_nfs --&amp;gt; off
httpd_use_opencryptoki --&amp;gt; off
httpd_use_openstack --&amp;gt; off
httpd_use_sasl --&amp;gt; off
httpd_verify_dns --&amp;gt; off
icecast_use_any_tcp_ports --&amp;gt; off
init_audit_control --&amp;gt; on
init_create_dirs --&amp;gt; on
irc_use_any_tcp_ports --&amp;gt; off
irqbalance_run_unconfined --&amp;gt; off
irssi_use_full_network --&amp;gt; off
kdumpgui_run_bootloader --&amp;gt; off
keepalived_connect_any --&amp;gt; off
kerberos_enabled --&amp;gt; on
ksmtuned_use_cifs --&amp;gt; off
ksmtuned_use_nfs --&amp;gt; off
logadm_exec_content --&amp;gt; on
logging_syslogd_append_public_content --&amp;gt; off
logging_syslogd_can_sendmail --&amp;gt; off
logging_syslogd_list_non_security_dirs --&amp;gt; off
logging_syslogd_run_nagios_plugins --&amp;gt; off
logging_syslogd_run_unconfined --&amp;gt; off
logging_syslogd_use_tty --&amp;gt; on
login_console_enabled --&amp;gt; on
logrotate_read_inside_containers --&amp;gt; off
logrotate_use_cifs --&amp;gt; off
logrotate_use_fusefs --&amp;gt; off
logrotate_use_nfs --&amp;gt; off
logwatch_can_network_connect_mail --&amp;gt; off
lsmd_plugin_connect_any --&amp;gt; off
mcelog_client --&amp;gt; off
mcelog_exec_scripts --&amp;gt; on
mcelog_foreground --&amp;gt; off
mcelog_server --&amp;gt; off
mmap_low_allowed --&amp;gt; off
mount_anyfile --&amp;gt; on
mozilla_plugin_bind_unreserved_ports --&amp;gt; off
mozilla_plugin_can_network_connect --&amp;gt; on
mozilla_plugin_use_bluejeans --&amp;gt; off
mozilla_plugin_use_gps --&amp;gt; off
mozilla_plugin_use_spice --&amp;gt; off
mozilla_read_content --&amp;gt; off
mpd_enable_homedirs --&amp;gt; off
mpd_use_cifs --&amp;gt; off
mpd_use_nfs --&amp;gt; off
mysql_connect_any --&amp;gt; off
mysql_connect_http --&amp;gt; off
named_tcp_bind_http_port --&amp;gt; off
named_write_master_zones --&amp;gt; on
neutron_can_network --&amp;gt; off
nfs_export_all_ro --&amp;gt; on
nfs_export_all_rw --&amp;gt; on
nfsd_anon_write --&amp;gt; off
nis_enabled --&amp;gt; off
nscd_use_shm --&amp;gt; on
openshift_use_nfs --&amp;gt; off
polipo_connect_all_unreserved --&amp;gt; off
polipo_session_bind_all_unreserved_ports --&amp;gt; off
polipo_session_users --&amp;gt; off
polipo_use_cifs --&amp;gt; off
polipo_use_nfs --&amp;gt; off
polyinstantiation_enabled --&amp;gt; off
postfix_local_write_mail_spool --&amp;gt; on
postgresql_can_rsync --&amp;gt; off
postgresql_selinux_transmit_client_label --&amp;gt; off
postgresql_selinux_unconfined_dbadm --&amp;gt; on
postgresql_selinux_users_ddl --&amp;gt; on
pppd_can_insmod --&amp;gt; off
pppd_for_user --&amp;gt; off
racoon_read_shadow --&amp;gt; off
radius_use_jit --&amp;gt; off
redis_enable_notify --&amp;gt; off
rngd_execmem --&amp;gt; off
rpcd_use_fusefs --&amp;gt; off
rsync_anon_write --&amp;gt; off
rsync_client --&amp;gt; off
rsync_export_all_ro --&amp;gt; off
rsync_full_access --&amp;gt; off
rsync_sys_admin --&amp;gt; off
samba_create_home_dirs --&amp;gt; off
samba_domain_controller --&amp;gt; off
samba_enable_home_dirs --&amp;gt; off
samba_export_all_ro --&amp;gt; off
samba_export_all_rw --&amp;gt; off
samba_load_libgfapi --&amp;gt; off
samba_portmapper --&amp;gt; off
samba_run_unconfined --&amp;gt; off
samba_share_fusefs --&amp;gt; off
samba_share_nfs --&amp;gt; off
sanlock_enable_home_dirs --&amp;gt; off
sanlock_use_fusefs --&amp;gt; off
sanlock_use_nfs --&amp;gt; off
sanlock_use_samba --&amp;gt; off
saslauthd_read_shadow --&amp;gt; off
screen_allow_session_sharing --&amp;gt; off
secadm_exec_content --&amp;gt; on
secure_mode --&amp;gt; off
secure_mode_insmod --&amp;gt; off
secure_mode_policyload --&amp;gt; off
selinuxuser_direct_dri_enabled --&amp;gt; on
selinuxuser_execheap --&amp;gt; off
selinuxuser_execmod --&amp;gt; on
selinuxuser_execstack --&amp;gt; on
selinuxuser_mysql_connect_enabled --&amp;gt; off
selinuxuser_ping --&amp;gt; on
selinuxuser_postgresql_connect_enabled --&amp;gt; off
selinuxuser_rw_noexattrfile --&amp;gt; on
selinuxuser_share_music --&amp;gt; off
selinuxuser_tcp_server --&amp;gt; off
selinuxuser_udp_server --&amp;gt; off
selinuxuser_use_ssh_chroot --&amp;gt; off
smartmon_3ware --&amp;gt; off
smbd_anon_write --&amp;gt; off
spamassassin_can_network --&amp;gt; off
spamd_enable_home_dirs --&amp;gt; on
spamd_update_can_network --&amp;gt; off
squid_bind_snmp_port --&amp;gt; off
squid_connect_any --&amp;gt; on
squid_use_tproxy --&amp;gt; off
ssh_chroot_rw_homedirs --&amp;gt; off
ssh_keysign --&amp;gt; off
ssh_sysadm_login --&amp;gt; off
ssh_use_tcpd --&amp;gt; off
sslh_can_bind_any_port --&amp;gt; off
sslh_can_connect_any_port --&amp;gt; off
sssd_access_kernel_keys --&amp;gt; off
sssd_connect_all_unreserved_ports --&amp;gt; off
sssd_use_usb --&amp;gt; off
staff_exec_content --&amp;gt; on
staff_use_svirt --&amp;gt; off
swift_can_network --&amp;gt; off
sysadm_exec_content --&amp;gt; on
systemd_socket_proxyd_bind_any --&amp;gt; off
systemd_socket_proxyd_connect_any --&amp;gt; off
telepathy_connect_all_ports --&amp;gt; off
telepathy_tcp_connect_generic_network_ports --&amp;gt; on
tftp_anon_write --&amp;gt; off
tftp_home_dir --&amp;gt; off
tmpreaper_use_cifs --&amp;gt; off
tmpreaper_use_nfs --&amp;gt; off
tmpreaper_use_samba --&amp;gt; off
tomcat_can_network_connect_db --&amp;gt; off
tomcat_read_rpm_db --&amp;gt; off
tomcat_use_execmem --&amp;gt; off
unconfined_chrome_sandbox_transition --&amp;gt; on
unconfined_dyntrans_all --&amp;gt; off
unconfined_login --&amp;gt; on
unconfined_mozilla_plugin_transition --&amp;gt; on
unprivuser_use_svirt --&amp;gt; off
use_ecryptfs_home_dirs --&amp;gt; off
use_fusefs_home_dirs --&amp;gt; off
use_lpd_server --&amp;gt; off
use_nfs_home_dirs --&amp;gt; off
use_samba_home_dirs --&amp;gt; off
use_virtualbox --&amp;gt; on
user_exec_content --&amp;gt; on
varnishd_connect_any --&amp;gt; off
virt_hooks_unconfined --&amp;gt; off
virt_lockd_blk_devs --&amp;gt; off
virt_qemu_ga_manage_ssh --&amp;gt; off
virt_qemu_ga_read_nonsecurity_files --&amp;gt; off
virt_qemu_ga_run_unconfined --&amp;gt; off
virt_read_qemu_ga_data --&amp;gt; off
virt_rw_qemu_ga_data --&amp;gt; off
virt_sandbox_share_apache_content --&amp;gt; off
virt_sandbox_use_all_caps --&amp;gt; on
virt_sandbox_use_audit --&amp;gt; on
virt_sandbox_use_fusefs --&amp;gt; off
virt_sandbox_use_mknod --&amp;gt; off
virt_sandbox_use_netlink --&amp;gt; off
virt_sandbox_use_sys_admin --&amp;gt; off
virt_transition_userdomain --&amp;gt; off
virt_use_comm --&amp;gt; off
virt_use_execmem --&amp;gt; off
virt_use_fusefs --&amp;gt; off
virt_use_glusterd --&amp;gt; off
virt_use_nfs --&amp;gt; off
virt_use_pcscd --&amp;gt; off
virt_use_pulseaudio --&amp;gt; off
virt_use_rawip --&amp;gt; off
virt_use_samba --&amp;gt; off
virt_use_sanlock --&amp;gt; off
virt_use_usb --&amp;gt; on
virt_use_xserver --&amp;gt; off
virtqemud_use_execmem --&amp;gt; on
webadm_manage_user_files --&amp;gt; off
webadm_read_user_files --&amp;gt; off
wine_mmap_zero_ignore --&amp;gt; off
xdm_bind_vnc_tcp_port --&amp;gt; off
xdm_exec_bootloader --&amp;gt; off
xdm_manage_bootloader --&amp;gt; on
xdm_sysadm_login --&amp;gt; off
xdm_write_home --&amp;gt; off
xen_use_nfs --&amp;gt; off
xend_run_blktap --&amp;gt; on
xend_run_qemu --&amp;gt; on
xguest_connect_network --&amp;gt; on
xguest_exec_content --&amp;gt; on
xguest_mount_media --&amp;gt; on
xguest_use_bluetooth --&amp;gt; on
xserver_clients_write_xshm --&amp;gt; off
xserver_execmem --&amp;gt; off
xserver_object_manager --&amp;gt; off
zarafa_setrlimit --&amp;gt; off
zoneminder_anon_write --&amp;gt; off
zoneminder_run_sudo --&amp;gt; off
[root@lab ~]# 
[root@lab ~]# 
[root@lab ~]# getsebool -a | grep httpd
httpd_anon_write --&amp;gt; off
httpd_builtin_scripting --&amp;gt; on
httpd_can_check_spam --&amp;gt; off
httpd_can_connect_ftp --&amp;gt; off
httpd_can_connect_ldap --&amp;gt; off
httpd_can_connect_mythtv --&amp;gt; off
httpd_can_connect_zabbix --&amp;gt; off
httpd_can_manage_courier_spool --&amp;gt; off
httpd_can_network_connect --&amp;gt; off
httpd_can_network_connect_cobbler --&amp;gt; off
httpd_can_network_connect_db --&amp;gt; off
httpd_can_network_memcache --&amp;gt; off
httpd_can_network_redis --&amp;gt; off
httpd_can_network_relay --&amp;gt; off
httpd_can_sendmail --&amp;gt; off
httpd_dbus_avahi --&amp;gt; off
httpd_dbus_sssd --&amp;gt; off
httpd_dontaudit_search_dirs --&amp;gt; off
httpd_enable_cgi --&amp;gt; on
httpd_enable_ftp_server --&amp;gt; off
httpd_enable_homedirs --&amp;gt; off
httpd_execmem --&amp;gt; off
httpd_graceful_shutdown --&amp;gt; off
httpd_manage_ipa --&amp;gt; off
httpd_mod_auth_ntlm_winbind --&amp;gt; off
httpd_mod_auth_pam --&amp;gt; off
httpd_read_user_content --&amp;gt; off
httpd_run_ipa --&amp;gt; off
httpd_run_preupgrade --&amp;gt; off
httpd_run_stickshift --&amp;gt; off
httpd_serve_cobbler_files --&amp;gt; off
httpd_setrlimit --&amp;gt; off
httpd_ssi_exec --&amp;gt; off
httpd_sys_script_anon_write --&amp;gt; off
httpd_tmp_exec --&amp;gt; off
httpd_tty_comm --&amp;gt; off
httpd_unified --&amp;gt; off
httpd_use_cifs --&amp;gt; off
httpd_use_fusefs --&amp;gt; off
httpd_use_gpg --&amp;gt; off
httpd_use_nfs --&amp;gt; off
httpd_use_opencryptoki --&amp;gt; off
httpd_use_openstack --&amp;gt; off
httpd_use_sasl --&amp;gt; off
httpd_verify_dns --&amp;gt; off
[root@lab ~]# 
[root@lab ~]# 
[root@lab ~]# getsebool -a | grep connect
cluster_can_network_connect --&amp;gt; off
condor_tcp_network_connect --&amp;gt; off
fenced_can_network_connect --&amp;gt; off
ftpd_connect_all_unreserved --&amp;gt; off
ftpd_connect_db --&amp;gt; off
haproxy_connect_any --&amp;gt; off
httpd_can_connect_ftp --&amp;gt; off
httpd_can_connect_ldap --&amp;gt; off
httpd_can_connect_mythtv --&amp;gt; off
httpd_can_connect_zabbix --&amp;gt; off
httpd_can_network_connect --&amp;gt; off
httpd_can_network_connect_cobbler --&amp;gt; off
httpd_can_network_connect_db --&amp;gt; off
keepalived_connect_any --&amp;gt; off
logwatch_can_network_connect_mail --&amp;gt; off
lsmd_plugin_connect_any --&amp;gt; off
mozilla_plugin_can_network_connect --&amp;gt; on
mysql_connect_any --&amp;gt; off
mysql_connect_http --&amp;gt; off
polipo_connect_all_unreserved --&amp;gt; off
selinuxuser_mysql_connect_enabled --&amp;gt; off
selinuxuser_postgresql_connect_enabled --&amp;gt; off
squid_connect_any --&amp;gt; on
sslh_can_connect_any_port --&amp;gt; off
sssd_connect_all_unreserved_ports --&amp;gt; off
systemd_socket_proxyd_connect_any --&amp;gt; off
telepathy_connect_all_ports --&amp;gt; off
telepathy_tcp_connect_generic_network_ports --&amp;gt; on
tomcat_can_network_connect_db --&amp;gt; off
varnishd_connect_any --&amp;gt; off
xguest_connect_network --&amp;gt; on
[root@lab ~]# 

 # Example use case: 
 # while configuring load balancers or deploying application and allowing access, we may need to turn on Booleans
 # also for some security purposes, we may need to turn off Booleans

[root@lab ~]# getsebool httpd_can_network_connect
httpd_can_network_connect --&amp;gt; off

 # Enable SELinux Boolean Parameter

[root@lab ~]# setsebool -P httpd_can_network_connect on

[root@lab ~]# getsebool httpd_can_network_connect
httpd_can_network_connect --&amp;gt; on
 
[root@lab ~]# getsebool -a | grep ftp
ftpd_anon_write --&amp;gt; off
ftpd_connect_all_unreserved --&amp;gt; off
ftpd_connect_db --&amp;gt; off
ftpd_full_access --&amp;gt; off
ftpd_use_cifs --&amp;gt; off
ftpd_use_fusefs --&amp;gt; off
ftpd_use_nfs --&amp;gt; off
ftpd_use_passive_mode --&amp;gt; off
httpd_can_connect_ftp --&amp;gt; off
httpd_enable_ftp_server --&amp;gt; off
tftp_anon_write --&amp;gt; off
tftp_home_dir --&amp;gt; off
[root@lab ~]# 
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>PL - 021 — Secure SSH Configuration &amp; Remote Access Hardening</title><link>https://aadarshakhadka.com.np/practice-log/linux/pl-021-ssh-configuration/</link><pubDate>Thu, 06 Aug 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/pl-021-ssh-configuration/</guid><description>&lt;h4 id="concepts"&gt;Concepts:&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;SSH access control, key-based authentication, sshd hardening, secure remote administration&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id="remote-access-methods-use-when"&gt;Remote Access Methods (&lt;strong&gt;Use when:&lt;/strong&gt;)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Telnet: legacy device access only; insecure due to plaintext communication&lt;/li&gt;
&lt;li&gt;SSH: secure remote shell access and server administration&lt;/li&gt;
&lt;li&gt;SSH tunneling: encrypted access to internal services through a trusted host&lt;/li&gt;
&lt;li&gt;Jump host / Bastion host: controlled access path to private infrastructure&lt;/li&gt;
&lt;li&gt;VPN: secure remote connectivity into protected networks&lt;/li&gt;
&lt;li&gt;Console / Out-of-band access: emergency server recovery and troubleshooting&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="ssh-client-tools"&gt;SSH Client Tools&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;OpenSSH Client (Linux/macOS/Windows CLI): native command-line SSH access for administrators and automation&lt;/li&gt;
&lt;li&gt;PuTTY : lightweight Windows SSH client, commonly used for manual server access&lt;/li&gt;
&lt;li&gt;MobaXterm: Windows terminal suite with SSH, SFTP, X11 forwarding, and remote administration features&lt;/li&gt;
&lt;li&gt;Bitvise SSH Client: Windows SSH/SFTP client with advanced session and file transfer features&lt;/li&gt;
&lt;li&gt;Git Bash: Windows Unix-like terminal environment that provides OpenSSH commands&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id="best-practices"&gt;Best Practices:&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Disable password authentication after key validation&lt;/li&gt;
&lt;li&gt;Disable direct root login&lt;/li&gt;
&lt;li&gt;Restrict SSH users and groups&lt;/li&gt;
&lt;li&gt;Validate &lt;code&gt;sshd_config&lt;/code&gt; before restarting SSH service&lt;/li&gt;
&lt;li&gt;Monitor SSH authentication logs&lt;/li&gt;
&lt;li&gt;Disable unnecessary SSH features&lt;/li&gt;
&lt;li&gt;Maintain recovery access before applying lockout restrictions&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h4 id="terminal-session"&gt;Terminal Session&lt;/h4&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;aadarkdk@pop-os:~$ whoami
aadarkdk

aadarkdk@pop-os:~$ hostname
pop-os

aadarkdk@pop-os:~$ ping -c 2 192.168.254.2
PING 192.168.254.2 (192.168.254.2) 56(84) bytes of data.
64 bytes from 192.168.254.2: icmp_seq=1 ttl=64 time=0.486 ms
64 bytes from 192.168.254.2: icmp_seq=2 ttl=64 time=0.573 ms

--- 192.168.254.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1008ms
rtt min/avg/max/mdev = 0.486/0.529/0.573/0.043 ms
aadarkdk@pop-os:~$ 

aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.2
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Mon Aug 3 12:37:57 2026 from 192.168.254.32

[aadarsha@labserver ~]$ date
Mon Aug 3 01:48:08 PM +0545 2026

[aadarsha@labserver ~]$ whoami
aadarsha

[aadarsha@labserver ~]$ hostname
labserver
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ hostname -I
192.168.254.3 2407:5200:404:17e1:a00:27nf:fec7:6ccb 
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Mon Aug 3 14:00:25 +0545 2026 on pts/0

[root@labserver ~]# whoami
root

[root@labserver ~]# yum update -y

[root@labserver ~]# rpm -q openssh-server
openssh-server-9.9p1-28.el10.x86_64

[root@labserver ~]# yum install -y openssh-server
Last metadata expiration check: 2:23:50 ago on Mon 03 Aug 2026 12:17:22 PM +0545.
Package openssh-server-9.9p1-28.el10.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@labserver ~]# 

[root@labserver ~]# systemctl status sshd
● sshd.service - OpenSSH server daemon
 Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
 Active: active (running) since Mon 2026-08-03 14:20:57 +0545; 20min ago
...
[root@labserver ~]# 
 
[root@labserver ~]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client ssh
 ports: 
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
[root@labserver ~]# 

[root@labserver ~]# exit
logout

[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.2 closed.

aadarkdk@pop-os:~$ ssh root@192.168.254.2		# prevent direct root login in prod env
root@192.168.254.2&amp;#39;s password: 
Last login: Mon Aug 3 14:03:33 2026

[root@labserver ~]# whoami
root

 # Configuring SSH Server

[root@labserver ~]# vi /etc/ssh/sshd_config
sshd_config sshd_config.d/ 

[root@labserver ~]# vi /etc/ssh/sshd_config

[root@labserver ~]# netstat -tnl
-bash: netstat: command not found

[root@labserver ~]# yum whatprovides netstat
...
net-tools-2.0-0.72.20160912git.el10.x86_64 : Basic networking tools
Repo : baseos
...
[root@labserver ~]#
 
[root@labserver ~]# yum -y install net-tools
...
[root@labserver ~]#

[root@labserver ~]# netstat -tnl | grep 5050
[root@labserver ~]# 

[root@labserver ~]# vi /etc/ssh/sshd_config

[root@labserver ~]# cat /etc/ssh/sshd_config
#	$OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $

# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
...
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
Port 5050
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
...
[root@labserver ~]# 

[root@labserver ~]# getenforce 
Enforcing

[root@labserver ~]# vi /etc/ssh/sshd_config
 
[root@labserver ~]# semanage port -a -t ssh_port_t -p tcp 5050
-bash: semanage: command not found

[root@labserver ~]# dnf provides &amp;#39;/*semanage&amp;#39;
... 

[root@labserver ~]# dnf search semanage
...

[root@labserver ~]# dnf install -y policycoreutils-python-utils
...
Installed:
 checkpolicy-3.11-1.el10.x86_64 policycoreutils-python-utils-3.11-1.el10.noarch python3-audit-4.0.3-5.el10.x86_64 python3-distro-1.9.0-5.el10.noarch 
 python3-libsemanage-3.11-1.el10.x86_64 python3-policycoreutils-3.11-1.el10.noarch python3-setools-4.7.0-1.el10.x86_64 
Complete!
[root@labserver ~]# 

[root@labserver ~]# which semanage
/usr/sbin/semanage

[root@labserver ~]# semanage port -a -t ssh_port_t -p tcp 5050
Port tcp/5050 already defined, modifying instead
[root@labserver ~]# 

[root@labserver ~]# semanage port -l | grep ssh
ssh_port_t tcp 5050, 22
[root@labserver ~]# 
[root@labserver ~]# systemctl status sshd
...

[root@labserver ~]# systemctl restart sshd

[root@labserver ~]# systemctl is-active sshd
active

[root@labserver ~]# systemctl reload sshd
...

[root@labserver ~]# systemctl reload sshd

[root@labserver ~]# exit
logout
Connection to 192.168.254.2 closed.

aadarkdk@pop-os:~$ ssh root@192.168.254.2
ssh: connect to host 192.168.254.2 port 22: Connection refused

aadarkdk@pop-os:~$ ssh -p 22 aadarsha@192.168.254.2
ssh: connect to host 192.168.254.2 port 22: Connection refused

aadarkdk@pop-os:~$ ssh -p 5050 aadarsha@192.168.254.2
ssh: connect to host 192.168.254.2 port 5050: No route to host

aadarkdk@pop-os:~$ ssh -p 5050 root@192.168.254.2
ssh: connect to host 192.168.254.2 port 5050: No route to host
aadarkdk@pop-os:~$ 

 # After configuring firewall:
 
 # &amp;lt;firewall-cmd --permanent --add-port=5050/tcp
 
 # &amp;lt;firewall-cmd --reload

aadarkdk@pop-os:~$ ssh -p 5050 root@192.168.254.2
root@192.168.254.2&amp;#39;s password: 
Last login: Mon Aug 3 18:52:50 2026

[root@labserver ~]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client ssh
 ports: 5050/tcp
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
[root@labserver ~]# 

[root@labserver ~]# ss -tlnp | grep sshd
LISTEN 0 128 0.0.0.0:5050 0.0.0.0:* users:((&amp;#34;sshd&amp;#34;,pid=19856,fd=7))
LISTEN 0 128 [::]:5050 [::]:* users:((&amp;#34;sshd&amp;#34;,pid=19856,fd=8))
[root@labserver ~]# 

 # Preventing root login

[root@labserver ~]# vim /etc/ssh/sshd_config

[root@labserver ~]# cat /etc/ssh/sshd_config
...
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
PermitRootLogin no
...

[root@labserver ~]# systemctl reload sshd

[root@labserver ~]# exit
logout
Connection to 192.168.254.2 closed.
aadarkdk@pop-os:~$ 

aadarkdk@pop-os:~$ ssh -p 5050 root@192.168.254.2
root@192.168.254.2&amp;#39;s password: 
Last login: Mon Aug 3 19:53:47 2026 from 192.168.254.32

[root@labserver ~]# sshd -T | grep permitrootlogin
permitrootlogin yes

[root@labserver ~]# grep -R &amp;#34;PermitRootLogin&amp;#34; /etc/ssh/sshd_config.d/
/etc/ssh/sshd_config.d/01-permitrootlogin.conf:PermitRootLogin yes
 
[root@labserver ~]# ls /etc/ssh/sshd_config.d/
01-permitrootlogin.conf 40-redhat-crypto-policies.conf 50-redhat.conf

[root@labserver ~]# vim /etc/ssh/sshd_config.d/01-permitrootlogin.conf 

[root@labserver ~]# cat /etc/ssh/sshd_config.d/01-permitrootlogin.conf 
# This file has been generated by the Anaconda Installer.
# Allow root to log in using ssh. Remove this file to opt-out.
# PermitRootLogin yes
PermitRootLogin no		# --&amp;gt; added line

[root@labserver ~]# systemctl reload sshd

[root@labserver ~]# exit
logout
Connection to 192.168.254.2 closed.

aadarkdk@pop-os:~$ ssh -p 5050 root@192.168.254.2
root@192.168.254.2&amp;#39;s password: 
Permission denied, please try again.
root@192.168.254.2&amp;#39;s password: 
Permission denied, please try again.
root@192.168.254.2&amp;#39;s password: 
root@192.168.254.2: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
aadarkdk@pop-os:~$ 

 # But if after logging in from normal user, then user can switch to root user 
 
aadarkdk@pop-os:~$ ssh -p 5050 aadarsha@192.168.254.2
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Mon Aug 3 13:57:55 2026 from 192.168.254.32

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Mon Aug 3 19:54:14 +0545 2026 from 192.168.254.32 on pts/0
Last failed login: Mon Aug 3 20:01:15 +0545 2026 from 192.168.254.32 on ssh:notty
There were 3 failed login attempts since the last successful login.
[root@labserver ~]# 

[root@labserver ~]# whoami
root

 # login shells

[root@labserver ~]# grep bash /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
milan:x:1001:1004::/home/milan:/bin/bash
suman:x:1002:1005::/home/suman:/bin/bash

 # /bin/bash, /bin/sh, /bin/csh, /bin/tcsh

[root@labserver ~]# ls /home/
aadarsha milan suman

[root@labserver ~]# useradd -r -s /sbin/nologin appuser1

[root@labserver ~]# ls /home/
aadarsha milan suman

[root@labserver ~]# cat /etc/passwd | grep appuser1
appuser1:x:994:994::/home/appuser1:/sbin/nologin

 # Allow only the specific users to login using SSH
 
[root@labserver ~]# vim /etc/ssh/sshd_config

[root@labserver ~]# cat /etc/ssh/sshd_config
...
# allow the following users for ssh login
AllowUsers suman aadarsha
...
[root@labserver ~]# 

[root@labserver ~]# systemctl restart sshd
Job for sshd.service failed because the control process exited with error code.
See &amp;#34;systemctl status sshd.service&amp;#34; and &amp;#34;journalctl -xeu sshd.service&amp;#34; for details.

[root@labserver ~]# systemctl reload sshd
sshd.service is not active, cannot reload.

[root@labserver ~]# sshd -t
/etc/ssh/sshd_config line 45: unsupported option &amp;#34;n&amp;#34;.

[root@labserver ~]# vi /etc/ssh/sshd_config

[root@labserver ~]# systemctl reload sshd

[root@labserver ~]# ls /home/
aadarsha milan suman

[root@labserver ~]# exit
logout

[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.2 closed.

aadarkdk@pop-os:~$ ssh -p 5050 aadarsha@192.168.254.2
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Mon Aug 3 20:01:42 2026 from 192.168.254.32

[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.2 closed.

aadarkdk@pop-os:~$ ssh -p 5050 suman@192.168.254.2
suman@192.168.254.2&amp;#39;s password: 
Permission denied, please try again.
suman@192.168.254.2&amp;#39;s password: 
Permission denied, please try again.
suman@192.168.254.2&amp;#39;s password: 
suman@192.168.254.2: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
aadarkdk@pop-os:~$ 

aadarkdk@pop-os:~$ ssh milan@192.168.254.2
ssh: connect to host 192.168.254.2 port 22: Connection refused

aadarkdk@pop-os:~$ ssh -p 5050 aadarsha@192.168.254.2
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Mon Aug 3 20:28:16 2026 from 192.168.254.32

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Mon Aug 3 20:01:51 +0545 2026 on pts/0

[root@labserver ~]# vim /etc/ssh/sshd_config

[root@labserver ~]# cat /etc/ssh/sshd_config
...
# Deny the following users for ssh login
DenyUsers suman aadarsha
...
[root@labserver ~]# 

[root@labserver ~]# vim /etc/ssh/sshd_config

[root@labserver ~]# systemctl restart sshd
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="configuring-openssh-and-restricting-ssh-access-using-firewalld-rich-rules"&gt;Configuring OpenSSH and Restricting SSH Access Using Firewalld Rich Rules&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt; # The SSH server is configured to listen on TCP port 5050. Firewalld rich rules are then used to demonstrate two access control scenarios:

 # Allow SSH connections from an entire subnet (192.168.254.0/24)
 # Allow SSH connections from a single host (192.168.254.2)
 
 # In Client machine
 
[root@labserver ~]# rpm -q openssh-clients
openssh-clients-9.9p1-28.el10.x86_64

 # Now we can use: ssh, scp, sftp

[root@labserver ~]# which ssh
/usr/bin/ssh
[root@labserver ~]# which scp 
/usr/bin/scp
[root@labserver ~]# which sftp
/usr/bin/sftp

[root@labserver ~]# rpm -qf /usr/bin/scp
openssh-clients-9.9p1-28.el10.x86_64

 # In Server machine 

[root@labserver ~]# rpm -q openssh-server
openssh-server-9.9p1-28.el10.x86_64

 # Allow SSH Login from Selected IPs/Networks Only

 # machine2: Client (192.168.254.2)

[root@labserver ~]# hostname -I
192.168.254.2

[root@labserver ~]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client ssh
 ports: 5050/tcp
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
[root@labserver ~]# 

[root@labserver ~]# man firewalld.richlanguage

 # machine1: Server (192.168.254.1)

[aadarsha@labserver ~]$ hostname -I
192.168.254.1 
 
[aadarsha@labserver ~]$ su - root
Password: 

[root@labserver ~]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client ssh
 ports: 
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
[root@labserver ~]# 

[aadarsha@labserver ~]$ man firewalld.richlanguage

[aadarsha@labserver ~]$ firewalld-cmd --permanent --add-rich-rule=&amp;#39;rule family=&amp;#34;ipv4&amp;#34; source address=&amp;#34;192.168.254.2/24&amp;#34; to-port=&amp;#34;5050&amp;#34; protocol=&amp;#34;tcp&amp;#34; accept&amp;#39;
-bash: firewalld-cmd: command not found
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Mon Aug 3 22:10:55 +0545 2026 on pts/0
[root@labserver ~]# 
 
 # Allow SSH from an Entire Network
 
[root@labserver ~]# firewall-cmd --permanent --add-rich-rule=&amp;#39;rule family=&amp;#34;ipv4&amp;#34; source address=&amp;#34;192.168.254.2/24&amp;#34; port port=&amp;#34;5050&amp;#34; protocol=&amp;#34;tcp&amp;#34; accept&amp;#39;
success
[root@labserver ~]# 

[root@labserver ~]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client ssh
 ports: 
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
[root@labserver ~]# 

[root@labserver ~]# firewall-cmd --reload
success

[root@labserver ~]# hostname -I
192.168.254.1 2407:5200:401:17e1:a00:27ff:fe36:47e4 
[root@labserver ~]# 

[root@labserver ~]# firewall-cmd --permanent --remove-service=ssh
success

[root@labserver ~]# firewall-cmd --reload
success

[root@labserver ~]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client
 ports: 
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
	rule family=&amp;#34;ipv4&amp;#34; source address=&amp;#34;192.168.254.2/24&amp;#34; port port=&amp;#34;5050&amp;#34; protocol=&amp;#34;tcp&amp;#34; accept
[root@labserver ~]# 

[root@labserver ~]# ss -tlnp | grep sshd
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:((&amp;#34;sshd&amp;#34;,pid=900,fd=7))
LISTEN 0 128 [::]:22 [::]:* users:((&amp;#34;sshd&amp;#34;,pid=900,fd=8))

[root@labserver ~]# systemctl status sshd

[root@labserver ~]# grep ^Port /etc/ssh/sshd_config
[root@labserver ~]# 

[root@labserver ~]# vi /etc/ssh/sshd_config

[root@labserver ~]# systemctl restart sshd

[root@labserver ~]# sshd -t
[root@labserver ~]# 
[root@labserver ~]# systemctl status sshd
...

[root@labserver ~]# journalctl -u sshd -n 20 --no-pager
...

[root@labserver ~]# getenforce
Enforcing

[root@labserver ~]# semanage port -l | grep ssh
-bash: semanage: command not found
 
[root@labserver ~]# dnf install policycoreutils-python-utils
...
[root@labserver ~]# 
[root@labserver ~]# semanage port -l | grep ssh
ssh_port_t tcp 22

[root@labserver ~]# semanage port -a -t ssh_port_t -p tcp 5050
Port tcp/5050 already defined, modifying instead

[root@labserver ~]# semanage port -l | grep ssh
ssh_port_t tcp 5050, 22

[root@labserver ~]# systemctl restart sshd

[root@labserver ~]# systemctl status sshd

[root@labserver ~]# ss -tlnp | grep sshd
LISTEN 0 128 0.0.0.0:5050 0.0.0.0:* users:((&amp;#34;sshd&amp;#34;,pid=3484,fd=7))
LISTEN 0 128 [::]:5050 [::]:* users:((&amp;#34;sshd&amp;#34;,pid=3484,fd=8))

[root@labserver ~]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client
 ports: 
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
	rule family=&amp;#34;ipv4&amp;#34; source address=&amp;#34;192.168.254.2/24&amp;#34; port port=&amp;#34;5050&amp;#34; protocol=&amp;#34;tcp&amp;#34; accept

[root@labserver ~]# hostname -I
192.168.254.1 

 # Login from authorized Client:

 # from host machine on both: 
 
aadarkdk@pop-os:~$ ssh -p 5050 aadarsha@192.168.254.2
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Tue Aug 4 06:43:15 2026 from 192.168.254.32

[aadarsha@labserver ~]$ whoami
aadarsha

[aadarsha@labserver ~]$ hostname -I
192.168.254.2 

[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.2 closed.
aadarkdk@pop-os:~$ 
 
aadarkdk@pop-os:~$ ssh -p 5050 aadarsha@192.168.254.1
aadarsha@192.168.254.1&amp;#39;s password: 
Last login: Tue Aug 4 06:47:53 2026 from 192.168.254.32

[aadarsha@labserver ~]$ whoami
aadarsha
[aadarsha@labserver ~]$ hostname -I
192.168.254.1 

[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.1 closed.

aadarkdk@pop-os:~$ hostname -I
192.168.254.32 
aadarkdk@pop-os:~$ 

 # from client machine: 
 
[root@labserver ~]# hostname -I
192.168.254.2 2407:5200:401:17e1:a00:27ff:fec7:6ccb 

[root@labserver ~]# ssh -p 5050 aadarsha@192.168.254.1
The authenticity of host &amp;#39;[192.168.254.1]:5050 ([192.168.254.1]:5050)&amp;#39; can&amp;#39;t be established.
ED25519 key fingerprint is SHA256:YEx3XBATYe8oAk1bquc9zLHIWFe8pFYnfXJZqQMVCaE.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added &amp;#39;[192.168.254.1]:5050&amp;#39; (ED25519) to the list of known hosts.
aadarsha@192.168.254.1&amp;#39;s password: 
Last login: Tue Aug 4 09:42:44 2026 from 192.168.254.32

[aadarsha@labserver ~]$ whoami
aadarsha

[aadarsha@labserver ~]$ hostname -I
192.168.254.1 2407:5200:401:17e1:a00:27ff:fe36:47e4 

[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.1 closed.
 
[root@labserver ~]# hostname -I
192.168.254.2 2407:5200:401:17e1:a00:27ff:fec7:6ccb 
[root@labserver ~]# 

 # Allowing only specific host only:
 
[root@labserver ~]# hostname -I
192.168.254.1 
 
[root@labserver ~]# firewall-cmd --permanent --add-rich-rule=&amp;#39;rule family=&amp;#34;ipv4&amp;#34; source address=&amp;#34;192.168.254.2&amp;#34; port port=&amp;#34;5050&amp;#34; protocol=&amp;#34;tcp&amp;#34; accept&amp;#39;
success

[root@labserver ~]# firewall-cmd --reload
success

[root@labserver ~]# firewall-cmd --permanent --remove-rich-rule=&amp;#39;rule family=&amp;#34;ipv4&amp;#34; source address=&amp;#34;192.168.254.2/24&amp;#34; port port=&amp;#34;5050&amp;#34; protocol=&amp;#34;tcp&amp;#34; accept&amp;#39;
success

[root@labserver ~]# firewall-cmd --reload
success

[root@labserver ~]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client
 ports: 
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
	rule family=&amp;#34;ipv4&amp;#34; source address=&amp;#34;192.168.254.2&amp;#34; port port=&amp;#34;5050&amp;#34; protocol=&amp;#34;tcp&amp;#34; accept
[root@labserver ~]# 

 # from client

[root@labserver ~]# hostname -I
192.168.254.2 

[root@labserver ~]# ssh -p 5050 aadarsha@192.168.254.1
aadarsha@192.168.254.1&amp;#39;s password: 
Last login: Tue Aug 4 09:43:39 2026 from 192.168.254.2

[aadarsha@labserver ~]$ hostname -I
192.168.254.1
 
[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.1 closed.
[root@labserver ~]# 
 
aadarkdk@pop-os:~$ hostname -I
192.168.254.32

 # from host
 
aadarkdk@pop-os:~$ ssh -p 5050 aadarsha@192.168.254.1
ssh: connect to host 192.168.254.1 port 5050: No route to host			# ( Denied)
aadarkdk@pop-os:~$ 

[root@labserver ~]# hostname -I
192.168.254.1
[root@labserver ~]# firewall-cmd --permanent --remove-rich-rule=&amp;#39;rule family=&amp;#34;ipv4&amp;#34; source address=&amp;#34;192.168.254.2&amp;#34; port port=&amp;#34;5050&amp;#34; protocol=&amp;#34;tcp&amp;#34; accept&amp;#39;
success
[root@labserver ~]# firewall-cmd --reload
success

 # Note:
 # The notation 192.168.254.2/24 matches the entire 192.168.254.0/24 subnet, not just the host 192.168.254.2

 # Network address: 192.168.254.0
 # Usable host range: 192.168.254.1 – 192.168.254.254
 # Broadcast address: 192.168.254.255

 # As a result, hosts such as 192.168.254.2, 192.168.254.32, and 192.168.254.100 all match the rule.
 # To allow only a single host, specify 192.168.254.2 or 192.168.254.2/32.
&lt;/code&gt;&lt;/pre&gt;&lt;hr&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt; # Allow Only Key-based Authentication for SSH Login ( PasswordLess Login )
 
 SSH Key-Based Login


 Machine A (Client) Machine B (Server)
 (Initiates SSH Login) (Accepts SSH Login)

 +--------------------+ +---------------------------+
 | Generate SSH Keys | | ~/.ssh/authorized_keys |
 | ssh-keygen | | |
 | | | |
 | Private Key 🔒 | | Public Key 🔑 |
 | Public Key 🔑 |------------&amp;gt;| (Copied from Client) |
 +--------------------+ +---------------------------+
 | ^
 | |
 +----------- ssh user@server -------+
 (Passwordless Login)
 
[root@labserver ~]# vi /etc/ssh/sshd_config
 
[root@labserver ~]# cat /etc/ssh/sshd_config
...
#Port 22
# port changed to:
Port 5050
...

# Allow the following users for ssh login
AllowUsers suman aadarsha
...
#PubkeyAuthentication yes
# uncommented
PubkeyAuthentication yes
...
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
# changed to no
PasswordAuthentication no
...
[root@labserver ~]# 

 # trying to login using ssh password based login
 
aadarkdk@pop-os:~$ ssh -p 5050 suman@192.168.254.2
suman@192.168.254.2: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

aadarkdk@pop-os:~$ ssh -p 5050 aadarsha@192.168.254.2
aadarsha@192.168.254.2: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
aadarkdk@pop-os:~$ 


 # Generating SSH Key Pair
 
[root@labserver ~]# whoami
root

[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ whoami
aadarsha

 # Generating SSH key from aadarsha user

[aadarsha@labserver ~]$ hostname
labserver

[aadarsha@labserver ~]$ pwd
/home/aadarsha

[aadarsha@labserver ~]$ hostname -I
192.168.254.2 

[aadarsha@labserver ~]$ ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .lesshst 

 # In previous versions

 # id_rsa ----&amp;gt; Private key
 # id_rsa.pub ----&amp;gt; Public key

[aadarsha@labserver ~]$ ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .lesshst 

[aadarsha@labserver ~]$ ssh-keygen 
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/aadarsha/.ssh/id_ed25519): 
Created directory &amp;#39;/home/aadarsha/.ssh&amp;#39;.
...
+--[ED25519 256]--+
| ++o |
| o.+ |
| .E = |
|+.+B.. |
|=*.++o S |
|=+=+++o. |
|o++ =*.o. |
|. .+o+o.o |
| .=++o |
+----[SHA256]-----+

[aadarsha@labserver ~]$ ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .lesshst .ssh

[aadarsha@labserver ~]$ cd .ssh/

[aadarsha@labserver .ssh]$ ls
id_ed25519 id_ed25519.pub

[aadarsha@labserver .ssh]$ cat id_ed25519
-----BEGIN OPENSSH PRIVATE KEY-----
...
-----END OPENSSH PRIVATE KEY-----

[aadarsha@labserver .ssh]$ cat id_ed25519.pub 
ssh-ed25519 AAAAC3NzaC1lZVI1NTE5AAAAILpf4TxhdlQ45+/z4RJeI/l1Q7LwbPpccIjcYm8xA/0b aadarsha@labserver

 # Client

[root@labserver ~]# hostname
labserver
[root@labserver ~]# hostname -I
192.168.254.2

[root@labserver ~]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client ssh
 ports: 5050/tcp
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
[root@labserver ~]#

[root@labserver ~]# ls /home/
aadarsha milan suman

[root@labserver ~]# su - aadarsha
Last login: Wed Aug 5 00:51:52 +0545 2026 from 192.168.254.32 on pts/0

[aadarsha@labserver ~]$ ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .lesshst .ssh
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cd .ssh/
[aadarsha@labserver .ssh]$ ls
id_ed25519 id_ed25519.pub

[aadarsha@labserver .ssh]$ scp id_ed25519.pub aadarsha@192.168.254.1 /home/aadarsha/lab-key.pub
/home/aadarsha/lab-key.pub: No such file or directory
[aadarsha@labserver .ssh]$ 

[aadarsha@labserver .ssh]$ scp id_ed25519.pub aadarsha@192.168.254.1:/home/aadarsha/lab-key.pub
The authenticity of host &amp;#39;192.168.254.1 (192.168.254.1)&amp;#39; can&amp;#39;t be established.
ED25519 key fingerprint is SHA256:YEx3XBATYe8oAk1bquc9zLHIWFe8pFYnfXJZqQMVCaE.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added &amp;#39;192.168.254.1&amp;#39; (ED25519) to the list of known hosts.
aadarsha@192.168.254.1&amp;#39;s password: 
id_ed25519.pub 100% 100 73.1KB/s 00:00 
[aadarsha@labserver .ssh]$ 
 
[aadarsha@labserver .ssh]$ # ssh-copy-id -p 22 aadarsha@192.168.254.1
 
[aadarsha@labserver .ssh]$ cd
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ hostname
labserver

[aadarsha@labserver ~]$ ssh -p 5050 -i /home/aadarsha/.ssh/id_ed25519.pub aadarsha@192.168.254.1
ssh: connect to host 192.168.254.1 port 5050: No route to host

[aadarsha@labserver ~]$ ssh -p 22 -i /home/aadarsha/.ssh/id_ed25519.pub aadarsha@192.168.254.1
aadarsha@192.168.254.1&amp;#39;s password: 
Last login: Wed Aug 5 01:20:33 2026

[aadarsha@mainserver ~]$ hostname
mainserver

[aadarsha@mainserver ~]$ hostname -I
192.168.254.1 
[aadarsha@mainserver ~]$ exit
logout
Connection to 192.168.254.1 closed.

[aadarsha@labserver ~]$ ssh -p 22 -i /home/aadarsha/.ssh/id_ed25519.pub aadarsha@192.168.254.1
aadarsha@192.168.254.1&amp;#39;s password: 
Last login: Wed Aug 5 01:36:46 2026 from 192.168.254.2
[aadarsha@mainserver ~]$ 

[aadarsha@mainserver ~]$ exit
logout
Connection to 192.168.254.1 closed.

[aadarsha@labserver ~]$ ssh -p 22 -i /home/aadarsha/.ssh/id_ed25519.pub aadarsha@192.168.254.1
aadarsha@192.168.254.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ ssh -p 22 -i /home/aadarsha/.ssh/id_ed25519 aadarsha@192.168.254.1
Last login: Wed Aug 5 01:39:05 2026 from 192.168.254.2
[aadarsha@mainserver ~]$
 
[aadarsha@mainserver ~]$ hostname
mainserver

[aadarsha@mainserver ~]$ hostname -I
192.168.254.1 
[aadarsha@mainserver ~]$ exit
logout
Connection to 192.168.254.1 closed.
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ hostname
labserver

[aadarsha@labserver ~]$ hostname -I
192.168.254.2 
 
[aadarsha@labserver ~]$ ssh aadarsha@192.168.254.1
Last login: Wed Aug 5 01:51:21 2026 from 192.168.254.2

[aadarsha@mainserver ~]$ exit
logout
Connection to 192.168.254.1 closed.

[aadarsha@labserver ~]$ ssh root@192.168.254.1
root@192.168.254.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
[aadarsha@labserver ~]$ 

 # Server

[root@mainserver ~]# hostname
mainserver
[root@mainserver ~]# hostname -I
192.168.254.1 

[root@mainserver ~]# firewall-cmd --list-all
public (default, active)
 target: default
 ingress-priority: 0
 egress-priority: 0
 icmp-block-inversion: no
 interfaces: enp0s3
 sources: 
 services: cockpit dhcpv6-client ssh
 ports: 
 protocols: 
 forward: yes
 masquerade: no
 forward-ports: 
 source-ports: 
 icmp-blocks: 
 rich rules: 
[root@mainserver ~]# 
[root@mainserver ~]# ls /home/
aadarsha
[root@mainserver ~]# 

[root@mainserver ~]# su - aadarsha
Last login: Wed Aug 5 01:19:55 +0545 2026 on pts/0

[aadarsha@mainserver ~]$ ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc .lesshst
[aadarsha@mainserver ~]$ pwd
/home/aadarsha

[aadarsha@mainserver ~]$ ls
lab-key.pub
 
[aadarsha@mainserver ~]$ ls -l
total 4
-rw-r--r--. 1 aadarsha aadarsha 100 Aug 5 01:23 lab-key.pub
[aadarsha@mainserver ~]$ 
[aadarsha@mainserver ~]$ ssh -p 5050 -i lab-key.pub aadarsha@192.168.254.2
The authenticity of host &amp;#39;[192.168.254.2]:5050 ([192.168.254.2]:5050)&amp;#39; can&amp;#39;t be established.
ED25519 key fingerprint is SHA256:YEx3XBATYe8oAk1bquc9zLHIWFe8pFYnfXJZqQMVCaE.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added &amp;#39;[192.168.254.2]:5050&amp;#39; (ED25519) to the list of known hosts.
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Wed Aug 5 01:07:59 2026
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ hostname
labserver

[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.2 closed.
[aadarsha@mainserver ~]$
 
[aadarsha@mainserver ~]$ hostname
mainserver

[aadarsha@mainserver ~]$ vi /etc/ssh/sshd_config

[aadarsha@mainserver ~]$ su - root
Password: 
Last login: Wed Aug 5 01:05:49 +0545 2026 on pts/0

[root@mainserver ~]# vi /etc/ssh/sshd_config

[root@mainserver ~]# cat /etc/ssh/sshd_config
...
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
...
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
...
#PubkeyAuthentication yes
# un-commented
PubkeyAuthentication yes
...
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
# yes --&amp;gt; no (don&amp;#39;t allow password based authentication)
PasswordAuthentication no
#PermitEmptyPasswords no
...
[root@mainserver ~]# 

[root@mainserver ~]# systemctl restart sshd

[root@mainserver ~]# exit
logout

[aadarsha@mainserver ~]$ ls -a
. .. .bash_history .bash_logout .bash_profile .bashrc lab-key.pub .lesshst .ssh
 
[aadarsha@mainserver ~]$ ls -la .ssh/
total 8
drwx------. 2 aadarsha aadarsha 48 Aug 5 01:27 .
drwx------. 3 aadarsha aadarsha 130 Aug 5 01:27 ..
-rw-------. 1 aadarsha aadarsha 858 Aug 5 01:27 known_hosts
-rw-r--r--. 1 aadarsha aadarsha 102 Aug 5 01:27 known_hosts.old

[aadarsha@mainserver ~]$ ls -ld .ssh/
drwx------. 2 aadarsha aadarsha 48 Aug 5 01:27 .ssh/

[aadarsha@mainserver ~]$ cat lab-key.pub &amp;gt;&amp;gt; .ssh/authorized_keys

[aadarsha@mainserver ~]$ ls .ssh/
authorized_keys known_hosts known_hosts.old

[aadarsha@mainserver ~]$ ls -l .ssh/authorized_keys 
-rw-r--r--. 1 aadarsha aadarsha 100 Aug 5 01:48 .ssh/authorized_keys

[aadarsha@mainserver ~]$ chmod 600 .ssh/authorized_keys 

[aadarsha@mainserver ~]$ ls -l .ssh/authorized_keys 
-rw-------. 1 aadarsha aadarsha 100 Aug 5 01:48 .ssh/authorized_keys

[aadarsha@mainserver ~]$ rm lab-key.pub 
[aadarsha@mainserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex="0"&gt;&lt;code&gt; Generate SSH Key Pair
 (On the machine initiating SSH)

 +----------------------+
 | Machine A |
 | (Client/Admin) |
 |----------------------|
 | Private Key |
 | Public Key |
 +----------+-----------+
 |
 Copy ONLY Public Key |
 |
 +---------------+----------------+
 | |
 v v
 +----------------------+ +----------------------+
 | Machine B | | Machine C |
 | (Server 1) | | (Server 2) |
 |----------------------| |----------------------|
 | ~/.ssh/ | | ~/.ssh/ |
 | authorized_keys | | authorized_keys |
 | (Public Key) | | (Public Key) |
 +----------------------+ +----------------------+

 SSH Login SSH Login
 Machine A ---------&amp;gt; Machine B
 Machine A ---------&amp;gt; Machine C
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id="authentication-process"&gt;Authentication Process&lt;/h4&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt; 	 SSH Login

	+---------------------------+ +---------------------------+
	| Machine A (Client) | | Machine B (Server) |
	|---------------------------| |---------------------------|
	| Private Key | | authorized_keys |
	| id_ed25519 | | contains Public Key |
	+-------------+-------------+ +-------------+-------------+
	 | ^
	 | 1. ssh user@server |
	 |----------------------------------------------&amp;gt;|
	 | |
	 | 2. Server sends a challenge |
	 |&amp;lt;----------------------------------------------|
	 | |
	 | 3. Client signs challenge |
	 | using PRIVATE KEY |
	 |----------------------------------------------&amp;gt;|
	 | |
	 | 4. Server verifies signature |
	 | using PUBLIC KEY |
	 | |
	 |&amp;lt;----------- Login Successful -----------------|


 # Generate Key Pair ---&amp;gt; Client Machine

 # Private Key ---&amp;gt; NEVER leaves the Client

 # Public Key ---&amp;gt; Copy to Server

 # Server ---&amp;gt; Stores Public Key in ~/.ssh/authorized_keys

 # SSH Login ---&amp;gt; Client proves ownership of the Private Key
 Server verifies using the Public Key
 No password required
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id="best-practices-1"&gt;Best Practices&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Generate the SSH key pair only on the client machine (Machine A).&lt;/li&gt;
&lt;li&gt;Copy only the public key (id_ed25519.pub) to each server&amp;rsquo;s ~/.ssh/authorized_keys.&lt;/li&gt;
&lt;li&gt;Never copy or share the private key (id_ed25519).&lt;/li&gt;
&lt;li&gt;Use one key pair per administrator/user for better auditing and access management.&lt;/li&gt;
&lt;li&gt;Set correct permissions:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Disable password authentication after verifying SSH key login (if required by your security policy).&lt;/li&gt;
&lt;li&gt;Rotate SSH keys periodically and remove unused public keys from authorized_keys.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Remember: The private key never leaves the client machine. Only the public key is copied to the server&amp;rsquo;s ~/.ssh/authorized_keys file.&lt;/p&gt;</description></item><item><title>PL - 013 — Task Scheduling &amp; Automation ( at Jobs / Cron Jobs)</title><link>https://aadarshakhadka.com.np/practice-log/linux/pl-013-task-scheduling/</link><pubDate>Mon, 03 Aug 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/pl-013-task-scheduling/</guid><description>&lt;h4 id="concepts"&gt;Concepts:&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;at jobs,
cron jobs&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id="task-scheduling--use-when-"&gt;Task Scheduling ( &lt;strong&gt;Use when:&lt;/strong&gt; )&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Run backups, Rotate logs, Clean temp files, Restart services, Send reports, Health checks, Database dumps, Automation scripts, etc &amp;hellip;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id="two-scheduling-methods"&gt;Two scheduling methods&lt;/h4&gt;
&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Tool&lt;/th&gt;
					&lt;th&gt;Best For&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;cron&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;Repeating jobs&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;&lt;code&gt;at&lt;/code&gt;&lt;/td&gt;
					&lt;td&gt;One-time future jobs&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id="best-practices"&gt;Best Practices:&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Use absolute paths (/usr/bin/python3).&lt;/li&gt;
&lt;li&gt;Make scripts executable: &lt;code&gt;chmod +x script.sh&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Test the script manually before scheduling.&lt;/li&gt;
&lt;li&gt;Redirect output to a log file.&lt;/li&gt;
&lt;li&gt;Use a dedicated service account for production jobs.&lt;/li&gt;
&lt;li&gt;Keep cron jobs in version control when possible.&lt;/li&gt;
&lt;li&gt;Add comments in crontab to describe each job.&lt;/li&gt;
&lt;li&gt;Monitor logs and verify jobs actually completed.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h4 id="terminal-session"&gt;Terminal Session&lt;/h4&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.2
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Wed Jul 29 13:46:18 2026

[aadarsha@labserver ~]$ date
Wed Jul 29 01:46:53 PM +0545 2026

[aadarsha@labserver ~]$ whoami
aadarsha

[root@labserver ~]# whoami
root

[root@labserver ~]# dnf -y install at

[root@labserver ~]# rpm -q at
at-3.2.5-14.el10.x86_64

[root@labserver ~]# systemctl status atd
● atd.service - Deferred execution scheduler
 Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; preset: enabled)
...
[root@labserver ~]# 

[root@labserver ~]# systemctl is-active atd
active

[root@labserver ~]# systemctl is-enabled atd
enabled

[root@labserver ~]# who
aadarsha pts/0 2026-07-29 20:20 (192.168.254.32)

 # Time format of at jobs

 # Time Only:
 - at 17:00

 # Relative Time:
 - at now + 10 minutes
 - at now + 2 hours
 - at now + 1 day / week / month / year

 # Time + Day of Week
 - at 09:00 Monday
 - at 17:00 Friday

 # Today / Tomorrow
 - at tomorrow
 - at 02:00 tomorrow

 # Month + Day
 - at 17:00 Nov 11

 # Month + Day + Year
 - at 17:00 Nov 11 2032

 # Ctrl+D --&amp;gt; after entering commands to submit the job

[root@labserver ~]# at now +3 minutes
warning: commands will be executed using /bin/sh
at Wed Jul 29 21:58:00 2026
at&amp;gt; echo &amp;#34;Hello, World!&amp;#34; &amp;gt;/root/message
at&amp;gt; &amp;lt;EOT&amp;gt;
job 4 at Wed Jul 29 21:58:00 2026
[root@labserver ~]#

[root@labserver ~]# atq
4	Wed Jul 29 21:58:00 2026 a root

[root@labserver ~]# date
Wed Jul 29 09:57:39 PM +0545 2026

[root@labserver ~]# atq
4	Wed Jul 29 21:58:00 2026 a root

[root@labserver ~]# ls /root/
anaconda-ks.cfg

[root@labserver ~]# atq
[root@labserver ~]# 

[root@labserver ~]# ls /root/
anaconda-ks.cfg message

[root@labserver ~]# pwd
/root
 
[root@labserver ~]# cat message 
Hello, World!

[root@labserver ~]# atq
5	Thu Jul 30 09:14:00 2026 a aadarsha
6	Fri Jul 31 05:00:00 2026 a root

 # format:
 
 # &amp;lt;job-id&amp;gt; &amp;lt;scheduled-date-and-time&amp;gt; &amp;lt;queue&amp;gt; &amp;lt;user&amp;gt;
 
 # a --&amp;gt; default queue used by the at command
 
[root@labserver ~]# pwd
/root
[root@labserver ~]# ls /var/spool/at
a0000501c60bd1 a0000601c61073 spool

[root@labserver ~]# cd /var/spool/at
[root@labserver at]# pwd
/var/spool/at
[root@labserver at]# ls
a0000501c60bd1 a0000601c61073 spool

 # file format : &amp;lt;queue&amp;gt; &amp;lt;encoded-job-identifier&amp;gt;
 # a --&amp;gt; queue name (default queue a)
 
[root@labserver at]# cat a0000501c60bd1 
#!/bin/sh
...
${SHELL:-/bin/sh} &amp;lt;&amp;lt; &amp;#39;marcinDELIMITER194b379f&amp;#39;
uptime &amp;gt; /aadarsha/uptime-output
marcinDELIMITER194b379f
[root@labserver at]# 

[root@labserver at]# cd -
/root

 # Remove an at job
 
[root@labserver ~]# atq
5	Thu Jul 30 09:14:00 2026 a aadarsha
6	Fri Jul 31 05:00:00 2026 a root
7	Fri Jul 30 05:00:00 2027 a root

[root@labserver ~]# atrm 6			 # atq &amp;lt;job-id&amp;gt;

[root@labserver ~]# atq
5	Thu Jul 30 09:14:00 2026 a aadarsha
7	Fri Jul 30 05:00:00 2027 a root

 # By default, if an at job produces output (stdout or stderr) and the output is not redirected, at sends the output by email to the job owner&amp;#39;s mail address.
 # A running mail transfer agent (MTA), such as Postfix, is required for email delivery.
 
[aadarsha@labserver ~]$ whoami
aadarsha

[aadarsha@labserver ~]$ atq
 
[aadarsha@labserver ~]$ at now + 3 minutes
warning: commands will be executed using /bin/sh
at Thu Jul 30 09:22:00 2026
at&amp;gt; ps 
at&amp;gt; free -h
at&amp;gt; &amp;lt;EOT&amp;gt;
job 8 at Thu Jul 30 09:22:00 2026
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ systemctl status postfix
○ postfix.service - Postfix Mail Transport Agent
 Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; preset: disabled)
 Active: inactive (dead)
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sudo systemctl start postfix
[sudo] password for aadarsha: 

[aadarsha@labserver ~]$ sudo systemctl enable postfix
Created symlink &amp;#39;/etc/systemd/system/multi-user.target.wants/postfix.service&amp;#39; → &amp;#39;/usr/lib/systemd/system/postfix.service&amp;#39;.
 
[aadarsha@labserver ~]$ systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
 Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; preset: disabled)
 Active: active (running) since Thu 2026-07-30 09:21:49 +0545; 32s ago
...
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ systemctl is-active postfix
active
You have new mail in /var/spool/mail/aadarsha
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat /var/spool/mail/aadarsha 
From aadarsha@labserver.localdomain Thu Jul 30 09:22:00 2026
Return-Path: &amp;lt;aadarsha@labserver.localdomain&amp;gt;
X-Original-To: aadarsha
Delivered-To: aadarsha@labserver.localdomain
Received: by labserver.localdomain (Postfix, from userid 1000)
	id 1714B8C17; Thu, 30 Jul 2026 09:22:00 +0545 (+0545)
Subject: Output from your job 8
To: aadarsha@labserver.localdomain
Message-Id: &amp;lt;20260730033700.1714B8C17@labserver.localdomain&amp;gt;
Date: Thu, 30 Jul 2026 09:22:00 +0545 (+0545)
From: Aadarsha Khadka &amp;lt;aadarsha@labserver.localdomain&amp;gt;
 PID TTY TIME CMD
 1905 ? 00:00:00 systemd
 1907 ? 00:00:00 (sd-pam)
 1960 ? 00:00:00 sshd-session
 2530 ? 00:00:00 sh
 2531 ? 00:00:00 bash
 2532 ? 00:00:00 ps
 total used free shared buff/cache available
Mem: 1.7Gi 350Mi 1.2Gi 4.9Mi 240Mi 1.3Gi
Swap: 2.0Gi 0B 2.0Gi
[aadarsha@labserver ~]$ 

 # A non-privileged user may schedule jobs only if authorized by the scheduler&amp;#39;s access control configuration 
 # (for example, cron.allow, cron.deny, at.allow, or at.deny).
 # Scheduled jobs execute with the effective user ID and group permissions of the user who scheduled them and cannot perform operations beyond that user&amp;#39;s assigned privileges.


 # running scripts by scheduling the job

[aadarsha@labserver ~]$ ls
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ mkdir scripts

[aadarsha@labserver ~]$ vi scripts/health_check.sh 

[aadarsha@labserver ~]$ cat scripts/health_check.sh 
#!/bin/bash

###############################################################################
# Script Name : health_check.sh
# Description : Basic Linux Health Check Script
# Author : aadarsha
###############################################################################

echo &amp;#34;==========================================&amp;#34;
echo &amp;#34; Linux Health Check Report&amp;#34;
echo &amp;#34;==========================================&amp;#34;
echo &amp;#34;Hostname : $(hostname)&amp;#34;
echo &amp;#34;Date : $(date)&amp;#34;
echo

# System Uptime
echo &amp;#34;1. System Uptime&amp;#34;
uptime
echo

# CPU Load
echo &amp;#34;2. CPU Load Average&amp;#34;
uptime | awk -F&amp;#39;load average:&amp;#39; &amp;#39;{print $2}&amp;#39;
echo

# Memory Usage
echo &amp;#34;3. Memory Usage&amp;#34;
free -h
echo

# Disk Usage
echo &amp;#34;4. Disk Usage&amp;#34;
df -h
echo

# SSH Service Status
echo &amp;#34;5. SSH Service Status&amp;#34;

if systemctl is-active --quiet sshd; then
 echo &amp;#34;sshd service is running.&amp;#34;
else
 echo &amp;#34;sshd service is NOT running.&amp;#34;
fi

echo
echo &amp;#34;==========================================&amp;#34;
echo &amp;#34;Health Check Completed Successfully&amp;#34;
echo &amp;#34;==========================================&amp;#34;
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -l scripts/health_check.sh 
-rw-r--r--. 1 aadarsha aadarsha 1047 Jul 30 21:50 scripts/health_check.sh
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ chmod +x scripts/health_check.sh 

[aadarsha@labserver ~]$ ls -l scripts/health_check.sh 
-rwxr-xr-x. 1 aadarsha aadarsha 1047 Jul 30 21:50 scripts/health_check.sh
[aadarsha@labserver ~]

[aadarsha@labserver ~]$ at now +3 minutes
warning: commands will be executed using /bin/sh
at Thu Jul 30 22:00:00 2026
at&amp;gt; /home/aadarsha/scripts/health_check.sh &amp;gt; /home/aadarsha/scripts_output
at&amp;gt; &amp;lt;EOT&amp;gt;
job 9 at Thu Jul 30 22:00:00 2026
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ atq
9	Thu Jul 30 22:00:00 2026 a aadarsha
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
scripts
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ pwd
/home/aadarsha
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ atq
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
scripts scripts_output
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ cat scripts_output 
==========================================
 Linux Health Check Report
==========================================
Hostname : labserver
Date : Thu Jul 30 10:00:00 PM +0545 2026

1. System Uptime
 22:00:00 up 42 min, 2 users, load average: 0.00, 0.00, 0.00

2. CPU Load Average
 0.00, 0.00, 0.00

3. Memory Usage
 total used free shared buff/cache available
Mem: 1.7Gi 361Mi 1.2Gi 4.8Mi 239Mi 1.3Gi
Swap: 2.0Gi 0B 2.0Gi

4. Disk Usage
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cs-root 20G 1.6G 19G 8% /
devtmpfs 830M 0 830M 0% /dev
tmpfs 853M 0 853M 0% /dev/shm
tmpfs 341M 4.9M 337M 2% /run
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-journald.service
/dev/sda2 960M 386M 575M 41% /boot
/dev/mapper/cs-var 5.0G 220M 4.8G 5% /var
tmpfs 1.0M 0 1.0M 0% /run/credentials/getty@tty1.service
tmpfs 171M 4.0K 171M 1% /run/user/1000

5. SSH Service Status
sshd service is running.

==========================================
Health Check Completed Successfully
==========================================
[aadarsha@labserver ~]$ 

 # Scheduling repeated tasks using cron
 
 # Common Cron Job Purposes (Notes)
 - Database backup – Run automatic backups daily or weekly.
 - Log rotation – Archive and remove old log files.
 - Temporary file cleanup – Delete unnecessary files periodically.
 - System monitoring – Check CPU, memory, disk, or server health.
 - Send emails/reports – Generate and email daily or weekly reports.
 - File synchronization – Sync files between servers or cloud storage.
 - Restart services – Restart applications or services at scheduled times.
 - Update software – Run package updates or security updates.
 - Execute scripts – Run automation scripts without manual intervention.
 - Data processing – Import, export, or transform data on a schedule.
 
[aadarsha@labserver ~]$ rpm -q cronie
cronie-1.7.0-14.el10.x86_64

[root@labserver ~]# man 4 crontabs

[root@labserver ~]# man crontab

[aadarsha@labserver ~]$ systemctl status crond
● crond.service - Command Scheduler
 Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; preset: enabled)
...
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ systemctl is-active crond
active

[aadarsha@labserver ~]$ systemctl is-enabled crond
enabled

 # Format of crontab:
 
 * * * * * &amp;lt; command/script &amp;gt;
 │ │ │ │ │
 │ │ │ │ └── Day of week (0-7)
 │ │ │ └──── Month
 │ │ └────── Day of month
 │ └──────── Hour
 └────────── Minute

[root@labserver ~]# cat /etc/crontab 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
[root@labserver ~]#
 
 # Common special characters
| Symbol | Meaning | Example |
|--------|---------------- | -------------------------- |
| * | Every value | * * * * * --&amp;gt; Every minute |
| , | Multiple values | 1,15,30 |
| - | Range | 1-5 |
| / | Step interval | */10 → Every 10 units |

 # Cron&amp;#39;s smallest unit is 1 minute,

 # Examples:
 
 * * * * * --&amp;gt; run every minute
 
 */5 * * * * --&amp;gt; every 5 minutes ( 00, 05, 10, ... , 55 )

 */15 * * * * --&amp;gt; every 15 minutes ( 00, 15, 30, 45 )
 
 0 * * * * --&amp;gt; every hour ( 01:00, 02:00, ... )
 
 0 0 * * * --&amp;gt; every da at midnight ( 00:00 )
 
 30 2 * * * --&amp;gt; every day at 2:30 AM
 
 0 9 * * 1-5 --&amp;gt; every week-day at 2:30 AM
 
 0 10 * * 6,0 --&amp;gt; every weekend at 10:00 AM
 
 0 8 * * 1 --&amp;gt; every Monday at 8:00 AM
 
 * * 1 * * --&amp;gt; first day of every month ( Jan 1, Feb 1, ... )
 
 0 0 1 1 * --&amp;gt; every January 1 ( once per year ) 
 
 0 3 * * 0 --&amp;gt; every Sunday at 3:00 AM
 
 */10 9-17 * * 1-5 --&amp;gt; every 10 minutes during business hours ( 9 AM to 5 PM, Mon - Fri )
 
 0 */2 * * * --&amp;gt; every 2 hours ( 00:00, 02:00, 04:00, .. )

 0 */6 * * * --&amp;gt; every 6 hours ( 00:00, 06:00, 12:00, 18:00 )
 
 0 0 */5 * * --&amp;gt; every 5 days
 
 0 8,20 * * * --&amp;gt; at 8:00 AM and 8:00 PM every day
 
 * 9-17 * * * --&amp;gt; every minute between 9 AM and 5 PM
 
 15 9 * * 1,3 --&amp;gt; at 9:15 every Monday and Wednesday
 
 */5 * * * 1-5 --&amp;gt; every 5 minutes on Weekdays
 
 * * * 1 * --&amp;gt; every minute in January
 
 0 12 * * * --&amp;gt; every day at noon
 
 30 5 * * 5 --&amp;gt; every Friday at 5:30

[root@labserver ~]# crontab -e
crontab: installing new crontab
Backup of root&amp;#39;s previous crontab saved to /root/.cache/crontab/crontab.bak
 
[root@labserver ~]# crontab -l
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 * * * * * ps
 */3 * * * * free -h
 30 5 * * * df -h 
[root@labserver ~]# 

[root@labserver ~]# cat /var/spool/cron/root 
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 * * * * * ps
 */3 * * * * free -h
 30 5 * * * df -h 
[root@labserver ~]# 

[root@labserver ~]# 
You have new mail in /var/spool/mail/root

[root@labserver ~]# cat /var/spool/mail/root 
From MAILER-DAEMON Sat Aug 1 19:03:02 2026
Return-Path: &amp;lt;&amp;gt;
X-Original-To: root
Delivered-To: root@labserver.localdomain
Received: by labserver.localdomain (Postfix, from userid 0)
	id 397C38C10; Sat, 1 Aug 2026 19:03:02 +0545 (+0545)
...
[root@labserver ~]#

[root@labserver ~]# crontab -l
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */3 * * * * free -h &amp;gt;&amp;gt;/root/mem-output
 30 5 * * * df -h &amp;gt;&amp;gt;/root/disk-output
[root@labserver ~]# 

[root@labserver ~]# ls
anaconda-ks.cfg message

[root@labserver ~]# ls
anaconda-ks.cfg mem-output message
 
[root@labserver ~]# cat mem-output 
 total used free shared buff/cache available
Mem: 1.7Gi 338Mi 1.2Gi 6.3Mi 262Mi 1.3Gi
Swap: 2.0Gi 0B 2.0Gi
[root@labserver ~]# 

[root@labserver ~]# crontab -l
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

# */3 * * * * free -h &amp;gt;&amp;gt;/root/mem-output
# 30 5 * * * df -h &amp;gt;&amp;gt;/root/disk-output
[root@labserver ~]# 

 # To edit or delete cron job

[root@labserver ~]# crontab -e
crontab: installing new crontab
Backup of root&amp;#39;s previous crontab saved to /root/.cache/crontab/crontab.bak

[root@labserver ~]# crontab -l
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */2 * * * * free -h &amp;gt;&amp;gt;/root/mem-output
[root@labserver ~]# 

[root@labserver ~]# ls
anaconda-ks.cfg mem-output message

[root@labserver ~]# rm mem-output 
rm: remove regular file &amp;#39;mem-output&amp;#39;? y

[root@labserver ~]# ls
anaconda-ks.cfg message
[root@labserver ~]# 

[root@labserver ~]# crontab -l
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */2 * * * * free -h &amp;gt;&amp;gt;/root/mem-output
[root@labserver ~]# 

[root@labserver ~]# crontab -r
Backup of root&amp;#39;s previous crontab saved to /root/.cache/crontab/crontab.bak # Backup saved by the system

[root@labserver ~]# crontab -l
no crontab for root

[root@labserver ~]# cat /root/.cache/crontab/crontab.bak # Backup saved by the system
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */2 * * * * free -h &amp;gt;&amp;gt;/root/mem-output
[root@labserver ~]# 

 # restore the backup 
 
[root@labserver ~]# crontab -l
no crontab for root

[root@labserver ~]# crontab /root/.cache/crontab/crontab.bak

[root@labserver ~]# crontab -l
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */2 * * * * free -h &amp;gt;&amp;gt;/root/mem-output
[root@labserver ~]# 

[root@labserver ~]# systemctl restart crond

[root@labserver ~]# systemctl is-active crond
active
[root@labserver ~]# 

 # Viewing the logs of cronjobs
 
[root@labserver ~]# tail /var/log/cron
Aug 2 21:35:27 labserver crontab[2187]: (root) END EDIT (root)
Aug 2 21:35:34 labserver crontab[2201]: (root) LIST (root)
Aug 2 21:36:02 labserver crond[967]: (root) RELOAD (/var/spool/cron/root)
Aug 2 21:36:02 labserver CROND[2226]: (root) CMD (free -h &amp;gt;&amp;gt;/root/mem-output)
Aug 2 21:36:02 labserver CROND[2209]: (root) CMDEND (free -h &amp;gt;&amp;gt;/root/mem-output)
Aug 2 21:36:26 labserver crond[967]: (CRON) INFO (Shutting down)
Aug 2 21:36:26 labserver crond[2239]: (CRON) STARTUP (1.7.0)
Aug 2 21:36:26 labserver crond[2239]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 12% if used.)
Aug 2 21:36:26 labserver crond[2239]: (CRON) INFO (running with inotify support)
Aug 2 21:36:26 labserver crond[2239]: (CRON) INFO (@reboot jobs will be run at computer&amp;#39;s startup.)
[root@labserver ~]# 

[root@labserver ~]# whoami
root
 
[root@labserver ~]# ls /var/spool/cron/
root

[root@labserver ~]# ls /var/spool/cron/root 
/var/spool/cron/root
 
[root@labserver ~]# cat /var/spool/cron/root 
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */2 * * * * free -h &amp;gt;&amp;gt;/root/mem-output
[root@labserver ~]# 

 # Controlling User Access to Cron
 
[root@labserver ~]# ls /home/
aadarsha milan suman
 
[root@labserver ~]# vi /etc/cron.deny 

[root@labserver ~]# cat /etc/cron.deny 

[root@labserver ~]# vi /etc/cron.deny 

[root@labserver ~]# cat /etc/cron.deny 
suman
ram
sita

[root@labserver ~]# su - milan
 
[milan@labserver ~]$ crontab -e
no crontab for milan - using an empty one
crontab: installing new crontab

[milan@labserver ~]$ crontab -l
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */3 * * * * whoami &amp;gt;&amp;gt;/root/job1-output

[milan@labserver ~]$ exit
logout

[root@labserver ~]# su - suman

[suman@labserver ~]$ crontab -e
You (suman) are not allowed to use this program (crontab)
See crontab(1) for more information

[suman@labserver ~]$ exit
logout

[root@labserver ~]# vi /etc/cron.deny 
[root@labserver ~]# cat /etc/cron.deny 
[root@labserver ~]# 
[root@labserver ~]# vi /etc/cron.allow
[root@labserver ~]# 
[root@labserver ~]# cat /etc/cron.allow 
suman
[root@labserver ~]# 

[root@labserver ~]# su - suman
Last login: Mon Aug 3 11:07:07 +0545 2026 on pts/0

[suman@labserver ~]$ crontab -e
no crontab for suman - using an empty one
crontab: installing new crontab
[suman@labserver ~]$ 
[suman@labserver ~]$ crontab -l
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */2 * * * * free -h &amp;gt;&amp;gt;/root/mem-output
[suman@labserver ~]$ 

[suman@labserver ~]$ exit
logout
[root@labserver ~]# 
 
[root@labserver ~]# ls /home/
aadarsha milan suman
[root@labserver ~]# 
[root@labserver ~]# su - milan
Last login: Mon Aug 3 11:05:29 +0545 2026 on pts/0
[milan@labserver ~]$ 
[milan@labserver ~]$ crontab -e
You (milan) are not allowed to use this program (crontab)
See crontab(1) for more information

[milan@labserver ~]$ exit
logout
[root@labserver ~]# 
[root@labserver ~]# su - aadarsha
Last login: Mon Aug 3 10:12:12 +0545 2026 from 192.168.254.32 on pts/0
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ crontab -e
You (aadarsha) are not allowed to use this program (crontab)
See crontab(1) for more information

[aadarsha@labserver ~]$ crontab -l
You (aadarsha) are not allowed to use this program (crontab)
See crontab(1) for more information

[aadarsha@labserver ~]$ exit
logout

[root@labserver ~]# vi /etc/cron.allow 

[root@labserver ~]# cat /etc/cron.allow 
[root@labserver ~]# 
[root@labserver ~]# cat /etc/cron.deny 
[root@labserver ~]# 

 # Now, any user can set the cronjobs

 # Similarly, for at jobs:
 # /etc/at.allow
 # /etc/at.deny

[root@labserver ~]# ls /var/spool/cron/
milan root suman

[root@labserver ~]# cat /var/spool/cron/milan 
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */3 * * * * whoami &amp;gt;&amp;gt;/root/job1-output

[root@labserver ~]# cat /var/spool/cron/suman 
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */2 * * * * free -h &amp;gt;&amp;gt;/root/mem-output

[root@labserver ~]# cat /var/spool/cron/root 
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

 */2 * * * * free -h &amp;gt;&amp;gt;/root/mem-output

[root@labserver ~]# rm /var/spool/cron/milan 
rm: remove regular file &amp;#39;/var/spool/cron/milan&amp;#39;? y

[root@labserver ~]# rm /var/spool/cron/suman 
rm: remove regular file &amp;#39;/var/spool/cron/suman&amp;#39;? y

[root@labserver ~]# ls /home
aadarsha milan suman
 
[root@labserver ~]# ls /var/spool/cron/
root
[root@labserver ~]# 

 # Creating a System-Wide Cron Job with /etc/cron.d
 
 # 7-Field Syntax:
 
 # ┌───────────── minute (0 - 59)
 # │ ┌─────────── hour (0 - 23)
 # │ │ ┌───────── day of month (1 - 31)
 # │ │ │ ┌─────── month (1 - 12)
 # │ │ │ │ ┌───── day of week (0 - 7) (Sunday = 0 or 7)
 # │ │ │ │ │ ┌─── user
 # │ │ │ │ │ │
 # * * * * * * &amp;lt;command&amp;gt;
 
[root@labserver ~]# cd /etc/cron.d

[root@labserver cron.d]# ls
0hourly

[root@labserver cron.d]# pwd
/etc/cron.d

[root@labserver cron.d]# crontab -e
crontab: installing new crontab
Backup of root&amp;#39;s previous crontab saved to /root/.cache/crontab/crontab.bak

[root@labserver cron.d]# vi mycronjob

[root@labserver cron.d]# crontab -l
# Min Hr M DoM DoW &amp;lt; command/script &amp;gt;

# */2 * * * * free -h &amp;gt;&amp;gt;/root/mem-output
[root@labserver cron.d]# 

[root@labserver cron.d]# ls -l /etc/cron.d/mycronjob
-rw-r--r--. 1 root root 236 Aug 3 11:52 /etc/cron.d/mycronjob
 
[root@labserver cron.d]# cat mycronjob 
# Min (0 - 59) # Hr (0 - 23) # DoM (1 - 31) # Mo (1 - 12) # DoW (0 - 7) # user # &amp;lt;command&amp;gt;

 */2 * * * * milan date &amp;gt;&amp;gt;/home/milan/job1-op
[root@labserver cron.d]# 

[root@labserver cron.d]# cat -A mycronjob 
# Min (0 - 59) # Hr (0 - 23) # DoM (1 - 31) # Mo (1 - 12) # DoW (0 - 7) # user # &amp;lt;command&amp;gt;$
$
 */2 * * * * milan date &amp;gt;&amp;gt;/home/milan/job1-op$
[root@labserver cron.d]# 

[root@labserver cron.d]# su - milan
Last login: Mon Aug 3 11:14:25 +0545 2026 on pts/0
[milan@labserver ~]$ 

[milan@labserver ~]$ ls
job1-op myfile
[milan@labserver ~]$ 
[milan@labserver ~]$ cat job1-op 
Mon Aug 3 11:54:01 AM +0545 2026
Mon Aug 3 11:56:02 AM +0545 2026
Mon Aug 3 11:58:01 AM +0545 2026
Mon Aug 3 12:00:01 PM +0545 2026
Mon Aug 3 12:02:01 PM +0545 2026
Mon Aug 3 12:04:02 PM +0545 2026
Mon Aug 3 12:06:01 PM +0545 2026
[milan@labserver ~]$ 

[milan@labserver ~]$ exit
logout
[root@labserver cron.d]# 
 
[root@labserver cron.d]# vi mycronjob 

[root@labserver cron.d]# cat mycronjob 
# Min (0 - 59) # Hr (0 - 23) # DoM (1 - 31) # Mo (1 - 12) # DoW (0 - 7) # user # &amp;lt;command/script&amp;gt;

# */2 * * * * milan date &amp;gt;&amp;gt;/home/milan/job1-op
[root@labserver cron.d]# 

 # Common Locations for Cron Jobs:

 # User crontabs

[root@labserver cron.d]# cd
[root@labserver ~]# 

 # User crontabs

[root@labserver ~]# ls /var/spool/cron/
root

 # System crontab
 
[root@labserver ~]# ls /etc/crontab 
/etc/crontab

 # Additional system cron files

[root@labserver ~]# ls /etc/cron.d/
0hourly mycronjob
 
 # Hourly jobs

[root@labserver ~]# ls /etc/cron.hourly/
0anacron

 # Daily jobs
 
[root@labserver ~]# ls /etc/cron.daily/
[root@labserver ~]#
 
 # Weekly jobs

[root@labserver ~]# ls /etc/cron.weekly/
[root@labserver ~]# 

 # Monthly jobs
 
[root@labserver ~]# ls /etc/cron.monthly/
[root@labserver ~]# 
 
 # System crontab

[root@labserver ~]# cat /etc/crontab 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed

[root@labserver ~]# 

[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.2 closed.
aadarkdk@pop-os:~$ 
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>PL - 007 — User and Group Administration</title><link>https://aadarshakhadka.com.np/practice-log/linux/pl-007-user-group-administration/</link><pubDate>Wed, 29 Jul 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/pl-007-user-group-administration/</guid><description>&lt;h4 id="concepts"&gt;Concepts:&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;User Management,
Group Management,
Special Permission Bits,
Password Policy,&lt;br&gt;
ACL (Access Control List)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt; # User Management Configuration files:

 #-----------------------------------------------------------------------------------------------------
 # File | Purpose | Key Contents
 #-----------------------------------------------------------------------------------------------------
 # /etc/passwd | User account registry | Username, UID, GID, home, shell
 #-----------------------------------------------------------------------------------------------------
 # /etc/shadow | Password storage &amp;amp; policy | Encrypted passwords, expiry rules
 #-----------------------------------------------------------------------------------------------------
 # /etc/login.defs | Default account creation settings | UID/GID ranges, password defaults
 #-----------------------------------------------------------------------------------------------------
 # /etc/group | Group definitions &amp;amp; memberships | Group name, GID, members
 #-----------------------------------------------------------------------------------------------------
 # /etc/gshadow | Group password security | Encrypted group passwords, admins
 #-----------------------------------------------------------------------------------------------------
 # /etc/sudoers | Privilege escalation control | Sudo rules for users/groups
 #-----------------------------------------------------------------------------------------------------
 # /etc/skel/ | New user home template | Default config files (.bashrc, .profile)
 #-----------------------------------------------------------------------------------------------------
 # /var/log/secure | authenticate &amp;amp; authorization events | Logins, sudo, authentication attempts
 #-----------------------------------------------------------------------------------------------------

 # /var/log/secure (RHEL-based systems) &amp;amp; /var/log/auth.log (Debian/Ubuntu)
 
aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.2
aadarsha@192.168.254.2&amp;#39;s password: 
Last login: Thu Jul 23 20:04:25 2026

[aadarsha@labserver ~]$ whoami
aadarsha
 
[aadarsha@labserver ~]$ su - root
Password: 
Last login: Wed Jul 22 19:07:43 +0545 2026 on pts/0
 
[root@labserver ~]# cat /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
...
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin		# --&amp;gt; nologin shell generally created for service accounts
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[root@labserver ~]# 

 # Format
 
 # &amp;lt;user-name&amp;gt; : &amp;lt;password&amp;gt; : &amp;lt;UID&amp;gt; : &amp;lt;GID&amp;gt; : &amp;lt;full-name or comment &amp;gt; : &amp;lt;home-directory&amp;gt; : &amp;lt;shell&amp;gt;
 
 # aadarsha : x : 1000 : 1000 : Aadarsha Khadka : /home/aadarsha : /bin/bash
 # | | | | | | |
 # | | | | | | +------- Shell (login shell)
 # | | | | | +---------------------- Home Directory
 # | | | | +----------------------------------------- GECOS (full name / comment)
 # | | | +-------------------------------------------------- Primary GID
 # | | +--------------------------------------------------------- UID
 # | +-------------------------------------------------------------- Password (x means in /etc/shadow)
 # +---------------------------------------------------------------------- Username
 
[root@labserver ~]# cat /etc/group
root:x:0:
...
systemd-coredump:x:995:
aadarsha:x:1000:
[root@labserver ~]# 

 # Format
 
 # &amp;lt;group-name&amp;gt; : &amp;lt;password&amp;gt; : &amp;lt;GID&amp;gt;
 
 # aadarsha : x : 1000 :
 # | | |
 # | | +---- GID (Group ID) - matches user&amp;#39;s primary GID in /etc/passwd
 # | +---------- Password (&amp;#39;x&amp;#39; = stored in /etc/gshadow, empty = no password)
 # +------------------ Group Name

 # Primary group is automatically created by default when a user is created, unless we specify an existing group using -g option.
 
[root@labserver ~]# cat /etc/shadow
root:$y$j9T$bSL.DYlX2bFQqj9MhuK1eNmo$lHY07CmxyKDGoHy3x9mjzRCV9/JicXeG0/Iovox9ZW1::0:99999:7:::
bin:*:20186:0:99999:7:::
...
systemd-coredump:!*:20647::::::
aadarsha:$y$j9T$hknYweHgxIvveqhAzwjsY4P4$f2Uowb.VrCDXEpbQo9Oj3sFsbQXfGaWHjtxwTCfUks4::0:99999:7:::
[root@labserver ~]# 
 
 # Format
 
 # &amp;lt;username&amp;gt; : &amp;lt;password-hash&amp;gt; : &amp;lt;last-change&amp;gt; : &amp;lt;min-age&amp;gt; : &amp;lt;max-age&amp;gt; : &amp;lt;warning&amp;gt; : &amp;lt;password-inactivity&amp;gt; : &amp;lt;account-expire&amp;gt; : &amp;lt;reserved&amp;gt;
 
 # aadarsha : $y$j9T$hknYweHgxIvveqhAzwjsY4P4$f2Uowb.VrCDXEpbQo9Oj3sFsbQXfGaWHjtxwTCfUks4 : : 0 : 99999 : 7 : : :
 # | | | | | | | | |
 # | | | | | | | | +--- Reserved (currently unused)
 # | | | | | | | +------- Account expiration date (days since Unix epoch; empty = never expires)
 # | | | | | | +----------- Password inactivity period (days after password expires before account is disabled; empty = no inactivity limit)
 # | | | | | +--------------- Warning period before password expiration (days; empty = no warning)
 # | | | | +--------------------- Maximum password age in days (99999 commonly means effectively never expires)
 # | | | +--------------------------- Minimum password age in days (0 = password may be changed immediately)
 # | | +------------------------------- Last password change (days since Unix epoch, Jan 1, 1970)
 # | +------------------ Salted, hashed password (! --&amp;gt; means account is locked and cannot be used for password login.)
 # +---------------------------------------------- Username
 
[root@labserver ~]# cat /etc/gshadow
root:::
...
systemd-coredump:!*::
aadarsha:!::
[root@labserver ~]#

 # Format
 
 # &amp;lt;group_name&amp;gt; : &amp;lt;password&amp;gt; : &amp;lt;administrators&amp;gt; : &amp;lt;members&amp;gt;
 
 # aadarsha : ! : :
 # | | | |
 # | | | +---- Group members (comma-separated; empty = no members)
 # | | +-------- Group administrators (comma-separated; empty = no administrators)
 # | +------------ Group password or status:
 # | ! = password is locked (cannot be used)
 # | * = no valid password (password login disabled)
 # | &amp;lt;hash&amp;gt; = encrypted group password
 # | empty = no password
 # | 
 # +--------------------- Group name
 
[root@labserver ~]# cat /etc/sudoers
## Sudoers allows particular users to run various commands as
## the root user, without needing the root password.
...
## Allows people in group wheel to run all commands
%wheel	ALL=(ALL)	ALL
...
[root@labserver ~]#

 # Meaning of:
 
 # %wheel ALL=(ALL) ALL
 
 # %wheel ALL = (ALL) ALL
 # | | | |
 # | | | +---- May run all commands
 # | | +------------- May run commands as any user
 # | +-------------------------- On all hosts
 # +----------------------------------- Members of the &amp;#34;wheel&amp;#34; group (% indicates a group)
 
 # ---&amp;gt; Any member of the wheel group can run any command as any user on any host (after authenticating with their password).

 # NOTE:
 
 | Rule | Meaning |
 | -------------------------------|-------------------------------------------------------------------------------------------------------------------------|
 | %wheel ALL=(ALL) ALL | Members of the wheel group may run any command as any user on any host, after authenticating. |
 | %wheel ALL=(ALL) NOPASSWD: ALL | Members of the wheel group may run any command as any user on any host **without entering a password** (if uncommented).|
 | root ALL=(ALL) ALL | The root user may run any command as any user on any host. |

[root@labserver ~]# cd /etc/skel/
[root@labserver skel]# ls
[root@labserver skel]# ls -la
total 24
drwxr-xr-x. 2 root root 62 Jul 13 14:29 .
drwxr-xr-x. 82 root root 8192 Jul 24 12:06 ..
-rw-r--r--. 1 root root 18 Oct 29 2024 .bash_logout # ---&amp;gt; Runs when a Bash login shell exits.
-rw-r--r--. 1 root root 144 Oct 29 2024 .bash_profile # ---&amp;gt; Runs when a Bash login shell starts.( Typically used to set environment variables and initialize the user&amp;#39;s login environment )
-rw-r--r--. 1 root root 522 Oct 29 2024 .bashrc # ---&amp;gt; Runs for every interactive non-login Bash shell.( Typically used for aliases, shell options, functions, and prompt customization )
[root@labserver skel]# 

 # Note: On most Linux systems, .bash_profile sources .bashrc so interactive login shells also inherit aliases, functions, and prompt settings.
 
[root@labserver]# cat /var/log/secure 
...
Jul 23 20:04:10 labserver sshd[943]: Server listening on 0.0.0.0 port 22.
Jul 23 20:04:10 labserver sshd[943]: Server listening on :: port 22.
Jul 23 20:04:24 labserver (systemd)[4818]: pam_unix(systemd-user:session): session opened for user aadarsha(uid=1000) by aadarsha(uid=0)
Jul 23 20:04:25 labserver login[956]: pam_unix(login:session): session opened for user aadarsha(uid=1000) by aadarsha(uid=0)
Jul 23 20:04:25 labserver login[956]: LOGIN ON tty1 BY aadarsha
Jul 23 20:04:57 labserver sshd-session[6619]: Accepted password for aadarsha from 192.168.254.32 port 35038 ssh2
Jul 23 20:04:57 labserver sshd-session[6619]: pam_unix(sshd:session): session opened for user aadarsha(uid=1000) by aadarsha(uid=0)
Jul 23 20:05:48 labserver su[6666]: pam_unix(su-l:session): session opened for user root(uid=0) by aadarsha(uid=1000)
...
[root@labserver]# 
 
 # Default settings used by useradd:
 
[root@labserver ~]# useradd -D
GROUP=100
GROUPS=
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
USRSKEL=/usr/etc/skel
CREATE_MAIL_SPOOL=yes
LOG_INIT=yes
[root@labserver ~]# 

[root@labserver ~]# cat /etc/default/useradd 
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@labserver ~]#

 # By default, when a user is created using useradd, the following changes happen internally:

[root@labserver ~]# ls /home/
aadarsha

[root@labserver ~]# useradd a-user

[root@labserver ~]# ls /home
aadarsha a-user

[root@labserver ~]# ls -l /home/
total 0
drwx------. 2 aadarsha aadarsha 83 Jul 13 14:46 aadarsha
drwx------. 2 a-user a-user 62 Jul 24 12:06 a-user # user ownership and group ownership --&amp;gt; user-a 
[root@labserver ~]#
 
[root@labserver ~]# cat /etc/passwd
...
a-user:x:1001:1001::/home/a-user:/bin/bash 
[root@labserver ~]#

[root@labserver ~]# grep a-user /etc/passwd
a-user:x:1001:1001::/home/a-user:/bin/bash
[root@labserver ~]# 

[root@labserver ~]# grep a-user /etc/group
a-user:x:1001:
[root@labserver ~]# 

[root@labserver ~]# grep a-user /etc/shadow
a-user:!:20658:0:99999:7:::				 # ! --&amp;gt; Password authentication is locked because no password has been assigned yet
[root@labserver ~]# 

[root@labserver ~]# pwd
/root
[root@labserver ~]# cd /home/a-user/
[root@labserver a-user]# pwd
/home/a-user
[root@labserver a-user]# ls
[root@labserver a-user]# ls -a
. .. .bash_logout .bash_profile .bashrc
[root@labserver a-user]# 
[root@labserver a-user]# cd
[root@labserver ~]# pwd
/root
[root@labserver ~]# 
 
 # useradd a-user
 # |
 # +--&amp;gt; /etc/passwd --&amp;gt; User account information added
 # |
 # +--&amp;gt; /etc/group --&amp;gt; Primary group created
 # |
 # +--&amp;gt; /etc/shadow --&amp;gt; Password entry created (locked initially)
 # |
 # +--&amp;gt; /etc/gshadow --&amp;gt; Secure group information created/updated
 # |
 # +--&amp;gt; /home/a-user --&amp;gt; User home directory created
 # |
 # +--&amp;gt; /etc/skel/* --&amp;gt; Default shell files copied to user&amp;#39;s home directory

 # The files placed in /etc/skel/ are automatically copied to the newly created user&amp;#39;s home directory.
 # Application:
 # Organization-specific files (company rules, login instructions, scripts,
 # configuration files, or user guidance documents) can be placed in /etc/skel/
 # so they are automatically provided to new users during account creation.

[root@labserver ~]# cd /etc/skel/
[root@labserver skel]# ls
[root@labserver skel]# vi myfile
[root@labserver skel]# ls
myfile
[root@labserver skel]# ls -a
. .. .bash_logout .bash_profile .bashrc myfile
[root@labserver skel]# cd
[root@labserver ~]# 
[root@labserver ~]# useradd b-user
[root@labserver ~]# cd /home/b-user/
[root@labserver b-user]# ls
myfile
[root@labserver b-user]# ls -a
. .. .bash_logout .bash_profile .bashrc myfile
[root@labserver b-user]# cd
[root@labserver ~]# 

 # Changes made to /etc/skel/ affect only users created after the change.
 # Existing users&amp;#39; home directories are not updated automatically.

[root@labserver ~]# cd /home/a-user/
[root@labserver a-user]# ls
[root@labserver a-user]# ls -a
. .. .bash_logout .bash_profile .bashrc
[root@labserver a-user]# 

 # /var/spool/mail/ --&amp;gt; User Mail Spool Directory

 # Stores local mail spool files for users on the system.
 # Each user has a mailbox file named after the username.
 # When a new user is created with useradd (CREATE_MAIL_SPOOL=yes), a mail spool file is automatically created:

[root@labserver ~]# cd /var/spool/mail/
[root@labserver mail]# ls
aadarsha a-user b-user
[root@labserver mail]# ls -la
total 0
drwxrwxr-x. 2 root mail 50 Jul 24 14:26 .
drwxr-xr-x. 6 root root 56 Jul 13 14:30 ..
-rw-rw----. 1 aadarsha mail 0 Jul 13 14:32 aadarsha
-rw-rw----. 1 a-user mail 0 Jul 24 12:06 a-user
-rw-rw----. 1 b-user mail 0 Jul 24 14:26 b-user

[root@labserver mail]# ls /var/mail
aadarsha a-user b-user

[root@labserver mail]# ls -l /var/mail
lrwxrwxrwx. 1 root root 10 Apr 2 2025 /var/mail -&amp;gt; spool/mail # /var/mail is normally a symbolic link to /var/spool/mail
[root@labserver mail]# 

 # add password

[root@labserver ~]# ls /home/
aadarsha a-user b-user
[root@labserver ~]# grep a-user /etc/shadow
a-user:!:20658:0:99999:7:::

[root@labserver ~]# passwd a-user
New password: 
Retype new password: 
passwd: password updated successfully

[root@labserver ~]# grep a-user /etc/shadow
a-user:$y$j9T$09jS8Aj4NajTvf3D9DItu1$ywEo4KJbYr64Y439Y7SmP3ZsWbFuKguoKuM8ex/GwI6:20658:0:99999:7:::
[root@labserver ~]# 

 # Get password age info
 
[root@labserver ~]# chage -l a-user
Last password change					: Jul 24, 2026
Password expires					: never
Password inactive					: never
Account expires						: never
Minimum number of days between password change		: 0
Maximum number of days between password change		: 99999
Number of days of warning before password expires	: 7
[root@labserver ~]# 

[root@labserver ~]# vi /etc/login.defs # --&amp;gt; contains the default settings used by tools such as useradd, passwd, and other shadow password utilities.

[root@labserver ~]# whoami
root

[root@labserver ~]# ps
 PID TTY TIME CMD
 1985 pts/0 00:00:00 su
 1991 pts/0 00:00:00 bash
 4043 pts/0 00:00:00 ps
[root@labserver ~]# 

[root@labserver ~]# su - a-user
[a-user@labserver ~]$ whoami
a-user
[a-user@labserver ~]$ ps
 PID TTY TIME CMD
 4058 pts/0 00:00:00 bash
 4088 pts/0 00:00:00 ps
[a-user@labserver ~]$ 

 # To create user accounts with non-default settings
 
 # useradd | usermod [options] &amp;lt;username&amp;gt;
 # [options]

 # -c --&amp;gt; &amp;lt;comment&amp;gt;
 # -d --&amp;gt; &amp;lt;home dir&amp;gt;
 # -e --&amp;gt; &amp;lt;a/c expiry date&amp;gt;
 # -g --&amp;gt; &amp;lt;primary group&amp;gt;
 # -G --&amp;gt; &amp;lt;secondary groups&amp;gt;
 # -u --&amp;gt; &amp;lt;UID &amp;gt;
 # -s --&amp;gt; &amp;lt;shell&amp;gt; 
 # -l --&amp;gt; &amp;lt;new login name&amp;gt;
 # -L --&amp;gt; &amp;lt;Lock user&amp;#39;s account&amp;gt;
 # -U --&amp;gt; &amp;lt;Unlock&amp;gt;
 
[root@labserver ~]# useradd --help

[root@labserver ~]# usermod -h

[root@labserver ~]# # useradd -u 3001 -s /bin/csh -c &amp;#34;Mission Karki, KTM-32, Tinkune, +977-9860397731&amp;#34; -d /opt/milan -e 2027-01-01 -g employee -G IT,admin mission # example 

[root@labserver ~]# ls /home
aadarsha a-user b-user
 
[root@labserver ~]# groups aadarsha
aadarsha : aadarsha wheel			 # first is primary group &amp;amp; remaining are secondary groups
 
[root@labserver ~]# groups b-user
b-user : b-user
[root@labserver ~]# 

[root@labserver ~]# grep b-user /etc/passwd
b-user:x:1002:1002::/home/b-user:/bin/bash
 
[root@labserver ~]# passwd b-user
New password: 
Retype new password: 
passwd: password updated successfully

[root@labserver ~]# grep b-user /etc/passwd
b-user:x:1002:1002::/home/b-user:/bin/bash

 # add dummy groups

[root@labserver ~]# groupadd managers
[root@labserver ~]# groupadd developers
[root@labserver ~]# groupadd operations

[root@labserver ~]# chage -l b-user
Last password change					: Jul 24, 2026
Password expires					: never
Password inactive					: never
Account expires						: never
Minimum number of days between password change		: 0
Maximum number of days between password change		: 99999
Number of days of warning before password expires	: 7

[root@labserver ~]# grep b-user /etc/group
b-user:x:1002:

[root@labserver ~]# usermod -c &amp;#34;Bb User, Lalitpur, 9798457832&amp;#34; -e 2027-01-01 -g managers -G developers,operations -u 2002 -s /bin/ksh b-user
usermod: Warning: missing or non-executable shell &amp;#39;/bin/ksh&amp;#39;

[root@labserver ~]# chage -l b-user
Last password change					: Jul 24, 2026
Password expires					: never
Password inactive					: never
Account expires						: Dec 31, 2026
Minimum number of days between password change		: 0
Maximum number of days between password change		: 99999
Number of days of warning before password expires	: 7

[root@labserver ~]# grep b-user /etc/passwd
b-user:x:2002:1003:Bb User, Lalitpur, 9798457832:/home/b-user:/bin/ksh
 
[root@labserver ~]# grep b-user /etc/group
b-user:x:1002:
developers:x:1004:b-user
operations:x:1005:b-user

[root@labserver ~]# groups b-user
b-user : managers developers operations
[root@labserver ~]# 

[root@labserver ~]# su - b-user
su: failed to execute /bin/ksh: No such file or directory

[root@labserver ~]# usermod -s /bin/bash b-user
[root@labserver ~]# su - b-user
Last login: Fri Jul 24 18:57:23 +0545 2026 on pts/0
[b-user@labserver ~]$ whoami
b-user
[b-user@labserver ~]$ pwd
/home/b-user

[b-user@labserver ~]$ exit
logout
[root@labserver ~]# usermod -l bishal b-user
[root@labserver ~]# grep b-user /etc/passwd
bishal:x:2002:1003:Bb User, Lalitpur, 9798457832:/home/b-user:/bin/bash # Home directory remains /home/b-user

[root@labserver ~]# grep b-user /etc/shadow

[root@labserver ~]# grep bishal /etc/shadow
bishal:$y$j9T$BOtZEsmKfliEvI/9VLki21$2GdWuL3462NjklMJaqok1Uy2rwtn/SpJRPTOpKjZrl9:20658:0:99999:7::20818:

[root@labserver ~]# groups bishal
bishal : managers developers operations

 # Lock and Unlock the user

[root@labserver ~]# grep bishal /etc/shadow
bishal:$y$j9T$BOtZEsmKfliEvI/9VLki21$2GdWuL3462NjklMJaqok1Uy2rwtn/SpJRPTOpKjZrl9:20658:0:99999:7::20818:
 
[root@labserver ~]# usermod -L bishal

[root@labserver ~]# grep bishal /etc/shadow
bishal:!$y$j9T$BOtZEsmKfliEvI/9VLki21$2GdWuL3462NjklMJaqok1Uy2rwtn/SpJRPTOpKjZrl9:20658:0:99999:7::20818:	 # Lock --&amp;gt; !
 
[root@labserver ~]# usermod -U bishal # Unlock

[root@labserver ~]# grep bishal /etc/shadow
bishal:$y$j9T$BOtZEsmKfliEvI/9VLki21$2GdWuL3462NjklMJaqok1Uy2rwtn/SpJRPTOpKjZrl9:20658:0:99999:7::20818:

[root@labserver ~]# tail -2 /var/log/secure 					# View Logs
Jul 24 08:36:21 labserver usermod[2079]: lock user &amp;#39;bishal&amp;#39; password
Jul 24 08:37:16 labserver usermod[2088]: unlock user &amp;#39;bishal&amp;#39; password

 # Setting User&amp;#39;s Password Policy
 
 # chage [options] &amp;lt;username/login name&amp;gt;
 
 # options
 
 # -l --&amp;gt; &amp;lt;list policy&amp;gt;
 # -m --&amp;gt; &amp;lt;min no of days between password change&amp;gt;
 # -M --&amp;gt; &amp;lt;max no. of days between password change&amp;gt;
 # -W --&amp;gt; &amp;lt;warning days before password expires&amp;gt;
 # -I --&amp;gt; &amp;lt;grace period before locking password after the password expires&amp;gt;
 # -E --&amp;gt; &amp;lt;a/c expiray date&amp;gt;
 
[root@labserver ~]# chage --h

[root@labserver ~]# chage -l bishal
Last password change					: Jul 24, 2026
Password expires					: never
Password inactive					: never
Account expires						: Dec 31, 2026
Minimum number of days between password change		: 0
Maximum number of days between password change		: 99999
Number of days of warning before password expires	: 7
 
[root@labserver ~]# vi /etc/login.defs 

[root@labserver ~]# vi /etc/default/useradd 

[root@labserver ~]# chage -l bishal
Last password change					: Jul 24, 2026
Password expires					: never
Password inactive					: never
Account expires						: Dec 31, 2026
Minimum number of days between password change		: 0
Maximum number of days between password change		: 99999
Number of days of warning before password expires	: 7

[root@labserver ~]# chage -m 5 -M 365 -W 10 -E 2028-01-01 -I 90 bishal
 
[root@labserver ~]# chage -l bishal
Last password change					: Jul 24, 2026
Password expires					: Jul 24, 2027
Password inactive					: Oct 22, 2027
Account expires						: Dec 31, 2027
Minimum number of days between password change		: 5
Maximum number of days between password change		: 365
Number of days of warning before password expires	: 10


 # Enforcing a user to change their password on First Login ( production use case )

[root@labserver ~]# chage -h

[root@labserver ~]# chage -d 0 bishal # Force the user bishal to change their password at the next login by setting the last password change date to 0.

 # --&amp;gt; chage -d 0 &amp;lt;username&amp;gt; sets the last password change date to January 1, 1970 (day 0), causing the password to be treated as expired immediately.
 
[root@labserver ~]# chage -l bishal
Last password change					: password must be changed
Password expires					: password must be changed
Password inactive					: password must be changed
Account expires						: Dec 31, 2027
Minimum number of days between password change		: 5
Maximum number of days between password change		: 365
Number of days of warning before password expires	: 10

[root@labserver ~]# exit
logout

[aadarsha@labserver ~]$ su - bishal
Password: 
You are required to change your password immediately (administrator enforced).
Current password: 
New password: 
Retype new password: 
Last login: Fri Jul 24 18:58:31 +0545 2026 on pts/0
Last failed login: Sat Jul 25 09:36:45 +0545 2026 on pts/0
There was 1 failed login attempt since the last successful login.

[bishal@labserver ~]$ whoami
bishal

[bishal@labserver ~]$ exit
logout

[aadarsha@labserver ~]$ su - bishal
Password: 
Last login: Sat Jul 25 09:37:40 +0545 2026 on pts/0
[bishal@labserver ~]$ 

[bishal@labserver ~]$ exit
logout

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Sat Jul 25 08:30:02 +0545 2026 on pts/0
[root@labserver ~]# 

 # PAM (Pluggable Authentication Modules) 
 # is the Linux authentication framework that enforces authentication, account, password, and session policies for services such as login, sshd, su, and sudo.
 
 # Primary PAM configuration: /etc/pam.d/ ---&amp;gt; Contains PAM configuration files for individual services (recommended location).
 # Supporting policy files: /etc/security/ ---&amp;gt; Contains supporting configuration files used by PAM modules (e.g., limits.conf, access.conf, faillock.conf).

[root@labserver ~]# ls /etc/pam.d/
chfn config-util fingerprint-auth other password-auth remote runuser-l sshd su sudo-i switchable-auth vlock
chsh crond login passwd postlogin runuser smartcard-auth sssd-shadowutils sudo su-l system-auth
[root@labserver ~]# 

 # Deleting User&amp;#39;s Account
 
 # userdel -r &amp;lt;username&amp;gt; ---&amp;gt; To delete the user completely (along with home dir and mail spool)
 # userdel &amp;lt;username&amp;gt; ---&amp;gt; To delete the user completely (except home dir and mail spool)

[root@labserver ~]# ls /home
aadarsha a-user b-user
 
[root@labserver ~]# tail -2 /etc/passwd
a-user:x:1001:1001::/home/a-user:/bin/bash
bishal:x:2002:1003:Bb User, Lalitpur, 9798457832:/home/b-user:/bin/bash

[root@labserver ~]# grep bishal /etc/shadow
bishal:$y$j9T$VlRZkORrgRGKkAJ.bJ2XJ.$GDc9S3J3VIp1ibU3tBO82T4Fdn5M4UZsgLQXqI5vr6.:20659:5:365:10:90:21183:

[root@labserver ~]# grep bishal /etc/group
developers:x:1004:bishal
operations:x:1005:bishal
 
[root@labserver ~]# groups bishal
bishal : managers developers operations
 
[root@labserver ~]# ls /var/spool/mail/
aadarsha a-user bishal

[root@labserver ~]# userdel -r bishal
 
[root@labserver ~]# ls /home/
aadarsha a-user
[root@labserver ~]# grep bishal /etc/passwd
[root@labserver ~]# grep bishal /etc/shadow
[root@labserver ~]# grep bishal /etc/group
[root@labserver ~]# groups bishal
groups: ‘bishal’: no such user
[root@labserver ~]# ls /var/spool/mail/
aadarsha a-user

[root@labserver ~]# useradd ram
[root@labserver ~]# ls /home/
aadarsha a-user ram
[root@labserver ~]# grep ram /etc/passwd
ram:x:1002:1006::/home/ram:/bin/bash
[root@labserver ~]# grep ram /etc/shadow
ram:!:20659:0:99999:7:::
[root@labserver ~]# passwd ram
New password: 
Retype new password: 
passwd: password updated successfully
[root@labserver ~]# grep ram /etc/shadow
ram:$y$j9T$kD5ld9mfTMku4r7MevImP1$GJWefZ6k9FpdExJke41Xl8WucFUPSUujue4wNsCr0Z2:20659:0:99999:7:::
[root@labserver ~]#
[root@labserver ~]# grep ram /etc/group
ram:x:1006:
[root@labserver ~]# ls -l /var/spool/mail/ram 
-rw-rw----. 1 ram mail 0 Jul 25 13:53 /var/spool/mail/ram
[root@labserver ~]# ls -l /home/ram/
total 4
-rw-r--r--. 1 ram ram 19 Jul 24 14:25 myfile
[root@labserver ~]# ls -ld /home/ram/
drwx------. 2 ram ram 76 Jul 25 13:53 /home/ram/
[root@labserver ~]# su - ram
[ram@labserver ~]$ pwd
/home/ram
[ram@labserver ~]$ ls
myfile
[ram@labserver ~]$ vi ram-file
[ram@labserver ~]$ ls -l
total 8
-rw-r--r--. 1 ram ram 19 Jul 24 14:25 myfile
-rw-r--r--. 1 ram ram 35 Jul 25 13:59 ram-file
[ram@labserver ~]$ 
 
[ram@labserver ~]$ userdel ram
userdel: user ram is currently used by process 4240
[ram@labserver ~]$ 
[ram@labserver ~]$ ps
 PID TTY TIME CMD
 4240 pts/0 00:00:00 bash
 4339 pts/0 00:00:00 ps
[ram@labserver ~]$ 
[ram@labserver ~]$ exit
logout
[root@labserver ~]# userdel ram
[root@labserver ~]# ls /home/
aadarsha a-user ram
[root@labserver ~]# 
[root@labserver ~]# ls -ld /home/ram
drwx------. 2 1002 1006 113 Jul 25 14:07 /home/ram
[root@labserver ~]# 
[root@labserver ~]# ls -l /home/ram/
total 8
-rw-r--r--. 1 1002 1006 19 Jul 24 14:25 myfile
-rw-r--r--. 1 1002 1006 35 Jul 25 13:59 ram-file
[root@labserver ~]# 
[root@labserver ~]# grep ram /etc/passwd
[root@labserver ~]# grep ram /etc/shadow
[root@labserver ~]# grep ram /etc/group
[root@labserver ~]# 
[root@labserver ~]# ls -ld /var/spool/mail/ram 
-rw-rw----. 1 1002 mail 0 Jul 25 13:53 /var/spool/mail/ram
[root@labserver ~]# 

 # When user ram is deleted, it&amp;#39;s home directory and mail directory remains, now giving new user permission to use those left directories
 # ( use case: When an employees leaves company, the resources used by them are handed to other employee )
 
[root@labserver ~]# useradd -u 1002 -d /home/ram sita # assign same UID and Home Directory to new user sita
useradd: warning: the home directory /home/ram already exists.
useradd: Not copying any file from skel directory into it.
[root@labserver ~]# 
[root@labserver ~]# passwd sita
New password: 
Retype new password: 
passwd: password updated successfully
[root@labserver ~]# ls -ld /home/ram
drwx------. 2 sita sita 113 Jul 25 14:07 /home/ram
[root@labserver ~]# 
[root@labserver ~]# ls -ld /var/spool/mail/ram 
-rw-rw----. 1 sita mail 0 Jul 25 13:53 /var/spool/mail/ram
[root@labserver ~]# 
[root@labserver ~]# ls -l /home/ram/
total 8
-rw-r--r--. 1 sita sita 19 Jul 24 14:25 myfile
-rw-r--r--. 1 sita sita 35 Jul 25 13:59 ram-file
[root@labserver ~]# 
[root@labserver ~]# su - sita
[sita@labserver ~]$ whoami
sita
[sita@labserver ~]$ pwd
/home/ram
[sita@labserver ~]$ ls -l
total 8
-rw-r--r--. 1 sita sita 19 Jul 24 14:25 myfile
-rw-r--r--. 1 sita sita 35 Jul 25 13:59 ram-file
[sita@labserver ~]$ 
[sita@labserver ~]$ exit
logout
[root@labserver ~]# grep sita /etc/passwd
sita:x:1002:1006::/home/ram:/bin/bash
[root@labserver ~]# 
[root@labserver ~]# cd /home/
[root@labserver home]# ls
aadarsha a-user ram
[root@labserver home]# mv ram sita
[root@labserver home]# ls
aadarsha a-user sita
[root@labserver home]#
[root@labserver home]# ls -l
total 0
drwx------. 2 aadarsha aadarsha 83 Jul 13 14:46 aadarsha
drwx------. 2 a-user a-user 83 Jul 24 17:28 a-user
drwx------. 2 sita sita 113 Jul 25 14:07 sita
[root@labserver home]# 
[root@labserver ~]# grep sita /etc/passwd
sita:x:1002:1006::/home/ram:/bin/bash
[root@labserver ~]# usermod -d /home/sita sita
[root@labserver ~]# grep sita /etc/passwd
sita:x:1002:1006::/home/sita:/bin/bash
[root@labserver ~]# 
[root@labserver ~]# cd /var/spool/mail/
[root@labserver mail]# ls
aadarsha a-user ram sita
[root@labserver mail]# mv ram sita 
mv: overwrite &amp;#39;sita&amp;#39;? y
[root@labserver mail]# ls -l
total 0
-rw-rw----. 1 aadarsha mail 0 Jul 13 14:32 aadarsha
-rw-rw----. 1 a-user mail 0 Jul 24 12:06 a-user
-rw-rw----. 1 sita mail 0 Jul 25 13:53 sita
[root@labserver mail]# 

 # Managing groups
 
[root@labserver ~]# groupadd friends

[root@labserver ~]# grep friends /etc/group
friends:x:1007:
[root@labserver ~]# tail -9 /etc/group
systemd-coredump:x:995:
aadarsha:x:1000:
a-user:x:1001:
b-user:x:1002:
managers:x:1003:
developers:x:1004:
operations:x:1005:
sita:x:1006:
friends:x:1007:
[root@labserver ~]# 

[root@labserver ~]# groupmod -g 1008 friends
[root@labserver ~]# grep friends /etc/group
friends:x:1008:
[root@labserver ~]#

[root@labserver ~]# groupmod -n newfriends friends
[root@labserver ~]# grep friends /etc/group
newfriends:x:1008:
[root@labserver ~]# 

[root@labserver ~]# groupdel newfriends
[root@labserver ~]# grep newfriends /etc/group
[root@labserver ~]#

 # Linux User and Group Management: Organizational Structure

		Boss
		│
		└── Manager
		 ├── Production
		 │ ├── prod-user1
		 │ └── prod-user2
		 ├── Marketing
		 │ ├── market-user1
		 │ └── market-user2
		 └── Sales
		 ├── sale-user1
		 └── sale-user2

 # 1. Create departments (groups)
 
[root@labserver ~]# groupadd production
[root@labserver ~]# groupadd marketing
[root@labserver ~]# groupadd sales

[root@labserver ~]# getent group

[root@labserver ~]# tail -4 /etc/group
aadarsha:x:1000:
production:x:1001:
marketing:x:1002:
sales:x:1003:

 # 2. Create users in each department (group)
 
[root@labserver ~]# useradd --help

 # production
 
[root@labserver ~]# useradd -G production prod-user1
[root@labserver ~]# useradd -G production prod-user2

[root@labserver ~]# grep production /etc/group
production:x:1001:prod-user1,prod-user2

 # marketing

[root@labserver ~]# useradd -G marketing market-user1
[root@labserver ~]# useradd -G marketing market-user2

[root@labserver ~]# grep marketing /etc/group
marketing:x:1002:market-user1,market-user2

 # sales 

[root@labserver ~]# useradd -G sales sale-user1
[root@labserver ~]# useradd -G sales sale-user2

[root@labserver ~]# grep sales /etc/group
sales:x:1003:sale-user1,sale-user2
 
[root@labserver ~]# tail /etc/group
aadarsha:x:1000:
production:x:1001:prod-user1,prod-user2
marketing:x:1002:market-user1,market-user2
sales:x:1003:sale-user1,sale-user2
prod-user1:x:1004:
prod-user2:x:1005:
market-user1:x:1006:
market-user2:x:1007:
sale-user1:x:1008:
sale-user2:x:1009:
[root@labserver ~]# 

 # 3. Create the manager user and assign supplementary groups

[root@labserver ~]# useradd --help

[root@labserver ~]# useradd -m -G production,marketing,sales manager

[root@labserver ~]# grep manager /etc/group
production:x:1001:prod-user1,prod-user2,manager
marketing:x:1002:market-user1,market-user2,manager
sales:x:1003:sale-user1,sale-user2,manager
manager:x:1010:

[root@labserver ~]# id manager
uid=1007(manager) gid=1010(manager) groups=1010(manager),1001(production),1002(marketing),1003(sales)

[root@labserver ~]# useradd -m -G production,marketing,sales boss
[root@labserver ~]# id boss
uid=1009(boss) gid=1012(boss) groups=1012(boss),1001(production),1002(marketing),1003(sales)

[root@labserver ~]# tail -13 /etc/group
aadarsha:x:1000:
production:x:1001:prod-user1,prod-user2,manager,new-user1,boss
marketing:x:1002:market-user1,market-user2,manager,new-user1,boss
sales:x:1003:sale-user1,sale-user2,manager,new-user1,boss
prod-user1:x:1004:
prod-user2:x:1005:
market-user1:x:1006:
market-user2:x:1007:
sale-user1:x:1008:
sale-user2:x:1009:
manager:x:1010:
new-user1:x:1011:
boss:x:1012:

 # add new-user1

[root@labserver ~]# useradd new-user1

[root@labserver ~]# grep new-user1 /etc/group
new-user1:x:1011:

 # To add new-user1 in production group (department)

[root@labserver ~]# usermod -G production new-user1
 
[root@labserver ~]# grep new-user1 /etc/group
production:x:1001:prod-user1,prod-user2,manager,new-user1
new-user1:x:1011:

[root@labserver ~]# usermod -G marketing,sales new-user1 # Replaces supplementary groups

[root@labserver ~]# grep new-user1 /etc/group
marketing:x:1002:market-user1,market-user2,manager,new-user1 # --&amp;gt; Verify that production membership was removed
sales:x:1003:sale-user1,sale-user2,manager,new-user1
new-user1:x:1011:

 # Append production without removing existing groups

[root@labserver ~]# usermod -aG production new-user1

[root@labserver ~]# grep new-user1 /etc/group
production:x:1001:prod-user1,prod-user2,manager,new-user1
marketing:x:1002:market-user1,market-user2,manager,new-user1
sales:x:1003:sale-user1,sale-user2,manager,new-user1
new-user1:x:1011:

[root@labserver ~]# groups new-user1
new-user1 : new-user1 production marketing sales

 # Assign a temporary password for testing purposes only. ( not used in production environment ) 
 
[root@labserver ~]# grep new-user1 /etc/shadow
new-user1:!:20659:0:99999:7:::
[root@labserver ~]# grep prod-user1 /etc/shadow
prod-user1:!:20659:0:99999:7:::
[root@labserver ~]# grep prod-user2 /etc/shadow
prod-user2:!:20659:0:99999:7:::

 # Read the password from standard input (stdin)
 
[root@labserver ~]# echo &amp;#34;Nepal-123&amp;#34; | passwd --stdin new-user1
[root@labserver ~]# echo &amp;#34;Nepal-123&amp;#34; | passwd --stdin prod-user1
[root@labserver ~]# echo &amp;#34;Nepal-123&amp;#34; | passwd --stdin prod-user2
[root@labserver ~]# echo &amp;#34;Nepal-123&amp;#34; | passwd --stdin sale-user1
[root@labserver ~]# echo &amp;#34;Nepal-123&amp;#34; | passwd --stdin sale-user2

[root@labserver ~]# grep new-user1 /etc/shadow
new-user1:$y$j9T$9g9Oov3zZEAi7LzA.X44u/$ZPuULJkBpBATIzw0.H..YVZ5gjGVt/38Y1ZcyJOO6m4:20659:0:99999:7:::
[root@labserver ~]# grep prod-user1 /etc/shadow
prod-user1:$y$j9T$Iagb2/1WX0DC4TB/aOdmp1$0Mop5VZb6qeDRGOj71bUbrov0tihMQ24Vh01LU1qLSD:20659:0:99999:7:::
[root@labserver ~]# grep prod-user2 /etc/shadow
prod-user2:$y$j9T$dRE4E7v0xEkEZBrhEbd.a1$ojJFePa/3H0vIuLsZ3MuJbWkmfv/TRw31Wpds8qGddA:20659:0:99999:7:::

[root@labserver ~]# echo &amp;#34;market-user1:Nepal-123&amp;#34; | chpasswd 
[root@labserver ~]# echo &amp;#34;market-user2:Nepal-123&amp;#34; | chpasswd 

[root@labserver ~]# grep market-user1 /etc/shadow
market-user1:$y$j9T$yCakDMvFpwR1s7yf9KwPs1$Q67N9G/x/i1RUhMjiY/rzXxK1Ov26cfrW1KM3JMb3BA:20660:0:99999:7:::
[root@labserver ~]# grep market-user2 /etc/shadow
market-user2:$y$j9T$wFAi7QKerJUzEHmeVYrpY/$JJcCxEuT/HnX3okVbjAcYVpqqqTHMupf00zi5jsPdf1:20660:0:99999:7:::

 # Note:
 # Linux does not support nested groups.
 # The company hierarchy is represented by supplementary group memberships
 # rather than parent-child relationships between groups.

 # 3. Create departmental directories/folders

[root@labserver ~]# cd /
[root@labserver /]# pwd
/
[root@labserver /]# ls -ld
dr-xr-xr-x. 19 root root 250 Jul 22 13:23 .

[root@labserver /]# ls
abcbank afs bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

[root@labserver /]# mkdir production marketing sales
[root@labserver /]# ls
abcbank afs bin boot dev etc home lib lib64 marketing media mnt opt proc production root run sales sbin srv sys tmp usr var

[root@labserver /]# ls -ld production marketing sales
drwxr-xr-x. 2 root root 6 Jul 25 21:44 marketing
drwxr-xr-x. 2 root root 6 Jul 25 21:44 production
drwxr-xr-x. 2 root root 6 Jul 25 21:44 sales

[root@labserver /]# whoami
root

 # 4. Change the ownership of the departmental directories 

 # chown -R &amp;lt;new owner&amp;gt;:&amp;lt;new group&amp;gt; &amp;lt;dir/file&amp;gt;		 # -R --&amp;gt; recursively apply inside the directories
 
[root@labserver /]# chown -R boss:marketing marketing
[root@labserver /]# chown -R boss:production production
[root@labserver /]# chown -R boss:sales sales

[root@labserver /]# ls -ld marketing production sales
drwxr-xr-x. 2 boss marketing 6 Jul 25 21:44 marketing
drwxr-xr-x. 2 boss production 6 Jul 25 21:44 production
drwxr-xr-x. 2 boss sales 6 Jul 25 21:44 sales

[root@labserver ~]# su - prod-user1
[prod-user1@labserver ~]$ whoami
prod-user1
[prod-user1@labserver ~]$ ls -ld /production
drwxr-xr-x. 2 boss production 6 Jul 25 21:44 /production

[prod-user1@labserver ~]$ cd /production
[prod-user1@labserver production]$ ls
[prod-user1@labserver production]$ mkdir dir1
mkdir: cannot create directory ‘dir1’: Permission denied
 
[prod-user1@labserver production]$ cd
[prod-user1@labserver ~]$ 

 # 5. Set the appropriate required persmissions on the departmental directories
 
[prod-user1@labserver ~]$ exit
logout

[root@labserver ~]# chmod 770 /production /marketing /sales

[root@labserver ~]# ls -ld /production /marketing /sales
drwxrwx---. 2 boss marketing 6 Jul 25 21:44 /marketing
drwxrwx---. 2 boss production 6 Jul 25 21:44 /production
drwxrwx---. 2 boss sales 6 Jul 25 21:44 /sales

[root@labserver ~]# su - prod-user1
Last login: Sun Jul 26 08:07:10 +0545 2026 on pts/0
[prod-user1@labserver ~]$ whoami
prod-user1
[prod-user1@labserver ~]$ cd /production

[prod-user1@labserver production]$ ls -ld
drwxrwx---. 3 boss production 39 Jul 26 08:19 .			 # on current directory ownership: &amp;lt;user = boss&amp;gt; : &amp;lt;group = production&amp;gt;

[prod-user1@labserver production]$ vi testfile1
[prod-user1@labserver production]$ mkdir testdir1

[prod-user1@labserver production]$ ls -l
total 4
drwxr-xr-x. 2 prod-user1 prod-user1 6 Jul 26 08:19 testdir1 # on current directory newly created files ownership: &amp;lt;user = prod-user1&amp;gt; : &amp;lt;group = prod-user1&amp;gt; BUT
-rw-r--r--. 1 prod-user1 prod-user1 25 Jul 26 08:19 testfile1 # By default we want: &amp;lt;user = prod-user1&amp;gt; : &amp;lt;group = production&amp;gt;

[prod-user1@labserver production]$ cd
[prod-user1@labserver ~]$ 

[prod-user1@labserver ~]$ cd /sales
-bash: cd: /sales: Permission denied

 # remove user from the particular group
 
[root@labserver ~]# groups new-user1
new-user1 : new-user1 production marketing sales

[root@labserver ~]# groups new-user1
new-user1 : new-user1 production marketing sales

[root@labserver ~]# vi /etc/group # remove new-user from production group in /etc/group file
 
[root@labserver ~]# groups new-user1
new-user1 : new-user1 marketing sales

[root@labserver ~]# man usermod

[root@labserver ~]# usermod -rG marketing new-user1 # remove from marketing group 

[root@labserver ~]# groups new-user1
new-user1 : new-user1 sales

[root@labserver ~]# su - sale-user1

[sale-user1@labserver ~]$ cd /sales/

[sale-user1@labserver sales]$ ls -ld
drwxrwx---. 2 boss sales 6 Jul 25 21:44 .

[sale-user1@labserver sales]$ mkdir dir1
[sale-user1@labserver sales]$ ls -ld dir1
drwxr-xr-x. 2 sale-user1 sale-user1 6 Jul 26 08:48 dir1 # By default group should be sales, so use SGID to inherit the parent directory&amp;#39;s group ownership
 
[sale-user1@labserver sales]$ exit
logout
[root@labserver ~]# 

 # Special permission bits : SUID (4), SGID (2), Sticky Bit (1)

 # SGID Bit - Set Group ID Bit
 # Octal Value: 2
 # SGID ensures that new files and directories inherit the parent directory&amp;#39;s group ownership instead of the creator&amp;#39;s primary group. 
 # If SGID bit is set on a directory then any files/dirs created inside the folder inherits group ownership of that group
 # Use Case: Shared team directories where multiple users need automatic, collaborative read/write access to newly created files.

[root@labserver ~]# whoami
root
[root@labserver ~]# cd /
[root@labserver /]# pwd
/
[root@labserver /]# ls -ld production marketing sales
drwxrwx---. 2 boss marketing 6 Jul 25 21:44 marketing
drwxrwx---. 3 boss production 39 Jul 26 08:19 production
drwxrwx---. 3 boss sales 18 Jul 26 08:48 sales
 
[root@labserver /]# chmod g+s marketing production sales

[root@labserver /]# ls -ld production marketing sales
drwxrws---. 2 boss marketing 6 Jul 25 21:44 marketing
drwxrws---. 3 boss production 39 Jul 26 08:19 production
drwxrws---. 3 boss sales 18 Jul 26 08:48 sales

 # &amp;#39;x&amp;#39; (execute) permission of group member is replaced by &amp;#39;s&amp;#39;

 # s --&amp;gt; SGID bit + Execute is set
 # S --&amp;gt; SGID bit only set
 # x --&amp;gt; Execute only set

[root@labserver /]# chmod g-x marketing

[root@labserver /]# ls -ld marketing production sales
drwxrwS---. 2 boss marketing 6 Jul 25 21:44 marketing
drwxrws---. 3 boss production 39 Jul 26 08:19 production
drwxrws---. 3 boss sales 18 Jul 26 08:48 sales

[root@labserver /]# chmod g+x marketing

[root@labserver /]# su - sale-user1
Last login: Sun Jul 26 08:47:31 +0545 2026 on pts/0

[sale-user1@labserver ~]$ whoami
sale-user1

[sale-user1@labserver ~]$ pwd
/home/sale-user1

[sale-user1@labserver ~]$ cd /sales

[sale-user1@labserver sales]$ pwd
/sales
[sale-user1@labserver sales]$ ls -l
total 0
drwxr-xr-x. 2 sale-user1 sale-user1 6 Jul 26 08:48 dir1

[sale-user1@labserver sales]$ ls -ld
drwxrws---. 3 boss sales 18 Jul 26 08:48 .

[sale-user1@labserver sales]$ mkdir dir2

[sale-user1@labserver sales]$ touch sales-report-2026

[sale-user1@labserver sales]$ ls -l
total 0
drwxr-xr-x. 2 sale-user1 sale-user1 6 Jul 26 08:48 dir1 # --&amp;gt; Created before setting SGID bit
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 16:17 dir2
-rw-r--r--. 1 sale-user1 sales 0 Jul 26 16:18 sales-report-2026

 # SGID is not retroactive. It affects only new files and directories created after the SGID bit is set.
 
 # So, manual change is required to change to sales group for dir1

[sale-user1@labserver sales]$ chgrp -R sales /sales/dir1

[sale-user1@labserver sales]$ ls -l
total 0
drwxr-xr-x. 2 sale-user1 sales 6 Jul 26 08:48 dir1
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 16:17 dir2
-rw-r--r--. 1 sale-user1 sales 0 Jul 26 16:18 sales-report-2026

[sale-user1@labserver sales]$ cd
[sale-user1@labserver ~]$ pwd
/home/sale-user1

[sale-user1@labserver ~]$ ls
[sale-user1@labserver ~]$ mkdir dir1
[sale-user1@labserver ~]$ vi report1
[sale-user1@labserver ~]$ ls -l
total 4
drwxr-xr-x. 2 sale-user1 sale-user1 6 Jul 26 16:37 dir1
-rw-r--r--. 1 sale-user1 sale-user1 43 Jul 26 16:37 report1

[sale-user1@labserver ~]$ ls -ld /home/sale-user1
drwx------. 3 sale-user1 sale-user1 110 Jul 26 16:37 /home/sale-user1

[sale-user1@labserver ~]$ exit
logout
[root@labserver /]# su - sale-user2
[sale-user2@labserver ~]$ pwd
/home/sale-user2
[sale-user2@labserver ~]$ cd /home/sale-user1
-bash: cd: /home/sale-user1: Permission denied

[sale-user2@labserver ~]$ ls -ld /home/sale-user1
drwx------. 3 sale-user1 sale-user1 110 Jul 26 16:37 /home/sale-user1

[sale-user2@labserver ~]$ cd /sales/
[sale-user2@labserver sales]$ ls
dir1 dir2 sales-report-2026
[sale-user2@labserver sales]$ ls -l
total 0
drwxr-xr-x. 2 sale-user1 sales 6 Jul 26 08:48 dir1
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 16:17 dir2
-rw-r--r--. 1 sale-user1 sales 0 Jul 26 16:18 sales-report-2026

[sale-user1@labserver sales]$ chmod g+s /sales/dir1

[sale-user1@labserver sales]$ ls -l
total 0
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 08:48 dir1
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 16:17 dir2
-rw-r--r--. 1 sale-user1 sales 0 Jul 26 17:12 sales-report-2026

[sale-user1@labserver sales]$ exit
logout
[root@labserver /]# su - sale-user2
Last login: Sun Jul 26 16:40:57 +0545 2026 on pts/0
[sale-user2@labserver ~]$ cd /sales/
[sale-user2@labserver sales]$ ls -l
total 0
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 08:48 dir1
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 16:17 dir2
-rw-r--r--. 1 sale-user1 sales 0 Jul 26 17:12 sales-report-2026

[sale-user2@labserver sales]$ touch report2
[sale-user2@labserver sales]$ mkdir dir3
[sale-user2@labserver sales]$ ls -l
total 0
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 08:48 dir1
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 16:17 dir2
drwxr-sr-x. 2 sale-user2 sales 6 Jul 26 17:39 dir3
-rw-r--r--. 1 sale-user2 sales 0 Jul 26 17:39 report2
-rw-r--r--. 1 sale-user1 sales 0 Jul 26 17:12 sales-report-2026

[sale-user2@labserver sales]$ echo &amp;#34;sale-user2 can not modify dir/files created by sale-user1&amp;#34; &amp;gt;&amp;gt; sales-report-2026 
-bash: sales-report-2026: Permission denied
[sale-user2@labserver sales]$ 

[sale-user2@labserver sales]$ umask
0022
 
 # SGID does not grant write access. It only controls group ownership inheritance.
 
 # Add umask 007 in /etc/bashrc 
 
 # For files:
 
 # 666 - 007 = 660
 # -rw-rw----
 
 # For directories:
 
 # 777 - 007 = 770
 # drwxrwx---

[root@labserver /]# vi /etc/bashrc 
[root@labserver /]# 
 
 # --- added line ---
 umask 007

[root@labserver /]# umask
0022

[root@labserver /]# source /etc/bashrc 

[root@labserver /]# umask
0007

[root@labserver /]# su - sale-user1
Last login: Sun Jul 26 17:11:09 +0545 2026 on pts/0
 
[sale-user1@labserver ~]$ whoami
sale-user1
[sale-user1@labserver ~]$ cd /sales/
[sale-user1@labserver sales]$ pwd
/sales
[sale-user1@labserver sales]$ ls
dir1 dir2 dir3 report2 sales-report-2026

[sale-user1@labserver sales]$ mkdir newdir1
[sale-user1@labserver sales]$ vi newsales-2026

[sale-user1@labserver sales]$ cat newsales-2026 
this is new sales data... added by sale-user1

[sale-user1@labserver sales]$ ls -l
total 4
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 08:48 dir1
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 16:17 dir2
drwxr-sr-x. 2 sale-user2 sales 6 Jul 26 17:39 dir3
drwxrws---. 2 sale-user1 sales 6 Jul 26 19:32 newdir1
-rw-rw----. 1 sale-user1 sales 26 Jul 26 19:32 newsales-2026
-rw-r--r--. 1 sale-user2 sales 0 Jul 26 17:39 report2
-rw-r--r--. 1 sale-user1 sales 0 Jul 26 17:12 sales-report-2026
[sale-user1@labserver sales]$ 

[sale-user1@labserver sales]$ exit
logout
[root@labserver /]# su - sale-user2
Last login: Sun Jul 26 19:35:49 +0545 2026 on pts/0
[sale-user2@labserver ~]$ cd /sales/
[sale-user2@labserver sales]$ ls
dir1 dir2 dir3 newdir1 newsales-2026 report2 sales-report-2026

[sale-user2@labserver sales]$ vi newsales-2026 
[sale-user2@labserver sales]$ cat newsales-2026 
this is new sales data... added by sale-user1
this is new sales data... added by sale-user2
[sale-user2@labserver sales]$ 
[sale-user2@labserver sales]$ cd newdir1/
[sale-user2@labserver newdir1]$ touch newreport2
[sale-user2@labserver newdir1]$ ls -l
total 0
-rw-rw----. 1 sale-user2 sales 0 Jul 26 19:43 newreport2
[sale-user2@labserver newdir1]$ cd ..
[sale-user2@labserver sales]$ ls -l
total 4
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 08:48 dir1
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 16:17 dir2
drwxr-sr-x. 2 sale-user2 sales 6 Jul 26 17:39 dir3
drwxrws---. 2 sale-user1 sales 24 Jul 26 19:43 newdir1
-rw-rw----. 1 sale-user1 sales 92 Jul 26 19:42 newsales-2026
-rw-r--r--. 1 sale-user2 sales 0 Jul 26 17:39 report2
-rw-r--r--. 1 sale-user1 sales 0 Jul 26 17:12 sales-report-2026
[sale-user2@labserver sales]$ 

 # Sticky Bit
 # Octal Value: 1
 # Restricts file deletion within a directory. Only the file owner, directory owner, or root can delete or rename files.
 # Use Case: Publicly accessible directories like /tmp, preventing users from accidentally or maliciously deleting each other&amp;#39;s work.

[sale-user2@labserver sales]$ ls 
dir1 dir2 dir3 newdir1 newsales-2026 report2 sales-report-2026
 
[sale-user2@labserver sales]$ ls newdir1/
newreport2

[sale-user2@labserver sales]$ ls -l newdir1/newreport2 
-rw-rw----. 1 sale-user2 sales 0 Jul 26 19:43 newdir1/newreport2

[sale-user2@labserver sales]$ exit
logout
[root@labserver /]# su - sale-user1
Last login: Sun Jul 26 19:38:33 +0545 2026 on pts/0

[sale-user1@labserver ~]$ cd /sales/
[sale-user1@labserver sales]$ ls -l newdir1/newreport2 
-rw-rw----. 1 sale-user2 sales 0 Jul 26 19:43 newdir1/newreport2

[sale-user1@labserver sales]$ rm newdir1/newreport2 		# newreport2 was created by sale-user2 and removed/deleted by sale-user1

[sale-user1@labserver sales]$ ls newdir1/
[sale-user1@labserver sales]$ 

[sale-user1@labserver sales]$ ls -ld /sales
drwxrws---. 6 boss sales 118 Jul 26 19:42 /sales

 # apply Stick Bit

[sale-user1@labserver sales]$ exit
logout
[root@labserver ~]# 

[root@labserver ~]# ls -ld /production /marketing /sales
drwxrws---. 2 boss marketing 6 Jul 25 21:44 /marketing
drwxrws---. 3 boss production 39 Jul 26 08:19 /production
drwxrws---. 6 boss sales 118 Jul 26 19:42 /sales
 
[root@labserver ~]# chmod o+t /production /marketing /sales

[root@labserver ~]# ls -ld /production /marketing /sales
drwxrws--T. 2 boss marketing 6 Jul 25 21:44 /marketing
drwxrws--T. 3 boss production 39 Jul 26 08:19 /production
drwxrws--T. 6 boss sales 118 Jul 26 19:42 /sales

 # T --&amp;gt; Sticky bit
 # x --&amp;gt; execute
 # t --&amp;gt; execute + Sticky bit

[root@labserver ~]# chmod o+x /production

[root@labserver ~]# ls -ld /production /marketing /sales
drwxrws--T. 2 boss marketing 6 Jul 25 21:44 /marketing
drwxrws--t. 3 boss production 39 Jul 26 08:19 /production
drwxrws--T. 6 boss sales 118 Jul 26 19:42 /sales
[root@labserver ~]# 

[root@labserver ~]# su - sale-user1
Last login: Mon Jul 27 06:30:29 +0545 2026 on pts/0

[sale-user1@labserver ~]$ cd /marketing	 # others don&amp;#39;t have execute permissions on marketing
-bash: cd: /marketing: Permission denied			

[sale-user1@labserver ~]$ cd /production		 # others have execute permissions on production
[sale-user1@labserver production]$ pwd
/production

[sale-user1@labserver production]$ cd -
/home/sale-user1

[sale-user1@labserver ~]$ exit
logout
[root@labserver ~]# chmod o-x /production/
[root@labserver ~]# ls -ld /production
drwxrws--T. 3 boss production 39 Jul 26 08:19 /production

[root@labserver ~]# su - sale-user1
Last login: Mon Jul 27 06:45:15 +0545 2026 on pts/0

[sale-user1@labserver ~]$ cd /sales/

[sale-user1@labserver sales]$ ls
dir1 dir2 dir3 newdir1 newsales-2026 report2 sales-report-2026

[sale-user1@labserver sales]$ ls -l 
total 4
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 08:48 dir1
drwxr-sr-x. 2 sale-user1 sales 6 Jul 26 16:17 dir2
drwxr-sr-x. 2 sale-user2 sales 6 Jul 26 17:39 dir3
drwxrws---. 2 sale-user1 sales 6 Jul 26 19:57 newdir1
-rw-rw----. 1 sale-user1 sales 92 Jul 26 19:42 newsales-2026
-rw-r--r--. 1 sale-user2 sales 0 Jul 26 17:39 report2
-rw-r--r--. 1 sale-user1 sales 0 Jul 26 17:12 sales-report-2026

[sale-user1@labserver sales]$ rm sales-report-2026 

[sale-user1@labserver sales]$ rmdir dir1 dir2
[sale-user1@labserver sales]$ ls -l
total 4
drwxr-sr-x. 2 sale-user2 sales 6 Jul 26 17:39 dir3
drwxrws---. 2 sale-user1 sales 6 Jul 26 19:57 newdir1
-rw-rw----. 1 sale-user1 sales 92 Jul 26 19:42 newsales-2026
-rw-r--r--. 1 sale-user2 sales 0 Jul 26 17:39 report2

[sale-user1@labserver ~]$ exit
logout
[root@labserver ~]# 

[root@labserver ~]# su - sale-user2
Last login: Sun Jul 26 19:38:55 +0545 2026 on pts/0
[sale-user2@labserver ~]$ 

[sale-user2@labserver ~]$ whoami
sale-user2
[sale-user2@labserver ~]$ pwd
/home/sale-user2

[sale-user2@labserver ~]$ cd /sales
[sale-user2@labserver sales]$ ls -ld
drwxrws--T. 4 boss sales 69 Jul 27 08:11 .

[sale-user2@labserver sales]$ ls -l
total 4
drwxr-sr-x. 2 sale-user2 sales 6 Jul 26 17:39 dir3
drwxrws---. 2 sale-user1 sales 24 Jul 27 08:13 newdir1
-rw-rw----. 1 sale-user1 sales 92 Jul 26 19:42 newsales-2026
-rw-r--r--. 1 sale-user2 sales 0 Jul 26 17:39 report2

[sale-user2@labserver sales]$ cd newdir1/
[sale-user2@labserver newdir1]$ ls -l 
total 4
-rw-rw----. 1 sale-user1 sales 54 Jul 27 08:13 newreport1

[sale-user2@labserver newdir1]$ cat newreport1 
this is new sales report 1 added by the sale-user1...

[sale-user2@labserver newdir1]$ vi newreport1 
[sale-user2@labserver newdir1]$ cat newreport1 
this is new sales report 1 added by the sale-user1...
this is new sales report 2 added by the sale-user2...

 # Sticky bit is not set on /newdir1 so deletion of newreport1 created by previous user is possible
 
[sale-user2@labserver newdir1]$ rm newreport1 
[sale-user2@labserver newdir1]$ ls -l
total 0
[sale-user2@labserver newdir1]$ 

[sale-user2@labserver newdir1]$ su - root
Password: 
Last login: Mon Jul 27 08:15:23 +0545 2026 on pts/0

[root@labserver ~]# cd /sales
[root@labserver sales]# ls -l
total 4
drwxr-sr-x. 2 sale-user2 sales 6 Jul 26 17:39 dir3
drwxrws---. 2 sale-user1 sales 6 Jul 27 08:18 newdir1
-rw-rw----. 1 sale-user1 sales 92 Jul 26 19:42 newsales-2026
-rw-r--r--. 1 sale-user2 sales 0 Jul 26 17:39 report2

[root@labserver sales]# ls -ld
drwxrws--T. 4 boss sales 69 Jul 27 08:11 .

[root@labserver sales]# chmod +t newdir1
[root@labserver sales]# ls -l
total 4
drwxr-sr-x. 2 sale-user2 sales 6 Jul 26 17:39 dir3
drwxrws--T. 2 sale-user1 sales 6 Jul 27 08:18 newdir1
-rw-rw----. 1 sale-user1 sales 92 Jul 26 19:42 newsales-2026
-rw-r--r--. 1 sale-user2 sales 0 Jul 26 17:39 report2

[root@labserver sales]# exit
logout

[sale-user2@labserver newdir1]$ ls -ld
drwxrws--T. 2 sale-user1 sales 6 Jul 27 08:18 .

 # A file in a sticky directory can be deleted only by:
 # the file owner
 # the directory owner
 # root

[sale-user2@labserver newdir1]$ ls

[sale-user2@labserver newdir1]$ vi file2

[sale-user2@labserver newdir1]$ ls -l
total 4
-rw-rw----. 1 sale-user2 sales 42 Jul 27 08:57 file2
[sale-user2@labserver newdir1]$ cat file2 
this is sales data added by sale-user2...

[sale-user2@labserver newdir1]$ exit
logout 
[root@labserver ~]# 

[root@labserver ~]# su - sale-user1
Last login: Mon Jul 27 08:14:53 +0545 2026 on pts/0
[sale-user1@labserver ~]$ 

[sale-user1@labserver ~]$ cd /sales
[sale-user1@labserver sales]$ 

[sale-user1@labserver sales]$ cd newdir1/

[sale-user1@labserver newdir1]$ ls -ld
drwxrws--T. 2 sale-user1 sales 19 Jul 27 08:57 .

[sale-user1@labserver newdir1]$ ls -l
total 4
-rw-rw----. 1 sale-user2 sales 42 Jul 27 08:57 file2

[sale-user1@labserver newdir1]$ vi file2 
[sale-user1@labserver newdir1]$ cat file2 
this is sales data added by sale-user2...
this is sales data added by sale-user1...

[sale-user1@labserver newdir1]$ rm file2 # sale-user2 created file2 but removed by sale-user1 is possible because newdir1 is owned by sale-user1
[sale-user1@labserver newdir1]$ ls
[sale-user1@labserver newdir1]$ 

[sale-user1@labserver newdir1]$ ls -ld
drwxrws--T. 2 sale-user1 sales 6 Jul 27 08:59 .

[sale-user1@labserver newdir1]$ vi file1
[sale-user1@labserver newdir1]$ ls -l
total 4
-rw-rw----. 1 sale-user1 sales 42 Jul 27 09:08 file1
[sale-user1@labserver newdir1]$ cat file1 
this sale data is added by the sale-user1

[sale-user1@labserver newdir1]$ exit
logout
[root@labserver ~]# 
[root@labserver ~]# su - sale-user2
Last login: Mon Jul 27 08:15:40 +0545 2026 on pts/0

[sale-user2@labserver ~]$ cd /sales/newdir1/
[sale-user2@labserver newdir1]$ ls -ld
drwxrws--T. 2 sale-user1 sales 19 Jul 27 09:08 .

[sale-user2@labserver newdir1]$ vi file1 
[sale-user2@labserver newdir1]$ cat file1 
this sale data is added by the sale-user1
this sales data is added by the sale-user2

[sale-user2@labserver newdir1]$ ls -l
total 4
-rw-rw----. 1 sale-user1 sales 85 Jul 27 09:09 file1
[sale-user2@labserver newdir1]$ ls -ld
drwxrws--T. 2 sale-user1 sales 19 Jul 27 09:09 .

 # file1 can be modified by sale-user2 as it is the member of sales but it can&amp;#39;t be deleted by sale-user2 because it is under the directory owned by sale-user1
 
[sale-user2@labserver newdir1]$ rm file1 	 
rm: cannot remove &amp;#39;file1&amp;#39;: Operation not permitted

[sale-user2@labserver newdir1]$ cd
[sale-user2@labserver ~]$ 
[sale-user2@labserver ~]$ exit
logout
[root@labserver ~]#

 # SUID (Set User ID) 
 # Octal Value: 4
 # Executes a file using the privileges of the file owner, not the user running it.
 # If SUID bit is set on an executable file/program file then it executes under the security context of owner rather than the user.
 # Use Case: The passwd command, which allows users to update their password by writing to root-restricted files.
 
[root@labserver ~]# useradd raman

[root@labserver ~]# passwd raman
New password: 
Retype new password: 
passwd: password updated successfully
[root@labserver ~]# 

 [root@labserver ~]# which passwd
/usr/bin/passwd

[root@labserver ~]# echo $PATH
/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
 
 # &amp;lt; passwd raman &amp;gt; is equivalent to &amp;lt; /usr/bin/passwd &amp;gt;
[root@labserver ~]#

[root@labserver ~]# ls -l /usr/bin/passwd 
-rwsr-xr-x. 1 root root 91424 Feb 23 05:45 /usr/bin/passwd

 # /usr/bin/passwd has user owner: root and group owner: root and others has execute permission.
 
[root@labserver ~]# ls -l /etc/shadow
----------. 1 root root 1554 Jul 27 09:46 /etc/shadow

 # root is SUPER user so can see modify any files eg. /etc/shadow

[root@labserver ~]# su - raman

[raman@labserver ~]$ whoami
raman

[raman@labserver ~]$ passwd 
Current password: 
New password: 
Retype new password: 
passwd: password updated successfully

 # by observing --&amp;gt; ----------. 1 root root 1554 Jul 27 09:46 /etc/shadow, raman should not be allowed to change the password
 
[raman@labserver ~]$ ls -l /usr/bin/passwd 
-rwsr-xr-x. 1 root root 91424 Feb 23 05:45 /usr/bin/passwd
[raman@labserver ~]$ 
 
 # it is possible because in /user/bin/passwd file, there is SUID bit (s)
 
 # - --s --- ---
 
 # - s --&amp;gt; represents SUID bit, so although user raman runs the program /usr/bin/passwd it runs under the security context of root
 #		s --&amp;gt; SUID + execute
	
 # find all the files with SUID bit
 
[root@labserver ~]# find / -perm /4000

[root@labserver ~]# find / -perm -4000 -type f

[root@labserver ~]# find / -perm /4000 -type f

[root@labserver ~]# find / -perm /4000 | wc -l

[root@labserver ~]# find / -perm /4000 -exec ls -ld {} \; # files with SUID bits only
...

[root@labserver ~]# find / -perm /2000 -exec ls -ld {} \; # files with SGID bits only
...

[root@labserver ~]# find / -perm /2000 -and -user sale-user1 2&amp;gt;/dev/null 
/sales/newdir1
/backup/sales/newdir1
/backup/newdir1
[root@labserver ~]# 
 
 # Copy all files and directories with the SGID bit to /backup
 
[root@labserver ~]# find / -perm /2000 -exec cp -pr {} /backup \; 2&amp;gt;/dev/null 

[root@labserver ~]# cd /backup/

[root@labserver backup]# ls -l
total 40
drwxr-s---+ 2 root systemd-journal 28 Jul 27 06:23 6051512a1e194d8fa01bc1948bcb0427
drwxr-sr-x+ 3 root systemd-journal 24 Jul 27 12:56 backup
drwxr-sr-x+ 2 sale-user2 sales 6 Jul 26 17:39 dir3
drwxrwsr-x+ 2 tss tss 6 Jul 27 06:23 eventlog
drwxr-sr-x+ 3 root systemd-journal 46 Jul 27 06:23 journal
drwxrwsr-x+ 2 tss tss 6 Jul 13 14:32 keystore
drwxrws--T+ 2 boss marketing 6 Jul 25 21:44 marketing
drwxrws--T+ 2 sale-user1 sales 19 Jul 27 09:09 newdir1
drwxrws--T+ 3 boss production 39 Jul 26 08:19 production
drwxrws--T+ 4 boss sales 69 Jul 27 08:11 sales
-rwx--s--x+ 1 root utmp 15976 Oct 29 2024 utempter
-rwxr-sr-x+ 1 root tty 24152 Mar 4 05:45 write
[root@labserver backup]# 

 # NOTE:

	# SGID = Group inheritance (new files/directories inherit the parent directory&amp;#39;s group)
	# g+w = Group collaboration (group members can modify shared files)
	# umask 0002 = Future files are created with group write permission
	# Sticky bit = Prevents users from deleting or renaming files owned by other users

	# Shared production directory:
	# chmod 3770 &amp;lt;directory-name&amp;gt; or chmod 2770 &amp;lt;directory-name&amp;gt; as required

	# 3 --&amp;gt; SGID + Sticky bit
	# 7 --&amp;gt; Owner: read/write/execute
	# 7 --&amp;gt; Group: read/write/execute
	# 0 --&amp;gt; Others: no access

	# SGID (2) --&amp;gt; Group inheritance
	# Sticky (1) --&amp;gt; Only file owner, directory owner, or root can delete/rename files


 # ACL ( Access Control List )

 # Extends standard Linux permissions by allowing fine-grained access control for specific users and groups on files and directories.
 
[root@labserver ~]# yum whatprovides setfacl
...
acl-2.3.2-3.el10.x86_64 : Access control list utilities
...
[root@labserver ~]# rpm -q acl
package acl is not installed
[root@labserver ~]# yum install -y acl
...
Installed:
 acl-2.3.2-4.el10.x86_64 
Complete!
[root@labserver ~]# 

[raman@labserver ~]$ whoami
raman
[raman@labserver ~]$ pwd
/home/raman
[raman@labserver ~]$ ls -ld
drwxrwx--- raman raman 97 Jul 27 11:57 .

[raman@labserver ~]$ setfacl -m u:sale-user1:rwx /home/raman

[raman@labserver ~]$ setfacl -m u:sale-user2:rx /home/raman
 
[raman@labserver ~]$ setfacl -m u:market-user1:x /home/raman

[raman@labserver ~]$ setfacl -m g:production:rx /home/raman
 
[raman@labserver ~]$ ls -ld /home/raman/
drwxrwx---+ 2 raman raman 97 Jul 27 11:57 /home/raman/

[raman@labserver ~]$ getfacl /home/raman
getfacl: Removing leading &amp;#39;/&amp;#39; from absolute path names
# file: home/raman
# owner: raman
# group: raman
user::rwx
user:market-user1:--x
user:sale-user1:rwx
user:sale-user2:r-x
group::---
group:production:r-x
mask::rwx
other::---

[raman@labserver ~]$ exit
logout
[root@labserver ~]# su - sale-user1
Last login: Mon Jul 27 08:58:15 +0545 2026 on pts/0

[sale-user1@labserver ~]$ whoami
sale-user1

[sale-user1@labserver ~]$ ls -ld /home/raman
drwxrwx---+ 2 raman raman 97 Jul 27 11:57 /home/raman

[sale-user1@labserver ~]$ cd /home/raman/
[sale-user1@labserver raman]$ pwd
/home/raman

[sale-user1@labserver raman]$ ls
myfile
[sale-user1@labserver raman]$ rm myfile 
rm: remove write-protected regular file &amp;#39;myfile&amp;#39;? y
[sale-user1@labserver raman]$ ls
[sale-user1@labserver raman]$ 

[sale-user1@labserver raman]$ vi newfile1
[sale-user1@labserver raman]$ cat newfile1
this is new file created by sale-user1

[sale-user1@labserver raman]$ ls -l newfile1 
-rw-rw----. 1 sale-user1 sale-user1 39 Jul 27 14:33 newfile1
[sale-user1@labserver raman]$ 

[sale-user1@labserver raman]$ exit
logout
[root@labserver ~]# su - raman
Last login: Mon Jul 27 14:10:45 +0545 2026 on pts/0

[raman@labserver ~]$ ls -l
total 4
-rw-rw----. 1 sale-user1 sale-user1 39 Jul 27 14:33 newfile1

[raman@labserver ~]$ cat newfile1 
cat: newfile1: Permission denied
[raman@labserver ~]$
&lt;/code&gt;&lt;/pre&gt;&lt;blockquote&gt;
&lt;p&gt;File ownership in Linux:&lt;/p&gt;</description></item><item><title>PL - 011 — Storage Management &amp; Logical Volume Administration</title><link>https://aadarshakhadka.com.np/practice-log/linux/pl-011-storage-lvm/</link><pubDate>Wed, 24 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/pl-011-storage-lvm/</guid><description>&lt;h4 id="concepts"&gt;Concepts:&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Partition,
Mounting,
File System Type,
LVM,
Troubleshooting&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[aadarsha@localhost ~]$ whoami
aadarsha

[aadarsha@localhost ~]$ date
Mon Jul 13 06:30:08 PM +0545 2026

[aadarsha@localhost ~]$ su - root
Password: 
Last login: Mon Jul 13 14:49:30 +0545 2026 on pts/0
[root@localhost ~]# 

[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 25.1G 0 disk 
├─sda1 8:1 0 2M 0 part 
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 24G 0 part 
 ├─cs-root 253:0 0 17G 0 lvm /
 ├─cs-swap 253:1 0 2G 0 lvm [SWAP]
 └─cs-var 253:2 0 5G 0 lvm /var
sr0 11:0 1 1024M 0 rom 
[root@localhost ~]# 

 # Here:
 
 #------------------------------------------------------------------------------------------------------------------------
 # Column | 		Description	 |	 Example Values
 #------------------------------------------------------------------------------------------------------------------------
 # MAJ | Major number - identifies the device driver type | 8 (SCSI/SATA), 11 (CD-ROM), 253 (device-mapper/LVM)
 #------------------------------------------------------------------------------------------------------------------------
 # MIN | Minor number - identifies specific device instance | 0, 1, 2, 3 (sequential per device)
 #------------------------------------------------------------------------------------------------------------------------
 # RM | Removable media flag | 0 (fixed), 1 (removable)
 #------------------------------------------------------------------------------------------------------------------------
 # SIZE | Device capacity in human-readable format | 25.1G, 2M, 1024M
 #------------------------------------------------------------------------------------------------------------------------
 # RO | Read-only flag | 0 (read-write), 1 (read-only)
 #------------------------------------------------------------------------------------------------------------------------
 # TYPE | Device classification | disk, part, lvm, rom, loop, crypt
 #------------------------------------------------------------------------------------------------------------------------
 # MOUNTPOINTS | Mount point path(s) | /, /boot, /var, [SWAP]
 #------------------------------------------------------------------------------------------------------------------------
 
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cs-root 17G 1.5G 16G 9% /
devtmpfs 830M 0 830M 0% /dev
tmpfs 853M 0 853M 0% /dev/shm
tmpfs 341M 4.9M 337M 2% /run
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-journald.service
/dev/sda2 960M 386M 575M 41% /boot
/dev/mapper/cs-var 5.0G 157M 4.8G 4% /var
tmpfs 1.0M 0 1.0M 0% /run/credentials/getty@tty1.service
tmpfs 171M 4.0K 171M 1% /run/user/1000
[root@localhost ~]# 

 # Disk Partitioning Tools:

 #-----------------------------------------------------------------------------------------------------------------------------------------
 # Tool | Partition Table Support | Key Feature | When to Use
 #-----------------------------------------------------------------------------------------------------------------------------------------
 #1. fdisk | MBR (msdos) only | Traditional, interactive CLI | Legacy systems, &amp;lt;2TB disks, simple MBR setups
 #-----------------------------------------------------------------------------------------------------------------------------------------
 #2. gdisk | GPT only | GPT-native, supports &amp;gt;2TB disks | Modern systems with UEFI, disks &amp;gt;2TB
 #-----------------------------------------------------------------------------------------------------------------------------------------
 #3. parted | Both MBR &amp;amp; GPT | Advanced scripting, resizing, alignment | Versatile tool, automated scripts, mixed environments
 #-----------------------------------------------------------------------------------------------------------------------------------------

[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 25.1G 0 disk 
├─sda1 8:1 0 2M 0 part 
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 24G 0 part 
 ├─cs-root 253:0 0 17G 0 lvm /
 ├─cs-swap 253:1 0 2G 0 lvm [SWAP]
 └─cs-var 253:2 0 5G 0 lvm /var
sr0 11:0 1 1024M 0 rom 
[root@localhost ~]# 

[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 25.08 GiB, 26926350336 bytes, 52590528 sectors
Disk model: VBOX HARDDISK 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 9214A82B-D2B3-419C-B8D1-27CF23F9B767

Device Start End Sectors Size Type
/dev/sda1 2048 6143 4096 2M BIOS boot
/dev/sda2 6144 2103295 2097152 1G Linux extended boot
/dev/sda3 2103296 52439039 50335744 24G Linux LVM
[root@localhost ~]# 
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="creating-partitioning"&gt;Creating Partitioning:&lt;/h3&gt;
&lt;p&gt;This lab demonstrates how to create an additional virtual disk in Oracle VirtualBox and configure an &lt;strong&gt;MBR (Master Boot Record)&lt;/strong&gt; partition table using the Linux &lt;code&gt;fdisk&lt;/code&gt; utility. The exercise covers the creation of primary, extended, and logical partitions.&lt;/p&gt;</description></item><item><title>Practice 010 — File Permission and Access Control Management</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-010/</link><pubDate>Tue, 16 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-010/</guid><description>&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# File Permission and Access Control Management

	 # Type of Users UID

	 # 1. Root User 0
	 # 2. System Users 1-200
	 # 3. App Users 201-999
	 # 4. Normal Users &amp;gt;=1000

	 # Type of groups GID
	 
	 # 1. Root user&amp;#39;s group 0
	 # 2. System Users group 1-200
	 # 3. App Users&amp;#39; group 201-999
	 # 4. Normal Users group &amp;gt;=1000

	 
[aadarsha@labserver ~]$ cat /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
adm:x:3:4:adm:/var/adm:/usr/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/usr/sbin/nologin
operator:x:11:0:operator:/root:/usr/sbin/nologin
games:x:12:100:games:/usr/games:/usr/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/usr/sbin/nologin
nobody:x:65534:65534:Kernel Overflow User:/:/usr/sbin/nologin
tss:x:59:59:Account used for TPM access:/:/usr/sbin/nologin
systemd-oom:x:999:999:systemd Userspace OOM Killer:/:/sbin/nologin
dbus:x:81:81:System Message Bus:/:/usr/sbin/nologin
sssd:x:998:997:User for sssd:/run/sssd/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
suman:x:1001:1001::/home/suman:/bin/bash
milan:x:1002:1002::/home/milan:/bin/bash
user1:x:1003:1003::/home/user1:/bin/bash
user2:x:1004:1004::/home/user2:/bin/bash
[aadarsha@labserver ~]$

[aadarsha@labserver ~]$ tail -5 /etc/passwd
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
suman:x:1001:1001::/home/suman:/bin/bash
milan:x:1002:1002::/home/milan:/bin/bash
user1:x:1003:1003::/home/user1:/bin/bash
user2:x:1004:1004::/home/user2:/bin/bash

 
 # Format of /etc/passwd
 
	# &amp;lt;username&amp;gt;:x(password):&amp;lt;UID&amp;gt;:&amp;lt;GID&amp;gt;::(&amp;lt;comment&amp;gt;):&amp;lt;home dir&amp;gt;:&amp;lt;shell&amp;gt;
	
	# &amp;lt;username&amp;gt;:x(password):&amp;lt;UID&amp;gt;:&amp;lt;GID&amp;gt;::(&amp;lt;comment&amp;gt;):&amp;lt;home dir&amp;gt;:&amp;lt;shell&amp;gt;

[aadarsha@labserver ~]$ rpm -q httpd
package httpd is not installed

[aadarsha@labserver ~]$ su - root
Password: 
[root@labserver ~]#

[root@labserver ~]# yum -y install httpd
...
[root@labserver ~]# rpm -q httpd
httpd-2.4.63-13.el10.x86_64

[root@labserver ~]# grep apache /etc/passwd
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@labserver ~]# 

aadarkdk@pop-os:~$ ssh aadarsha@192.168.1.66
aadarsha@192.168.1.66&amp;#39;s password: 
Last login: Tue Jun 16 05:08:06 2026

[aadarsha@labserver ~]$ whoami
aadarsha
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Mon Jun 15 21:59:35 +0545 2026 on tty1
[root@labserver ~]# 

[root@labserver ~]# cat /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
adm:x:3:4:adm:/var/adm:/usr/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/usr/sbin/nologin
operator:x:11:0:operator:/root:/usr/sbin/nologin
games:x:12:100:games:/usr/games:/usr/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/usr/sbin/nologin
nobody:x:65534:65534:Kernel Overflow User:/:/usr/sbin/nologin
tss:x:59:59:Account used for TPM access:/:/usr/sbin/nologin
systemd-oom:x:999:999:systemd Userspace OOM Killer:/:/sbin/nologin
dbus:x:81:81:System Message Bus:/:/usr/sbin/nologin
sssd:x:998:997:User for sssd:/run/sssd/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
suman:x:1001:1001::/home/suman:/bin/bash
milan:x:1002:1002::/home/milan:/bin/bash
user1:x:1003:1003::/home/user1:/bin/bash
user2:x:1004:1004::/home/user2:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@labserver ~]# 

[root@labserver ~]# cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:aadarsha
cdrom:x:11:
mail:x:12:
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:33:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
users:x:100:
clock:x:103:
nobody:x:65534:
tss:x:59:
utmp:x:22:
utempter:x:35:
systemd-oom:x:999:
input:x:104:
kvm:x:36:
render:x:105:
sgx:x:106:
systemd-journal:x:190:
dbus:x:81:
printadmin:x:998:
sssd:x:997:
sshd:x:74:
chrony:x:996:
systemd-coredump:x:995:
aadarsha:x:1000:
suman:x:1001:
milan:x:1002:
user1:x:1003:
user2:x:1004:
apache:x:48:
[root@labserver ~]#

[root@labserver ~]# useradd sima
[root@labserver ~]# passwd sima
New password: 
Retype new password: 
passwd: password updated successfully
[root@labserver ~]# 

[root@labserver ~]# cat /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
...
sima:x:1005:1005::/home/sima:/bin/bash
[root@labserver ~]# 

[root@labserver ~]# cat /etc/group
root:x:0:
...
sima:x:1005:
[root@labserver ~]# 


# Types of groups

 # 1. Primary group
 # 2. Secondary group

# 1. Primary group (Mandatory --&amp;gt; each user has a primary group)
# 2. Secondary group (Optional)


[root@labserver ~]# tail -3 /etc/group
user2:x:1004:
apache:x:48:
sima:x:1005:
[root@labserver ~]# 

# primary group is assigned a name same as user name by default 

[root@labserver ~]# tail -3 /etc/group
user2:x:1004:
apache:x:48:
sima:x:1005:
[root@labserver ~]# 

# format of /etc/group

# &amp;lt;group-name&amp;gt;:x(password):&amp;lt;GID&amp;gt;: users (primary user is hidden) for eg: sima is hidden in (sima:x:1005: )

# password for users exist in file ---&amp;gt; cat /etc/shadow

[root@labserver ~]# cat /etc/shadow
root:$y$j9T$xHwjHrmsH4/sp62As3eE8bHB$CwQ0bGTIi1ehU4oeMhbRX8E.5YbCJgUxSeazFAxh1q/::0:99999:7:::
bin:*:20186:0:99999:7:::
daemon:*:20186:0:99999:7:::
adm:*:20186:0:99999:7:::
lp:*:20186:0:99999:7:::
sync:*:20186:0:99999:7:::
shutdown:*:20186:0:99999:7:::
halt:*:20186:0:99999:7:::
mail:*:20186:0:99999:7:::
operator:*:20186:0:99999:7:::
games:*:20186:0:99999:7:::
ftp:*:20186:0:99999:7:::
nobody:*:20186:0:99999:7:::
tss:!:20599::::::
systemd-oom:!:20599::::::
dbus:!*:20599::::::
sssd:!:20599::::::
sshd:!:20599::::::
chrony:!:20599::::::
systemd-coredump:!*:20599::::::
aadarsha:$y$j9T$obRuZ4304azSixvHlfBTNl9N$zhF91IWpfwj.lLrH4LGrGZNNt8dGRTfKnzOyDNqNkX7::0:99999:7:::
suman:$y$j9T$7AODYF0LFq9aC2XK7RkTa1$QRsBJu.4yuPz2E6uaVsH4WUsxeB2cPQsYFPi77XnAI6:20619:0:99999:7:::
milan:$y$j9T$7kuVLa3q32wOz1rE4XVYi.$KS8ZM5hcJI9ZcHznzCU/uPBr9rJ5bnrryag5oR3TsMD:20619:0:99999:7:::
user1:$y$j9T$QuQXx9tw9Y.3c6/zUycbI.$rutoU2GiuC20OC.XNNXKSBHTpY8vQmKc8n5ygAOAP39:20619:0:99999:7:::
user2:!:20619:0:99999:7:::
apache:!:20619::::::
sima:$y$j9T$5Q7Xya0gUOf619bhxe.Ae0$hMhERRPD3IBfRd1/c.xOWwM9NwCzkIYFLUyD/PSlNyD:20619:0:99999:7:::
[root@labserver ~]# 

 # Default hashing algorithm SHA512

[root@labserver ~]# whoami
root
[root@labserver ~]# 

# Viewing the details of the currently logged in users

[root@labserver ~]# users
aadarsha aadarsha
[root@labserver ~]# 
[root@labserver ~]# who
aadarsha tty1 2026-06-16 05:08
aadarsha pts/0 2026-06-16 05:08 (192.168.1.98)
[root@labserver ~]# 
[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ who
aadarsha tty1 2026-06-16 05:08
aadarsha pts/0 2026-06-16 05:08 (192.168.1.98)
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ su - root
Password: 
Last login: Tue Jun 16 05:09:49 +0545 2026 on pts/0
[root@labserver ~]# 

[root@labserver ~]# who
aadarsha tty1 2026-06-16 05:08
aadarsha pts/0 2026-06-16 05:08 (192.168.1.98)
sima pts/1 2026-06-16 05:24 (192.168.1.98)
[root@labserver ~]# 

[root@labserver ~]# w
 05:29:35 up 22 min, 3 users, load average: 0.05, 0.03, 0.00
USER TTY LOGIN@ IDLE JCPU PCPU WHAT
aadarsha tty1 05:08 21:22 0.02s 0.02s -bash
aadarsha 05:08 22:04 0.00s 0.03s sshd-session: aadarsha [priv]
sima 05:24 22:04 0.00s 0.03s sshd-session: sima [priv]
[root@labserver ~]# 

# information about the range of users, customize: in /etc/login.defs and /etc/default/useradd 

 # Permissions:
 # Types of Permissions
 # 1. General Permission
 # 2. Special Permission


 # 1. General Permission

 # Permission Type | Symbolic Representation | Numeric Representation 
 #----------------------------------------------------------------------------
 # Read | r | 4
 # Write | w | 2
 # Execute | x | 1
 # No Permission | - | 0
 # Full Permission | rwx | 7

 
 # Meaning/Effect of Permission on a File/Directory
 
 # Permission | Effect on a File | Effect on a Directory
 #----------------------------------------------------------------------------------------------------------------
 # Read (r-4) | It allows to view the content of file (cat, less,...) | 


# ___fill___ ???

[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cd /etc
[aadarsha@labserver etc]$ pwd
/etc
[aadarsha@labserver etc]$ 

[aadarsha@labserver etc]$ cd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cd /root
-bash: cd: /root: Permission denied
[aadarsha@labserver ~]$ 

# there is no execute permission in root for current user in root directory

[aadarsha@labserver ~]$ ls
dir1 dira extracted testcompany testfile words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ touch file1 file2
[aadarsha@labserver ~]$ ls
dir1 dira extracted file1 file2 testcompany testfile words
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -l
total 4844
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
drwxr-xr-x. 4 root root 28 Jun 8 20:16 extracted
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file1
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile
-rw-r--r--. 1 aadarsha aadarsha 4953598 Jun 8 09:52 words
[aadarsha@labserver ~]$ 

# Viewing Permission on a File/Dir

[aadarsha@labserver ~]$ ls -l
total 4844
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
drwxr-xr-x. 4 root root 28 Jun 8 20:16 extracted
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file1
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile
-rw-r--r--. 1 aadarsha aadarsha 4953598 Jun 8 09:52 words
[aadarsha@labserver ~]$ 

 # first field: ----------
 
 # - --- --- ---
 # Type Owner Group Others
 # Permission Permission Permission

 # Type
 # d --&amp;gt; directory
 # - --&amp;gt; normal file
 # l --&amp;gt; soft link
 
 # first field: ----------.
 # . ---&amp;gt; ACL
 
 # permission string: 9 characters


[aadarsha@labserver ~]$ ls -l words 
-rw-r--r--. 1 aadarsha aadarsha 4953598 Jun 8 09:52 words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -lh
total 4.8M
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
drwxr-xr-x. 4 root root 28 Jun 8 20:16 extracted
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file1
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile
-rw-r--r--. 1 aadarsha aadarsha 4.8M Jun 8 09:52 words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -ld
drwx------. 6 aadarsha aadarsha 4096 Jun 16 05:53 .
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -ldh
drwx------. 6 aadarsha aadarsha 4.0K Jun 16 05:53 .
[aadarsha@labserver ~]$ 

 # Changing permission of a file/dir

[aadarsha@labserver ~]$ whoami
aadarsha
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ vi file1
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ mkdir dir2
[aadarsha@labserver ~]$ cd dir2
[aadarsha@labserver dir2]$ 

[aadarsha@labserver dir2]$ touch file1
[aadarsha@labserver dir2]$ vi file1 

[aadarsha@labserver dir2]$ cd
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -l file1
-rw-r--r--. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
[aadarsha@labserver ~]$ 

 # Changing Permission of a File/Dir
 # Method-I: Symbolic Method
 # chmod u=rwx, g=rw, o= in file1
 # chmod u+x, g+w, o-r file1
 
[aadarsha@labserver ~]$ chmod u=rwx,g=rw,o= file1
[aadarsha@labserver ~]$ ls -lh file1
-rwxrw----. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dir2 dira extracted file1 file2 testcompany testfile words
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -lh file2
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
[aadarsha@labserver ~]$ 

 # Method-II: Numeric Method

 # chmod u=rwx,g=rw,o= file2
 
 # chmod 760 file2

[aadarsha@labserver ~]$ ls -lh file2
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ chmod 760 file2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -lh file2
-rwxrw----. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
[aadarsha@labserver ~]$ 

 # chmod u=rx,g=rx,o=rx file1
 
 # chmod ugo=rx file1
 
 # chmod 555 file1
 
 # chmod 444 file1 file2

[aadarsha@labserver ~]$ chmod 555 file1
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -lh file1
-r-xr-xr-x. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ chmod 444 file1 file2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -lh
total 4.8M
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 2 aadarsha aadarsha 19 Jun 16 06:09 dir2
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
drwxr-xr-x. 4 root root 28 Jun 8 20:16 extracted
-r--r--r--. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
-r--r--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile
-rw-r--r--. 1 aadarsha aadarsha 4.8M Jun 8 09:52 words
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ ls -lh file1 file2
-r--r--r--. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
-r--r--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
[aadarsha@labserver ~]$ 

 # ugo or a same --&amp;gt; all ( owner, user, others)

[aadarsha@labserver ~]$ chmod a+x file1 file2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -lh file1 file2
-r-xr-xr-x. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
-r-xr-xr-x. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ chmod go-x file2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -lh file1 file2
-r-xr-xr-x. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
-r-xr--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -ld dir2
drwxr-xr-x. 2 aadarsha aadarsha 19 Jun 16 06:09 dir2
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ chmod 700 dir2
[aadarsha@labserver ~]$ ls -ld dir2
drwx------. 2 aadarsha aadarsha 19 Jun 16 06:09 dir2
[aadarsha@labserver ~]$ 

 # chmod -R 700 dir2 (recursive --&amp;gt; -R)

[aadarsha@labserver ~]$ cd dir2
[aadarsha@labserver dir2]$ ls
file1
[aadarsha@labserver dir2]$ ls -l file1 
-rw-r--r--. 1 aadarsha aadarsha 34 Jun 16 06:09 file1
[aadarsha@labserver dir2]$ 
[aadarsha@labserver dir2]$ cd
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ chmod -R 700 dir2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -l dir2
total 4
-rwx------. 1 aadarsha aadarsha 34 Jun 16 06:09 file1
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ cd dir2
[aadarsha@labserver dir2]$ 
[aadarsha@labserver dir2]$ ls -l file1
-rwx------. 1 aadarsha aadarsha 34 Jun 16 06:09 file1
[aadarsha@labserver dir2]$ 

 # all the inside files and directories get the same permission using -R

[aadarsha@labserver ~]$ date
Wed Jun 17 05:03:18 AM +0545 2026
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dir2 dira extracted file1 file2 testcompany testfile words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -l file1 file2
-r-xr-xr-x. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
-r-xr--r--. 1 aadarsha aadarsha 0 Jun 16 05:53 file2
[aadarsha@labserver ~]$ 

 # Verifying Effects of Permissions on a File

[aadarsha@labserver ~]$ ls -l file1
-r-xr-xr-x. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ chmod 000 file1
[aadarsha@labserver ~]$ ls -l file1
----------. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
[aadarsha@labserver ~]$ cat file1
cat: file1: Permission denied
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ chmod u+r file1
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -l file1
-r--------. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
[aadarsha@labserver ~]$ cat file1
this is the first file...
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ chmod u=w file1
[aadarsha@labserver ~]$ ls -l file1
--w-------. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
[aadarsha@labserver ~]$ 

 # read also removed when using =
 
[aadarsha@labserver ~]$ chmod u+rw file1
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -l file1
-rw-------. 1 aadarsha aadarsha 26 Jun 16 06:08 file1
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ cat file1
this is the first file...
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ vi file1
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ cat file1
this is the first file...
this is added line
[aadarsha@labserver ~]$ 

 # Verifying effects of permissions on a dir
 
[aadarsha@labserver ~]$ ls -ld dir2
drwx------. 2 aadarsha aadarsha 19 Jun 16 06:09 dir2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ chmod 000 dir2
[aadarsha@labserver ~]$ ls -ld dir2
d---------. 2 aadarsha aadarsha 19 Jun 16 06:09 dir2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ cd dir2
-bash: cd: dir2: Permission denied
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ whoami
aadarsha
[aadarsha@labserver ~]$ 

 # there is no execute permissions on the directory

[aadarsha@labserver ~]$ chmod u+x dir2

[aadarsha@labserver ~]$ ls -ld dir2
d--x------. 2 aadarsha aadarsha 19 Jun 16 06:09 dir2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ cd dir2
[aadarsha@labserver dir2]$ ls
ls: cannot open directory &amp;#39;.&amp;#39;: Permission denied
[aadarsha@labserver dir2]$ 
[aadarsha@labserver dir2]$ chmod u+r ../dir2

[aadarsha@labserver dir2]$ pwd
/home/aadarsha/dir2
[aadarsha@labserver dir2]$ 
[aadarsha@labserver dir2]$ ls -ld /home/aadarsha/dir2
dr-x------. 2 aadarsha aadarsha 19 Jun 16 06:09 /home/aadarsha/dir2
[aadarsha@labserver dir2]$ 

[aadarsha@labserver dir2]$ ls
file1
[aadarsha@labserver dir2]$ touch newfile2
touch: cannot touch &amp;#39;newfile2&amp;#39;: Permission denied
[aadarsha@labserver dir2]$ 
[aadarsha@labserver dir2]$ chmod u+w /home/aadarsha/dir2
[aadarsha@labserver dir2]$ 
[aadarsha@labserver dir2]$ ls -ld /home/aadarsha/dir2
drwx------. 2 aadarsha aadarsha 19 Jun 16 06:09 /home/aadarsha/dir2
[aadarsha@labserver dir2]$ 
[aadarsha@labserver dir2]$ touch newfile1
[aadarsha@labserver dir2]$ 
[aadarsha@labserver dir2]$ ls
file1 newfile1
[aadarsha@labserver dir2]$ which ls
alias ls=&amp;#39;ls --color=auto&amp;#39;
	/usr/bin/ls
[aadarsha@labserver dir2]$ 

[aadarsha@labserver dir2]$ 
[aadarsha@labserver dir2]$ cd
[aadarsha@labserver ~]$ 

# umask

[aadarsha@labserver ~]$ ls
dir1 dir2 dira extracted file1 file2 testcompany testfile words
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ touch newfile1
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -l testfile1
ls: cannot access &amp;#39;testfile1&amp;#39;: No such file or directory
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -l newfile1 
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 17 05:26 newfile1
[aadarsha@labserver ~]$ 

 # default permission: 644
 
[aadarsha@labserver ~]$ mkdir newdir1
[aadarsha@labserver ~]$ ls -ld newdir1
drwxr-xr-x. 2 aadarsha aadarsha 6 Jun 17 05:27 newdir1
[aadarsha@labserver ~]$ 

 # default permission: 755

 # How does OS know to keep this permission?
 # Ans: umask 

 # umask for normal user vs root user (different)

 # umask for normal user vs root user (different in previous versions but same in current version)
 
[aadarsha@labserver ~]$ su - root 
Password: 
[root@labserver ~]# 

[root@labserver ~]# umask
0022
[root@labserver ~]# 

[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ 

 # umask
 # umask is a value that determines that default permission on directory or file at the time of creation
 
 # Formula to calculate default permission on a file
 # max allowed permission on a file at the time of file creation (666) - unmask(value)
 
[aadarsha@labserver ~]$ umask
0022
[aadarsha@labserver ~]$ 

 # ----------------------------
 # Default permission on a file
 # ----------------------------

 # 666 - 022 ---&amp;gt; 644

 # By default execute permission is never set in files by security reason
 
 # we can change the value of default (umask: 0022) value

 # Formula to calculate default permission on a directory

 # max allowed permission on a Dir at the time of file creation (777) - umask(value)

 # ----------------------------
 # Default permission on a Directory
 # ----------------------------

 # 777 - 022 ---&amp;gt; 755

[aadarsha@labserver ~]$ whoami
aadarsha
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ umask
0022
[aadarsha@labserver ~]$ 

 # Let&amp;#39;s set the default permission : -rw-------

 # Let&amp;#39;s set the default permission : -rw------- i.e. 600

 # we should set: umask 066

 # Changing the value of umask

 # Case-I: Temporary Change

[aadarsha@labserver ~]$ umask 066
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ umask
0066
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls 
dir1 dir2 dira extracted file1 file2 newdir1 newfile1 testcompany testfile words
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ touch newfile2
[aadarsha@labserver ~]$ ls -l newfile2
-rw-------. 1 aadarsha aadarsha 0 Jun 17 05:46 newfile2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -ld newdir1
drwxr-xr-x. 2 aadarsha aadarsha 6 Jun 17 05:27 newdir1
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ mkdir newdir2
[aadarsha@labserver ~]$ ls -ld newdir2
drwx--x--x. 2 aadarsha aadarsha 6 Jun 17 05:49 newdir2
[aadarsha@labserver ~]$ 

 # 777 - 066 --&amp;gt; 711

 # to set: drwx------

[aadarsha@labserver ~]$ umask
0066
[aadarsha@labserver ~]$ 

 # to set: drwx------ i.e 700
 # 777 - ??? ---&amp;gt; 700

 # 077

[aadarsha@labserver ~]$ umask 077

[aadarsha@labserver ~]$ mkdir newdir3
 
[aadarsha@labserver ~]$ ls -ld newdir3
drwx------. 2 aadarsha aadarsha 6 Jun 17 05:52 newdir3
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ touch newfile3
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -l newfile3
-rw-------. 1 aadarsha aadarsha 0 Jun 17 05:55 newfile3
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ umask
0077
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.170 closed.
aadarkdk@pop-os:~$
 
aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.170
aadarsha@192.168.254.170&amp;#39;s password: 
Last login: Wed Jun 17 05:03:13 2026 from 192.168.254.152
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ umask
0022
[aadarsha@labserver ~]$ 

 # Permanently setting value of umask
 # Case-I: user-specific setting
 
[aadarsha@labserver ~]$ vi .bashrc
[aadarsha@labserver ~]$ source .bashrc 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ umask
0000
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ # Case-I: for-all users (System-wide): set in /root/etc/bashrc
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ su - root
Password: 
Last login: Wed Jun 17 05:30:09 +0545 2026 on pts/0
[root@labserver ~]# 
[root@labserver ~]# ls /home/
aadarsha milan sima suman user1 user2
[root@labserver ~]# 
[root@labserver ~]# umask
0022
[root@labserver ~]# 
[root@labserver ~]# vi /etc/bashrc 
[root@labserver ~]# 
[root@labserver ~]# umask
0022
[root@labserver ~]# vi /etc/bashrc 
[root@labserver ~]# vi /etc/bashrc 
[root@labserver ~]# 
[root@labserver ~]# umask
0022
[root@labserver ~]# source /etc/bashrc 
[root@labserver ~]# 
[root@labserver ~]# umask
0066
[root@labserver ~]# 
[root@labserver ~]# su - sima
Last login: Tue Jun 16 05:24:58 +0545 2026 from 192.168.1.98 on pts/1
[sima@labserver ~]$ 
[sima@labserver ~]$ umask
0066
[sima@labserver ~]$ 
[sima@labserver ~]$ exit
logout
[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ umask
0000
[aadarsha@labserver ~]$ 


# user-specific configuration is superior than system-wide
 # because Global script runs first and then user-sepcific script runs after that

 # Login Scripts
 
 # /etc/bashrc
 # /etc/profile

 # Login Scripts: system-wide
 # /etc/profile
 # /etc/bashrc
 # Login Scripts: user-specific

[aadarsha@labserver ~]$ # ~/.bashrc
[aadarsha@labserver ~]$ # ~/.bash_profile
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ whoami
aadarsha
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ vi .bashrc 
[aadarsha@labserver ~]$ su - root
Password: 
Last login: Wed Jun 17 06:02:42 +0545 2026 on pts/0
[root@labserver ~]# 
[root@labserver ~]# vi /etc/bashrc 

[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ 

 # example of user-specific configuration in login scripts
 
[aadarsha@labserver ~]$ vi .bashrc 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ exit
logout
Connection to 192.168.254.170 closed.
aadarkdk@pop-os:~$ 
aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.170
aadarsha@192.168.254.170&amp;#39;s password: 
Last login: Wed Jun 17 05:55:55 2026 from 192.168.254.152
Hello, WELCOME
Wed Jun 17 06:17:51 AM +0545 2026
 06:17:51 up 1:15, 2 users, load average: 0.00, 0.00, 0.00
aadarsha
 total used free shared buff/cache available
Mem: 1.7Gi 369Mi 1.2Gi 4.8Mi 219Mi 1.3Gi
Swap: 2.0Gi 0B 2.0Gi
[aadarsha@labserver ~]$ 

 # for system-wide (for all users )login scripts: change /root/etc/profile
 # Log OUT scripts

[aadarsha@labserver ~]$ ls -a
. .bash_logout dir2 file2 newdir3 .secretdata .vimrc
.. .bash_profile dira .lesshst newfile1 testcompany words
.bash_history .bashrc extracted newdir1 newfile2 testfile
.bash_history-01834.tmp dir1 file1 newdir2 newfile3 .viminfo
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ # Log OUT scripts exits only user-specific: not all the users

[aadarsha@labserver ~]$ # Log OUT script: .bash_logout 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ vi .bash_logout 
[aadarsha@labserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Practice 009 — File Search, Redirection &amp; Output Control</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-009/</link><pubDate>Sat, 13 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-009/</guid><description>&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# File Search, Redirection &amp;amp; Output Control

# Standard Input/Output Devices

# Keyboard --&amp;gt; Standard Input device (ch 0)
# Terminal Window --&amp;gt; Standard Output device (ch 1)
# Terminal Window --&amp;gt; Standard Error device (ch 2)

# Re-direction operators
# &amp;gt; filename --&amp;gt; redirects the standard output to the given file (ovewrite)

# &amp;gt;&amp;gt; filename --&amp;gt; appends the standard output to the given file (no ovewrite)

# 2&amp;gt; filename --&amp;gt; appends the standard error to the given file ( ovewrite)

# 2&amp;gt;&amp;gt; filename --&amp;gt; appends the standard error to the given file ( no ovewrite)

# 2&amp;gt; filename --&amp;gt; redirects the standard error to the given file ( ovewrite)

# something left above see recording jun 12

[aadarsha@labserver ~]$ ls
cut_result extracted passwd sort_result testfile words
dir1 multiple_changes passwd_YESLOGIN testcompany testthis
dira newfile1 secret_data testdatafile uniq_result
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

# This above output is standard output on terminal window

[aadarsha@labserver ~]$ grep bash -r /etc
grep: /etc/crypttab: Permission denied
...
grep: /etc/sudo-ldap.conf: Permission denied
grep: /etc/udev/hwdb.bin: binary file matches
grep: /etc/NetworkManager/system-connections/enp0s3.nmconnection: Permission denied
grep: /etc/sssd: Permission denied
[aadarsha@labserver ~]$ 

# permission denied, error message, .... ---&amp;gt; standard error

# results ---&amp;gt; standard output

[aadarsha@labserver ~]$ # grep bash -r /etc &amp;gt; bash_output
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
cut_result extracted passwd sort_result testfile words
dir1 multiple_changes passwd_YESLOGIN testcompany testthis
dira newfile1 secret_data testdatafile uniq_result
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ rm -r cut_result extracted/ passwd sort_result multiple_changes passwd testthis secret_data testdatafile uniq_result 
...
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash -r /etc &amp;gt; bash_output
grep: /etc/crypttab: Permission denied
...
grep: /etc/sssd: Permission denied
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
bash_output dir1 dira extracted newfile1 passwd_YESLOGIN testcompany testfile words
[aadarsha@labserver ~]$
 
[aadarsha@labserver ~]$ cat bash_output 
/etc/profile.d/which2.sh:# Initialization script for bash, sh, mksh and ksh
/etc/profile.d/which2.sh:bash|sh)
...
/etc/crontab:SHELL=/bin/bash
/etc/sestatus.conf:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash -r /etc 2&amp;gt;bash_error
/etc/profile.d/which2.sh:# Initialization script for bash, sh, mksh and ksh
/etc/profile.d/which2.sh:bash|sh)
/etc/profile.d/bash_completion.sh:# Check for interactive bash and that we haven&amp;#39;t already been sourced.
...
/etc/sestatus.conf:/bin/bash
[aadarsha@labserver ~]$ 

# only error exists in bash_error

[aadarsha@labserver ~]$ ls
bash_error dir1 extracted passwd_YESLOGIN testfile
bash_output dira newfile1 testcompany words
[aadarsha@labserver ~]$ 

# only output exists in bash_output

[aadarsha@labserver ~]$ cat bash_error 
grep: /etc/crypttab: Permission denied
...
grep: /etc/udev/hwdb.bin: binary file matches
grep: /etc/NetworkManager/system-connections/enp0s3.nmconnection: Permission denied
grep: /etc/sssd: Permission denied
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash -r /etc &amp;gt;output 2&amp;gt;error

# output in output file and error in error file

[aadarsha@labserver ~]$ ls
bash_error dir1 error newfile1 passwd_YESLOGIN testfile
bash_output dira extracted output testcompany words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash -r /etc &amp;gt;all_output_error 2&amp;gt;&amp;amp;1

[aadarsha@labserver ~]$ ls
all_output_error bash_output dira extracted output testcompany words
bash_error dir1 error newfile1 passwd_YESLOGIN testfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi all_output_error 

[aadarsha@labserver ~]$ cat all_output_error 
grep: /etc/crypttab: Permission denied
...
grep: /etc/udev/hwdb.bin: binary file matches
grep: /etc/NetworkManager/system-connections/enp0s3.nmconnection: Permission denied
grep: /etc/sssd: Permission denied
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 7 -d : /etc/passwd | sort | uniq -c
 2 /bin/bash
 1 /bin/sync
 1 /sbin/halt
 3 /sbin/nologin
 1 /sbin/shutdown
 13 /usr/sbin/nologin
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 7 -d : /etc/passwd | tee cutout | sort | tee sort_out | uniq -c | tee uniq_out
 2 /bin/bash
 1 /bin/sync
 1 /sbin/halt
 3 /sbin/nologin
 1 /sbin/shutdown
 13 /usr/sbin/nologin
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
all_output_error cutout error output testcompany words
bash_error dir1 extracted passwd_YESLOGIN testfile
bash_output dira newfile1 sort_out uniq_out
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
all_output_error cutout error output testcompany words
bash_error dir1 extracted passwd_YESLOGIN testfile
bash_output dira newfile1 sort_out uniq_out
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi imp_output

[aadarsha@labserver ~]$ cat imp_output 
this file contains the imp data.....
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash -r /etc &amp;gt;imp_output 
grep: /etc/crypttab: Permission denied
...
grep: /etc/NetworkManager/system-connections/enp0s3.nmconnection: Permission denied
grep: /etc/sssd: Permission denied
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat imp_output 
/etc/profile.d/which2.sh:# Initialization script for bash, sh, mksh and ksh
...
/etc/dhcp/dhclient.d/chrony.sh:#!/usr/bin/bash
/etc/crontab:SHELL=/bin/bash
/etc/sestatus.conf:/bin/bash
[aadarsha@labserver ~]$ 

# file is overwritten

[aadarsha@labserver ~]$ vi new_output

[aadarsha@labserver ~]$ cat new
cat: new: No such file or directory
[aadarsha@labserver ~]$ cat new_output 
this is important data file which is new....

[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash -r /etc/passwd &amp;gt;&amp;gt; new_output 

[aadarsha@labserver ~]$ cat new_output 
this is important data file which is new....

root:x:0:0:Super User:/root:/bin/bash
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash

# appended on previous file

# look the recording about lsattr and immutable and prevent overwrite

[aadarsha@labserver ~]$ # chattr +a &amp;lt;filename&amp;gt;

# to destroy error
 
[aadarsha@labserver ~]$ grep bash -r /etc 2&amp;gt;/dev/null 
/etc/profile.d/which2.sh:# Initialization script for bash, sh, mksh and ksh
...
/etc/dhcp/dhclient.d/chrony.sh:#!/usr/bin/bash
/etc/crontab:SHELL=/bin/bash
/etc/sestatus.conf:/bin/bash
[aadarsha@labserver ~]$ 

# all errors are destroyed or removed

# tr - Character Translator

[aadarsha@labserver ~]$ ls
all_output_error cutout error newfile1 passwd_YESLOGIN testfile
bash_error dir1 extracted new_output sort_out uniq_out
bash_output dira imp_output output testcompany words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat output 
/etc/profile.d/which2.sh:# Initialization script for bash, sh, mksh and ksh
...
/etc/selinux/targeted/contexts/files/file_contexts:/usr/bin/bash2	--	system_u:object_r:shell_exec_t:s0
/etc/cron.d/0hourly:SHELL=/bin/bash
/etc/dhcp/dhclient.d/chrony.sh:#!/usr/bin/bash
/etc/crontab:SHELL=/bin/bash
/etc/sestatus.conf:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
all_output_error cutout error newfile1 passwd_YESLOGIN testfile
bash_error dir1 extracted new_output sort_out uniq_out
bash_output dira imp_output output testcompany words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ tr &amp;#39;a-z&amp;#39; &amp;#39;A-Z&amp;#39; &amp;lt;cutout 
/BIN/BASH
/USR/SBIN/NOLOGIN
...
/USR/SBIN/NOLOGIN
/BIN/BASH
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ cat cutout 
/bin/bash
/usr/sbin/nologin
...
/usr/sbin/nologin
/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ tr &amp;#39;a-z&amp;#39; &amp;#39;A-Z&amp;#39; &amp;lt;cutout &amp;gt;CUTOUT

[aadarsha@labserver ~]$ ls
all_output_error cutout dira imp_output output testcompany words
bash_error CUTOUT error newfile1 passwd_YESLOGIN testfile
bash_output dir1 extracted new_output sort_out uniq_out
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat CUTOUT 
/BIN/BASH
/USR/SBIN/NOLOGIN
...
/BIN/BASH
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ 

# redirection can be used for any commands

# Searching Files using &amp;#39;find&amp;#39; Command
 	# find [path] [option] &amp;lt;argument&amp;gt;
 	# options:
 		# -atime &amp;lt;+N/-N/N&amp;gt; --&amp;gt; performs access-time bases search ( N --&amp;gt; Day)
 		# -mtime &amp;lt;+N/-N/N&amp;gt; --&amp;gt; performs modification-time bases search ( N --&amp;gt; Day)
 		# -ntime &amp;lt;+N/-N/N&amp;gt; --&amp;gt; performs name-based search ( case sensitive )
 		# -intime &amp;lt;+N/-N/N&amp;gt; --&amp;gt; performs name-based search ( case in-sensitive )
 		# -name &amp;lt;name&amp;gt; --&amp;gt; performs name-based search ( case sensitive )
 		# -iname &amp;lt;name&amp;gt; --&amp;gt; performs name-based search ( case insensitive )
 		# -size &amp;lt;+N/-N/N&amp;gt; --&amp;gt; performs size-based search (N --&amp;gt; KB, MB, GB, .. )
 		# -user &amp;lt;owner&amp;gt; --&amp;gt; performs user-ownership based search
 		# -group &amp;lt;group&amp;gt; --&amp;gt; perform group-ownership based search
 		# -type &amp;lt;type&amp;gt; --&amp;gt; perform file-type based search
 			 # types:
 			 # f --&amp;gt; search normal files only
 			 # d --&amp;gt; search directories
 			 # l --&amp;gt; search soft links
 
[aadarsha@labserver ~]$ date
Mon Jun 15 04:59:06 PM +0545 2026
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Mon Jun 15 16:48:46 +0545 2026 on pts/0
[root@labserver ~]# 

[root@labserver ~]# find /etc -name passwd
/etc/passwd
/etc/pam.d/passwd
[root@labserver ~]# find /etc -name passwd 2&amp;gt;/dev/null
/etc/passwd
/etc/pam.d/passwd
[root@labserver ~]# 
[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /etc -name passwd 
find: ‘/etc/lvm/devices’: Permission denied
...
find: ‘/etc/audit’: Permission denied
find: ‘/etc/sssd’: Permission denied
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /etc -name passwd 2&amp;gt;/dev/null 
/etc/passwd
/etc/pam.d/passwd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ touch /tmp/passwd
[aadarsha@labserver ~]$ find /etc -name passwd 2&amp;gt;/dev/null
/etc/passwd
/etc/pam.d/passwd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find / -name passwd 2&amp;gt;/dev/null
/sys/fs/selinux/class/passwd
/sys/fs/selinux/class/passwd/perms/passwd
/tmp/passwd
/etc/passwd
/etc/pam.d/passwd
/usr/bin/passwd
/usr/share/bash-completion/completions/passwd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find / -iname pAsswd 2&amp;gt;/dev/null
/sys/fs/selinux/class/passwd
/sys/fs/selinux/class/passwd/perms/passwd
/tmp/passwd
/tmp/Passwd
/tmp/PassWD
/etc/passwd
/etc/pam.d/passwd
/usr/bin/passwd
/usr/share/bash-completion/completions/passwd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ touch /tmp/PassWD
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find / -iname passwd 2&amp;gt;/dev/null
/sys/fs/selinux/class/passwd
/sys/fs/selinux/class/passwd/perms/passwd
/tmp/passwd
/tmp/Passwd
/tmp/PassWD
/etc/passwd
/etc/pam.d/passwd
/usr/bin/passwd
/usr/share/bash-completion/completions/passwd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find / -name passwd 2&amp;gt;/dev/null | wc -l
7
[aadarsha@labserver ~]$ find / -iname passwd 2&amp;gt;/dev/null | wc -l
9
[aadarsha@labserver ~]$ 

# access time

[aadarsha@labserver ~]$ find / -atime -2
...
...

/tmp/PassWD
/etc
/etc/fstab
/etc/lvm
/etc/lvm/devices
find: ‘/etc/lvm/devices’: Permission denied
/etc/lvm/archive
find: ‘/etc/lvm/archive’: Permission denied
/etc/lvm/backup
find: ‘/etc/lvm/backup’: Permission denied
/etc/lvm/cache
find: ‘/etc/lvm/cache’: Permission denied
/etc/lvm/profile
...
...

[aadarsha@labserver ~]$ find / -atime -2 2&amp;gt;/dev/null | wc -l
83501
[aadarsha@labserver ~]$ find / -mtime -2 2&amp;gt;/dev/null | wc -l
76970
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find / -atime -2 2&amp;gt;/dev/null | wc -l
83268
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find / -atime -2 | wc -l
find: ‘/boot/efi/EFI/centos’: Permission denied
find: ‘/boot/grub2’: Permission denied


[aadarsha@labserver ~]$ find / -atime -2 2&amp;gt;/dev/null | wc -l
83501
[aadarsha@labserver ~]$ find / -mtime -2 2&amp;gt;/dev/null | wc -l
76970
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find /etc -mtime -2 2&amp;gt;/dev/null | wc -l
2
[aadarsha@labserver ~]$ find / -mtime -2 2&amp;gt;/dev/null | wc -l
76970
[aadarsha@labserver ~]$ find /etc -atime -2 2&amp;gt;/dev/null | wc -l
323
[aadarsha@labserver ~]$ 


[aadarsha@labserver ~]$ find / -atime -2 2&amp;gt;/dev/null | wc -l
83501
[aadarsha@labserver ~]$ find / -mtime -2 2&amp;gt;/dev/null | wc -l
76970
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find /etc -mtime -2 2&amp;gt;/dev/null | wc -l
2
[aadarsha@labserver ~]$ find / -mtime -2 2&amp;gt;/dev/null | wc -l
76970
[aadarsha@labserver ~]$ find /etc -atime -2 2&amp;gt;/dev/null | wc -l
323
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find /etc -atime -2 2&amp;gt;/dev/null | wc -l
323
[aadarsha@labserver ~]$ find /etc -mtime -2 2&amp;gt;/dev/null | wc -l
2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find /var/l
lib/ local/ lock/ log/ 
[aadarsha@labserver ~]$ find /var -size +10M 2&amp;gt;/dev/null 
/var/cache/dnf/appstream-25519c512d836b42/repodata/28fcbe99d124870c057e25d821ae6d6d4c8fa1e58c8609ffe3511cdf0fd53b66-filelists.xml.gz
/var/cache/dnf/appstream-filenames.solvx
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /var -size +10M
find: ‘/var/lib/selinux/targeted/active’: Permission denied
...
find: ‘/var/tmp/systemd-private-e670512019ad43ffb843c29fe99f0b06-systemd-logind.service-9Mcv0n’: Permission denied
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /var -size +10M 2&amp;gt;/dev/null 
/var/cache/dnf/appstream-25519c512d836b42/repodata/28fcbe99d124870c057e25d821ae6d6d4c8fa1e58c8609ffe3511cdf0fd53b66-filelists.xml.gz
/var/cache/dnf/appstream-filenames.solvx
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /var -size +10M 2&amp;gt;/dev/null 
/var/cache/dnf/appstream-25519c512d836b42/repodata/28fcbe99d124870c057e25d821ae6d6d4c8fa1e58c8609ffe3511cdf0fd53b66-filelists.xml.gz
/var/cache/dnf/appstream-filenames.solvx
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Mon Jun 15 16:59:23 +0545 2026 on pts/0
[root@labserver ~]# 

[root@labserver ~]# find /var/log -size +1M
/var/log/audit/audit.log
/var/log/anaconda/journal.log
/var/log/messages-20260611
[root@labserver ~]# 

[root@labserver ~]# find /var/log -size -1M
/var/log/anaconda/dnf.librepo.log
/var/log/firewalld
/var/log/maillog-20260611
/var/log/maillog
/var/log/spooler-20260611
/var/log/spooler
[root@labserver ~]# 

# Finding and processing

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Mon Jun 15 17:44:27 +0545 2026 on pts/0
[root@labserver ~]# 
[root@labserver ~]# find /var/log -size +1M -exec ls -ldh {} \;
-rw-------. 1 root root 1.1M Jun 15 18:03 /var/log/audit/audit.log
-rw-------. 1 root root 2.7M May 26 15:37 /var/log/anaconda/journal.log
-rw-------. 1 root root 1.4M Jun 11 05:39 /var/log/messages-20260611
[root@labserver ~]# 

[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /var/log -size +1M -exec ls -ldh {} \;
find: ‘/var/log/private’: Permission denied
find: ‘/var/log/samba’: Permission denied
find: ‘/var/log/audit’: Permission denied
find: ‘/var/log/sssd’: Permission denied
find: ‘/var/log/chrony’: Permission denied
-rw-------. 1 root root 2.7M May 26 15:37 /var/log/anaconda/journal.log
-rw-------. 1 root root 1.4M Jun 11 05:39 /var/log/messages-20260611
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ # find /var/log -size +1M -exec ls -ldh {} \;
[aadarsha@labserver ~]$ # ---&amp;gt;finding-part&amp;lt;------ ----&amp;gt;processing-part&amp;lt;--

[aadarsha@labserver ~]$ # ---&amp;gt;finding-part&amp;lt;------|----&amp;gt;processing-part&amp;lt;--

# exec --&amp;gt; execute action on the found files without asking for confirmation
# ok --&amp;gt; execute action on the found files after asking for confirmation

# ls -ldh --&amp;gt; It represents the action to be taken on the found files

# {} --&amp;gt; place holder of the found files

# \; --&amp;gt; escape delimeter
# {} --&amp;gt; place holder of the found files (buffer)


[root@labserver ~]# find /var/log -size +1M -exec ls -ldh {} \;
-rw-------. 1 root root 1.1M Jun 15 18:12 /var/log/audit/audit.log
-rw-------. 1 root root 2.7M May 26 15:37 /var/log/anaconda/journal.log
-rw-------. 1 root root 1.4M Jun 11 05:39 /var/log/messages-20260611
[root@labserver ~]# 

[root@labserver ~]# find /var/log -size +1M -ok ls -ldh {} \;
&amp;lt; ls ... /var/log/audit/audit.log &amp;gt; ? y
-rw-------. 1 root root 1.1M Jun 15 18:12 /var/log/audit/audit.log
&amp;lt; ls ... /var/log/anaconda/journal.log &amp;gt; ? n
&amp;lt; ls ... /var/log/messages-20260611 &amp;gt; ? y
-rw-------. 1 root root 1.4M Jun 11 05:39 /var/log/messages-20260611
[root@labserver ~]# 

[root@labserver ~]# find /var/log -size +1M -ok ls -ldh {} \;
&amp;lt; ls ... /var/log/audit/audit.log &amp;gt; ? y
-rw-------. 1 root root 1.1M Jun 15 18:12 /var/log/audit/audit.log
&amp;lt; ls ... /var/log/anaconda/journal.log &amp;gt; ? y
-rw-------. 1 root root 2.7M May 26 15:37 /var/log/anaconda/journal.log
&amp;lt; ls ... /var/log/messages-20260611 &amp;gt; ? y
-rw-------. 1 root root 1.4M Jun 11 05:39 /var/log/messages-20260611
[root@labserver ~]# 

[root@labserver ~]# find /var/log -size +1M -ok ls -ldh {} \;
&amp;lt; ls ... /var/log/audit/audit.log &amp;gt; ? n
&amp;lt; ls ... /var/log/anaconda/journal.log &amp;gt; ? n
&amp;lt; ls ... /var/log/messages-20260611 &amp;gt; ? n
[root@labserver ~]# 

[root@labserver ~]# mkdir -p /root/largefiles

[root@labserver ~]# ls /root/largefiles/
 
[root@labserver ~]# # find /var/log -size +1M -exec cp -pr {}(acts as the source for found files) /root/largefiles/ (destination) \;

[root@labserver ~]# # find /var/log -size +1M -exec cp -pr {} /root/largefiles/ \;

[root@labserver ~]# ls /root/largefiles/

[root@labserver ~]# # find /var/log -size +1M -exec cp -pr {} /root/largefiles \;

[root@labserver ~]# find /var/log -size +1M -exec cp -pr {} /root/largefiles \;
 
[root@labserver ~]# ls /root/largefiles/
audit.log journal.log messages-20260611
[root@labserver ~]# 

[root@labserver ~]# ls -ldh /root/largefiles/
drwxr-xr-x. 2 root root 67 Jun 15 18:17 /root/largefiles/
[root@labserver ~]# 

[root@labserver ~]# ls -lh /root/largefiles/
total 5.1M
-rw-------. 1 root root 1.1M Jun 15 18:12 audit.log
-rw-------. 1 root root 2.7M May 26 15:37 journal.log
-rw-------. 1 root root 1.4M Jun 11 05:39 messages-20260611
[root@labserver ~]# 

[root@labserver ~]# # eg: back of .conf type of files 

[root@labserver ~]# mkdir -p /root/confbkp

[root@labserver ~]# ls -ldh /root/confbkp
drwxr-xr-x. 2 root root 6 Jun 15 18:18 /root/confbkp
[root@labserver ~]# 

[root@labserver ~]# find /etc -name *.conf -exec cp -p {} /root/confbkp \;

[root@labserver ~]# ls -ldh /root/confbkp
drwxr-xr-x. 2 root root 4.0K Jun 15 18:22 /root/confbkp
[root@labserver ~]#
 
[root@labserver ~]# rm -r /root/confbkp/*
rm: remove regular file &amp;#39;/root/confbkp/00-keyboard.conf&amp;#39;? ^C
[root@labserver ~]# 

[root@labserver ~]# unalias rm
[root@labserver ~]# 
[root@labserver ~]# rm -r /root/confbkp/*
[root@labserver ~]# 
[root@labserver ~]# ls -ldh /root/confbkp
drwxr-xr-x. 2 root root 6 Jun 15 18:51 /root/confbkp
[root@labserver ~]# 

[root@labserver ~]# ls /root/confbkp | wc -l
0
[root@labserver ~]# 
[root@labserver ~]# find /etc -name *.conf -exec cp -p {} /root/confbkp \;
[root@labserver ~]# 
[root@labserver ~]# ls /root/confbkp | wc -l
75
[root@labserver ~]# 
[root@labserver ~]# ls -ldh /root/confbkp
drwxr-xr-x. 2 root root 4.0K Jun 15 18:53 /root/confbkp
[root@labserver ~]# 

# Using Logical Operators with find
[root@labserver ~]# 
[root@labserver ~]# # -and --&amp;gt; logical AND
[root@labserver ~]# # -o --&amp;gt; logical OR
[root@labserver ~]# # ! --&amp;gt; logical NOT

[root@labserver ~]# find /var/log --size +1M -and -size -3M
find: unknown predicate `--size&amp;#39;
[root@labserver ~]# 
[root@labserver ~]# find /var/log -size +1M -and -size -3M
/var/log/audit/audit.log
/var/log/messages-20260611
[root@labserver ~]# 

[root@labserver ~]# find /var/log -size +1M -and -size -3M -exec ls -lh {} \;
-rw-------. 1 root root 1.1M Jun 15 18:32 /var/log/audit/audit.log
-rw-------. 1 root root 1.4M Jun 11 05:39 /var/log/messages-20260611
[root@labserver ~]# 

[root@labserver ~]# find /var/log -size +1k -and -size -3k -exec ls -lh {} \;
-rw-------. 1 root root 1.2K May 26 15:37 /var/log/anaconda/program.log
-rw-r--r--. 1 root root 1.7K Jun 10 05:29 /var/log/hawkey.log-20260611
[root@labserver ~]# 

[root@labserver ~]# find /etc/ -size 100c -exec ls -lhd {} \;
lrwxrwxrwx. 1 root root 100 May 26 15:34 /etc/pki/tls/certs/9b5697b0.0 -&amp;gt; /etc/pki/ca-trust/extracted/pem/directory-hash/Trustwave_Global_ECC_P256_Certification_Authority.pem
lrwxrwxrwx. 1 root root 100 May 26 15:34 /etc/pki/tls/certs/1ae85e5e.0 -&amp;gt; /etc/pki/ca-trust/extracted/pem/directory-hash/Trustwave_Global_ECC_P256_Certification_Authority.pem
lrwxrwxrwx. 1 root root 100 May 26 15:34 /etc/pki/tls/certs/d887a5bb.0 -&amp;gt; /etc/pki/ca-trust/extracted/pem/directory-hash/Trustwave_Global_ECC_P384_Certification_Authority.pem
lrwxrwxrwx. 1 root root 100 May 26 15:34 /etc/pki/tls/certs/9aef356c.0 -&amp;gt; /etc/pki/ca-trust/extracted/pem/directory-hash/Trustwave_Global_ECC_P384_Certification_Authority.pem
drwxr-x---. 4 root root 100 May 26 15:33 /etc/audit
[root@labserver ~]# 
 
[root@labserver ~]# find /var/log -size +10M -o -size -10K -exec ls -lh {} \;
find: invalid -size type `K&amp;#39;
[root@labserver ~]# 
[root@labserver ~]# find /var/log -size +10M -o -size -10k -exec ls -lh {} \;
total 2.2M
drwxr-xr-x. 2 root root 4.0K May 26 15:37 anaconda
drwx------. 2 root root 23 May 26 15:39 audit
-rw-rw----. 1 root utmp 4.5K Jun 15 16:31 btmp
drwxr-x---. 2 chrony chrony 6 Nov 20 2025 chrony
-rw-------. 1 root root 4.9K Jun 15 19:01 cron
...
... 
[root@labserver ~]# 
[root@labserver ~]# find /var/log -size +10M -o -size -10k -exec ls -lh {} \; | wc -l
61
[root@labserver ~]# 

[root@labserver ~]# ls /home/
aadarsha milan suman user1 user2
[root@labserver ~]# 

[root@labserver ~]# su - user2
[user2@labserver ~]$ 
[user2@labserver ~]$ touch f1 f2 f3
[user2@labserver ~]$ ls
f1 f2 f3
[user2@labserver ~]$ ls -l
total 0
-rw-r--r--. 1 user2 user2 0 Jun 15 19:12 f1
-rw-r--r--. 1 user2 user2 0 Jun 15 19:12 f2
-rw-r--r--. 1 user2 user2 0 Jun 15 19:12 f3
[user2@labserver ~]$ 
[user2@labserver ~]$ exit
logout
[root@labserver ~]# 
[root@labserver ~]# su - user1
[user1@labserver ~]$ 
[user1@labserver ~]$ pwd
/home/user1
[user1@labserver ~]$ 
[user1@labserver ~]$ touch abc0 abc1 abc2 abc3
[user1@labserver ~]$ ls
abc0 abc1 abc2 abc3
[user1@labserver ~]$ ls -l
total 0
-rw-r--r--. 1 user1 user1 0 Jun 15 19:14 abc0
-rw-r--r--. 1 user1 user1 0 Jun 15 19:14 abc1
-rw-r--r--. 1 user1 user1 0 Jun 15 19:14 abc2
-rw-r--r--. 1 user1 user1 0 Jun 15 19:14 abc3
[user1@labserver ~]$ 

[user1@labserver ~]$ exit
logout
[root@labserver ~]# 
[root@labserver ~]# find /home -user user1
/home/user1
/home/user1/.bash_logout
/home/user1/.bash_profile
/home/user1/.bashrc
/home/user1/abc0
/home/user1/abc1
/home/user1/abc2
/home/user1/abc3
/home/user1/.bash_history
[root@labserver ~]# 

[root@labserver ~]# find /home -user user1 -o -user user2
/home/user1
/home/user1/.bash_logout
/home/user1/.bash_profile
/home/user1/.bashrc
/home/user1/abc0
/home/user1/abc1
/home/user1/abc2
/home/user1/abc3
/home/user1/.bash_history
/home/user2
/home/user2/.bash_logout
/home/user2/.bash_profile
/home/user2/.bashrc
/home/user2/f1
/home/user2/f2
/home/user2/f3
/home/user2/.bash_history
[root@labserver ~]# 

[root@labserver ~]# mkdir -p /bkp

[root@labserver ~]# find /home -user user1 -o user user2 -exec cp -p {} /bkp \;
find: paths must precede expression: `user&amp;#39;
[root@labserver ~]# 
[root@labserver ~]# ls -l /bkp
total 0
[root@labserver ~]# 

[root@labserver ~]# find /home /(-user user1 -o user user2\) -exec cp -p {} /bkp \;
-bash: syntax error near unexpected token `(&amp;#39;
[root@labserver ~]# find /home /(-user user1 -o user user2/) -exec cp -p {} /bkp \;
-bash: syntax error near unexpected token `(&amp;#39;
[root@labserver ~]# 

[root@labserver ~]# find /home \(-user user1 -o user user2\) -exec cp -p {} /bkp \;
find: paths must precede expression: `user&amp;#39;
[root@labserver ~]# 

[root@labserver ~]# find /home \(-user user1 -o -user user2\) -exec cp -p {} /bkp \;
find: invalid user name or UID argument to -user: ‘user2)’
[root@labserver ~]# 

[root@labserver ~]# find /home \( -user user1 -o -user user2 \) -exec cp -p {} /bkp \;
cp: -r not specified; omitting directory &amp;#39;/home/user1&amp;#39;
cp: -r not specified; omitting directory &amp;#39;/home/user2&amp;#39;
[root@labserver ~]# 

[root@labserver ~]# ls /bkp
abc0 abc1 abc2 abc3 f1 f2 f3
[root@labserver ~]# 
 
[root@labserver ~]# find /home \( -user user1 -o -user user2 \) -exec cp -p {} /bkp \;
cp: -r not specified; omitting directory &amp;#39;/home/user1&amp;#39;
cp: -r not specified; omitting directory &amp;#39;/home/user2&amp;#39;
[root@labserver ~]# 

[root@labserver ~]# ls /bkp
abc0 abc1 abc2 abc3 f1 f2 f3
[root@labserver ~]# 

[root@labserver ~]# find / -group marketting
find: invalid group name or GID argument to -group: ‘marketting’
[root@labserver ~]# 
[root@labserver ~]# # find / -group marketting

[root@labserver ~]# find /etc -type l | wc -l
707
[root@labserver ~]# 
[root@labserver ~]# find /etc -type d | wc -l
195
[root@labserver ~]# 
[root@labserver ~]# find /etc -type f | wc -l
488
[root@labserver ~]# 
[root@labserver ~]# 
[root@labserver ~]# find /home -user aadarsha | wc -l
41
[root@labserver ~]# 
[root@labserver ~]# find /home ! c-user aadarsha | wc -l
find: paths must precede expression: `c-user&amp;#39;
0
[root@labserver ~]# 
 
[root@labserver ~]# find /home ! -user aadarsha | wc -l
85
[root@labserver ~]# 
 
[root@labserver ~]# find /home \( -user user1 -o -user user2 \) -exec ll {} /bkp \;
find: ‘ll’: No such file or directory
find: ‘ll’: No such file or directory
find: ‘ll’: No such file or directory
find: ‘ll’: No such file or directory
[root@labserver ~]# 

[root@labserver ~]# find /home \( -user user1 -o -user user2 \) -exec ls -l {} /bkp \;
/bkp:

[root@labserver ~]# touch emp1 emp2 emp3 emp4
[root@labserver ~]# ls
anaconda-ks.cfg confbkp emp1 emp2 emp3 emp4 largefiles
[root@labserver ~]# 

[root@labserver ~]# pwd
/root
[root@labserver ~]# 
[root@labserver ~]# find -size 0
./emp1
./emp2
./emp3
./emp4
[root@labserver ~]# 

[root@labserver ~]# find -size 0
./emp1
./emp2
./emp3
./emp4
[root@labserver ~]# 

[root@labserver ~]# find -size 0 -exec rm -f {} \;

[root@labserver ~]# find -size 0

[root@labserver ~]# ls
anaconda-ks.cfg confbkp largefiles
[root@labserver ~]# 

[root@labserver ~]# ls /root/confbkp/
00-keyboard.conf grub2-pc.conf pwhistory.conf
01-permitrootlogin.conf grub2-tools-minimal.conf pwquality.conf
40-redhat-crypto-policies.conf host.conf request-key.conf
50-redhat.conf kdump.conf resolv.conf
56-google-noto-sans-mono-vf.conf krb5.conf rsyslog.conf
56-google-noto-sans-vf.conf l2tp_eth-blacklist.conf sctp-blacklist.conf
56-google-noto-serif-vf.conf l2tp_ip6-blacklist.conf sctp_diag-blacklist.conf
64-redhat-mono-vf.conf l2tp_ip-blacklist.conf selinux-policy-targeted.conf
64-redhat-text-vf.conf l2tp_netlink-blacklist.conf semanage.conf
99-sysctl.conf l2tp_ppp-blacklist.conf sepermit.conf
access.conf ldap.conf session.conf
auditd.conf ld.so.conf sestatus.conf
authselect.conf libaudit.conf setrans.conf
ca-legacy.conf limits.conf setup.conf
chrony.conf locale.conf smb.conf
chroot.conf logrotate.conf sudo.conf
copr.conf lvm.conf sudo-ldap.conf
debuginfo-install.conf lvmlocal.conf sysctl.conf
dist.conf man_db.conf system.conf
dnf.conf mke2fs.conf systemd.conf
dracut.conf namespace.conf time.conf
faillock.conf NetworkManager.conf tipc_diag-blacklist.conf
firewalld.conf nftables.conf vconsole.conf
firewalld-sysctls.conf nsswitch.conf xattr.conf
group.conf pam_env.conf yum.conf
[root@labserver ~]# 

[root@labserver ~]# cd /root/confbkp/
[root@labserver confbkp]# 
[root@labserver confbkp]# touch f1 f2 f3
[root@labserver confbkp]# 
[root@labserver confbkp]# cd
[root@labserver ~]# 

[root@labserver ~]# find /root/confbkp/ -name *.conf -exec mv {} {}.bak \;
[root@labserver ~]# 
[root@labserver ~]# ls /root/confbkp
00-keyboard.conf.bak.conf.bak ld.so.conf.bak.conf.bak
01-permitrootlogin.conf.bak.conf.bak libaudit.conf.bak.conf.bak
40-redhat-crypto-policies.conf.bak.conf.bak limits.conf.bak.conf.bak
50-redhat.conf.bak.conf.bak locale.conf.bak.conf.bak
56-google-noto-sans-mono-vf.conf.bak.conf.bak logrotate.conf.bak.conf.bak
56-google-noto-sans-vf.conf.bak.conf.bak lvm.conf.bak.conf.bak
56-google-noto-serif-vf.conf.bak.conf.bak lvmlocal.conf.bak.conf.bak
64-redhat-mono-vf.conf.bak.conf.bak man_db.conf.bak.conf.bak
64-redhat-text-vf.conf.bak.conf.bak mke2fs.conf.bak.conf.bak
99-sysctl.conf.bak.conf.bak namespace.conf.bak.conf.bak
access.conf.bak.conf.bak NetworkManager.conf.bak.conf.bak
auditd.conf.bak.conf.bak nftables.conf.bak.conf.bak
authselect.conf.bak.conf.bak nsswitch.conf.bak.conf.bak
ca-legacy.conf.bak.conf.bak pam_env.conf.bak.conf.bak
chrony.conf.bak.conf.bak pwhistory.conf.bak.conf.bak
chroot.conf.bak.conf.bak pwquality.conf.bak.conf.bak
copr.conf.bak.conf.bak request-key.conf.bak.conf.bak
debuginfo-install.conf.bak.conf.bak resolv.conf.bak.conf.bak
dist.conf.bak.conf.bak rsyslog.conf.bak.conf.bak
dnf.conf.bak.conf.bak sctp-blacklist.conf.bak.conf.bak
dracut.conf.bak.conf.bak sctp_diag-blacklist.conf.bak.conf.bak
f1 selinux-policy-targeted.conf.bak.conf.bak
f2 semanage.conf.bak.conf.bak
f3 sepermit.conf.bak.conf.bak
faillock.conf.bak.conf.bak session.conf.bak.conf.bak
firewalld.conf.bak.conf.bak sestatus.conf.bak.conf.bak
firewalld-sysctls.conf.bak.conf.bak setrans.conf.bak.conf.bak
group.conf.bak.conf.bak setup.conf.bak.conf.bak
grub2-pc.conf.bak.conf.bak smb.conf.bak.conf.bak
grub2-tools-minimal.conf.bak.conf.bak sudo.conf.bak.conf.bak
host.conf.bak.conf.bak sudo-ldap.conf.bak.conf.bak
kdump.conf.bak.conf.bak sysctl.conf.bak.conf.bak
krb5.conf.bak.conf.bak system.conf.bak.conf.bak
l2tp_eth-blacklist.conf.bak.conf.bak systemd.conf.bak.conf.bak
l2tp_ip6-blacklist.conf.bak.conf.bak time.conf.bak.conf.bak
l2tp_ip-blacklist.conf.bak.conf.bak tipc_diag-blacklist.conf.bak.conf.bak
l2tp_netlink-blacklist.conf.bak.conf.bak vconsole.conf.bak.conf.bak
l2tp_ppp-blacklist.conf.bak.conf.bak xattr.conf.bak.conf.bak
ldap.conf.bak.conf.bak yum.conf.bak.conf.bak
[root@labserver ~]# 

# log processing

[root@labserver ~]# ls
anaconda-ks.cfg confbkp f1 f2 f3 largefiles
[root@labserver ~]# 

[root@labserver ~]# mkdir logdir
[root@labserver ~]# ls
anaconda-ks.cfg confbkp f1 f2 f3 largefiles logdir
[root@labserver ~]# cd logdir/
[root@labserver logdir]# 

[root@labserver logdir]# vi app.log
[root@labserver logdir]# cat app.log 
INFO Application started successfully
INFO User Alice logged in
ERROR Payment Gateway timeout
WARNING Memory usage reached 75%
INFO User bob logged in
ERROR Database connection lost ...
INFO Backup completed successfully
WARNING Disk space reached 85%
ERROR Invalid API request received
INFO User charlie logged out
ERROR Payment gateway timeout
ERROR Database connection lost
INFO User Alice logged out
[root@labserver logdir]# 

[root@labserver logdir]# vi employees.csv
[root@labserver logdir]# cat employees.csv 
empid,name,destination,department,salary
E001,Ram Bahadur Thapa,Manager,Administration,85000
E002,Sita Kumari Sharma,Officer,Finance,65000
E003,Hari Prasad Adhikari,Engineer,IT,78000
E004,Gita Devi Koirala,Assistant,Human Resources,52000
E005,Binod Kumar Nepal,Supervisor,Operations,60000
E006,Manisha Rai,Analyst,Marketing,70000
E007,Rajan Gurung,Coordinator,Procurement,58000
E008,Sujan Shrestha,Developer,IT,75000
E009,Kavita Bhattarai,Accountant,Finance,62000
E010,Prakash Tamang,Technician,Maintenance,55000
[root@labserver logdir]# 

[root@labserver logdir]# ls
app.log employees.csv
[root@labserver logdir]# 

[root@labserver logdir]# sed &amp;#39;s/ERROR/CRITICAL/g&amp;#39; app.log 
INFO Application started successfully
INFO User Alice logged in
CRITICAL Payment Gateway timeout
WARNING Memory usage reached 75%
INFO User bob logged in
CRITICAL Database connection lost ...
INFO Backup completed successfully
WARNING Disk space reached 85%
CRITICAL Invalid API request received
INFO User charlie logged out
CRITICAL Payment gateway timeout
CRITICAL Database connection lost
INFO User Alice logged out
[root@labserver logdir]# 

[root@labserver logdir]# sed &amp;#39;s/ERROR/CRITICAL/g&amp;#39; app.log &amp;gt;criticallogs
[root@labserver logdir]# ls
app.log criticallogs employees.csv
[root@labserver logdir]# cat criticallogs 
INFO Application started successfully
INFO User Alice logged in
CRITICAL Payment Gateway timeout
WARNING Memory usage reached 75%
INFO User bob logged in
CRITICAL Database connection lost ...
INFO Backup completed successfully
WARNING Disk space reached 85%
CRITICAL Invalid API request received
INFO User charlie logged out
CRITICAL Payment gateway timeout
CRITICAL Database connection lost
INFO User Alice logged out
[root@labserver logdir]# 

[root@labserver logdir]# sed &amp;#39;/INFO/d&amp;#39; criticallogs 
CRITICAL Payment Gateway timeout
WARNING Memory usage reached 75%
CRITICAL Database connection lost ...
WARNING Disk space reached 85%
CRITICAL Invalid API request received
CRITICAL Payment gateway timeout
CRITICAL Database connection lost
[root@labserver logdir]# 

[root@labserver logdir]# cat criticallogs 
INFO Application started successfully
INFO User Alice logged in
CRITICAL Payment Gateway timeout
WARNING Memory usage reached 75%
INFO User bob logged in
CRITICAL Database connection lost ...
INFO Backup completed successfully
WARNING Disk space reached 85%
CRITICAL Invalid API request received
INFO User charlie logged out
CRITICAL Payment gateway timeout
CRITICAL Database connection lost
INFO User Alice logged out
[root@labserver logdir]# 

[root@labserver logdir]# sed &amp;#39;/INFO/d&amp;#39; criticallogs &amp;gt;noinfo.log
[root@labserver logdir]# ls
app.log criticallogs employees.csv noinfo.log
[root@labserver logdir]# cat noinfo.log 
CRITICAL Payment Gateway timeout
WARNING Memory usage reached 75%
CRITICAL Database connection lost ...
WARNING Disk space reached 85%
CRITICAL Invalid API request received
CRITICAL Payment gateway timeout
CRITICAL Database connection lost
[root@labserver logdir]# 

[root@labserver logdir]# sed &amp;#39;s/Database/Postgres Database&amp;#39; app.log 
sed: -e expression #1, char 28: unterminated `s&amp;#39; command
[root@labserver logdir]# 

[root@labserver logdir]# sed &amp;#39;s/Database/Postgres Database/g&amp;#39; app.log 
INFO Application started successfully
INFO User Alice logged in
ERROR Payment Gateway timeout
WARNING Memory usage reached 75%
INFO User bob logged in
ERROR Postgres Database connection lost ...
INFO Backup completed successfully
WARNING Disk space reached 85%
ERROR Invalid API request received
INFO User charlie logged out
ERROR Payment gateway timeout
ERROR Postgres Database connection lost
INFO User Alice logged out
[root@labserver logdir]# 

[root@labserver logdir]# ls
app.log criticallogs employees.csv noinfo.log
[root@labserver logdir]# 

[root@labserver logdir]# sed &amp;#39;/INFO/d&amp;#39; app.log 
ERROR Payment Gateway timeout
WARNING Memory usage reached 75%
ERROR Database connection lost ...
WARNING Disk space reached 85%
ERROR Invalid API request received
ERROR Payment gateway timeout
ERROR Database connection lost
[root@labserver logdir]#
 
[root@labserver logdir]# cat app.log 
INFO Application started successfully
INFO User Alice logged in
ERROR Payment Gateway timeout
WARNING Memory usage reached 75%
INFO User bob logged in
ERROR Database connection lost ...
INFO Backup completed successfully
WARNING Disk space reached 85%
ERROR Invalid API request received
INFO User charlie logged out
ERROR Payment gateway timeout
ERROR Database connection lost
INFO User Alice logged out
[root@labserver logdir]# 

[root@labserver logdir]# sed -i &amp;#39;/INFO/d&amp;#39; app.log 

[root@labserver logdir]# cat app.log 
ERROR Payment Gateway timeout
WARNING Memory usage reached 75%
ERROR Database connection lost ...
WARNING Disk space reached 85%
ERROR Invalid API request received
ERROR Payment gateway timeout
ERROR Database connection lost
[root@labserver logdir]# 

[root@labserver logdir]# ls
app.log criticallogs employees.csv noinfo.log
[root@labserver logdir]# cat criticallogs 
INFO Application started successfully
INFO User Alice logged in
CRITICAL Payment Gateway timeout
WARNING Memory usage reached 75%
INFO User bob logged in
CRITICAL Database connection lost ...
INFO Backup completed successfully
WARNING Disk space reached 85%
CRITICAL Invalid API request received
INFO User charlie logged out
CRITICAL Payment gateway timeout
CRITICAL Database connection lost
INFO User Alice logged out
[root@labserver logdir]# 

[root@labserver logdir]# ls
app.log criticallogs employees.csv noinfo.log
[root@labserver logdir]# 

[root@labserver logdir]# man sed
 
[root@labserver logdir]# sed -n &amp;#39;/CRITICAL/p&amp;#39; app.log 

[root@labserver logdir]# sed -n &amp;#39;/CRITICAL/p&amp;#39; criticallogs 
CRITICAL Payment Gateway timeout
CRITICAL Database connection lost ...
CRITICAL Invalid API request received
CRITICAL Payment gateway timeout
CRITICAL Database connection lost
[root@labserver logdir]# 

# Using awk

[root@labserver logdir]# ls
app.log criticallogs employees.csv noinfo.log
[root@labserver logdir]# 

[root@labserver logdir]# cat employees.csv 
empid,name,destination,department,salary
E001,Ram Bahadur Thapa,Manager,Administration,85000
E002,Sita Kumari Sharma,Officer,Finance,65000
E003,Hari Prasad Adhikari,Engineer,IT,78000
E004,Gita Devi Koirala,Assistant,Human Resources,52000
E005,Binod Kumar Nepal,Supervisor,Operations,60000
E006,Manisha Rai,Analyst,Marketing,70000
E007,Rajan Gurung,Coordinator,Procurement,58000
E008,Sujan Shrestha,Developer,IT,75000
E009,Kavita Bhattarai,Accountant,Finance,62000
E010,Prakash Tamang,Technician,Maintenance,55000
[root@labserver logdir]# 

[root@labserver logdir]# cut -f 2 -d, employees.csv 
name
Ram Bahadur Thapa
Sita Kumari Sharma
Hari Prasad Adhikari
Gita Devi Koirala
Binod Kumar Nepal
Manisha Rai
Rajan Gurung
Sujan Shrestha
Kavita Bhattarai
Prakash Tamang
[root@labserver logdir]# 

[root@labserver logdir]# awk -F &amp;#39;,&amp;#39; &amp;#39;{print $2}&amp;#39; employees.csv 
name
Ram Bahadur Thapa
Sita Kumari Sharma
Hari Prasad Adhikari
Gita Devi Koirala
Binod Kumar Nepal
Manisha Rai
Rajan Gurung
Sujan Shrestha
Kavita Bhattarai
Prakash Tamang
[root@labserver logdir]# 

[root@labserver logdir]# awk -F &amp;#39;,&amp;#39; &amp;#39;{print $2, $5}&amp;#39; employees.csv 
name salary
Ram Bahadur Thapa 85000
Sita Kumari Sharma 65000
Hari Prasad Adhikari 78000
Gita Devi Koirala 52000
Binod Kumar Nepal 60000
Manisha Rai 70000
Rajan Gurung 58000
Sujan Shrestha 75000
Kavita Bhattarai 62000
Prakash Tamang 55000
[root@labserver logdir]# 

[root@labserver logdir]# awk -F &amp;#39;,&amp;#39; &amp;#39;$5 &amp;gt;70000&amp;#39; &amp;#39;{print $2, $5}&amp;#39; employees.csv 
awk: fatal: cannot open file `{print $2, $5}&amp;#39; for reading: No such file or directory
[root@labserver logdir]# 

[root@labserver logdir]# awk -F &amp;#39;,&amp;#39; &amp;#39;$5 &amp;gt;70000 {print $2, $5}&amp;#39; employees.csv 
name salary
Ram Bahadur Thapa 85000
Hari Prasad Adhikari 78000
Sujan Shrestha 75000
[root@labserver logdir]# 
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Practice 008 — Text processing, Data Manipulation and Finding files</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-008/</link><pubDate>Fri, 12 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-008/</guid><description>&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# Text processing and Data Manipulation

# commands: head, tail, cat, less, wc, sort, cut, tee, uniq

# pipeline
# grep, sed

[aadarsha@labserver ~]$ cat passwd 
root:x:0:0:Super User:/root:/bin/bash
...
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
adm:x:3:4:adm:/var/adm:/usr/sbin/nologin
...
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
[aadarsha@labserver ~]$ 
 
# viewing First/Last few lines of a file

[aadarsha@labserver ~]$ head passwd 
root:x:0:0:Super User:/root:/bin/bash
...
operator:x:11:0:operator:/root:/usr/sbin/nologin
[aadarsha@labserver ~]$ 

# By default 10 lines

[aadarsha@labserver ~]$ head -2 passwd 
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ head -10 passwd 
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
adm:x:3:4:adm:/var/adm:/usr/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/usr/sbin/nologin
operator:x:11:0:operator:/root:/usr/sbin/nologin
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ tail passwd 
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
...
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi passwd 
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ tail -5 /etc/passwd
sssd:x:998:997:User for sssd:/run/sssd/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi passwd 

[aadarsha@labserver ~]$ tail -5 /etc/passwd
sssd:x:998:997:User for sssd:/run/sssd/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ tail /var/log/secure 
tail: cannot open &amp;#39;/var/log/secure&amp;#39; for reading: Permission denied
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ sudo su
[sudo] password for aadarsha: 
[root@labserver aadarsha]# 
[root@labserver aadarsha]# 
[root@labserver aadarsha]# tail /var/log/secure 
Jun 9 05:24:00 labserver su[2184]: pam_unix(su:session): session closed for user root
Jun 9 05:24:00 labserver sudo[2179]: pam_unix(sudo:session): session closed for user root
Jun 9 06:04:24 labserver sudo[2754]: aadarsha : TTY=pts/0 ; PWD=/home/aadarsha ; USER=root ; COMMAND=/bin/su
Jun 9 06:04:24 labserver sudo[2754]: pam_unix(sudo:session): session opened for user root(uid=0) by aadarsha(uid=1000)
Jun 9 06:04:24 labserver su[2761]: pam_unix(su:session): session opened for user root(uid=0) by aadarsha(uid=0)
Jun 9 06:04:45 labserver su[2761]: pam_unix(su:session): session closed for user root
Jun 9 06:04:45 labserver sudo[2754]: pam_unix(sudo:session): session closed for user root
Jun 9 06:20:51 labserver sudo[2991]: aadarsha : TTY=pts/0 ; PWD=/home/aadarsha ; USER=root ; COMMAND=/bin/su
Jun 9 06:20:51 labserver sudo[2991]: pam_unix(sudo:session): session opened for user root(uid=0) by aadarsha(uid=1000)
Jun 9 06:20:51 labserver su[2996]: pam_unix(su:session): session opened for user root(uid=0) by aadarsha(uid=0)
[root@labserver aadarsha]# 

[root@labserver aadarsha]# tail -f /var/log/secure 
Jun 9 05:24:00 labserver su[2184]: pam_unix(su:session): session closed for user root
Jun 9 05:24:00 labserver sudo[2179]: pam_unix(sudo:session): session closed for user root
Jun 9 06:04:24 labserver sudo[2754]: aadarsha : TTY=pts/0 ; PWD=/home/aadarsha ; USER=root ; COMMAND=/bin/su
Jun 9 06:04:24 labserver sudo[2754]: pam_unix(sudo:session): session opened for user root(uid=0) by aadarsha(uid=1000)
...
[root@labserver aadarsha]# 

# checking the realtime live activities using tail -f /var/log/secure and use ----------------(line)

# using sort

[aadarsha@labserver ~]$ cat /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
adm:x:3:4:adm:/var/adm:/usr/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/usr/sbin/nologin
operator:x:11:0:operator:/root:/usr/sbin/nologin
games:x:12:100:games:/usr/games:/usr/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/usr/sbin/nologin
nobody:x:65534:65534:Kernel Overflow User:/:/usr/sbin/nologin
tss:x:59:59:Account used for TPM access:/:/usr/sbin/nologin
systemd-oom:x:999:999:systemd Userspace OOM Killer:/:/sbin/nologin
dbus:x:81:81:System Message Bus:/:/usr/sbin/nologin
sssd:x:998:997:User for sssd:/run/sssd/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Wed Jun 10 05:48:53 +0545 2026 on pts/0
[root@labserver ~]# 

[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sort /etc/passwd
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
adm:x:3:4:adm:/var/adm:/usr/sbin/nologin
bin:x:1:1:bin:/bin:/usr/sbin/nologin
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
dbus:x:81:81:System Message Bus:/:/usr/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/usr/sbin/nologin
games:x:12:100:games:/usr/games:/usr/sbin/nologin
halt:x:7:0:halt:/sbin:/sbin/halt
lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:12:mail:/var/spool/mail:/usr/sbin/nologin
nobody:x:65534:65534:Kernel Overflow User:/:/usr/sbin/nologin
operator:x:11:0:operator:/root:/usr/sbin/nologin
root:x:0:0:Super User:/root:/bin/bash
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin
sssd:x:998:997:User for sssd:/run/sssd/:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
systemd-oom:x:999:999:systemd Userspace OOM Killer:/:/sbin/nologin
tss:x:59:59:Account used for TPM access:/:/usr/sbin/nologin
[aadarsha@labserver ~]$ 

# sort [option] &amp;lt;argument&amp;gt;

# -n --&amp;gt; numeric sort

# -r --&amp;gt; reverse sort

# -k --&amp;gt;
 
# -t --&amp;gt; 

[aadarsha@labserver ~]$ sort -n -k 3 -t: /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
adm:x:3:4:adm:/var/adm:/usr/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/usr/sbin/nologin
operator:x:11:0:operator:/root:/usr/sbin/nologin
games:x:12:100:games:/usr/games:/usr/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/usr/sbin/nologin
tss:x:59:59:Account used for TPM access:/:/usr/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin
dbus:x:81:81:System Message Bus:/:/usr/sbin/nologin
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
sssd:x:998:997:User for sssd:/run/sssd/:/sbin/nologin
systemd-oom:x:999:999:systemd Userspace OOM Killer:/:/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
nobody:x:65534:65534:Kernel Overflow User:/:/usr/sbin/nologin
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sort -n -k 3 -t: -r /etc/passwd
nobody:x:65534:65534:Kernel Overflow User:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
systemd-oom:x:999:999:systemd Userspace OOM Killer:/:/sbin/nologin
sssd:x:998:997:User for sssd:/run/sssd/:/sbin/nologin
...
root:x:0:0:Super User:/root:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sort -nrk 3 -t: /etc/passwd
nobody:x:65534:65534:Kernel Overflow User:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
systemd-oom:x:999:999:systemd Userspace OOM Killer:/:/sbin/nologin
...
bin:x:1:1:bin:/bin:/usr/sbin/nologin
root:x:0:0:Super User:/root:/bin/bash
[aadarsha@labserver ~]$ 

# using cut

[aadarsha@labserver ~]$ cat /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
...
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

# cut [option] &amp;lt;argument&amp;gt;

# -f &amp;lt;field no&amp;gt;
# -d &amp;lt;delimeter&amp;gt;

[aadarsha@labserver ~]$ cut -f 1 -d : /etc/passwd
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
operator
games
ftp
nobody
tss
systemd-oom
dbus
sssd
sshd
chrony
systemd-coredump
aadarsha
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 1,3,6 -d : /etc/passwd
root:0:/root
bin:1:/bin
daemon:2:/sbin
...
aadarsha:1000:/home/aadarsha
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 1,3,6,7 -d : /etc/passwd
root:0:/root:/bin/bash
bin:1:/bin:/usr/sbin/nologin
daemon:2:/sbin:/usr/sbin/nologin
...
systemd-coredump:995:/:/usr/sbin/nologin
aadarsha:1000:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ cut -f 1-4 -d : /etc/passwd
root:x:0:0
bin:x:1:1
daemon:x:2:2
...
systemd-coredump:x:995:995
aadarsha:x:1000:1000
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f -4 -d : /etc/passwd
root:x:0:0
...
systemd-coredump:x:995:995
aadarsha:x:1000:1000
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 4- -d : /etc/passwd
0:Super User:/root:/bin/bash
1:bin:/bin:/usr/sbin/nologin
2:daemon:/sbin:/usr/sbin/nologin
...
1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

# Linux principles

# small single purpose commands
# small commands can be combined

# small commands can be combined using pipelines

[aadarsha@labserver ~]$ cut -f 1 d: /etc/passwd
cut: &amp;#39;d:&amp;#39;: No such file or directory
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
...
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 1 d : /etc/passwd
cut: d: No such file or directory
cut: &amp;#39;:&amp;#39;: No such file or directory
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
...
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 1 -d : /etc/passwd
root
...
aadarsha
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 1 -d : /etc/passwd | sort
aadarsha
...
tss
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 1 -d : /etc/passwd | sort
aadarsha
adm
...
systemd-oom
tss
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sort /etc/passwd | cut -f 1 -d : 
aadarsha
...
systemd-oom
tss
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sort /etc/passwd | cut -f 1 -d : | less


# using uniq

[aadarsha@labserver ~]$ cut -f 7 d : /etc/passwd
cut: d: No such file or directory
cut: &amp;#39;:&amp;#39;: No such file or directory
root:x:0:0:Super User:/root:/bin/bash
...
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 7 -d : /etc/passwd
/bin/bash
/usr/sbin/nologin
...
/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 7 -d : /etc/passwd | uniq
/bin/bash
/usr/sbin/nologin
...
/bin/bash
[aadarsha@labserver ~]$ 

# uniq --&amp;gt; continuous repeating is replaced by single 

[aadarsha@labserver ~]$ cut -f 7 -d : /etc/passwd | sort | uniq
/bin/bash
/bin/sync
/sbin/halt
/sbin/nologin
/sbin/shutdown
/usr/sbin/nologin
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 7 -d : /etc/passwd | sort | uniq -c
 2 /bin/bash
 1 /bin/sync
 1 /sbin/halt
 3 /sbin/nologin
 1 /sbin/shutdown
 13 /usr/sbin/nologin
[aadarsha@labserver ~]$ 

# tee --&amp;gt; it saves intermediate results of a pipeline
 
[aadarsha@labserver ~]$ ls 
dir1 dira extracted newfile1 passwd secret_data testcompany testfile words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cut -f 7 -d : /etc/passwd | tee cut_result | sort | tee sort_result | uniq -c | tee uniq_result
 2 /bin/bash
 1 /bin/sync
 1 /sbin/halt
 3 /sbin/nologin
 1 /sbin/shutdown
 13 /usr/sbin/nologin
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
cut_result dira newfile1 secret_data testcompany uniq_result
dir1 extracted passwd sort_result testfile words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat cut_result 
/bin/bash
...
/usr/sbin/nologin
/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat uniq_result 
 2 /bin/bash
 1 /bin/sync
 1 /sbin/halt
 3 /sbin/nologin
 1 /sbin/shutdown
 13 /usr/sbin/nologin
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat sort_result 
...
/usr/sbin/nologin
[aadarsha@labserver ~]$ 

# grep
# grep --&amp;gt; it searches for a pattern in a file and displays only those lines that have a matching pattern

# grep &amp;lt;pattern&amp;gt; [option] &amp;lt;argument&amp;gt;

# -v --&amp;gt; displays non-matching lines

# -V --&amp;gt; displays non-matching lines

# -c --&amp;gt; displays total count of lines

# -i --&amp;gt; ignores line

# -r --&amp;gt; searches resursive

[aadarsha@labserver ~]$ grep aadarsha /etc/passwd
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep aadar /etc/passwd
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep a /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
...
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

# matches pattern in all lines by default 

[aadarsha@labserver ~]$ grep iv /etc/passwd
sshd:x:74:74:Privilege-separated SSH:/usr/share/empty.sshd:/usr/sbin/nologin
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash -c /etc/passwd
2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ grep bash /etc/passwd | wc
 2 4 100
[aadarsha@labserver ~]$ grep bash /etc/passwd | wc -l
2
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat /etc/passwd | grep bash
root:x:0:0:Super User:/root:/bin/bash
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat /etc/passwd | grep bash | wc -l
2
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat /etc/passwd | grep bash | wc
 2 4 100
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash -c /etc/passwd
2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ grep bash /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash -r /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash -v /etc/passwd
bin:x:1:1:bin:/bin:/usr/sbin/nologin
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
...
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi testdatafile
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ grep boy testdatafile 
i&amp;#39;m a good boy
are you a boy or girl?
[aadarsha@labserver ~]$

[aadarsha@labserver ~]$ vi testfile 
[aadarsha@labserver ~]$ vi testdatafile 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ grep ^boy testdatafile 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ grep boy$ testdatafile 
i&amp;#39;m a good boy
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
...
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep ^s /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
...
chrony:x:997:996:chrony system user:/var/lib/chrony:/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep bash$ /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi testdatafile 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ grep boy testdatafile 
i&amp;#39;m a good boy
is this boy who is the best man in the world
are you a boy or girl?
Boy is running and you boy?
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ grep Boy testdatafile 
Boy is running and you boy?
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep -i Boy testdatafile 
i&amp;#39;m a good boy
is this boy who is the best man in the world
are you a boy or girl?
Boy is running and you boy?
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep -i Boy|girl testdatafile 
-bash: girl: command not found
^Z 
[1]+ Stopped grep --color=auto -i Boy | girl testdatafile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ egrep &amp;#39;boy|girl&amp;#39; testdatafile 
i&amp;#39;m a good boy
this is the beautiful girl 
is this boy who is the best man in the world
are you a boy or girl?
Boy is running and you boy?
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep -e boy -e girl testdatafile 
i&amp;#39;m a good boy
this is the beautiful girl 
is this boy who is the best man in the world
are you a boy or girl?
Boy is running and you boy?
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi testthis 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ whoami
aadarsha
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep -r good .
./dira/words:aftergood
./dira/words:a-good
./dira/words:Allgood
...
./testdatafile:good morning 
./testthis:are you good or bad
./testthis:I want good
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep -r good 
dira/words:aftergood
dira/words:a-good
dira/words:Allgood
...
grep: extracted/var/log/cron: Permission denied
testdatafile:i&amp;#39;m a good boy
testdatafile:good morning 
testthis:are you good or bad
testthis:I want good
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ su - root 
Password: 
Last login: Thu Jun 11 05:12:59 +0545 2026 on pts/0
[root@labserver ~]# 

[root@labserver ~]# grep -r good /etc/
/etc/lvm/lvm.conf:	# to have good deduplication rates but compression is still desired.
/etc/lvm/lvm.conf:	# device if there is only one remaining good copy.
/etc/nftables/osf/pf.os:# A fairly good method is to simply round the observed TTL up to
/etc/bashrc:# It&amp;#39;s NOT a good idea to change this file unless you know what you
/etc/profile:# It&amp;#39;s NOT a good idea to change this file unless you know what you
/etc/firewalld/firewalld.conf:# time that is needed to apply changes and to start the daemon, but is good for
grep: /etc/udev/hwdb.bin: binary file matches
[root@labserver ~]# 

[root@labserver ~]# cd 
[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep -r boy .
./words:boycottage
...
grep: ./extracted/var/log/cron: Permission denied
./testdatafile:i&amp;#39;m a good boy
./testdatafile:is this boy who is the best man in the world
./testdatafile:are you a boy or girl?
./testdatafile:Boy is running and you boy?
./testthis:boy and girl are beautiful
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ grep -r boy . | wc -l
grep: ./extracted/etc/libaudit.conf: Permission denied
...
grep: ./extracted/var/log/firewalld: Permission denied
grep: ./extracted/var/log/cron: Permission denied
481
[aadarsha@labserver ~]$ 

# sed

# using &amp;#39;sed&amp;#39;

# sed --&amp;gt; perfroms search and replace operations

[aadarsha@labserver ~]$ ls
cut_result dira newfile1 secret_data testcompany testfile uniq_result
dir1 extracted passwd sort_result testdatafile testthis words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat passwd 
root:x:0:0:Super User:/root:/bin/bash
...
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/nologin
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 
 
# sed

[aadarsha@labserver ~]$ sed &amp;#39;s/nologin/YESLOGIN/g&amp;#39; /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
...
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/YESLOGIN
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sed &amp;#39;s/nologin/YESLOGIN/g&amp;#39; /etc/passwd &amp;gt; passwd_YESLOGIN

[aadarsha@labserver ~]$ ls
cut_result extracted passwd_YESLOGIN testcompany testthis
dir1 newfile1 secret_data testdatafile uniq_result
dira passwd sort_result testfile words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat passwd_YESLOGIN 
root:x:0:0:Super User:/root:/bin/bash
...
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/YESLOGIN
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/bash
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat passwd
root:x:0:0:Super User:/root:/bin/bash
...
lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sed -e &amp;#39;s/bash/CASH/g&amp;#39; -e &amp;#39;s/nologin/YESLOGIN/g&amp;#39; /etc/passwd &amp;gt; multiple_changes

[aadarsha@labserver ~]$ ls
cut_result extracted passwd sort_result testfile words
dir1 multiple_changes passwd_YESLOGIN testcompany testthis
dira newfile1 secret_data testdatafile uniq_result
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat multiple_changes 
root:x:0:0:Super User:/root:/bin/CASH
...
systemd-coredump:x:995:995:systemd Core Dumper:/:/usr/sbin/YESLOGIN
aadarsha:x:1000:1000:Aadarsha Khadka:/home/aadarsha:/bin/CASH
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat testdatafile 
i&amp;#39;m a good boy
this is the beautiful girl 
how are you 
is this your baby boy?
boy understand fundamental concepts
good morning 
why are visiting the USA?
Boy is running?
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sed -i &amp;#39;s/boy/BOY/g&amp;#39; testdatafile 

[aadarsha@labserver ~]$ cat testdatafile 
i&amp;#39;m a good BOY
this is the beautiful girl 
how are you 
is this your baby BOY?
BOY understand the fundamental concepts
good morning 
why are visiting the USA?
Boy is running?
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ 

# To search whole line

[aadarsha@labserver ~]$ grep &amp;#39;boy and&amp;#39; testdatafile 
[aadarsha@labserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="file-searching-and-finding"&gt;File Searching and finding&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# File Search

# Searching Files using &amp;#39;find&amp;#39; command
 
# find [path] [options] &amp;lt;argument&amp;gt;

# -atime &amp;lt;+N/-N/N&amp;gt; ---&amp;gt; performs access-time bases search (N--&amp;gt;Day)

# -mtime &amp;lt;+N/-N/N&amp;gt; ---&amp;gt; performs modification-time bases search (N--&amp;gt;Day)

# -ntime &amp;lt;name&amp;gt; ---&amp;gt; performs name-based bases search (case sensitive)
 
# -intime &amp;lt;name&amp;gt; ---&amp;gt; performs name-based bases search (case insensitive)

# -size &amp;lt;+N/-N/N&amp;gt; --&amp;gt; performs size-based search

# -user &amp;lt;owner&amp;gt; --&amp;gt; performs user-ownership based search

# -group &amp;lt;group&amp;gt; --&amp;gt; performs group-ownership based search

# -type &amp;lt;type&amp;gt; --&amp;gt; 

[aadarsha@labserver ~]$ find / -name passwd 2&amp;gt;/dev/null 
/sys/fs/selinux/class/passwd
/sys/fs/selinux/class/passwd/perms/passwd
/etc/passwd
/etc/pam.d/passwd
/usr/bin/passwd
/usr/share/bash-completion/completions/passwd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /etc -name passwd 2&amp;gt;/dev/null 
/etc/passwd
/etc/pam.d/passwd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ touch /tmp/passwd
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find / -name passwd 2&amp;gt;/dev/null 
/sys/fs/selinux/class/passwd
/sys/fs/selinux/class/passwd/perms/passwd
/tmp/passwd
/etc/passwd
/etc/pam.d/passwd
/usr/bin/passwd
/usr/share/bash-completion/completions/passwd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ touch /tmp/Passwd
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find / -name passwd 2&amp;gt;/dev/null 
/sys/fs/selinux/class/passwd
/sys/fs/selinux/class/passwd/perms/passwd
/tmp/passwd
/etc/passwd
/etc/pam.d/passwd
/usr/bin/passwd
/usr/share/bash-completion/completions/passwd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find / -iname passwd 2&amp;gt;/dev/null 
/sys/fs/selinux/class/passwd
/sys/fs/selinux/class/passwd/perms/passwd
/tmp/passwd
/tmp/Passwd
/etc/passwd
/etc/pam.d/passwd
/usr/bin/passwd
/usr/share/bash-completion/completions/passwd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find / -iname passwd 2&amp;gt;/dev/null | wc -l
8
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find / -name passwd 2&amp;gt;/dev/null | wc -l
7
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find / -atime -7 | wc -l
find: ‘/boot/efi/EFI/centos’: Permission denied
find: ‘/boot/grub2’: Permission denied
find: ‘/boot/loader/entries’: Permission denied
find: ‘/proc/tty/driver’: Permission denied
find: ‘/proc/1/task/1/fd’: Permission denied
...
find: ‘/usr/libexec/initscripts/legacy-actions/auditd’: Permission denied
find: ‘/home/aadarsha/extracted/var/log/private’: Permission denied
find: ‘/home/aadarsha/extracted/var/log/samba’: Permission denied
find: ‘/home/aadarsha/extracted/var/log/audit’: Permission denied
find: ‘/home/aadarsha/extracted/var/log/sssd’: Permission denied
find: ‘/home/aadarsha/extracted/var/log/chrony’: Permission denied
87254
[aadarsha@labserver ~]$

[aadarsha@labserver ~]$ find / -atime -7 2&amp;gt;/dev/null | wc -l
87254
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find / -mtime -7 2&amp;gt;/dev/null | wc -l # modified
77799
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find /etc -mtime -7 2&amp;gt;/dev/null | wc -l # modified
7
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ find /etc -atime -7 2&amp;gt;/dev/null | wc -l # accessed
685
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /etc -mtime -7 2&amp;gt;/dev/null # modified
/etc
/etc/resolv.conf
/etc/profile.d
/etc/bashrc
/etc/profile
/etc/ld.so.cache
/etc/pkgconfig
[aadarsha@labserver ~]$ 

# focused auditing and non focused auditing in security auditing

# focused auditing and non-focused auditing in security auditing

# safety and performance can not be achieved at a time


# finding based on size

[aadarsha@labserver ~]$ ls /var/l
lib/ local/ lock/ log/ 
[aadarsha@labserver ~]$ ls /var/log/
anaconda cron-20260611 hawkey.log messages secure-20260611
audit dnf.librepo.log hawkey.log-20260611 messages-20260611 spooler
btmp dnf.log lastlog private spooler-20260611
chrony dnf.rpm.log maillog samba sssd
cron firewalld maillog-20260611 secure wtmp
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /var -size +10M &amp;gt;/dev/null 
find: ‘/var/lib/selinux/targeted/active’: Permission denied
find: ‘/var/lib/selinux/final’: Permission denied
find: ‘/var/lib/private’: Permission denied
...
find: ‘/var/tmp/systemd-private-6d5f834212da46da9320190dce0efa12-systemd-logind.service-WsqjBK’: Permission denied
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /var -size +10M 2&amp;gt;/dev/null 
/var/cache/dnf/appstream-25519c512d836b42/repodata/28fcbe99d124870c057e25d821ae6d6d4c8fa1e58c8609ffe3511cdf0fd53b66-filelists.xml.gz
/var/cache/dnf/appstream-filenames.solvx
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ find /var -size +10M 2&amp;gt;/dev/null 
/var/cache/dnf/appstream-25519c512d836b42/repodata/28fcbe99d124870c057e25d821ae6d6d4c8fa1e58c8609ffe3511cdf0fd53b66-filelists.xml.gz
/var/cache/dnf/appstream-filenames.solvx
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -lh /var/cache/dnf/appstream-25519c512d836b42/repodata/28fcbe99d124870c057e25d821ae6d6d4c8fa1e58c8609ffe3511cdf0fd53b66-filelists.xml.gz 
-rw-r--r--. 1 root root 16M Jun 8 09:51 /var/cache/dnf/appstream-25519c512d836b42/repodata/28fcbe99d124870c057e25d821ae6d6d4c8fa1e58c8609ffe3511cdf0fd53b66-filelists.xml.gz
[aadarsha@labserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Practice 006 — Working with Vi Editor</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-007/</link><pubDate>Thu, 11 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-007/</guid><description>&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# Modes of vi editor
# 1. Insert Mode
# 2. Command Mode
# 3. Ex Mode
# 4. Visual Mode


# 1. Insert Mode
# i
# ESC
# :wq OR :x --&amp;gt; Save &amp;amp; Exit


# 2. Command Mode
# cursor movement

# G --&amp;gt; move to the bottom of the file
# gg --&amp;gt; Move to the top 

# &amp;#39;N&amp;#39;G --&amp;gt; Move to the n(th) line

[aadarsha@labserver ~]$ ls
dir1 extracted newimpfiles.tar.gz testfile words.gz
dira impfiles.tar testcompany words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cp /etc/passwd .

[aadarsha@labserver ~]$ ls
dir1 extracted newimpfiles.tar.gz testcompany words
dira impfiles.tar passwd testfile words.gz
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi passwd
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ cd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi .vimrc
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ source .vimrc 
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sudo su
[sudo] password for aadarsha: 
[root@labserver aadarsha]# 
 
# vi
# vim = vi + extra features
[root@labserver aadarsha]# 

[root@labserver aadarsha]# yum list vim*
...
[root@labserver aadarsha]# 

[root@labserver aadarsha]# exit
exit
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 extracted newimpfiles.tar.gz testcompany words
dira impfiles.tar passwd testfile words.gz

[aadarsha@labserver ~]$ ls -la
total 18544
drwx------. 6 aadarsha aadarsha 4096 Jun 9 05:19 .
drwxr-xr-x. 3 root root 22 May 26 15:36 ..
-rw-------. 1 aadarsha aadarsha 16303 Jun 8 22:34 .bash_history
-rw-r--r--. 1 aadarsha aadarsha 18 Oct 29 2024 .bash_logout
-rw-r--r--. 1 aadarsha aadarsha 144 Oct 29 2024 .bash_profile
-rw-r--r--. 1 aadarsha aadarsha 609 Jun 8 07:20 .bashrc
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
drwxr-xr-x. 4 root root 28 Jun 8 20:16 extracted
-rw-r--r--. 1 root root 11704320 Jun 8 16:38 impfiles.tar
-rw-------. 1 aadarsha aadarsha 51 Jun 8 21:54 .lesshst
-rw-r--r--. 1 root root 784897 Jun 8 16:33 newimpfiles.tar.gz
-rw-r--r--. 1 aadarsha aadarsha 1080 Jun 9 05:17 passwd
-rw-r--r--. 1 aadarsha aadarsha 24 Jun 7 07:54 .secretdata
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile
-rw-------. 1 aadarsha aadarsha 7727 Jun 8 08:47 .viminfo
-rw-r--r--. 1 aadarsha aadarsha 11 Jun 9 05:18 .vimrc
-rw-r--r--. 1 aadarsha aadarsha 4953598 Jun 8 09:52 words
-rw-r--r--. 1 aadarsha aadarsha 1476067 Jun 8 12:09 words.gz
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vim .vimrc 

[aadarsha@labserver ~]$ vi passwd 

[aadarsha@labserver ~]$ cat .vimrc 
set number
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -a
. .bash_logout dir1 impfiles.tar passwd testfile words
.. .bash_profile dira .lesshst .secretdata .viminfo words.gz
.bash_history .bashrc extracted newimpfiles.tar.gz testcompany .vimrc
[aadarsha@labserver ~]$ vi .vimrc 

[aadarsha@labserver ~]$ vi passwd 

[aadarsha@labserver ~]$ vi .vimrc 

[aadarsha@labserver ~]$ vi .vimrc

[aadarsha@labserver ~]$ cat .vimrc 
set nu
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi passwd 

# not working above --&amp;gt; set number permanently 

[aadarsha@labserver ~]$ vi +10 passwd # set cursor in line number 10

[aadarsha@labserver ~]$ vi +18 passwd # set cursor in line number 18

 
# Delete, Copy and Paste

# yy --&amp;gt; copy the current line

# &amp;#39;N&amp;#39;yy --&amp;gt; copy the next N lines

# dd --&amp;gt; Delete the current line

# &amp;#39;N&amp;#39;dd --&amp;gt; Delete the next N lines

# p --&amp;gt; To paste the copied/deleted text

# u --&amp;gt; To undo the last change

# CTRL + r --&amp;gt; To redo the last change

[aadarsha@labserver ~]$ vi passwd 


# Ex Mode

# Searching Text

# /&amp;lt;text&amp;gt;

# n --&amp;gt; next 

# N --&amp;gt; backward next

# same as in man page

# Search and Replace Text

# :%s/current text/new text/c --&amp;gt; search and replace in the whole file with confirmation

# :%s/current text/new text/g --&amp;gt; search and replace in the whole file without confirmation

# :%5,15s/current text/new text/ c or g --&amp;gt; search and replace in the whole file with or without confirmation in the given lines

[aadarsha@labserver ~]$ vi passwd 

# Visual Mode

[aadarsha@labserver ~]$ vi passwd 

# v --&amp;gt; line oriented mode
# V --&amp;gt; Block oriented visual mode

# y --&amp;gt; 
# d --&amp;gt; 
# p --&amp;gt;

[aadarsha@labserver ~]$ vi passwd 

# V --&amp;gt; line oriented visual mode

# v --&amp;gt; line oriented mode

[aadarsha@labserver ~]$ vi passwd 

# Password Protect a file

[aadarsha@labserver ~]$ vi secret_data

[aadarsha@labserver ~]$ ls
dir1 extracted newimpfiles.tar.gz secret_data testfile words.gz
dira impfiles.tar passwd testcompany words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat secret_data 
this is secret file
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi secret_data 

[aadarsha@labserver ~]$ vim passwd 

[aadarsha@labserver ~]$ vim passwd 

[aadarsha@labserver ~]$ vi secret_data 

[aadarsha@labserver ~]$ vi secret_data 

[aadarsha@labserver ~]$ alias vi=&amp;#39;vim&amp;#39;

[aadarsha@labserver ~]$ vi secret_data 

[aadarsha@labserver ~]$ vi secret_data 
 
[aadarsha@labserver ~]$ vi secret_data 

[aadarsha@labserver ~]$ vi secret_data 

[aadarsha@labserver ~]$ vim .bashrc 

[aadarsha@labserver ~]$ sudo su
[sudo] password for aadarsha: 
[root@labserver aadarsha]# 

[root@labserver aadarsha]# vim .bashrc 
[root@labserver aadarsha]# exit
exit
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi secret_data 
[aadarsha@labserver ~]$ 

# File Recovery after crash

[aadarsha@labserver ~]$ whoami
aadarsha
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 extracted newimpfiles.tar.gz secret_data testfile words.gz
dira impfiles.tar passwd testcompany words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ rm -r newimpfiles.tar.gz words.gz impfiles.tar 
rm: remove write-protected regular file &amp;#39;newimpfiles.tar.gz&amp;#39;? 
rm: remove regular file &amp;#39;words.gz&amp;#39;? y
rm: remove write-protected regular file &amp;#39;impfiles.tar&amp;#39;? y
[aadarsha@labserver ~]$ y
-bash: y: command not found
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ rm -r newimpfiles.tar.gz words.gz impfiles.tar 
rm: remove write-protected regular file &amp;#39;newimpfiles.tar.gz&amp;#39;? y
rm: cannot remove &amp;#39;words.gz&amp;#39;: No such file or directory
rm: cannot remove &amp;#39;impfiles.tar&amp;#39;: No such file or directory
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira extracted passwd secret_data testcompany testfile words
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ ls
dir1 dira extracted passwd secret_data testcompany testfile words
[aadarsha@labserver ~]$ 

# swap file or guard file --&amp;gt; created to protect the currently opening file when sudden incident like poweroff or terminate 

# recover from .swp file

# vir -r passwd.swp

[aadarsha@labserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Practice 006 — Linux Basic Information &amp; Getting Help</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-006/</link><pubDate>Wed, 10 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-006/</guid><description>&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;h4 id="getting-some-information"&gt;Getting some information&lt;/h4&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# Displays the system&amp;#39;s network hostname.

[aadarsha@labserver ~]$ hostname
labserver
[aadarsha@labserver ~]$

[aadarsha@labserver ~]$ cat /etc/redhat-release 
CentOS Stream release 10 (Coughlan)
[aadarsha@labserver ~]$ 

# Show comprehensive system information including OS version, kernel, and virtualization details.

[root@labserver ~]# hostnamectl
 Static hostname: labserver
 Icon name: computer-vm
 Chassis: vm 🖴
 Machine ID: 6051312a1e194d8ga01bc1948bcb0427
 Boot ID: 9299b2f276724g30b3efeb72835f0131
 Product UUID: 28702045-a8d5-de9b-a9ca-a7526d5a6ece
 Virtualization: oracle
Operating System: CentOS Stream 10 (Coughlan) 
 CPE OS Name: cpe:/o:centos:centos:10
 Kernel: Linux 6.12.0-228.el10.x86_64
 Architecture: x86-64
 Hardware Vendor: innotek GmbH
 Hardware Model: VirtualBox
 Hardware Serial: VirtualBox-45206028-d5a9-7bde-a5ca-a7526d7a6ece
Firmware Version: VirtualBox
 Firmware Date: Fri 2006-12-01
 Firmware Age: 19y 7month 2w 2d 
[root@labserver ~]# 

# Shows only kernel version

[aadarsha@labserver ~]$ uname -r
6.12.0-228.el10.x86_64
[aadarsha@labserver ~]$

# Show complete system information

[aadarsha@labserver ~]$ uname -a
Linux labserver 6.12.0-228.el10.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 14 14:51:31 UTC 2026 x86_64 GNU/Linux
[aadarsha@labserver ~]$ 

# Show Linux distribution details

[aadarsha@labserver ~]$ cat /etc/os-release
NAME=&amp;#34;CentOS Stream&amp;#34;
VERSION=&amp;#34;10 (Coughlan)&amp;#34;
RELEASE_TYPE=stable
ID=&amp;#34;centos&amp;#34;
ID_LIKE=&amp;#34;rhel fedora&amp;#34;
VERSION_ID=&amp;#34;10&amp;#34;
PLATFORM_ID=&amp;#34;platform:el10&amp;#34;
PRETTY_NAME=&amp;#34;CentOS Stream 10 (Coughlan)&amp;#34;
ANSI_COLOR=&amp;#34;0;31&amp;#34;
LOGO=&amp;#34;fedora-logo-icon&amp;#34;
CPE_NAME=&amp;#34;cpe:/o:centos:centos:10&amp;#34;
HOME_URL=&amp;#34;https://centos.org/&amp;#34;
VENDOR_NAME=&amp;#34;CentOS&amp;#34;
VENDOR_URL=&amp;#34;https://centos.org/&amp;#34;
BUG_REPORT_URL=&amp;#34;https://issues.redhat.com/&amp;#34;
REDHAT_SUPPORT_PRODUCT=&amp;#34;Red Hat Enterprise Linux 10&amp;#34;
REDHAT_SUPPORT_PRODUCT_VERSION=&amp;#34;CentOS Stream&amp;#34;
[aadarsha@labserver ~]$ 

# Shows current username

[aadarsha@labserver ~]$ whoami
aadarsha
[aadarsha@labserver ~]$ 

# Shows user ID, group ID, and group memberships

[aadarsha@labserver ~]$ id
uid=1000(aadarsha) gid=1000(aadarsha) groups=1000(aadarsha),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[aadarsha@labserver ~]$ 

# Show current directory

[aadarsha@labserver ~]$ pwd
/home/aadarsha
[aadarsha@labserver ~]$ 

# Detailed memory statistics from the kernel

[aadarsha@labserver ~]$ cat /proc/meminfo | head
MemTotal: 1745836 kB
MemFree: 1304920 kB
MemAvailable: 1380824 kB
Buffers: 5304 kB
Cached: 198944 kB
SwapCached: 0 kB
Active: 190272 kB
Inactive: 94280 kB
Active(anon): 85168 kB
Inactive(anon): 0 kB
[aadarsha@labserver ~]$ 

# Number of processing units

[aadarsha@labserver ~]$ nproc
2
[aadarsha@labserver ~]$ 

# Shows block devices (disks and partitions) in a tree format
# LVM (Logical Volume Manager) is being used for flexible storage management

[aadarsha@labserver ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 25.1G 0 disk 
├─sda1 8:1 0 2M 0 part 
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 24G 0 part 
 ├─cs-root 253:0 0 17G 0 lvm /
 ├─cs-swap 253:1 0 2G 0 lvm [SWAP]
 └─cs-var 253:2 0 5G 0 lvm /var
sr0 11:0 1 1024M 0 rom 
[aadarsha@labserver ~]$

# Shows mounted filesystems

[aadarsha@labserver ~]$ mount | head
/dev/mapper/cs-root on / type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=849912k,nr_inodes=212478,mode=755,inode64)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel,inode64,usrquota)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,seclabel,nsdelegate,memory_recursiveprot)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime,seclabel)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
[aadarsha@labserver ~]$ 



# Memory Information

[aadarsha@labserver ~]$ free -h
 total used free shared buff/cache available
Mem: 1.7Gi 363Mi 1.1Gi 4.8Mi 308Mi 1.3Gi
Swap: 2.0Gi 0B 2.0Gi
[aadarsha@labserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Field&lt;/th&gt;
					&lt;th&gt;Meaning&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;total&lt;/td&gt;
					&lt;td&gt;Total installed RAM&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;used&lt;/td&gt;
					&lt;td&gt;Memory currently used&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;free&lt;/td&gt;
					&lt;td&gt;Completely unused memory&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;shared&lt;/td&gt;
					&lt;td&gt;Shared memory&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;buff/cache&lt;/td&gt;
					&lt;td&gt;Memory used by kernel cache&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;available&lt;/td&gt;
					&lt;td&gt;Memory available for new processes&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Swap&lt;/td&gt;
					&lt;td&gt;Swap partition usage&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# Disk Information

[aadarsha@labserver ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cs-root 16G 1.6G 15G 10% /
devtmpfs 830M 0 830M 0% /dev
tmpfs 853M 0 853M 0% /dev/shm
tmpfs 341M 4.9M 337M 2% /run
tmpfs 1.0M 0 1.0M 0% /run/credentials/systemd-journald.service
/dev/sda2 2.0G 405M 1.6G 21% /boot
tmpfs 1.0M 0 1.0M 0% /run/credentials/getty@tty1.service
tmpfs 171M 4.0K 171M 1% /run/user/1000
[aadarsha@labserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;&lt;table&gt;
	&lt;thead&gt;
			&lt;tr&gt;
					&lt;th&gt;Field&lt;/th&gt;
					&lt;th&gt;Meaning&lt;/th&gt;
			&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
			&lt;tr&gt;
					&lt;td&gt;Filesystem&lt;/td&gt;
					&lt;td&gt;Mounted filesystem&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Size&lt;/td&gt;
					&lt;td&gt;Total filesystem size&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Used&lt;/td&gt;
					&lt;td&gt;Used space&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Avail&lt;/td&gt;
					&lt;td&gt;Available space&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Use%&lt;/td&gt;
					&lt;td&gt;Percentage used&lt;/td&gt;
			&lt;/tr&gt;
			&lt;tr&gt;
					&lt;td&gt;Mounted on&lt;/td&gt;
					&lt;td&gt;Mount point&lt;/td&gt;
			&lt;/tr&gt;
	&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# Detailed CPU architecture information.

[aadarsha@labserver ~]$ lscpu
Architecture: x86_64
 CPU op-mode(s): 32-bit, 64-bit
 Address sizes: 39 bits physical, 48 bits virtual
 Byte Order: Little Endian
CPU(s): 2
 On-line CPU(s) list: 0,1
Vendor ID: GenuineIntel
 Model name: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
 CPU family: 6
 Model: 140
 Thread(s) per core: 1
 Core(s) per socket: 2
 Socket(s): 1
 Stepping: 1
 BogoMIPS: 4838.46
 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology n
 onstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefet
 ch fsgsbase bmi1 avx2 bmi2 invpcid rdseed adx clflushopt sha_ni arat md_clear flush_l1d arch_capabilities
Virtualization features: 
 Hypervisor vendor: KVM
 Virtualization type: full
Caches (sum of all): 
 L1d: 96 KiB (2 instances)
 L1i: 64 KiB (2 instances)
 L2: 2.5 MiB (2 instances)
 L3: 16 MiB (2 instances)
NUMA: 
 NUMA node(s): 1
 NUMA node0 CPU(s): 0,1
Vulnerabilities: 
 Gather data sampling: Unknown: Dependent on hypervisor status
 Indirect target selection: Mitigation; Aligned branch/return thunks
 Itlb multihit: Not affected
 L1tf: Not affected
 Mds: Not affected
 Meltdown: Not affected
 Mmio stale data: Not affected
 Old microcode: Not affected
 Reg file data sampling: Not affected
 Retbleed: Not affected
 Spec rstack overflow: Not affected
 Spec store bypass: Vulnerable
 Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
 Spectre v2: Mitigation; Retpolines; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Retpoline
 Srbds: Not affected
 Tsa: Not affected
 Tsx async abort: Not affected
 Vmscape: Not affected
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ stat testfile 
 File: testfile
 Size: 56 	Blocks: 8 IO Block: 4096 regular file
Device: 253,0	Inode: 526546 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/aadarsha) Gid: ( 1000/aadarsha)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2026-06-07 21:33:39.784384746 +0545
Modify: 2026-06-07 21:33:34.476381274 +0545
Change: 2026-06-07 21:33:34.476381274 +0545
 Birth: 2026-06-07 09:23:07.596008113 +0545
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ stat impfiles.tar 
 File: impfiles.tar
 Size: 11704320 	Blocks: 22864 IO Block: 4096 regular file
Device: 253,0	Inode: 527801 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2026-06-08 16:35:14.826687643 +0545
Modify: 2026-06-08 16:38:29.505323470 +0545
Change: 2026-06-08 16:38:29.505323470 +0545
 Birth: 2026-06-08 16:34:03.703711086 +0545
[aadarsha@labserver ~]$

[aadarsha@labserver ~]$ ls -lh dir1/
total 0
drwxr-xr-x. 3 aadarsha aadarsha 18 Jun 7 15:41 dir2
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 7 15:48 numfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -lh dira
total 4.8M
drwxr-xr-x. 3 aadarsha aadarsha 18 Jun 8 07:50 dirb
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 7 16:10 letfile
-rw-r--r--. 1 aadarsha aadarsha 73 Jun 8 08:47 myfile_hard
-rw-r--r--. 1 aadarsha aadarsha 4.8M Jun 8 09:52 words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -ld dira
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -ld dira # to see the details of the directory itself
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ stat dira
 File: dira
 Size: 65 	Blocks: 0 IO Block: 4096 directory
Device: 253,0	Inode: 25447633 Links: 3
Access: (0755/drwxr-xr-x) Uid: ( 1000/aadarsha) Gid: ( 1000/aadarsha)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2026-06-08 12:07:35.289248194 +0545
Modify: 2026-06-08 12:07:19.877766384 +0545
Change: 2026-06-08 12:07:19.877766384 +0545
 Birth: 2026-06-07 15:42:17.367604410 +0545
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ file testfile 
testfile: ASCII text
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ file words.gz 
words.gz: gzip compressed data, was &amp;#34;words&amp;#34;, last modified: Mon Jun 8 04:07:53 2026, from Unix, original size modulo 2^32 4953598
[aadarsha@labserver ~]$

[aadarsha@labserver ~]$ file newimpfiles.tar.gz 
newimpfiles.tar.gz: gzip compressed data, from Unix, original size modulo 2^32 6737920
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ 
 
# note: /etc/skel/ --&amp;gt; contains .bashrc ( main location which contain .bashrc, which comes in the user&amp;#39;s home directory when the user is created )

# cp /etc/skel/.bashrc . ( copy .bashrc here )


-------------------------------------------------------------------------------------------------

[aadarsha@labserver ~]$ ls
dir1 dira extracted impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -l /etc/
total 1048
-rw-r--r--. 1 root root 16 May 26 15:36 adjtime
-rw-r--r--. 1 root root 1529 Nov 29 2023 aliases
drwxr-xr-x. 2 root root 4096 May 26 15:34 alternatives
-rw-r--r--. 1 root root 541 Jan 14 05:45 anacrontab
drwxr-x---. 4 root root 100 May 26 15:33 audit
drwxr-xr-x. 3 root root 4096 May 26 15:34 authselect
drwxr-xr-x. 2 root root 38 May 26 15:34 bash_completion.d
-rw-r--r--. 1 root root 2777 Jun 7 19:59 bashrc
-rw-r--r--. 1 root root 535 Oct 29 2024 bindresvport.blacklist
drwxr-xr-x. 2 root root 6 May 12 05:45 binfmt.d
-rw-r--r--. 1 root root 36 Apr 7 05:45 centos-release
-rw-r--r--. 1 root root 1382 Nov 20 2025 chrony.conf
drwxr-xr-x. 2 root root 26 May 26 15:33 cifs-utils
drwx------. 2 root root 6 May 12 05:45 credstore
drwx------. 2 root root 6 May 12 05:45 credstore.encrypted
drwxr-xr-x. 2 root root 21 May 26 15:33 cron.d
drwxr-xr-x. 2 root root 6 Oct 29 2024 cron.daily
-rw-r--r--. 1 root root 0 Jan 14 05:45 cron.deny
drwxr-xr-x. 2 root root 22 Oct 29 2024 cron.hourly
drwxr-xr-x. 2 root root 6 Oct 29 2024 cron.monthly
-rw-r--r--. 1 root root 451 Oct 29 2024 crontab
drwxr-xr-x. 2 root root 6 Oct 29 2024 cron.weekly
drwxr-xr-x. 6 root root 81 May 26 15:33 crypto-policies
-rw-------. 1 root root 0 May 26 15:32 crypttab
-rw-r--r--. 1 root root 1401 Nov 29 2023 csh.cshrc
-rw-r--r--. 1 root root 1569 Nov 29 2023 csh.login
drwxr-xr-x. 4 root root 78 May 26 15:33 dbus-1
drwxr-xr-x. 3 root root 16 May 26 15:34 dconf
drwxr-xr-x. 2 root root 52 May 26 15:33 debuginfod
drwxr-xr-x. 2 root root 33 May 26 15:36 default
drwxr-xr-x. 2 root root 23 May 26 15:33 depmod.d
drwxr-xr-x. 3 root root 24 May 26 15:33 dhcp
-rw-r--r--. 1 root root 5923 Jan 15 05:45 DIR_COLORS
-rw-r--r--. 1 root root 6005 Jan 15 05:45 DIR_COLORS.lightbgcolor
drwxr-xr-x. 9 root root 163 May 26 15:33 dnf
-rw-r--r--. 1 root root 117 Jan 30 05:45 dracut.conf
drwxr-xr-x. 2 root root 6 Jan 30 05:45 dracut.conf.d
-rw-r--r--. 1 root root 0 Apr 8 2025 environment
-rw-r--r--. 1 root root 1362 Nov 29 2023 ethertypes
-rw-r--r--. 1 root root 0 Nov 29 2023 exports
-rw-r--r--. 1 root root 66 Nov 29 2023 filesystems
drwxr-x---. 8 root root 119 May 26 15:33 firewalld
drwxr-xr-x. 3 root root 20 May 26 15:33 fonts
-rw-r--r--. 1 root root 615 May 26 15:32 fstab
-rw-r--r--. 1 root root 94 Oct 29 2024 GREP_COLORS
drwxr-xr-x. 4 root root 40 May 26 15:33 groff
-rw-r--r--. 1 root root 518 May 26 15:36 group
-rw-r--r--. 1 root root 493 May 26 15:36 group-
lrwxrwxrwx. 1 root root 22 Feb 10 05:45 grub2.cfg -&amp;gt; ../boot/grub2/grub.cfg
drwx------. 2 root root 4096 May 26 15:33 grub.d
----------. 1 root root 412 May 26 15:36 gshadow
----------. 1 root root 391 May 26 15:36 gshadow-
drwxr-xr-x. 3 root root 20 May 26 15:33 gss
-rw-r--r--. 1 root root 9 Nov 29 2023 host.conf
-rw-r--r--. 1 root root 10 May 26 15:36 hostname
-rw-r--r--. 1 root root 384 Nov 29 2023 hosts
-rw-r--r--. 1 root root 490 May 12 05:45 inittab
-rw-r--r--. 1 root root 943 Nov 29 2023 inputrc
drwxr-xr-x. 2 root root 20 May 26 15:33 iproute2
-rw-r--r--. 1 root root 20 Apr 7 05:45 issue
drwxr-xr-x. 2 root root 6 Apr 7 05:45 issue.d
-rw-r--r--. 1 root root 19 Apr 7 05:45 issue.net
drwxr-xr-x. 4 root root 33 May 26 15:33 kdump
-rw-r--r--. 1 root root 8782 May 26 15:33 kdump.conf
drwxr-xr-x. 3 root root 38 May 26 15:36 kernel
drwxr-xr-x. 3 root root 17 May 26 15:33 keys
drwxr-xr-x. 2 root root 6 Oct 29 2024 keyutils
-rw-r--r--. 1 root root 880 Apr 28 05:45 krb5.conf
drwxr-xr-x. 2 root root 55 May 26 15:33 krb5.conf.d
-rw-r--r--. 1 root root 13567 Jun 8 16:27 ld.so.cache
-rw-r--r--. 1 root root 28 Feb 1 2024 ld.so.conf
drwxr-xr-x. 2 root root 6 May 11 05:45 ld.so.conf.d
-rw-r-----. 1 root root 191 Jan 6 05:45 libaudit.conf
drwxr-xr-x. 2 root root 35 May 26 15:33 libnl
drwxr-xr-x. 2 root root 62 May 26 15:33 libssh
-rw-r--r--. 1 root root 19 May 26 15:36 locale.conf
lrwxrwxrwx. 1 root root 36 May 26 15:36 localtime -&amp;gt; ../usr/share/zoneinfo/Asia/Kathmandu
-rw-r--r--. 1 root root 8888 Feb 23 05:45 login.defs
-rw-r--r--. 1 root root 493 Jul 5 2021 logrotate.conf
drwxr-xr-x. 2 root root 128 May 26 15:33 logrotate.d
drwxr-xr-x. 7 root root 115 May 26 15:33 lvm
-r--r--r--. 1 root root 33 May 26 15:33 machine-id
-rw-r--r--. 1 root root 110 May 11 05:45 magic
-rw-r--r--. 1 root root 5122 Nov 3 2025 makedumpfile.conf.sample
-rw-r--r--. 1 root root 5242 Jun 10 2025 man_db.conf
drwxr-xr-x. 3 root root 32 May 26 15:33 microcode_ctl
-rw-r--r--. 1 root root 782 Nov 19 2025 mke2fs.conf
drwxr-xr-x. 2 root root 4096 May 26 15:33 modprobe.d
drwxr-xr-x. 2 root root 6 May 12 05:45 modules-load.d
-rw-r--r--. 1 root root 0 Nov 29 2023 motd
drwxr-xr-x. 2 root root 6 Apr 8 2025 motd.d
lrwxrwxrwx. 1 root root 19 Mar 4 05:45 mtab -&amp;gt; ../proc/self/mounts
-rw-r--r--. 1 root root 767 Oct 29 2024 netconfig
drwxr-xr-x. 7 root root 134 May 26 15:33 NetworkManager
-rw-r--r--. 1 root root 58 Nov 29 2023 networks
drwx------. 3 root root 66 May 26 15:33 nftables
lrwxrwxrwx. 1 root root 29 May 26 15:34 nsswitch.conf -&amp;gt; /etc/authselect/nsswitch.conf
drwxr-xr-x. 2 root root 35 May 26 15:32 nvme
drwxr-xr-x. 3 root root 36 May 26 15:33 openldap
drwxr-xr-x. 2 root root 6 Apr 2 2025 opt
lrwxrwxrwx. 1 root root 21 Apr 7 05:45 os-release -&amp;gt; ../usr/lib/os-release
drwxr-xr-x. 2 root root 4096 May 26 15:34 pam.d
-rw-r--r--. 1 root root 1080 May 26 15:36 passwd
-rw-r--r--. 1 root root 1018 May 26 15:36 passwd-
drwxr-xr-x. 3 root root 21 May 26 15:33 pkcs11
drwxr-xr-x. 3 root root 27 Jun 7 18:08 pkgconfig
drwxr-xr-x. 7 root root 75 May 26 15:33 pki
drwxr-xr-x. 5 root root 52 May 26 15:33 pm
drwxr-xr-x. 2 root root 6 Oct 29 2024 popt.d
-rw-r--r--. 1 root root 233 Nov 29 2023 printcap
-rw-r--r--. 1 root root 1982 Nov 29 2023 profile
drwxr-xr-x. 2 root root 4096 Jun 7 18:08 profile.d
-rw-r--r--. 1 root root 6714 Nov 29 2023 protocols
drwxr-xr-x. 3 root root 36 May 26 15:33 rc.d
lrwxrwxrwx. 1 root root 13 May 12 05:45 rc.local -&amp;gt; rc.d/rc.local
lrwxrwxrwx. 1 root root 14 Apr 7 05:45 redhat-release -&amp;gt; centos-release
-rw-r--r--. 1 root root 1787 Oct 29 2024 request-key.conf
drwxr-xr-x. 2 root root 6 Oct 29 2024 request-key.d
-rw-r--r--. 1 root root 57 Jun 8 15:59 resolv.conf
-rw-r--r--. 1 root root 1634 Jan 31 2024 rpc
drwxr-xr-x. 2 root root 6 Feb 5 05:45 rpm
-rw-r--r--. 1 root root 3300 Apr 29 05:45 rsyslog.conf
drwxr-xr-x. 2 root root 6 Apr 29 05:45 rsyslog.d
drwxr-xr-x. 2 root root 35 May 26 15:33 rwtab.d
drwxr-xr-x. 2 root root 61 May 26 15:33 samba
drwxr-xr-x. 2 root root 6 Dec 4 2024 sasl2
drwxr-xr-x. 5 root root 4096 May 26 15:33 security
drwxr-xr-x. 3 root root 57 May 26 15:33 selinux
-rw-r--r--. 1 root root 701707 Nov 29 2023 services
-rw-r--r--. 1 root root 216 Apr 7 05:45 sestatus.conf
----------. 1 root root 669 May 26 15:37 shadow
----------. 1 root root 674 May 26 15:37 shadow-
-rw-r--r--. 1 root root 44 Nov 29 2023 shells
drwxr-xr-x. 2 root root 62 May 26 15:33 skel
drwxr-xr-x. 4 root root 4096 May 26 15:39 ssh
drwxr-xr-x. 2 root root 91 May 26 15:33 ssl
drwxr-x---. 4 root sssd 31 May 26 15:33 sssd
drwxr-xr-x. 2 root root 6 Apr 2 2025 statetab.d
-rw-r--r--. 1 root root 22 May 26 15:36 subgid
-rw-r--r--. 1 root root 0 Nov 29 2023 subgid-
-rw-r--r--. 1 root root 22 May 26 15:36 subuid
-rw-r--r--. 1 root root 0 Nov 29 2023 subuid-
-rw-r-----. 1 root root 4356 Apr 10 05:45 sudo.conf
-r--r-----. 1 root root 4328 Apr 10 05:45 sudoers
drwxr-x---. 2 root root 6 Apr 10 05:45 sudoers.d
-rw-r-----. 1 root root 3181 Apr 10 05:45 sudo-ldap.conf
drwxr-xr-x. 2 root root 4096 May 26 15:36 sysconfig
-rw-r--r--. 1 root root 449 May 12 05:45 sysctl.conf
drwxr-xr-x. 2 root root 28 May 26 15:33 sysctl.d
drwxr-xr-x. 5 root root 47 May 26 15:33 systemd
lrwxrwxrwx. 1 root root 14 Apr 7 05:45 system-release -&amp;gt; centos-release
-rw-r--r--. 1 root root 24 Apr 7 05:45 system-release-cpe
drwxr-xr-x. 2 root root 6 Mar 24 05:45 terminfo
drwxr-xr-x. 2 root root 6 May 12 05:45 tmpfiles.d
drwxr-xr-x. 3 root root 51 May 26 15:33 tpm2-tss
drwxr-xr-x. 4 root root 51 May 26 15:39 udev
-rw-r--r--. 1 root root 28 May 26 15:36 vconsole.conf
-rw-r--r--. 1 root root 4017 May 27 05:45 vimrc
-rw-r--r--. 1 root root 1183 May 27 05:45 virc
drwxr-xr-x. 6 root root 70 May 26 15:36 X11
-rw-r--r--. 1 root root 817 Oct 29 2024 xattr.conf
drwxr-xr-x. 4 root root 38 May 26 15:33 xdg
drwxr-xr-x. 2 root root 57 May 26 15:33 yum
lrwxrwxrwx. 1 root root 12 Mar 25 05:45 yum.conf -&amp;gt; dnf/dnf.conf
drwxr-xr-x. 2 root root 51 Apr 7 05:45 yum.repos.d
[aadarsha@labserver ~]$ 


# Getting Help 

[aadarsha@labserver ~]$ ls -l --color=auto
total 18488
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
drwxr-xr-x. 4 root root 28 Jun 8 20:16 extracted
-rw-r--r--. 1 root root 11704320 Jun 8 16:38 impfiles.tar
-rw-r--r--. 1 root root 784897 Jun 8 16:33 newimpfiles.tar.gz
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile
-rw-r--r--. 1 aadarsha aadarsha 4953598 Jun 8 09:52 words
-rw-r--r--. 1 aadarsha aadarsha 1476067 Jun 8 12:09 words.gz
[aadarsha@labserver ~]$ 

# using man command

[aadarsha@labserver ~]$ man ls

# search text in man page

# /text
 
# use n: next forward direction and N: backward direction

[aadarsha@labserver ~]$ man ls

[aadarsha@labserver ~]$ man ls

[aadarsha@labserver ~]$ ls -Sl /etc
total 1048
-rw-r--r--. 1 root root 701707 Nov 29 2023 services
...
...
-rw-r--r--. 1 root root 0 Nov 29 2023 subuid-
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ man ls

[aadarsha@labserver ~]$ ls -Slr /etc
total 1048
-rw-r--r--. 1 root root 0 Nov 29 2023 subuid-
...
...
-rw-r--r--. 1 root root 6714 Nov 29 2023 protocols
-rw-r--r--. 1 root root 8782 May 26 15:33 kdump.conf
-rw-r--r--. 1 root root 8888 Feb 23 05:45 login.defs
-rw-r--r--. 1 root root 13567 Jun 8 16:27 ld.so.cache
-rw-r--r--. 1 root root 701707 Nov 29 2023 services
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -S -l -r /etc
total 1048
-rw-r--r--. 1 root root 0 Nov 29 2023 subuid-
-rw-r--r--. 1 root root 0 Nov 29 2023 subgid-
-rw-r--r--. 1 root root 0 Nov 29 2023 motd
...
...
-rw-r--r--. 1 root root 701707 Nov 29 2023 services
[aadarsha@labserver ~]$ 

# man -k &amp;lt;key word related to task&amp;gt;

[aadarsha@labserver ~]$ man -k copy
cp (1) - copy files and directories
cpio (1) - copy files to and from archives
dd (1) - convert and copy a file
install (1) - copy files and set attributes
scp (1) - OpenSSH secure file copy
sg_copy_results (8) - send SCSI RECEIVE COPY RESULTS command (XCOPY related)
sg_dd (8) - copy data to and from files and devices, especially SCSI devices
sg_xcopy (8) - copy data to and from files and devices using SCSI EXTENDED COPY (XCOPY)
sgm_dd (8) - copy data to and from files and devices, especially SCSI devices
sgp_dd (8) - copy data to and from files and devices, especially SCSI devices
ssh-copy-id (1) - use locally available keys to authorise logins on a remote machine
xfs_copy (8) - copy the contents of an XFS filesystem
xfs_metadump (8) - copy XFS filesystem metadata to a file
xfs_rtcp (8) - XFS realtime copy command
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ man -k &amp;#34;copy file&amp;#34;
cp (1) - copy files and directories
cpio (1) - copy files to and from archives
install (1) - copy files and set attributes
[aadarsha@labserver ~]$ 


# practice: how to sort the output of ls -l /etc/ in descending order of files size

# getting online docs:
# docs.redhat.com
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Practice 005 — Compression and Archiving</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-005/</link><pubDate>Tue, 09 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-005/</guid><description>&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;h4 id="compression-and-archiving"&gt;Compression and Archiving&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;compression and archiving are different concepts&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Archiving packages files together.&lt;/li&gt;
&lt;li&gt;Compression reduces the size of the archive.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile
[aadarsha@labserver ~]$ 

# Compression

[root@labserver ~]# yum whatprovides /usr/share/dict/words
...

[root@labserver ~]# yum install -y words
Last metadata expiration check: 0:00:56 ago on Mon 08 Jun 2026 09:51:15 AM +0545.
Dependencies resolved.
...
Installed:
 words-3.0-47.el10.noarch 
Complete!
[root@labserver ~]# ls /usr/share/dict/
linux.words words
[root@labserver ~]# 

[root@labserver ~]# exit
logout
[aadarsha@labserver ~]$ cp /usr/share/dict/words .

[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -l words 
-rw-r--r--. 1 aadarsha aadarsha 4953598 Jun 8 09:52 words
[aadarsha@labserver ~]$ ls -lh words 
-rw-r--r--. 1 aadarsha aadarsha 4.8M Jun 8 09:52 words
[aadarsha@labserver ~]$ 

# we will use words to practice compression

# compression tools
 # 1. gzip (.gz) --&amp;gt; gunzip
 # 2. bzip2 (.) --&amp;gt; bunzip2
 # 2. bzip2 (.bz2) --&amp;gt; bunzip2
 # 3. zip (.zip) --&amp;gt; unzip2 # compatible to cross platform

 # Some history commands:

 ls -lh words 
 rpm -q gzip
 rpm -q bgzip2
 rpm -q bzip2
 rpm -q zip
 which gzip
 which gunzip
 which bzip2
 which zip
 su - root
 ls
 ll words 
 ll -h words 
 gzip words 
 ls
 ls -lh words.gz 
 gunzip words.gz 
 ls
 ls -lh words 
 gzip -v words 
 ls
 ls -lh words.gz 
 gunzip words.gz 
 ls
 bzip2 -v words 
 ls 
 ls -lh words.bz2 
 bunzip2 words.bz2 
 ls
 ls -lh words 
 ls
 zip -o compressed-words.zip words 
 ls
 ls -lh compressed-words.zip 
 unzip compressed-words.zip 
 ls
 unzip -l compressed-words.zip 
 unzip -v compressed-words.zip
 unzip -p compressed-words.zip
 history

[aadarsha@labserver ~]$ unzip -p compressed-words.zip words | head
1080
10-point
10th
11-point
12-point
16-point
18-point
1st
2
20-point
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ unzip -p compressed-words.zip words | head
1080
10-point
10th
11-point
12-point
16-point
18-point
1st
2
20-point
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
compressed-words.zip dir1 dira testcompany testfile words
[aadarsha@labserver ~]$ rm -r compressed-words.zip 
rm: remove regular file &amp;#39;compressed-words.zip&amp;#39;? y
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -lh words 
-rw-r--r--. 1 aadarsha aadarsha 4.8M Jun 8 09:52 words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ which gz
gzexe gzip 
[aadarsha@labserver ~]$ which gzip 
/usr/bin/gzip
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ gzip words 
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words.gz

[aadarsha@labserver ~]$ ll -lh words.gz 
-rw-r--r--. 1 aadarsha aadarsha 1.5M Jun 8 09:52 words.gz
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ gunzip words.gz words.gz 
gzip: words.gz: No such file or directory
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words
[aadarsha@labserver ~]$ gzip words 

[aadarsha@labserver ~]$ ls -lh words.gz 
-rw-r--r--. 1 aadarsha aadarsha 1.5M Jun 8 09:52 words.gz
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ gunzip words.gz 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ gzip -v words 
words:	 70.2% -- replaced with words.gz
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -lh words.gz 
-rw-r--r--. 1 aadarsha aadarsha 1.5M Jun 8 09:52 words.gz
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ gunzip words.gz 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words
[aadarsha@labserver ~]$

[aadarsha@labserver ~]$ bzip2 -v words 
 words: 2.893:1, 2.766 bits/byte, 65.43% saved, 4953598 in, 1712421 out.
[aadarsha@labserver ~]$ ls -lh words.bz2 
-rw-r--r--. 1 aadarsha aadarsha 1.7M Jun 8 09:52 words.bz2
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words.bz2
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -lh words.bz2 
-rw-r--r--. 1 aadarsha aadarsha 1.7M Jun 8 09:52 words.bz2
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ bunzip2 words.bz2 
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -lh words 
-rw-r--r--. 1 aadarsha aadarsha 4.8M Jun 8 09:52 words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ zip -o words.zip words 
 adding: words (deflated 70%)
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -l
total 6288
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 3 aadarsha aadarsha 52 Jun 8 09:39 dira
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile
-rw-r--r--. 1 aadarsha aadarsha 4953598 Jun 8 09:52 words
-rw-r--r--. 1 aadarsha aadarsha 1476203 Jun 8 09:52 words.zip
[aadarsha@labserver ~]$ ls -lh words
-rw-r--r--. 1 aadarsha aadarsha 4.8M Jun 8 09:52 words
[aadarsha@labserver ~]$

[aadarsha@labserver ~]$ ls -lh words.zip 
-rw-r--r--. 1 aadarsha aadarsha 1.5M Jun 8 09:52 words.zip
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ unzip words.zip 
Archive: words.zip
replace words? [y]es, [n]o, [A]ll, [N]one, [r]ename: N
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words words.zip
[aadarsha@labserver ~]$ unzip words.zip dira/
Archive: words.zip
caution: filename not matched: dira/
[aadarsha@labserver ~]$ unzip words.zip dira/words
Archive: words.zip
caution: filename not matched: dira/words
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words words.zip
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ unzip -l words.zip 
Archive: words.zip
 Length Date Time Name
--------- ---------- ----- ----
 4953598 06-08-2026 09:52 words
--------- -------
 4953598 1 file
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ unzip -v compressed-words.zip
unzip: cannot find or open compressed-words.zip, compressed-words.zip.zip or compressed-words.zip.ZIP.
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ unzip -v words.zip
Archive: words.zip
 Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
 4953598 Defl:N 1476043 70% 06-08-2026 09:52 b81d644b words
-------- ------- --- -------
 4953598 1476043 70% 1 file
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ unzip words.zip -d dira
Archive: words.zip
 inflating: dira/words 
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words words.zip
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls dira/
dirb letfile myfile_hard words
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words words.zip
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ rm -r words.zip 
rm: remove regular file &amp;#39;words.zip&amp;#39;? 
[aadarsha@labserver ~]$ rm -r words.zip 
rm: remove regular file &amp;#39;words.zip&amp;#39;? y
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ gzip -vc words &amp;gt;words.gz
words:	 70.2% -- replaced with stdout
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls 
dir1 dira testcompany testfile words words.gz
[aadarsha@labserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id="archiving"&gt;Archiving&lt;/h4&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# Archiving Files/Dirs (tar)

# what is archiving?
# --&amp;gt; 

# tar [options] &amp;lt;files/dirs to be archived&amp;gt;

# -c --&amp;gt; create archive
# -v --&amp;gt; verbose (show details)
# -f &amp;lt;archive filename&amp;gt; --&amp;gt; to define archive file 
# -t --&amp;gt; list contents of archive
# -r --&amp;gt; add new files into an archive 
# -z --&amp;gt; to compress archive using gzip ( use .tar.gz or .tgz filename extension )
# -j --&amp;gt; to compress archive using bgzip2 ( use .tar.gz2 or .tbz filename extension )

aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.170
aadarsha@192.168.254.170&amp;#39;s password: 
Last login: Mon Jun 8 16:00:16 2026 from 192.168.254.152
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words words.gz
[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile words words.gz
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Mon Jun 8 11:21:38 +0545 2026 on pts/1
[root@labserver ~]# 

# tar -cvf impfiles.tar # here -f must be at last after which we can write the file name

[root@labserver ~]# ls
anaconda-ks.cfg
[root@labserver ~]# cd /home/aadarsha/
[root@labserver aadarsha]# ls
dir1 dira testcompany testfile words words.gz
[root@labserver aadarsha]# 


[root@labserver aadarsha]# # tar -cvf impfiles.tar /etc/*.conf /var/log /etc/hosts # archive all the files of .conf extension from /etc/, /var/log and /etc/hosts 
[root@labserver aadarsha]# 

[root@labserver aadarsha]# tar -cvf impfiles.tar /etc/*.conf /var/log /etc/hosts 
-bash: tar: command not found
[root@labserver aadarsha]# 

[root@labserver aadarsha]# tar -cvf impfiles.tar /etc/*.conf /var/log /etc/hosts 
-bash: tar: command not found
[root@labserver aadarsha]# 

[root@labserver aadarsha]# which tar
/usr/bin/which: no tar in (/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
[root@labserver aadarsha]# 

[root@labserver aadarsha]# rpm -q tar
package tar is not installed
[root@labserver aadarsha]# 

[root@labserver aadarsha]# yum install -y tar
Last metadata expiration check: 4:20:18 ago on Mon 08 Jun 2026 12:06:47 PM +0545.
Complete!
[root@labserver aadarsha]# 

[root@labserver aadarsha]# tar --version
tar (GNU tar) 1.35
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later &amp;lt;https://gnu.org/licenses/gpl.html&amp;gt;.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.
[root@labserver aadarsha]# 

[root@labserver aadarsha]# tar -cvf impfiles.tar /etc/*.conf /var/log /etc/hosts 
tar: Removing leading `/&amp;#39; from member names
/etc/chrony.conf
tar: Removing leading `/&amp;#39; from hard link targets
/etc/dracut.conf
/etc/host.conf
/etc/kdump.conf
/etc/krb5.conf
/etc/ld.so.conf
...
/var/log/firewalld
/var/log/cron
/var/log/dnf.log
/var/log/dnf.librepo.log
/var/log/dnf.rpm.log
/var/log/hawkey.log
/etc/hosts
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls 
dir1 dira impfiles.tar testcompany testfile words words.gz
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls -lh impfiles.tar 
-rw-r--r--. 1 root root 6.5M Jun 8 16:27 impfiles.tar
[root@labserver aadarsha]# 
 
[root@labserver aadarsha]# gzip impfiles.tar 
[root@labserver aadarsha]# 
[root@labserver aadarsha]# ls
dir1 dira impfiles.tar.gz testcompany testfile words words.gz
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls -lh impfiles.tar.gz 
-rw-r--r--. 1 root root 767K Jun 8 16:27 impfiles.tar.gz
[root@labserver aadarsha]# 

[root@labserver aadarsha]# 
[root@labserver aadarsha]# # better compress file while creating archive using -z
[root@labserver aadarsha]# 

[root@labserver aadarsha]# 
[root@labserver aadarsha]# tar -cvzf newimpfiles.tar /etc/*.conf /var/log /etc/hosts 
tar: Removing leading `/&amp;#39; from member names
/etc/chrony.conf
tar: Removing leading `/&amp;#39; from hard link targets
/etc/dracut.conf
/etc/host.conf
...
/var/log/firewalld
/var/log/cron
/var/log/dnf.log
/var/log/dnf.librepo.log
/var/log/dnf.rpm.log
/var/log/hawkey.log
/etc/hosts
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls
dir1 dira impfiles.tar.gz newimpfiles.tar testcompany testfile words words.gz
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls -lh newimpfiles.tar 
-rw-r--r--. 1 root root 767K Jun 8 16:30 newimpfiles.tar
[root@labserver aadarsha]#

[root@labserver aadarsha]# rm -r newimpfiles.tar 
rm: remove regular file &amp;#39;newimpfiles.tar&amp;#39;? 
[root@labserver aadarsha]# rm -r newimpfiles.tar 
rm: remove regular file &amp;#39;newimpfiles.tar&amp;#39;? y
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls
dir1 dira impfiles.tar.gz testcompany testfile words words.gz
[root@labserver aadarsha]# 

# tar -cvzf newimpfiles.tar.gz /etc/*.conf /var/log /etc/hosts ( use extension .tar.gz or .tgz not to confuse )

[root@labserver aadarsha]# tar -cvzf newimpfiles.tar.gz /etc/*.conf /var/log /etc/hosts 
tar: Removing leading `/&amp;#39; from member names
/etc/chrony.conf
tar: Removing leading `/&amp;#39; from hard link targets
/etc/dracut.conf
/etc/host.conf
/etc/kdump.conf
...
/etc/hosts
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls 
dir1 dira impfiles.tar.gz newimpfiles.tar.gz testcompany testfile words words.gz
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls -lh newimpfiles.tar.gz 
-rw-r--r--. 1 root root 767K Jun 8 16:33 newimpfiles.tar.gz
[root@labserver aadarsha]# 

[root@labserver aadarsha]# gunzip impfiles.tar.gz 
[root@labserver aadarsha]# ls
dir1 dira impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[root@labserver aadarsha]# ls -lh 
total 14M
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
-rw-r--r--. 1 root root 6.5M Jun 8 16:27 impfiles.tar
-rw-r--r--. 1 root root 767K Jun 8 16:33 newimpfiles.tar.gz
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile
-rw-r--r--. 1 aadarsha aadarsha 4.8M Jun 8 09:52 words
-rw-r--r--. 1 aadarsha aadarsha 1.5M Jun 8 12:09 words.gz
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls -lh impfiles.tar 
-rw-r--r--. 1 root root 6.5M Jun 8 16:27 impfiles.tar
[root@labserver aadarsha]# 

[root@labserver aadarsha]# tar -t impfiles.tar
tar: Refusing to read archive contents from terminal (missing -f option?)
tar: Error is not recoverable: exiting now
[root@labserver aadarsha]# 

[root@labserver aadarsha]# tar -tf impfiles.tar
etc/chrony.conf
...
etc/hosts
[root@labserver aadarsha]# 
 
[root@labserver aadarsha]# tar -tvf impfiles.tar 
-rw-r--r-- root/root 1382 2025-11-20 05:45 etc/chrony.conf
-rw-r--r-- root/root 117 2026-01-30 05:45 etc/dracut.conf
...
-rw-r--r-- root/root 28 2024-02-01 03:47 etc/ld.so.conf
...
-rw-r--r-- root/root 2844 2026-06-08 16:27 var/log/dnf.rpm.log
-rw-r--r-- root/root 1380 2026-06-08 16:27 var/log/hawkey.log
-rw-r--r-- root/root 384 2023-11-29 16:19 etc/hosts
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls
dir1 dira impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[root@labserver aadarsha]# 

# add another file in archive .tar use -r but not cannot add in .tar.gz

[root@labserver aadarsha]# tar -rvf impfiles.tar /etc/passwd dira
tar: Removing leading `/&amp;#39; from member names
/etc/passwd
tar: Removing leading `/&amp;#39; from hard link targets
dira/
dira/dirb/
dira/dirb/dirc/
dira/dirb/dirc/dird/
dira/dirb/dirc/dird/dire/
dira/letfile
dira/myfile_hard
dira/words
[root@labserver aadarsha]# 

# -x --&amp;gt; to extract contents from archive 

# previous archive

[aadarsha@labserver ~]$ ls
dir1 dira impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[aadarsha@labserver ~]$

[aadarsha@labserver ~]$ su - root
Password: 
su: Authentication failure
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Mon Jun 8 16:19:02 +0545 2026 on pts/0
[root@labserver ~]# 

[root@labserver ~]# ls
anaconda-ks.cfg
[root@labserver ~]# cd /home/aadarsha/
[root@labserver aadarsha]# ls
dir1 dira impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls
dir1 dira impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[root@labserver aadarsha]# 

[root@labserver aadarsha]# mkdir extracted

[root@labserver aadarsha]# ls
dir1 dira extracted impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[root@labserver aadarsha]# cd extracted/
[root@labserver extracted]# 

[root@labserver extracted]# ls
[root@labserver extracted]# pwd
/home/aadarsha/extracted
[root@labserver extracted]# 
[root@labserver extracted]# ls -lh ../impfiles.tar 
-rw-r--r--. 1 root root 12M Jun 8 16:38 ../impfiles.tar
[root@labserver extracted]# 
[root@labserver extracted]# exit
logout
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira extracted impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[aadarsha@labserver ~]$ cd extracted/
[aadarsha@labserver extracted]$ 

[aadarsha@labserver extracted]$ pwd
/home/aadarsha/extracted
[aadarsha@labserver extracted]$ 

[aadarsha@labserver extracted]$ tar -xvf ../impfiles.tar 
etc/chrony.conf
tar: etc: Cannot mkdir: Permission denied
tar: etc/chrony.conf: Cannot open: No such file or directory
etc/dracut.conf
tar: etc: Cannot mkdir: Permission denied
tar: etc/dracut.conf: Cannot open: No such file or directory
etc/host.conf
...
tar: dira: Cannot mkdir: Permission denied
tar: dira/words: Cannot open: No such file or directory
tar: Exiting with failure status due to previous errors
[aadarsha@labserver extracted]$ 

[aadarsha@labserver extracted]$ ls
[aadarsha@labserver extracted]$ 
[aadarsha@labserver extracted]$ cd ..
[aadarsha@labserver ~]$ ls -ld extracted/
drwxr-xr-x. 2 root root 6 Jun 8 20:07 extracted/
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ sudo su
[sudo] password for aadarsha: 
[root@labserver aadarsha]# 

[root@labserver aadarsha]# ls
dir1 dira extracted impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[root@labserver aadarsha]# cd extracted/
[root@labserver extracted]# 

[root@labserver extracted]# tar -xvf ../impfiles.tar 
etc/chrony.conf
etc/dracut.conf
etc/host.conf
...
dira/myfile_hard
dira/words
[root@labserver extracted]# 

[root@labserver extracted]# ls
dira etc var
[root@labserver extracted]# cd etc/
[root@labserver etc]# ls
chrony.conf host.conf kdump.conf ld.so.conf locale.conf man_db.conf nsswitch.conf request-key.conf rsyslog.conf sudo.conf sysctl.conf xattr.conf
dracut.conf hosts krb5.conf libaudit.conf logrotate.conf mke2fs.conf passwd resolv.conf sestatus.conf sudo-ldap.conf vconsole.conf yum.conf
[root@labserver etc]# cd ../var/

[root@labserver var]# ls
log
[root@labserver var]# cd log/
[root@labserver log]# ls
anaconda audit btmp chrony cron dnf.librepo.log dnf.log dnf.rpm.log firewalld hawkey.log lastlog maillog messages private samba secure spooler sssd wtmp
[root@labserver log]# cd ../../dira/
[root@labserver dira]# ls
dirb letfile myfile_hard words
[root@labserver dira]# cd -
/home/aadarsha/extracted/var/log
[root@labserver log]# cd ../../
[root@labserver extracted]# ls
dira etc var
[root@labserver extracted]# 

[root@labserver extracted]# ls
dira etc var
[root@labserver extracted]# ls -lh
total 4.0K
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
drwxr-xr-x. 2 root root 4.0K Jun 8 20:10 etc
drwxr-xr-x. 3 root root 17 Jun 8 20:10 var
[root@labserver extracted]# 

[root@labserver extracted]# ls var/log/
anaconda audit btmp chrony cron dnf.librepo.log dnf.log dnf.rpm.log firewalld hawkey.log lastlog maillog messages private samba secure spooler sssd wtmp
[root@labserver extracted]# 

# to extract compressed files use -z

[root@labserver extracted]# cd 
[root@labserver ~]# 
[root@labserver ~]# ls
anaconda-ks.cfg
[root@labserver ~]# cd /home/aadarsha/
[root@labserver aadarsha]# ls
dir1 dira extracted impfiles.tar newimpfiles.tar.gz testcompany testfile words words.gz
[root@labserver aadarsha]# 

[root@labserver aadarsha]# cd extracted/
[root@labserver extracted]# 
[root@labserver extracted]# tar -xvf ../newimpfiles.tar.gz 
etc/chrony.conf
etc/dracut.conf
etc/host.conf
etc/kdump.conf
...
etc/hosts
[root@labserver extracted]# 

[root@labserver extracted]# ls
dira etc var
[root@labserver extracted]# ls -la
total 8
drwxr-xr-x. 5 root root 40 Jun 8 20:10 .
drwx------. 6 aadarsha aadarsha 4096 Jun 8 20:07 ..
drwxr-xr-x. 3 aadarsha aadarsha 65 Jun 8 12:07 dira
drwxr-xr-x. 2 root root 4096 Jun 8 20:13 etc
drwxr-xr-x. 3 root root 17 Jun 8 20:10 var
[root@labserver extracted]# 

[root@labserver extracted]# tar -zxvf ../newimpfiles.tar.gz 
etc/chrony.conf
etc/dracut.conf
...
etc/hosts
[root@labserver extracted]#
[root@labserver extracted]# ls
dira etc var
[root@labserver extracted]# 

[root@labserver extracted]# ls
dira etc var
[root@labserver extracted]# 

[root@labserver extracted]# rm -r dira/ etc/ var/
...
[root@labserver extracted]# 

[root@labserver extracted]# ls

[root@labserver extracted]# tar -zxvf ../newimpfiles.tar.gz 
etc/chrony.conf
...
var/log/hawkey.log
etc/hosts
[root@labserver extracted]# ls
etc var
[root@labserver extracted]# 
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Practice 004 — Creating Soft Link &amp; Hard Link</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-004/</link><pubDate>Mon, 08 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-004/</guid><description>&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;h4 id="command-history"&gt;Command History&lt;/h4&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[aadarsha@labserver ~]$ ls limited/
host.conf locale.conf logrotate.conf
[aadarsha@labserver ~]$ 

aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.72
aadarsha@192.168.254.72&amp;#39;s password: 
Last login: Mon Jun 8 06:45:39 2026 from 192.168.254.152
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
backup_conf dir1 dira limited testcompany testfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls backup_conf/
chrony.conf kdump.conf ld.so.conf mke2fs.conf request-key.conf rsyslog.conf sysctl.conf xattr.conf
dracut.conf krb5.conf man_db.conf nsswitch.conf resolv.conf sestatus.conf vconsole.conf yum.conf
[aadarsha@labserver ~]$ 

# command history and running already run history

[aadarsha@labserver ~]$ echo $HISTSIZE		 
1000 # ---&amp;gt; Default history limit : 1000
[aadarsha@labserver ~]$

# FIFO --&amp;gt; first entered command removes at first after reaching history limit number
 
[aadarsha@labserver ~]$ history
 1 ip a
 2 sudo -i
 3 clear
 4 ip a
 5 clear
 6 whoami
 7 ls
 8 clear
 9 ls
 10 clear
 11 hostname -I
 ...
[aadarsha@labserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id="soft-link-and-hard-link"&gt;Soft Link and Hard Link&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;Hard link = another name for the same inode.
Soft link = a shortcut that stores a path.


Hard link → “same file, different name”
Soft link → “different file pointing to a name (path)”


| Feature | Hard Link | Soft Link (Symbolic Link) |
| --------------------------------- | ------------------------------ | -------------------------------------- |
| Creates with | `ln source target` | `ln -s source target` |
| Points to | Same inode as original file | Pathname of target file |
| Has its own inode? | No (shares inode with target) | Yes (separate inode) |
| Inode number (`ls -i`) | Same as original | Different from target |
| If original file is deleted | Still works | Breaks |
| If original file is renamed | Still works | Breaks |
| If original file is moved | Still works | Usually breaks |
| Can link directories? | Generally not allowed | Yes |
| Can cross filesystems/partitions? | No | Yes |
| Size of link | Same file data | Small file containing path |
| Permissions | Same underlying file | Symlink permissions usually ignored |
| Broken/Dangling possible? | No | Yes |
| Uses inode count | Increases link count | Does not increase target&amp;#39;s link count |

[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vim dir1/dir2/dir3/dir4/dir5/myfile

[aadarsha@labserver ~]$ cat dir1/dir2/dir3/dir4/dir5/myfile 
this is myfile created in dir5.
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira testcompany testfile
[aadarsha@labserver ~]$ 

# creating soft link
 
[aadarsha@labserver ~]$ ln -s dir1/dir2/dir3/dir4/dir5/myfile .

[aadarsha@labserver ~]$ ls
dir1 dira myfile testcompany testfile
[aadarsha@labserver ~]$ ls -l
total 4
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dira
lrwxrwxrwx. 1 aadarsha aadarsha 31 Jun 8 07:53 myfile -&amp;gt; dir1/dir2/dir3/dir4/dir5/myfile
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ln -s dir1/dir2/dir3/dir4/dir5/myfile dira/

[aadarsha@labserver ~]$ ls -l dira/
total 0
drwxr-xr-x. 3 aadarsha aadarsha 18 Jun 8 07:50 dirb
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 7 16:10 letfile
lrwxrwxrwx. 1 aadarsha aadarsha 31 Jun 8 07:53 myfile -&amp;gt; dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat dira/myfile 
cat: dira/myfile: No such file or directory
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cd dira/
[aadarsha@labserver dira]$ ls
dirb letfile myfile
[aadarsha@labserver dira]$ cat myfile 
cat: myfile: No such file or directory
[aadarsha@labserver dira]$ 

[aadarsha@labserver dira]$ cat myfile 
cat: myfile: No such file or directory
[aadarsha@labserver dira]$ 

[aadarsha@labserver dira]$ ls -l myfile 
lrwxrwxrwx. 1 aadarsha aadarsha 31 Jun 8 07:53 myfile -&amp;gt; dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver dira]$ 

[aadarsha@labserver dira]$ ls
dirb letfile myfile
[aadarsha@labserver dira]$ 

[aadarsha@labserver dira]$ ls
dirb letfile myfile
[aadarsha@labserver dira]$ readlink myfile 
dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver dira]$ 

[aadarsha@labserver dira]$ cd
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
dir1 dira myfile testcompany testfile
[aadarsha@labserver ~]$ ls dir1/
dir2 numfile
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls dir1/
dir2/ numfile 
[aadarsha@labserver ~]$ ls dir1/dir2/dir3/dir4/dir5/
myfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira myfile testcompany testfile
[aadarsha@labserver ~]$ cd dira/
[aadarsha@labserver dira]$ ls
dirb letfile myfile
[aadarsha@labserver dira]$ rm myfile 
rm: remove symbolic link &amp;#39;myfile&amp;#39;? y
[aadarsha@labserver dira]$ 

[aadarsha@labserver dira]$ cd
[aadarsha@labserver ~]$ ls
dir1 dira myfile testcompany testfile
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
dir1 dira myfile testcompany testfile
[aadarsha@labserver ~]$ tree dir1/dir2/dir3/dir4/dir5/
dir1/dir2/dir3/dir4/dir5/
└── myfile

1 directory, 1 file
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1 dira myfile testcompany testfile
[aadarsha@labserver ~]$ ls dira/
dirb letfile
[aadarsha@labserver ~]$ ls
dir1 dira myfile testcompany testfile
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ln -s ../dir1/dir2/dir3/dir4/dir5/myfile dira/myfile_soft
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls dira/
dirb letfile myfile_soft
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls -l dira/
total 0
drwxr-xr-x. 3 aadarsha aadarsha 18 Jun 8 07:50 dirb
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 7 16:10 letfile
lrwxrwxrwx. 1 aadarsha aadarsha 34 Jun 8 08:25 myfile_soft -&amp;gt; ../dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver ~]$ cat dira/myfile_soft 
this is myfile created in dir5.
[aadarsha@labserver ~]$ 

# OR using the absolute path is better approach

[aadarsha@labserver ~]$ vim dira/myfile_soft 
[aadarsha@labserver ~]$ cat dira/myfile_soft 
this is myfile created in dir5.
this line is added after creating soft link
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat dir1/dir2/dir3/dir4/dir5/myfile 
this is myfile created in dir5.
this line is added after creating soft link
[aadarsha@labserver ~]$ 

# since soft link is like pointer, when I change the soft link, original file also got changed

[aadarsha@labserver ~]$ ls -l dir1/dir2/dir3/dir4/dir5/myfile 
-rw-r--r--. 1 aadarsha aadarsha 77 Jun 8 08:33 dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -l dira/myfile_soft 
lrwxrwxrwx. 1 aadarsha aadarsha 34 Jun 8 08:25 dira/myfile_soft -&amp;gt; ../dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver ~]$ 

# size 77 bytes and softlink size 34 bytes ---&amp;gt; size of a regular file represents the amount of data stored in the file.
# AND
# size of a symbolic (soft) link represents the number of bytes required to store the target pathname, not the size of the target file.


# creating hard link

[aadarsha@labserver ~]$ ln /home/aadarsha/dir1/dir2/dir3/dir4/dir5/myfile dira/myfile_hard

[aadarsha@labserver ~]$ ls -l dira/myfile_hard 
-rw-r--r--. 2 aadarsha aadarsha 77 Jun 8 08:33 dira/myfile_hard
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls dira/
dirb letfile myfile_hard myfile_soft
[aadarsha@labserver ~]$ ls -l dira/
total 4
drwxr-xr-x. 3 aadarsha aadarsha 18 Jun 8 07:50 dirb
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 7 16:10 letfile
-rw-r--r--. 2 aadarsha aadarsha 77 Jun 8 08:33 myfile_hard
lrwxrwxrwx. 1 aadarsha aadarsha 34 Jun 8 08:25 myfile_soft -&amp;gt; ../dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat dira/myfile_hard 
this is myfile created in dir5.
this line is added after creating soft link
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vim dira/myfile_hard 
[aadarsha@labserver ~]$ cat dira/myfile_hard 
this is myfile created in dir5.
this line is written from hard link file
[aadarsha@labserver ~]$
 
[aadarsha@labserver ~]$ cat dir1/dir2/dir3/dir4/dir5/myfile 
this is myfile created in dir5.
this line is written from hard link file
[aadarsha@labserver ~]$

[aadarsha@labserver ~]$ ls -l dir1/dir2/dir3/dir4/dir5/myfile 
-rw-r--r--. 2 aadarsha aadarsha 73 Jun 8 08:47 dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -l dira/myfile_hard 
-rw-r--r--. 2 aadarsha aadarsha 73 Jun 8 08:47 dira/myfile_hard
[aadarsha@labserver ~]$ 

# same size for original file and hard link ---&amp;gt; A hard link has the same file size as the original file because 
# both are directory entries pointing to the same inode and share the same underlying file data.

[aadarsha@labserver ~]$ ls -i dira/
 473657 dirb 526555 letfile 473651 myfile_hard 25447628 myfile_soft
[aadarsha@labserver ~]$ ls -il dira/
total 4
 473657 drwxr-xr-x. 3 aadarsha aadarsha 18 Jun 8 07:50 dirb
 526555 -rw-r--r--. 1 aadarsha aadarsha 0 Jun 7 16:10 letfile
 473651 -rw-r--r--. 2 aadarsha aadarsha 73 Jun 8 08:47 myfile_hard
25447628 lrwxrwxrwx. 1 aadarsha aadarsha 34 Jun 8 08:25 myfile_soft -&amp;gt; ../dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -i dir1/dir2/dir3/dir4/dir5/
473651 myfile
[aadarsha@labserver ~]$ 

# Hard-linked files have the same inode number as the original file.
# Changes made through either the original file or the hard link are reflected in both, as they reference the same underlying file.
# If the original file is deleted, the hard link continues to provide access to the file data because it still references the same inode.
# If the original file is deleted, the symbolic (soft) link becomes a broken (dangling) link because it only stores the pathname to the original file.

[aadarsha@labserver ~]$ ls -l
total 4
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 3 aadarsha aadarsha 71 Jun 8 08:47 dira
lrwxrwxrwx. 1 aadarsha aadarsha 31 Jun 8 07:53 myfile -&amp;gt; dir1/dir2/dir3/dir4/dir5/myfile
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile
[aadarsha@labserver ~]$
 
[aadarsha@labserver ~]$ ls -l dir1/dir2/dir3/dir4/dir5/
total 4
-rw-r--r--. 2 aadarsha aadarsha 73 Jun 8 08:47 myfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -l dira/
total 4
drwxr-xr-x. 3 aadarsha aadarsha 18 Jun 8 07:50 dirb
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 7 16:10 letfile
-rw-r--r--. 2 aadarsha aadarsha 73 Jun 8 08:47 myfile_hard
lrwxrwxrwx. 1 aadarsha aadarsha 34 Jun 8 08:25 myfile_soft -&amp;gt; ../dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver ~]$ 

# now delete original source file myfile

[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ rm -r dir1/dir2/dir3/dir4/dir5/myfile 
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -l
total 4
drwxr-xr-x. 3 aadarsha aadarsha 33 Jun 8 06:47 dir1
drwxr-xr-x. 3 aadarsha aadarsha 71 Jun 8 08:47 dira
lrwxrwxrwx. 1 aadarsha aadarsha 31 Jun 8 07:53 myfile -&amp;gt; dir1/dir2/dir3/dir4/dir5/myfile
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
-rw-r--r--. 1 aadarsha aadarsha 56 Jun 7 21:33 testfile

[aadarsha@labserver ~]$ cat myfile 
cat: myfile: No such file or directory
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -l dira/
total 4
drwxr-xr-x. 3 aadarsha aadarsha 18 Jun 8 07:50 dirb
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 7 16:10 letfile
-rw-r--r--. 1 aadarsha aadarsha 73 Jun 8 08:47 myfile_hard
lrwxrwxrwx. 1 aadarsha aadarsha 34 Jun 8 08:25 myfile_soft -&amp;gt; ../dir1/dir2/dir3/dir4/dir5/myfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat dira/myfile_soft 
cat: dira/myfile_soft: No such file or directory
[aadarsha@labserver ~]$ 

# But for hard link

[aadarsha@labserver ~]$ cat dira/myfile_hard 
this is myfile created in dir5.
this line is written from hard link file
[aadarsha@labserver ~]$ 

# Getting files/directory details

[aadarsha@labserver ~]$ ls
dir1 dira myfile testcompany testfile
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ stat myfile 
 File: myfile -&amp;gt; dir1/dir2/dir3/dir4/dir5/myfile
 Size: 31 	Blocks: 0 IO Block: 4096 symbolic link
Device: 253,0	Inode: 473659 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 1000/aadarsha) Gid: ( 1000/aadarsha)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2026-06-08 07:53:09.245051929 +0545
Modify: 2026-06-08 07:53:07.765053104 +0545
Change: 2026-06-08 07:53:07.765053104 +0545
 Birth: 2026-06-08 07:53:07.765053104 +0545
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ stat dira/myfile_hard 
 File: dira/myfile_hard
 Size: 73 	Blocks: 8 IO Block: 4096 regular file
Device: 253,0	Inode: 473651 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/aadarsha) Gid: ( 1000/aadarsha)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2026-06-08 09:02:10.463769531 +0545
Modify: 2026-06-08 08:47:34.586697736 +0545
Change: 2026-06-08 08:57:30.271064335 +0545
 Birth: 2026-06-08 07:52:05.533102327 +0545
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ rm myfile dira/myfile_soft 
rm: remove symbolic link &amp;#39;myfile&amp;#39;? y
rm: remove symbolic link &amp;#39;dira/myfile_soft&amp;#39;? y
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ stat testcompany/
 File: testcompany/
 Size: 54 	Blocks: 0 IO Block: 4096 directory
Device: 253,0	Inode: 8398100 Links: 5
Access: (0755/drwxr-xr-x) Uid: ( 1000/aadarsha) Gid: ( 1000/aadarsha)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2026-06-08 07:50:40.423169663 +0545
Modify: 2026-06-07 07:24:23.317639366 +0545
Change: 2026-06-07 07:24:23.317639366 +0545
 Birth: 2026-06-07 07:24:23.317639366 +0545
[aadarsha@labserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Practice 003 — Redirecting Output and Using Wildcards</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-003/</link><pubDate>Sun, 07 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-003/</guid><description>&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# using () ---&amp;gt; redirect the output on the file 

[aadarsha@labserver ~]$ date; cal ; ls
Sun Jun 7 06:48:59 AM +0545 2026
 June 2026 
Su Mo Tu We Th Fr Sa
 1 2 3 4 5 6
 7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 
 
dir1 dir2 dir3 file1 file2 file3

[aadarsha@labserver ~]$ date; cal; ls &amp;gt; command_output		# Only output of ls command is saved
Sun Jun 7 06:49:34 AM +0545 2026
 June 2026 
Su Mo Tu We Th Fr Sa
 1 2 3 4 5 6
 7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 
 
[aadarsha@labserver ~]$ cat command_output 
command_output
dir1
dir2
dir3
file1
file2
file3
[aadarsha@labserver ~]$						

[aadarsha@labserver ~]$ (date; cal; ls) &amp;gt; command_output # using () ---&amp;gt; output of all commands is saved
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ cat command_output 
Sun Jun 7 06:50:12 AM +0545 2026
 June 2026 
Su Mo Tu We Th Fr Sa
 1 2 3 4 5 6
 7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 
 
command_output
dir1
dir2
dir3
file1
file2
file3
[aadarsha@labserver ~]$

# use of {} ---&amp;gt; use to define the range
# creating multiple Dir/Sub-dir at a time

[aadarsha@labserver ~]$ ls
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ mkdir dir{1..25}
[aadarsha@labserver ~]$ ls
dir1 dir10 dir11 dir12 dir13 dir14 dir15 dir16 dir17 dir18 dir19 dir2 dir20 dir21 dir22 dir23 dir24 dir25 dir3 dir4 dir5 dir6 dir7 dir8 dir9
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ rmdir dir{10..25}

[aadarsha@labserver ~]$ ls
dir1 dir2 dir3 dir4 dir5 dir6 dir7 dir8 dir9
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ touch file{10..20}
[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ ls
dir1 dir2 dir3 dir4 dir5 dir6 dir7 dir8 dir9 file10 file11 file12 file13 file14 file15 file16 file17 file18 file19 file20
[aadarsha@labserver ~]$ rm -f file{16..20} 
[aadarsha@labserver ~]$ ls
dir1 dir2 dir3 dir4 dir5 dir6 dir7 dir8 dir9 file10 file11 file12 file13 file14 file15
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ rm -r *
[aadarsha@labserver ~]$ ls
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ mkdir -p dir1/dir2/dir3/dir4/dir5
[aadarsha@labserver ~]$ ls
dir1
[aadarsha@labserver ~]$ tree
.
└── dir1
 └── dir2
 └── dir3
 └── dir4
 └── dir5

6 directories, 0 files
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
dir1
 
# use of {} and -p

[aadarsha@labserver ~]$ 
[aadarsha@labserver ~]$ mkdir -p testcompany/{service/{development,devops/{cloud/{aws,azure,gcp},onpremise},security,AI},support/{technical,others},management}
[aadarsha@labserver ~]$ ls
dir1 testcompany
[aadarsha@labserver ~]$ tree testcompany/
testcompany/
├── management
├── service
│   ├── AI
│   ├── development
│   ├── devops
│   │   ├── cloud
│   │   │   ├── aws
│   │   │   ├── azure
│   │   │   └── gcp
│   │   └── onpremise
│   └── security
└── support
 ├── others
 └── technical

15 directories, 0 files
[aadarsha@labserver ~]$
 
# Creating a file/dir with special characters in their name

[aadarsha@labserver ~]$ ls
dir1 testcompany

[aadarsha@labserver ~]$ vi &amp;#34;my file&amp;#34; # file name with space inside &amp;#34; &amp;#34;
[aadarsha@labserver ~]$ ls
 dir1 &amp;#39;my file&amp;#39; testcompany
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cat my\ file		# escape sequence --&amp;gt; \
This is the test file.
[aadarsha@labserver ~]$ 


# creating a hidden file

[aadarsha@labserver ~]$ touch .secretdata
[aadarsha@labserver ~]$ ls
 dir1 &amp;#39;my file&amp;#39; testcompany
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls -a
 . .. .bash_history .bash_logout .bash_profile .bashrc dir1 &amp;#39;my file&amp;#39; .secretdata testcompany
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ vi .secretdata 

[aadarsha@labserver ~]$ cat .secretdata 
this is the hidden file

[aadarsha@labserver ~]$ ls -a -l 		# ( ls -al ) --&amp;gt; in the most cases options sequence doesn&amp;#39;t matter
total 24
drwx------. 4 aadarsha aadarsha 148 Jun 7 07:54 .
drwxr-xr-x. 3 root root 22 May 26 15:36 ..
-rw-------. 1 aadarsha aadarsha 3843 Jun 4 22:45 .bash_history
-rw-r--r--. 1 aadarsha aadarsha 18 Oct 29 2024 .bash_logout
-rw-r--r--. 1 aadarsha aadarsha 144 Oct 29 2024 .bash_profile
-rw-r--r--. 1 aadarsha aadarsha 522 Oct 29 2024 .bashrc
drwxr-xr-x. 3 aadarsha aadarsha 18 Jun 7 07:02 dir1
-rw-r--r--. 1 aadarsha aadarsha 23 Jun 7 07:29 &amp;#39;my file&amp;#39;
-rw-r--r--. 1 aadarsha aadarsha 24 Jun 7 07:54 .secretdata
drwxr-xr-x. 5 aadarsha aadarsha 54 Jun 7 07:24 testcompany
[aadarsha@labserver ~]$
 

# using wildcard characters

# ?	 --&amp;gt; matches any single character
# * 	 --&amp;gt; matches no. of characters
# [a-z] --&amp;gt; matches within the range
# [^a-z] --&amp;gt; matches out of the range
# [az] --&amp;gt; matches within the set
# [^az] --&amp;gt; matches out of the set

[aadarsha@labserver ~]$ cd /
[aadarsha@labserver /]$ ls
afs bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

[aadarsha@labserver /]$ ls -d ??? 					# to search on first level directory not inside
afs bin dev etc lib mnt opt run srv sys tmp usr var

[aadarsha@labserver /]$ ls -d b??
bin

[aadarsha@labserver /]$ ls -d b*
bin boot

[aadarsha@labserver /]$ ls -d *t
boot mnt opt root
 
[aadarsha@labserver /]$ ls -d *r
usr var

[aadarsha@labserver /]$ ls -d r??t
root

[aadarsha@labserver /]$ ls -d [b-p]*
bin boot dev etc home lib lib64 media mnt opt proc

[aadarsha@labserver /]$ ls -d [^b-p]*
afs root run sbin srv sys tmp usr var

[aadarsha@labserver /]$ ls -d [b-p]*
bin boot dev etc home lib lib64 media mnt opt proc

[aadarsha@labserver /]$ ls -d [^b-p]*
afs root run sbin srv sys tmp usr var

[aadarsha@labserver /]$ ls -d *[c-z]
afs bin boot dev etc home mnt opt proc root run sbin srv sys tmp usr var
 
[aadarsha@labserver /]$ ls -d *[c-f]
etc home proc

[aadarsha@labserver /]$ ls -d *[bh]
lib

[aadarsha@labserver /]$ ls -d [bh]*
bin boot home

[aadarsha@labserver /]$ ls -d [hs]*
home sbin srv sys

[aadarsha@labserver /]$ ls -d [hs]*
home sbin srv sys

[aadarsha@labserver /]$ ls -d [sh]*
home sbin srv sys

[aadarsha@labserver /]$ ls -d [^she]*
afs bin boot dev lib lib64 media mnt opt proc root run tmp usr var
 
[aadarsha@labserver /]$ ls -d [she]*
etc home sbin srv sys

[aadarsha@labserver /]$ pwd
/
[aadarsha@labserver /]$ cd ~			# home directory
[aadarsha@labserver ~]$ pwd
/home/aadarsha

[aadarsha@labserver ~]$ ls
 dir1 &amp;#39;my file&amp;#39; testcompany

# path navigation

[aadarsha@labserver ~]$ tree 
.
├── dir1
│   └── dir2
│   └── dir3
│   └── dir4
│   └── dir5
├── my file
└── testcompany
 ├── management
 ├── service
 │   ├── AI
 │   ├── development
 │   ├── devops
 │   │   ├── cloud
 │   │   │   ├── aws
 │   │   │   ├── azure
 │   │   │   └── gcp
 │   │   └── onpremise
 │   └── security
 └── support
 ├── others
 └── technical

21 directories, 1 file
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ cd /home/aadarsha/testcompany/service/security/

[aadarsha@labserver security]$ pwd
/home/aadarsha/testcompany/service/security

[aadarsha@labserver security]$ cd /home/aadarsha/testcompany/service/security/ 	# from root: absolute path

[aadarsha@labserver security]$ cd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cd /home/aadarsha/testcompany/service/security/ 		# from root: absolute path
[aadarsha@labserver security]$ 

[aadarsha@labserver security]$ cd ../../../dir1/dir2/dir3/dir4/ 			# from current path: relative path

[aadarsha@labserver dir4]$ pwd
/home/aadarsha/dir1/dir2/dir3/dir4

[aadarsha@labserver dir4]$ ls
dir5
[aadarsha@labserver dir4]$ cd
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ ls
 dir1 &amp;#39;my file&amp;#39; testcompany
 
# moving and renaming files/dirs : mv command

# mv [options] &amp;lt;source&amp;gt; &amp;lt;destination&amp;gt;

# [option]
 
# -i --&amp;gt; ask for confirmation
# -f --&amp;gt; forcefully overwrite
# -i --&amp;gt; ask for confirmation (default for root) 
# -f --&amp;gt; forcefully overwrite (default for normal users)

[aadarsha@labserver ~]$ pwd
/home/aadarsha

[aadarsha@labserver ~]$ ls
 dir1 &amp;#39;my file&amp;#39; testcompany
 
[aadarsha@labserver ~]$ rm &amp;#39;my file&amp;#39; 

[aadarsha@labserver ~]$ ls
dir1 testcompany
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ cd dir1/dir2/dir3/
[aadarsha@labserver dir3]$ 
[aadarsha@labserver dir3]$ vi ~?
&lt;/code&gt;&lt;/pre&gt;</description></item><item><title>Practice 002 — Linux Filesystem</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-002/</link><pubDate>Sat, 06 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-002/</guid><description>&lt;h3 id="linux-filesystem"&gt;Linux Filesystem&lt;/h3&gt;
&lt;p&gt;The Linux filesystem hierarchy generally follows the &lt;strong&gt;Filesystem Hierarchy Standard (FHS)&lt;/strong&gt;.
Some distributions may organize files differently (e.g., merged &lt;code&gt;/usr&lt;/code&gt;, &lt;code&gt;systemd&lt;/code&gt;-based layouts), but the purpose of each directory remains largely the same.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&amp;ldquo;everything is represented as a file interface whenever practical.&amp;rdquo;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;[aadarsha@labserver ~]$ whoami
aadarsha

[aadarsha@labserver ~]$ pwd
/home/aadarsha
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex="0"&gt;&lt;code&gt;[aadarsha@labserver ~]$ cd /
[aadarsha@labserver /]$ 

# / ---&amp;gt; ( root directory )
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The top-level directory of the Linux filesystem.
Everything in Linux exists under &lt;code&gt;/&lt;/code&gt;, including:&lt;/p&gt;</description></item><item><title>Practice 001 — General Shell Commands</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-001/</link><pubDate>Fri, 05 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-001/</guid><description>&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;# General Syntax of Commands

# command_name [options] &amp;lt;arguments&amp;gt;

[aadarsha@labserver ~]$ touch file1 file2 file3
[aadarsha@labserver ~]$ ls
file1 file2 file3

[aadarsha@labserver ~]$ pwd
/home/aadarsha
[aadarsha@labserver ~]$ ls /
afs boot etc lib media opt root sbin sys usr
bin dev home lib64 mnt proc run srv tmp var

[aadarsha@labserver ~]$ ls /etc/
adjtime firewalld magic samba
aliases fonts makedumpfile.conf.sample sasl2
alternatives fstab man_db.conf security
anacrontab GREP_COLORS microcode_ctl selinux
audit groff mke2fs.conf services
authselect group modprobe.d sestatus.conf
bash_completion.d group- modules-load.d shadow
bashrc grub2.cfg motd shadow-
bindresvport.blacklist grub.d motd.d shells
binfmt.d gshadow mtab skel
centos-release gshadow- netconfig ssh
chrony.conf gss NetworkManager ssl
cifs-utils host.conf networks sssd
credstore hostname nftables statetab.d
credstore.encrypted hosts nsswitch.conf subgid
cron.d inittab nvme subgid-
cron.daily inputrc openldap subuid
cron.deny iproute2 opt subuid-
cron.hourly issue os-release sudo.conf
cron.monthly issue.d pam.d sudoers
crontab issue.net passwd sudoers.d
cron.weekly kdump passwd- sudo-ldap.conf
crypto-policies kdump.conf pkcs11 sysconfig
crypttab kernel pki sysctl.conf
csh.cshrc keys pm sysctl.d
csh.login keyutils popt.d systemd
dbus-1 krb5.conf printcap system-release
dconf krb5.conf.d profile system-release-cpe
debuginfod ld.so.cache profile.d terminfo
default ld.so.conf protocols tmpfiles.d
depmod.d ld.so.conf.d rc.d tpm2-tss
dhcp libaudit.conf rc.local udev
DIR_COLORS libnl redhat-release vconsole.conf
DIR_COLORS.lightbgcolor libssh request-key.conf virc
dnf locale.conf request-key.d X11
dracut.conf localtime resolv.conf xattr.conf
dracut.conf.d login.defs rpc xdg
environment logrotate.conf rpm yum
ethertypes logrotate.d rsyslog.conf yum.conf
exports lvm rsyslog.d yum.repos.d
filesystems machine-id rwtab.d

[aadarsha@labserver ~]$ ls -l /etc
total 1044
-rw-r--r--. 1 root root 16 May 26 15:36 adjtime
-rw-r--r--. 1 root root 1529 Nov 29 2023 aliases
drwxr-xr-x. 2 root root 4096 May 26 15:34 alternatives
-rw-r--r--. 1 root root 541 Jan 14 05:45 anacrontab
drwxr-x---. 4 root root 100 May 26 15:33 audit
drwxr-xr-x. 3 root root 4096 May 26 15:34 authselect
drwxr-xr-x. 2 root root 38 May 26 15:34 bash_completion.d
-rw-r--r--. 1 root root 2709 Nov 29 2023 bashrc
...
...
lrwxrwxrwx. 1 root root 12 Mar 25 05:45 yum.conf -&amp;gt; dnf/dnf.conf
drwxr-xr-x. 2 root root 51 Apr 7 05:45 yum.repos.d

[aadarsha@labserver ~]$ ls -l
total 0
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 4 21:29 file1
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 4 21:29 file2
-rw-r--r--. 1 aadarsha aadarsha 0 Jun 4 21:29 file3
[aadarsha@labserver ~]$ 
 
[aadarsha@labserver ~]$ whoami
aadarsha
[aadarsha@labserver ~]$ 

[aadarsha@labserver ~]$ date
Thu Jun 4 09:33:38 PM +0545 2026

[aadarsha@labserver ~]$ cal
 June 2026 
Su Mo Tu We Th Fr Sa
 1 2 3 4 5 6
 7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 
 
[aadarsha@labserver ~]$ ls
file1 file2 file3
[aadarsha@labserver ~]$ mkdir dir1 dir2 dir3

[aadarsha@labserver ~]$ ls
dir1 dir2 dir3 file1 file2 file3

# running multiple commands at a time

[aadarsha@labserver ~]$ date; cal; ls
Thu Jun 4 09:34:10 PM +0545 2026
 June 2026 
Su Mo Tu We Th Fr Sa
 1 2 3 4 5 6
 7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 
 
dir1 dir2 dir3 file1 file2 file3

[aadarsha@labserver ~]$ date &amp;amp;&amp;amp; cal &amp;amp;&amp;amp; ls
Thu Jun 4 09:34:31 PM +0545 2026
 June 2026 
Su Mo Tu We Th Fr Sa
 1 2 3 4 5 6
 7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 
 
dir1 dir2 dir3 file1 file2 file3
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note:&lt;/p&gt;</description></item><item><title>Practice 000 — SSH Login and Basic Shell Commands</title><link>https://aadarshakhadka.com.np/practice-log/linux/practice-000/</link><pubDate>Thu, 04 Jun 2026 00:00:00 +0000</pubDate><guid>https://aadarshakhadka.com.np/practice-log/linux/practice-000/</guid><description>&lt;h3 id="terminal-session"&gt;Terminal Session&lt;/h3&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;aadarkdk@pop-os:~$ ssh aadarsha@192.168.254.67
aadarsha@192.168.254.67&amp;#39;s password: 
Last login: Thu Jun 4 06:34:06 2026

[aadarsha@labserver ~]$ hostname
labserver

[aadarsha@labserver ~]$ pwd
/home/aadarsha

[aadarsha@labserver ~]$ whoami
aadarsha

# Switching User&amp;#39;s account
# su - &amp;lt;username&amp;gt;

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Tue Jun 2 16:55:19 +0545 2026 on pts/1

[root@labserver ~]# whoami
root

[root@labserver ~]# exit
logout

[aadarsha@labserver ~]$ sudo -i
[sudo] password for aadarsha: 
[root@labserver ~]# whoami
root
[root@labserver ~]# exit
logout

[root@labserver ~]# useradd myuser1
[root@labserver ~]# passwd myuser1
New password: 
Retype new password: 
passwd: password updated successfully
[root@labserver ~]# su - myuser1
[myuser1@labserver ~]$ whoami
myuser1
[myuser1@labserver ~]$ passwd myuser1
Current password: 
New password: 
Retype new password: 
passwd: password updated successfully
[myuser1@labserver ~]$ pwd
/home/myuser1
[myuser1@labserver ~]$ exit
logout

[myuser1@labserver ~]$ su - aadarsha
Password: 
Last login: Thu Jun 4 06:35:22 +0545 2026 from 192.168.254.69 on pts/0


[aadarsha@labserver ~]$ date
Thu Jun 4 08:09:21 AM +0545 2026

[aadarsha@labserver ~]$ su - root
Password: 
Last login: Thu Jun 4 08:05:52 +0545 2026 on pts/0

[root@labserver ~]# date --set=2026-06-01

Mon Jun 1 12:00:00 AM +0545 2026

[root@labserver ~]# date
Mon Jun 1 12:00:03 AM +0545 2026

[root@labserver ~]# date --set=2026-06-04
Thu Jun 4 12:00:00 AM +0545 2026

[root@labserver ~]# date --set=08:13:00
Thu Jun 4 08:13:00 AM +0545 2026

[root@labserver ~]# exit
logout

[aadarsha@labserver ~]$ cal
 June 2026 
Su Mo Tu We Th Fr Sa
 1 2 3 4 5 6
 7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 
 
[aadarsha@labserver ~]$ cal 2026
 2026 

 January February March 
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7
 4 5 6 7 8 9 10 8 9 10 11 12 13 14 8 9 10 11 12 13 14
11 12 13 14 15 16 17 15 16 17 18 19 20 21 15 16 17 18 19 20 21
18 19 20 21 22 23 24 22 23 24 25 26 27 28 22 23 24 25 26 27 28
25 26 27 28 29 30 31 29 30 31 
 
 April May June 
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
 1 2 3 4 1 2 1 2 3 4 5 6
 5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29 30 28 29 30 
 31 
 July August September 
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
 1 2 3 4 1 1 2 3 4 5
 5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30 
 30 31 
 October November December 
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
25 26 27 28 29 30 31 29 30 27 28 29 30 31 
 
[aadarsha@labserver ~]$ pwd
/home/aadarsha

[myuser1@labserver ~]$ cd /
[myuser1@labserver /]$ pwd
/
[myuser1@labserver /]$ cd
[myuser1@labserver ~]$ exit
logout

# Creating a directory 
[aadarsha@labserver ~]$ mkdir mydir1

# Creating a File
# using &amp;#39;cat&amp;#39; command

[aadarsha@labserver ~]$ cat &amp;gt; file1
This is my first file... 

# CTRL + D --&amp;gt; Save and exit

[aadarsha@labserver ~]$ ls
file1 mydir1

[aadarsha@labserver ~]$ cat file1
This is my first file...

# using &amp;#39;vi&amp;#39; editor
[aadarsha@labserver ~]$ vi file2


# home directory of the current user --&amp;gt; /home/&amp;lt;user-name&amp;gt;

# Viewing the contents of the file
[aadarsha@labserver ~]$ cat file1
This is my first file...
[aadarsha@labserver ~]$ cat file2 
This is my second file...

# Modifying the content of the file
[aadarsha@labserver ~]$ vi file2
[aadarsha@labserver ~]$ cat file2
This is my second file...
This is added later

[aadarsha@labserver ~]$ ls
file1 file2 mydir1

[aadarsha@labserver ~]$ cd mydir1/
[aadarsha@labserver mydir1]$ pwd
/home/aadarsha/mydir1

[aadarsha@labserver ~]$ cd /

[aadarsha@labserver /]$ cd ~
[aadarsha@labserver ~]$ 
&lt;/code&gt;&lt;/pre&gt;</description></item></channel></rss>