0% found this document useful (0 votes)
52 views7 pages

Linux Commands and Administration Guide

kb8day 3

Uploaded by

Rubi Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Topics covered

  • soft link vs hard link,
  • systemd,
  • system logs,
  • file modification,
  • environment variables,
  • file system hierarchy,
  • system security,
  • file operations,
  • shell commands,
  • system troubleshooting
0% found this document useful (0 votes)
52 views7 pages

Linux Commands and Administration Guide

kb8day 3

Uploaded by

Rubi Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Topics covered

  • soft link vs hard link,
  • systemd,
  • system logs,
  • file modification,
  • environment variables,
  • file system hierarchy,
  • system security,
  • file operations,
  • shell commands,
  • system troubleshooting

sudo -i

*.pem --> *.ppk (puttyKeyGen)


sudo su -

Delhi --> Eye Close --> Australia


ec2-user root ec2-user

sudo su -

sudo su ( Existing user home directory)

sudo su -

dr-xr-xr-x 4 root root 4096 Mar 21 22:01 boot


permission SymLink Owner Group Size Date/Time Dir

ls
ls -l
ls -la
ls -ltr

ls -al

. -> Current File System


.. -> Prevous File System

whoami
id
pwd
cd
.
..
ls
ls -l
ls -la
ls -ltr

mkdir
echo "hihi" > [Link]

touch [Link]

init 0
----------------------------------------
cat [Link]
tail -f
head
tail

Apache Web server :


80 http://
443 https://

RHEL -> yum


DEBIAN (ubuntu) -> apt-get
yum install httpd -y

systemctl status httpd

systemctl start httpd

Open port in Security group of AWS EC2 instance ( 80 / 443)

netstat -plant

Cross test on browser

[Link]

Customize webpage

cd /var/www/html/

echo "hello world" > [Link]

systemctl restart httpd

Cross test on browser

[Link]

Read log frequently :

cd /var/log/httpd/

ls -ltr

tail -f access_log

--------------------------------------
Soft Link vs Hard Link :

ln
Soft Link -> Short-Cut (-s)
Hard Link -> Store at differnt Memory address

inode number ( Unique Integer number)

ls -iltr

Soft Link ( Differ inode)

ln -s [Link] /opt/

/root/[Link] --> /opt/[Link]

If we delete origional file of symlink, then link file will treated Dangling
link.

Hard link :

- same inode number


- If we delete origional of that link, hard link will work as actual
file.
----------------------------------------
network commands:
ifconfig
nmcli (need to install when we read RPM command)
ip a
ip addr
ip route
cat /etc/hosts
curl [Link]
netstat -plant
man
cat
-------------------------------------
less

more

Linux FHS

df -hT
/ -> Main file system
/dev -> HDD + USB + CDROM mount here
/bin/ -> Binary command (ls , pwd, mkdir)
/sbin/ -> system binary (OS)
/home/ -> Local user create (By default)
/home/tgIndia/
/home/Mahindra/

/usr/ -> user file system (Program files)


/var/ -> variable file system (Web Hosting) most of the
servers are exist here.
/srv/

/etc/ -> Configuraton file system (Config files)


/opt/ -> optional file system
/mnt/ -> mount point
/tmp/ -> temp file system (30 days data can store)

mount point --> logical location where partition availble for access.
/ \
Temp FS Parmanent FS

/lib/
/lib64/
Kernel -> Itermediate unit (OS Software) Intraction between h/w and s/w.

(Kernel is collection of multiple modules


Bluetooth module
wifi module
Graphics module)

Linux -> Kernel

Linux Operating System -> Kernel + applications


------------------------------------------------------------------
Unix : HP-UX , IBM - AIX , Sun Microsystem , Apple ios
------------------------------------------------------------------
du
-> Disk Usages

Ex: du -hs <File-or-Dir>

du -hs *

pwd

free -gh

(Diff b/w buffer and cache memory)


cat /proc/meminfo
cat /proc/cpuinfo

id
uid - user id
gid - group id

/etc/passwd

root :x: 0: 0 :root: /root/: /bin/bash


Uname Password UID GID Gcos Home Directory shell
(Comment Area)

User / Process

0 -> root (Super user)


1-999 -> process (Mysql database, Apache webserver, Oracle)

1 -> PID -> SystemD (init)

1000 - 65k (Local Users range)


/etc/passwd
-> /sbin/nologin (System)
-> /bin/bash (User can login)

> -> STDOUTPUT operator


>> -> Append operator
< -> STDINPUT operator

cat /etc/passwd | grep '/sbin/nologin' > [Link]

cat /etc/passwd | grep '/bin/bash' >> [Link]

-------------------------------------------------------
ps aux | less

top

ps -> process
a -> all
u -> user
x -> executable

Daemon -> Background Process are k/as daemons


(Antivirus / Clock / apache web server)
Zoombiee ->
-------------------------------------------------------
useradd or adduser

passwd

ls -l /home/

When we create user in Linux OS , where its password and structure create ?

Local user Schema --> /etc/passwd


Password -> /etc/shadow
Hint for Shadow Encryption Algorithm -->
[Link]
%246%20%E2%80%93%20The%20hashing%20algorithm%20prefix,Linux%20but%20not%20common
%20elsewhere.

group -> /etc/group


group password --> /etc/gshadow

groupadd tgIndia
--------------------------------------------------
Permission in Linux OS

r read 4
w write 2
x execute 1
-------
rwx 7

USer/Owner Group Others

- rw- r-- r-- 1 root root 0 Apr 8 03:30 [Link]


6 4 4

d rwx r-x r-x 2 root root 6 Apr 8 03:30 TgIndia


7 5 5

Permission bits = 10 bits

7 5 0
rwx r-x ---

7 7 7
rwx rwx rwx

u user
g group
o other

a all

+ allow
- deny
= assign
--------------------------------------------------

chmod --> Change Modification of permission bit


chown -> Change ownership of file / dir
chgrp -> Change group ownership

Special permission
Stricky bit
SGID
SUID
---------------------------------------------------
Group
/ \
P. Group Supplimentry / Secondary Group
-g -G
(1) (n)

---------------------------------------------------
chattr

usermod

uname

timedatectl

hostnamectl
---------------------------------------------------
cp
rm
mv
--------------------------------------------------
ssh-keygen
scp
tar

cronjob

yum / dnf / rpm

ps
kill
top
htop
nice
renice

nmap
host
dig
nslookup

screen
last
lastlog
w
whoami
which
whereis

grep -> Pattern find (like operater in SQL)

cat /etc/acpi/actions/[Link] | grep -i gnome --color

pgrep
----------------------------------------
cut

awk

sed

------------------------------------

Common questions

Powered by AI

Process management tools such as 'ps', 'top', and 'htop' are instrumental in monitoring and managing Linux system performance by offering real-time insights into running processes. 'ps' provides a snapshot of current processes, their statuses, and associated details like IDs and resource usage, aiding in identifying rogue processes . 'top' offers dynamic, real-time process listing with resource usage metrics like CPU and memory load, enabling administrators to make on-the-fly management decisions . 'htop' extends this capability with an interactive interface, displaying comprehensive details and facilitating easier filtering and manipulation of processes. Together, these tools empower system managers with the ability to efficiently diagnose performance issues, manage system resources, and enhance overall stability.

To install and start an Apache HTTP server on a Linux-based AWS EC2 instance, first update the package list using a package manager like 'yum' on RHEL-based systems or 'apt-get' on Debian-based systems . Install the Apache HTTP server with commands such as 'yum install httpd -y' or 'apt-get install apache2'. After installation, start the Apache service using 'systemctl start httpd' and check its status with 'systemctl status httpd' to ensure the service is active and running . It is crucial to open ports 80 (HTTP) and 443 (HTTPS) in the AWS EC2 security group to allow external access to the web server . This setup is essential for serving web content, hosting websites, and ensuring secure and reliable access over the internet.

Soft links, or symbolic links, serve as shortcuts that point to the original file using a different inode number, making them a separate entry with their path. Deleting the original file of a soft link results in a dangling link, as the link depends on the path of the original file . In contrast, hard links share the same inode number with the original file, effectively serving as an additional name for the same file data. Deleting the original file does not affect a hard link because the data is still present on disk, and remains accessible through the hard link . The fundamental difference lies in the storage, as soft links merely point to another file, whereas hard links maintain the file data directly by referencing the same inode.

The Linux kernel plays a pivotal role in system operations by acting as the core interface between hardware and software. It manages system resources effectively and provides essential abstractions for sophisticated operations . Key components include modules like the Bluetooth, Wi-Fi, and Graphics modules, which facilitate hardware compatibility and performance . The kernel ensures smooth communication by regulating tasks such as memory management, process scheduling, and I/O operations. By abstracting hardware functions into manageable software calls, it allows applications to function efficiently across varied hardware setups, ensuring optimal interactions and maximizing resource efficiency. The kernel's modular nature enables customizable and scalable system operations tailored to specific workload demands, thereby enhancing the adaptability and robustness of Linux systems.

Reading Apache log files is crucial for monitoring web server activity and diagnosing potential issues. Logs such as 'access_log' and 'error_log' provide detailed records of client requests and server errors, respectively . To analyze these files, navigate to '/var/log/httpd/' and use terminal commands like 'tail -f access_log' to view live logs or 'less' to browse through them at a manageable pace . Monitoring logs help in identifying traffic patterns, unauthorized access attempts, and internal server problems, thus aiding in maintaining server health and enhancing security. By frequently examining logs, administrators can make informed decisions to optimize server performance and preemptively address concerns before they escalate.

In Linux, the file system is organized into directories each serving a particular purpose: /bin contains essential binary commands necessary for the user's and boot processes like 'ls' and 'mkdir'. /sbin hosts system binaries like system administrative commands primarily used by the 'root' user . /home is designated for user-specific files and directories, containing each user's data and settings . /usr stores user-related programs and libraries but not essential for the basic functionality of the system at boot . /var holds variable data files, including log files, web files, and temporary data used by various services . /etc is critical for configuration files which administer system settings and service configurations . Each directory is structured to compartmentalize the system's functions, aiding organized and efficient management.

The Linux File System Hierarchy Standards (FHS) optimize system performance and organization by establishing a consistent directory tree layout, essential for users and applications. Directories are tailored for specific uses: '/bin' and '/sbin' contain essential binaries for general and system use; '/home' organizes personal user files; '/var' holds variable data such as logs and temporary files used by programs, facilitating efficient access and resource management . This structured storage ensures that programs and users have predictable paths for accessing needed resources, improving efficiency. Furthermore, FHS provides a unified framework for diverse applications to adhere to which reduces compatibility issues and simplifies admin operations, contributing to enhanced performance and streamlined resource access.

In Linux, user IDs (UIDs) and group IDs (GIDs) are essential for managing access permissions and security. A UID is a unique number assigned to every user, dictating access levels and ownership over files and processes . GIDs identify a group, encompassing multiple users, allowing for collective permission assignments . This dual identification system enables fine-grained permission management, facilitating secure group-based access control while ensuring individual accountability. Moreover, tools like '/etc/passwd' and '/etc/group' manage these IDs and affiliations, acting as critical components in preventing unauthorized access and maintaining system integrity through defined user roles and permissions.

In Linux, inodes are fundamentally significant to file management as they store metadata like file size, permissions, and ownership. Each file has a unique inode number within a file system, which is critical in distinguishing hard and soft links . Hard links share the same inode number with the original file, which means they directly point to the same storage blocks, making them indistinguishable from the original and immune to data loss if the original is deleted . In contrast, soft links use different inode numbers and instead, reference the path to the original file. Consequently, soft links function as shortcuts and become dangling if the target is deleted, showcasing the inode's role in differentiating link types in file systems.

File directory permissions in Linux are structured in a tripartite format - owner (user), group, and others, each with distinct permission settings including read (r), write (w), and execute (x). These permissions are represented numerically where "r" equals 4, "w" equals 2, and "x" equals 1 . For instance, the permission 755 translates to the owner having full access (rwx or 7), while the group and others have read and execute permissions (r-x or 5). This structure governs the control over who can read, modify, or execute files, thus impacting user access control by offering flexible yet secure management at various hierarchical levels . Adjustments in permissions, done using commands like 'chmod', allow administrators to tailor access as required.

You might also like