Linux-All Lectures
Linux-All Lectures
System Administration
Ubuntu-
▪ It can be used as easy graphical Linux desktop without the use of command line.
▪ It comes with a lots of pre-installed apps and easy to use repositories libraries.
▪ It releases every six months and currently working to expand to run on tablets and
Prepared by- Amitabh Srivastava
smartphones.
Linux Distributions
Linux Mint-
▪ Mint is based on Ubuntu and uses its repository software so some packages are
common in both.
▪ Earlier it was an alternative of Ubuntu because media codecs and proprietary software
are included in mint but was absent in Ubuntu.
▪ But now it has its own popularity and it uses cinnamon and mate desktop instead of
Ubuntu's unity desktop environment.
▪ Debian has its existence since 1993 and releases its versions much slowly then Ubuntu
and mint.
▪ Ubuntu is based on Debian and was founded to improve the core bits of Debian more
quickly and make it more user friendly.
▪ Every release name of Debian is based on the name of the movie Toy Story.
▪ There products are red hat enterprise Linux (RHEL) and Fedora which are freely
available.
▪ RHEL is well tested before release and supported till seven years after the release,
whereas, fedora provides faster update and without any support.
▪ CentOS is a community project that uses RedHat enterprise Linux code but removes all
its trademark and make it freely available. In other words, it is a free version of RHEL
and provide a stable platform for a long time.
Prepared by- Amitabh Srivastava
Linux Distributions
Fedora-
▪ It is a project that mainly focuses on free software and provides latest version of
software.
▪ It doesn't make its own desktop environment but used 'upstream' software.
➢ Memory Management
➢ Resource Management
▪ The shell gets started when the user logs in or starts the
terminal. Prepared by- Amitabh Srivastava
Types of Shell
▪ There are many different types of shell available in
Linux. Some of them are-
✓ Csh- C Shell
▪ It is a primary platform for all major IDEs, game development tools and AI/ML
software.
▪ It offers essential applications for web browsing, messaging, gaming and content
creation, including Firefox, Chrome, OBS Studio, supporting all daily computing
needs.
▪ It prioritizes user privacy and system integrity, making it the secure choice for
those who value data protection.
Prepared by- Amitabh Srivastava
Ubuntu Server
▪ Ubuntu Server is a Free and Open-source operating system.
▪ Developed and maintained by Canonical Ltd. with regular LTS (Long Term Support) releases.
▪ No GUI by default, which reduces system overhead and makes it ideal for performance.
▪ Pre-packaged software in the Ubuntu repository (e.g., Apache, Nginx, MySQL, PostgreSQL,
Docker).
▪ Excellent support for cloud platforms like AWS, Azure, and Google Cloud.
▪ Kubuntu is an official Ubuntu flavour that uses the KDE Plasma desktop environment instead
of the default GNOME desktop found in Ubuntu.
▪ Plasma offers a sleek, visually stunning desktop with modern animations and effects.
▪ Users can modify themes, widgets, taskbars, and window decorations easily with the KDE
System Settings.
▪ Plasma includes many productivity tools like Krita, Kdenlive, and Okular for drawing, video
editing, and document viewing.
▪ KRunner is a powerful launcher that helps you quickly access apps, settings, and files.
Prepared by- Amitabh Srivastava
Key Apps of Kubuntu
▪ Dolphin File Manager-
A powerful file manager with features like tabbed browsing, advanced file search,
and integration with cloud services.
▪ Konsole Terminal-
A robust terminal emulator, great for developers and advanced users who need
command-line access.
▪ LibreOffice Suite-
Kubuntu comes with LibreOffice pre-installed for word processing, spreadsheets,
and presentations. Prepared by- Amitabh Srivastava
Xubuntu
▪ Xubuntu is an official Ubuntu flavor that uses the XFCE desktop environment, focusing on
providing a lightweight, efficient, and user-friendly experience.
▪ XFCE is a lightweight desktop environment that uses fewer system resources, making it ideal
for low-resource or older hardware.
▪ Xubuntu provides a fast, responsive experience even on systems with limited RAM or CPU
power.
▪ XFCE offers a simple, straightforward interface with a traditional desktop layout (menu, taskbar,
system tray).
▪ XFCE is customizable, allowing users to tweak the appearance and functionality of the desktop
environment to suit their preferences.
▪ Includes the ability to change themes, panel layouts, and add widgets, but it remains simple
and uncluttered. Prepared by- Amitabh Srivastava
Key Apps of xubuntu
▪ Thunar File Manager-
It is a lightweight, easy to use, and highly customizable, allowing users to manage
files quickly and efficiently. Includes features like customizable actions, a simple
search function, and file previews.
▪ XFCE Terminal-
A fast and efficient terminal emulator, perfect for users who prefer command-line
operations.
▪ You can verify whether GParted is successfully installed or not using the below
command which gives an output similar to below image-
• Loads the operating system's kernel and necessary files into memory from the
boot device.
• Sets up the necessary environment for the operating system to start execution.
• Transfers control to the operating system, handing off the boot process to the
kernel. Prepared by- Amitabh Srivastava
Best Linux Bootloader
GRUB-
GRUB or Grand Unified Bootloader is one of the most popular and widely used
bootloaders in Linux. It supports a wide range of operating systems, provides a user-
friendly interface, and offers advanced features. GRUB supports features like dual-
booting, customizable boot menus, and compatibility with various filesystems. It is
highly flexible and is the default bootloader in many Linux distributions.
LILO-
LILO or Linux Loader is another well-known bootloader that has been used in Linux
for a long time. It is known for its simplicity and reliability. LILO can handle various
disk layouts and supports multiple boot options. While it may not have as many
advanced features as GRUB, LILO is still a solid choice, especially for users seeking a
straightforward and stable bootloader.
Prepared by- Amitabh Srivastava
Linux Boot Process
BIOS is an acronym for Basic Input/Output System. In other words, the BIOS can load
and run the MBR (Master Boot Record) boot loader. When we first turn on our system,
the BIOS first implements a few integrity checks of the SSD or HDD.
After that, the BIOS finds, loads, and runs the boot loader function, which can be
detected in the MBR. Then, the boot loader function is loaded into memory.
Step-2- MBR
MBR is an acronym for Master Boot Record and is liable to load and run the GRUB boot
loader. MBR is placed in the first bootable disk sector, which is generally /dev/sda,
relying on our hardware.
GRUB is known as GRand Unified Bootloader. It is the classic bootloader for almost all
the latest Linux systems. The splash screen of GRUB is often the initial thing we see
when we boot our system.
It contains a general menu where we can choose some portions. We can use our
keyboard to choose the one we wish our system to initiate with if we have multiple
installed kernel images. The latest kernel image is chosen by default.
The splash screen will delay for some seconds for us to choose options. It will load the
kernel image (default) if we don't. In several systems, we can see the GRUB
configuration file at /etc/grub/conf or /boot/grub/grub.conf.
Often, the kernel is called the code of an operating system. In this boot process stage,
the kernel mounts the base file system that was chosen that is set up in the file,
i.e., grub.conf.
Then, it runs the /sbin/init function, which is always the initial function to be run. We
can confirm it with its PID (process id), which should be always 1.
Then, the kernel creates a temporary base file system with the help of initrd (Initial
RAM Disk) until the actual file system is mounted.
init is the parent of all processes and it is executed by the kernel and is responsible for
starting all other processes.
At this stage, our system runs runlevel programs. It would find an init file, generally
detected at /etc/inittab, to determine the run level of Linux. Modern Linux systems use
systemd to select a run level rather. There are six runlevels in the Linux-
Runlevel 0- halt
Runlevel 1- single-user mode
Runlevel 2- multiuser, without NFS
Runlevel 3- Full multiuser mode
Runlevel 4- unused
Runlevel 5- X11
Runlevel 6- reboot Prepared by- Amitabh Srivastava
Linux File System Structure
▪ Linux file system has a hierarchal file structure as it contains a root
directory and its subdirectories.
touch -- -file.txt
It will create an empty file as ‘-file.txt’ whose first character is hyphen (-). in current directory.
touch –a file1.txt
It will change the access time of file called ‘file1.txt’ and set it as current time.
(use ‘stat <filename>’ command to check the access time of file)
touch –m file1.txt
It will change only the modification date & time of file ‘file1.txt’ to current date and time.
touch –t 201210280605 file1.txt (format used- YYYYMMDDHHMM)
It will change the access & modification date & time of file ‘file1.txt’ to 2012-10-28 06-05.
Options-
mkdir mydir
It will create the directory “mydir” in the current directory.
mkdir –p one/two/mydir
The –p option allows the creation of parent directories if required. So, the above
command will create directories one and two if they do not exists and then finally
create mydir inside the directory two.
wsl –u root
rm –i <filename(s)>
It will interactively confirm the deletion of file from the user.
rm –f <filename>
If the file is write-protected, it will not ask for the confirmation and forcefully deletes the file.
rm –r <dirname> or rm –R <dirname>
It performs a tree-walk and delete all the files and sub-directories recursively from the current directory.
rm-- <-filename>
It will delete the file whose first character is hyphen (-). Prepared by- Amitabh Srivastava
rmdir command
rmdir command is used to remove empty directories.
By default, it does not remove directories. It works silently so we should be careful while deleting any
file/directory using ‘rm’ command.
Options-
rmdir dir1
This will delete single directory ‘dir1’ only if it is empty.
rmdir –p dir1/d1/d2/d3
This will delete the entire given directory structured only if it is empty(no files/subdirectories should be inside).
Merging Commands
▪ We can also execute two or multiple commands in a single line.
▪ To do so separate the commands with semicolon (;) symbol.
Prepared by- Amitabh Srivastava
Some Useful Commands
▪ mv file1 file2
It will change the name (rename) of ‘file1’ to ‘file2’.
▪ mv file1 dir1/file2
It will move the file ‘file1’ into the directory ‘dir1’ and set the filename as ‘file2’.
▪ pwd
It will display the absolute path of current directory. (Present Working Directory)
▪ whoami
It will print the logged in username.
▪ man <command>
It will display the manual/help of the given command. ‘spacebar’ to move screen forward, ‘b’ to move
screen backword and ‘q’ to quit from manual.
▪ file <filename>
It will display the file type information along with filename.
▪ file –b <filename>
Prepared by- Amitabh Srivastava
Will display the file type information in brief mode. Removes the filename from output.
cp Command
▪ cp command is used to create copy of file(s).
▪ Syntax-
cp source_file destination
▪ This command creates a copy of the source_file at the specified destination.
▪ Examples-
▪ cp a.txt b.txt
This command contains two file names, it copies the contents of the first file
(a.txt) to the second file (b.txt). If the second file (b.txt) doesn’t exist, it is
created, and the content is copied into it. However, if the second file (b.txt)
already exists, it is overwritten without warning.
Prepared by- Amitabh Srivastava
cp Command- Examples
▪ Examples-
▪ To Interactive copying with a warning before overwriting the destination file, we can
use –i option with cp command.
Prepared by- Amitabh Srivastava
Practice Question
▪ Create the files and directories as per the below tree diagram-
Options-
ls-l
It will show the list of files / directories in a long list format in total 7 respective
columns.
ls –a
In Linux, hidden files start with . (dot) symbol and they are not visible in the regular directory.
This option will enlist the whole list of the current directory including the hidden files.
ls –i or ls--inode
Shows the index number of each file and directory.
ls –lh
This command will show you the file sizes in human readable format.
ls –lS
It will display the files in descending order (highest at the top) according to their size.
ls –lr
It will display the files in reverse order. Prepared by- Amitabh Srivastava
find command
find command is used to find files and directories in a Linux file system.
Options-
-name <filename>
Search files with specific filename.
-inum <inode_number>
Search file having specified i-node / index number.
-empty
Search only empty files and directories.
-perm <permission_in_number>
Search files and directories having specified permissions.
-user <username>
Search files owned by specified username.
-type f/d
Display regular files with ‘f’ and directories with ‘d’.
Prepared by- Amitabh Srivastava
locate command
locate is an utility command used to search files and directories quickly. It is more convenient and
effective than ‘find’ command.
locate command doesn’t search the entire file system, but it looks through a regularly updated file
database called ‘mlocate’ or ‘plocate’ in the system. To update the locate database, ‘updatedb’
command is used.
If any file created after updating the locate database, it will not include in the search result.
Example-
locate file1-> this command will search and display all files containing the ‘file1’ pattern in the filename.
Options-
locate file1 | less
This will be convenient way to see the output if there are large number of files in the output. ‘Spacebar’ is used to
move forward, ‘b’ key to move backward and ‘q’ key to quit.
locate –h or locate--help
Displays the usage of locate command with its available options.
▪ It facilitates to display the contents one screen/page at a time in case of large files along with the
display ratio (in percentage).
Options-
more <filename>
It will display the contents one screen/page at a time.
more –d <filename>
It will display the help to the user regarding navigation controls at the end of every screen.
“[Press space to continue, ‘q’ to quit.]”
more-5 <filename>
It will display 5 number of lines per screen of the given filename.
history
It will display the list of previously used commands.
history 5
It will display the last/recent 5 commands used. (including this command)
!!
It will execute the last command used.
!<command_number>
It will display and excutes the the command from history at given command_number.
Example- !1201
history –d <command_number>
It will delete the command from history at given command number position.
Prepared by- Amitabh Srivastava
head command
▪ head command is used to display the top N number of lines from the given input.
▪ By default, it will print first 10 lines from the given file/input.
Options-
head myfile
It will display the first 10 lines of file called ‘myfile’.
head –v <filename>
It will always displays the filename before the contents of the file. Prepared by- Amitabh Srivastava
head Examples
▪ Examples-
head –n-7 file1.txt
It will ignore last 7 lines from the file ‘file1.txt’.
Q.2
▪ Print the most recently 3 modified files from the current directory.
▪ Solution-
ls –t | head-3
Prepared by- Amitabh Srivastava
id command
▪ Prints the User and Group IDs of currently logged user if username is omitted.
▪ If username is given, will display the User and Group IDs of given username.
Options-
$ id –g or id –group
Prints only the effective group id.
$ id –G or id –groups
Prints all the group ids user belongs to.
$ id-u
Prints only the user id of currently logged user.
$ id <username>
Prints all the User and Group IDs of specified username. Prepared by- Amitabh Srivastava
uname command
▪ Prints the system information.
Options-
$ uname-s $ uname-o
Prints the kernel name. Prints the operating system name.
$ uname –n $ uname-a
Prints the host name. Prints all the system information.
$ uname –r $ uname-p
Prints the kernel release. Prints the processor type.
$ uname-v
Prints the kernel version with release date.
$ uname-m
Prints the machine’s hardware type.
Prepared by- Amitabh Srivastava
date & timedatectl command
date command displays the current date and time, including the abbreviated day name,
abbreviated month name, day of the month, the time separated by colons, the time
zone name, and the year.
timedatectl command lets you set your time, date, and time-zone for your system clock.
Options-
timedatectl list-timezones
It will display the list of all time zones.
date
It will display the current system date and time. The format is-
date –u
It will display the system date and time in GMT(Greenwich Mean Time)/UTC(Coordinated Universal
Time).
date--date “5 days”
It will display the date 5 days after the current system date and time. Prepared by- Amitabh Srivastava
date command...contd.
Options and Examples-
Examples-
$ date +%D
11/28/23
cal
It will display the calendar of current month.
cal <yyyy>
It will display all the months of given year.
cal –j <yyyy>
It will display the calendar of given year in Julian calendar format. In Julian calendar date is not reset to
1st after every month.
$ echo ‘20+5’ | bc
$ echo ‘scale=2; 3/2’ | bc
▪ To add any user in sudo group, just give the following command-
▪ To confirm if the user is successfully added in sudo group, just open the /etc/group
file and see the added username entry against the sudo group.
▪ $ cat /etc/group
$chmod u-x,g-x,o-wx file1.txt (to remove permissions, use- sign) Prepared by- Amitabh Srivastava
chmod Operators
Examples-
▪ umask value is responsible to set default permissions for files and directories created
by the user.
▪ umask value is subtracted from the full file permission and full directory permission.
▪ Default umask value can be defined under user’s home directory .bashrc file.
Prepared by- Amitabh Srivastava
chown command
▪ chown command is used to change the owner or group of a file/directory.
▪ Only root or sudo users can run this command.
Options-
chown <username> <filename/directory>
It will change the current user/owner of the file/directory to the given username.
▪ It is used to install new software packages, upgrade existing software packages, update the
package list index, and even upgrade the entire Ubuntu system.
▪ Actions like installation and removal of packages are logged under the /var/log/dpkg.log file.
▪ Examples-
✓ Installing packages-
sudo apt install <package_name>
✓ Removing packages-
sudo apt remove <package_name>
adding the --purge option with remove will remove the package along with its
configuration files as well, so use it with caution. Prepared by- Amitabh Srivastava
Advanced Packaging Tool (apt)
▪ Examples-
✓ Upgrading packages-
To upgrade your system, first update your package index and then perform the
upgrade as follows-
sudo apt update
sudo apt upgrade
✓ $ apt list
List packages based on package names
▪ It can install, remove, and build packages, but unlike other package management
systems, it cannot automatically download and install the dependencies required for
that package.
Options-
df
It displays information about all the mounted file systems like total size, used space, usage percentage, and the
mount point.
df <filename>
It will display the mount information of the given filename.
df -h
It will display the disk space usage in human readable form (in KB/MB/GB).
df --total
It will display the grand total of disk space usage at the end.
df --help
It will display the help on ‘df’ command.
Prepared by- Amitabh Srivastava
du command
▪ Disk Usage utility provides information of a directory or file space usage.
▪ Displays information about the storage consumption of files and directories.
Options-
du
It displays the disk usage information of current directory. (by default, numbers in KB)
du <filename>
It will display the storage information of the given filename.
du -h
It will display the disk space usage in human readable form (in KB/MB/GB).
du --time <filename>
It will display the disk space usage along with the last modification time of the given filename.
du --help
It will display the help on ‘du’ command.
Prepared by- Amitabh Srivastava
Linux
System Administration
[ ST.2 ]
▪ Creating a user is automatically creating a primary group for the user. So, a user is
automatically a member of its primary group.
▪ For example, if I create a user Kavita, Kavita group is automatically a primary group
for the user Kavita.
▪ If you create a new user and open the “/etc/passwd” file where the attributes of
users are found, you will notice in one of the fields, a primary group ID is
automatically assigned to the user.
▪ Similarly, open the “/etc/group” file where the group information is stored, you will
by default see the name of the group as the username with the corresponding group
ID in the file. Prepared by- Amitabh Srivastava
Secondary Group of User
▪ The secondary group is the second, third, n.. group that a user is added
to.
▪ In other words, the secondary group is the other group a user is added
to.
▪ No user can have more than one primary group but a user can be added
to more than one secondary group.
passwd –e <username>
It will enforce the user to change the account password on next login attempt. Prepared by- Amitabh Srivastava
passwd command...(cntd.)
▪ All the password information is stored in a file /etc/shadow.
▪ User password expiry information can be viewed using command ‘chage –l <username>’
Options-
passwd –n <no. of days> <username>
It will change the minimum number of days between password change. Means, if the no. of days is set to 2, and user
changes its own password one time then he/she cannot change its own password until 2 days have passed. By
default, this value is set to ‘zero’ (0) means, user can change its own password at any time.
passwd –S <username>
It will show the password status of the user in 7 fields.
First field- User’s login name
Second field- Indicates if user has a locked password (L), has no Password (NP), or has a usable password (P).
Third field- Date of the last password change.
Next four fields are the minimum age, maximum age (enforce to change the password), warning period, and
inactivity period for the password. These ages are expressed in days.
▪ Now, save the file and give the chpasswd command with following syntax-
chpasswd < filename
▪ Ownership of user for user & group assigns to the home directory.
▪ Primary group is also created for the user with same name as
username.
Prepared by- Amitabh Srivastava
useradd command
▪ It is used to add/create new user accounts through command line.
Options-
useradd –m <username>
It will add a new user and creates the home directory as specified.
useradd --help
It will display the help section of useradd command.
Prepared by- Amitabh Srivastava
usermod command
▪ It is used to change/modify the properties of an existing user through command line.
▪ After creating a user, if you want to change its home directory or group information, etc. then you can
use ‘usermod’ command.
Options-
usermod –c “Local user” <username>
It will add a comment “Local user” for the given username. Comments are stored in 5th field of /etc/passwd file.
usermod –d /home/ram ram001
It will change the default home directory of user ram001 to /home/ram. This new home directory must be created
separately. Home directories are stored in 6th field of /etc/passwd file.
usermod –e 2023-12-25 <username>
It will set the expiry date for the given username. Expiry dates are stored inside /etc/shadow file.
Check expiry information using command- ‘chage –l <username>’
usermod –g <newgroup> <username>
It will change the primary group for the given username to <newgroup>. Group-id is stored in 4th field of /etc/passwd
file. All group names are stored in /etc/group file.
usermod –aG sudo <username>
It will add the given username to the ‘sudo’ group. ‘id’ command is used to check the group information.
Prepared by- Amitabh Srivastava
usermod: Practice Exercise
▪ Create a new user account by name: testuser001
▪ Now, do the following-
▪ Change testuser001 username to test_user1
▪ Set test_user1 home directory to /home/test_user1
▪ Add test_user1 to sudo group to grant him administrative priviliges.
Solution-
Change testuser001 username to test_user1.
$ sudo usermod –l test_user1 testuser001
$ chage –E 2025-12-31 newuser001 use -1 with –E option to remove the expiration date.
Will set the account expiration date to 31st December 2025 for user ‘newuser001’.
$ chage –W 3 newuser001
Will set the warning period (in days) before the password expires.
$ chage –M 5 newuser001 user –m for minimum no. of days between password change.
Will set the maximum number of days between password change.
Solution-
groupadd <grpname>
It will create the specified group.
groupadd –r <grpname>
It will create the specified system group. The IDs of system groups are chosen from a
range 1 to 999 defined for system groups in the configuration file. The IDs of normal
users start from 1000. Prepared by- Amitabh Srivastava
groupdel command
▪ It is used to delete an existing group.
Options-
groupdel <grpname>
It will delete the specified group.
groupdel –f <grpname>
It will delete the specified group even if it is the primary group of a user.
userdel <username>
It will delete the specified user account.
userdel –f <username>
It will delete the specified user even if the user still logged in.
userdel –r <username>
It will also delete the user’s home directory.
Step-1-
Login as ‘root’ user.
Step-2-
Run the following command-
# chsh –s /usr/sbin/nologin <username>
Step-3-
Exit from ‘root’ user and try to login with blocked username.
Step-2-
Create a file with name ‘security’ under /home and write following contents in it-
#!/usr/bin/tail +2
This account has been temporarily blocked due to SECURITY BREACH!
Please contact your system administrator or call at 0512-06321.
Step-3-
Run the following command-
# chmod 755 security
Step-4-
Run the following command-
# chsh –s /home/security <username> Prepared by- Amitabh Srivastava
Practice Question
▪ Add 3 users as Ram, Shiva and Shree.
▪ To paste- Ctrl + u
grep –l “linux” *
It will display the filenames that matches that pattern.
Example-
Example-
$ cd ..
$ grep –r user *
ls –l | grep “file”
It will display all the files having name containing the given pattern.
To display all the files having extension .txt. To display total no. of directories.
ls –l | grep “.txt$” ls –l | grep –c ^d
To display the user information of the users those names start with the word user.
cat /etc/passwd | grep ^user
Question-
Write a grep command to display all those lines with there line numbers containing
words either ‘then’ or ‘those’.
Solution-
▪ Write the egrep command with correct regular expression that matches only valid email addresses.
▪ Solution-
▪ Write the egrep command with correct regular expression pattern that matches the
passwords having exactly one uppercase and one lowercase letter in it.
▪ Solution-
OR
➢ Remove duplicates-
Solution-
$ ls –l | sort –Mk6
wc <filename>
It will produce 4 columnar output- no. of lines, word count, char(byte) count and filename, respectively.
wc –l <filename1>
It will display no. of lines for the mentioned filename.
wc –w <filename1>
It will display no. of words for the mentioned filename.
wc –c <filename1> OR wc –m <filename>
It will display no. of characters (bytes) for the mentioned filename. Prepared by- Amitabh Srivastava
wc command...contd.
Options-
wc –L <filename>
It will display the length of longest line (characters count) of mentioned filename.
wc--version
It will display the version, author and copyright information of wc command.
Examples-
ls | wc –l
To count the no. of files and directories in the current directory.
cat /etc/passwd | wc –l
To count the total no. of users.
$ uniq --version
Prints the version details of uniq command.
Prepared by- Amitabh Srivastava
Practice Question-1
Consider the file ‘Employees’-
Question-
Display the fourth field (Dept.) in descending order only with the uniq values without
the heading (Dept).
Solution-
$ cut -d "," -f4 Employees | tail +2 | sort -r | uniq
Prepared by- Amitabh Srivastava
Practice Question-2
Consider the file ‘Emp’-
Question-
Display the employees firstname and Department whose firstname start with letter ‘D’
and department name starts with letter ‘S’ AND also the employees whose firstname
starts with either ‘G’ or ‘R’ and department name starts with letter ‘A’. Header row not
required.
Solution-
$ cut -d "," -f 1,4 Emp | tail +2 | grep -E '^D.*,[S]|^[GR].*,[A]'
Prepared by- Amitabh Srivastava
uptime command
▪ This command is used to find out the time for which the system has been in active(running) state.
▪ It returns a set of values that include the current time, and the amount of time the system is in
running state, number of users currently logged into, and the load time for the past 1, 5 and 15
minutes respectively.
$ uptime
Options-
$ uptime -p
Returns the total no. of hours and minutes of system active.
$ uptime -s
Returns the starting time by when the system is running.
Process can be a system process or user process. System processes are initiated by the kernel, while
users initiate User processes. Prepared by- Amitabh Srivastava
Process States in Linux
▪ The state of a running process at any point in time is called the context of a process.
▪ In Linux, a process can be in one of the five states-
▪ Running-
✓ The process is currently executing on the CPU.
▪ Sleeping-
✓ The process is waiting for a resource to become available.
▪ Stopped-
✓ The process has been terminated by a user.
▪ Zombie-
✓ The process has completed execution but has not yet been cleaned by the system.
▪ Orphan-
✓ The parent process of the current process has been terminated.
Prepared by- Amitabh Srivastava
Process Identity
▪ A process is identified by the process id (PID).
▪ By default, every process that you start runs in the foreground. It gets its
input from the keyboard and sends its output to the screen.
$ ps -x
Output contains four columns- Shows processes owned by currently logged user.
PID- the unique process ID
TTY- terminal type that the user is logged into $ ps -C <command_name>
TIME- amount of CPU in minutes and seconds Shows process by command name.
that the process has been running
CMD- name of the command that launched the process.
Prepared by- Amitabh Srivastava
top command
▪ The top command is used to display real-time information about processes running on a system,
including CPU and memory usage.
▪ It allows users to monitor the processes in real-time.
▪ it will open an interactive command mode where the top-half screen will contain the statistics of
processes and resource usage.
▪ The lower-half screen contains a list of the currently running processes.
▪ To kill a process, highlight it with up/down arrow keys and press ‘k’ key.
▪ To exit from the top view press ‘q‘ key.
$ top
➢ Memory Usage-
Fourth line reflects Physical memory classified as total, free, used and buffered/cached.
Fifth line reflects Virtual memory classified as total, free, used and available.
➢ $ top –d
Specifies the delay in seconds between screen updates.
Example-
$ top –d 2 this will refresh top screen every 2 seconds.
$ top--delay 2 same as –d option.
➢ $ top –E
Instructs top to force summary area memory to be scaled as kibibytes/mebibytes/gibibytes/tebibytes.
Example-
$ top –E k displays the memory usage summary in kilobytes. Prepared by- Amitabh Srivastava
nice/renice command
▪ nice and renice commands are used to manage the priority of a running process.
▪ The nice command is used to modify the priority of a process. It assigns a lower priority to a process
to reduce its resource usage.
▪ The renice command is used to modify the priority of an already running process. It can increase or
decrease the priority of a process which depends on the given value.
▪ There are different types of signals that you can send. However, the most common one is ‘kill
-9’ which is ‘SIGKILL’.
▪ If process ignore the default kill signal and doesn’t stop, you can send the SIGKILL signal to
terminate the process.
$ kill -9 pid Prepared by- Amitabh Srivastava
‘trap’ Command
The trap command run a certain piece of code in response to a particular signal. It
monitors signals and activates the specific code when the selected signal is received.
Example 1-
$ trap “echo You pressed CTRL+C” SIGINT
Example 2-
$cat > myscript.sh
echo “Hello Tech Guy!”
echo “How are you?”
Note- By default, the sed command replaces the first occurrence of the pattern/word in each line and it wouldn’t
replace the second or other occurrences in the same line.
=====OUTPUT====➔
Solution-
$ sed '/[cC]herry/s/Red/Maroon/' fruitcolor.txt
Prepared by- Amitabh Srivastava
Sed: Practice Question-2
Consider the below file fruitcolor.txt-
=====OUTPUT====➔
Q. Write the sed command to add “ish” at the end of each line except for
the color “Orange”?
Solution-
$ sed '/Orange/!s/$/ish/' fruitcolor.txt
Prepared by- Amitabh Srivastava
Sed: Practice Question-3
Consider the below file fruitcolor.txt-
=====OUTPUT====➔
=====OUTPUT====➔
Q. Write the sed command to add heading in the file as “Fruit Color”
and also creates a backup copy as fruitcolor.txt.bak?
Solution-
$ sed –i.bak '1i Fruit Color' fruitcolor.txt
The –i option make the changes inside file and .bak creates a backup copy of original file
fruitcolor.txt as fruitcolor.txt.bak. Prepared by- Amitabh Srivastava
Sed: Practice Question-4
Q. Create a pipeline using grep and sed command to display all the lines
containing the pattern “error” (as a whole word and ignore case sensitivity)
from file /var/log/syslog and also insert a blank line after every matched
line.
Solution-
$ grep -iw "error" /var/log/syslog | sed 'G'
===OUTPUT===➔
Solution-
$ grep '[0-9]' contacts.txt | sed 's/[0-9]/#/g'
Prepared by- Amitabh Srivastava
Sed: Practice Question-6
Q. Consider below a file “contacts.txt”. Now write a pipeline command to
display the lines containing the mobile numbers only and also replace all
mobile number digits with # symbol.
===OUTPUT===➔
Solution-
$ egrep "[0-9]{9}" contacts.txt | sed 's/[0-9]/#/g'
===OUTPUT===➔
Solution-
$ grep '@' contacts.txt | cut -d "@" -f 2
Q. Write an awk statement/command to print all the employee names only whose
salary is greater than 45k?
Solution-
$ awk -F ", " '{ if($5 > 45000) print $3}' Employees
Solution-
$ awk -F', ' '$4 == "Sales" {sum += $5} END {print sum}' Employees
53000
$ awk -F', ' '$4 == "Sales" {sum += $5} END {print "Total salary of Sales: " sum}' Employees
Total salary of Sales: 53000 Prepared by- Amitabh Srivastava
Awk: Practice Question-3
Consider the below file ‘Employees’-
$ awk -F', ' '$4 == "IT" {sum += $5; count++} END {print "Average Salary(IT): " sum/count}'
Employees
Average Salary(IT): 82000
Prepared by- Amitabh Srivastava
Awk: Practice Question-4
Consider the below file ‘Employees’-
Q. Print the name and salary of the employee with highest salary?
Solution-
$ awk -F', ' 'max < $5 {max = $5; name = $3} END {print name, max}' Employees
Gopal 86000
$ awk -F', ' 'BEGIN {max = 0} max < $5 {max = $5; name = $3} END {print name, max}' Employees
Gopal 86000
Q. Print the name and salary of the employee with minimum salary?
Solution-
$ awk -F', ' 'BEGIN {min = 999999} min > $5 {min = $5; name = $3} END {print name,
min}' Employees
Alok 25000
Q. Print the name and salary of the employees belongs to Sales and IT department?
Solution-
$ awk -F', ' '$4 == "Sales" || $4 == "IT" {print $3, $5}' Employees
Alok 25000
Firoz 28000
Ram 78000
Gopal 86000
Prepared by- Amitabh Srivastava
Awk: Practice Question-7
Consider the below file ‘Employees’-
Q. Print the name and salary of the employees belongs to Sales and IT department?
Show your output in the descending order of their salary?
Solution-
$ awk -F', ' '$4 == "Sales" || $4 == "IT" {print $3, $5}' Employees | sort –t “ “ –k2,2nr
Output-
Gopal 86000
Ram 78000
Firoz 28000
Alok 25000 Prepared by- Amitabh Srivastava
Shell Scripting
First Shell Script-
$ cat script1.sh
#!/bin/bash
echo “Hello World!”
The first line #! Is known as Shebang, a special comment which indicates what interpreter to use when
running this script. This comment is optional, if not used, the current shell is used as an interpreter.
$ sh script1.sh
Hello World!
$ ./script1.sh
-bash- ./script1.sh- Permission denied
$ ./script1.sh
Hello World! Prepared by- Amitabh Srivastava
User Defined Variables
Assignment with equal-to sign and returns value with $ sign as prefix in variable name.
$ x=10
$ y=20 Spaces are not allowed while assignment.
$ echo $x and $y $ x = 10
10 and 20 x- command not found
▪ To make sure the directory change persists even after the script finishes, you need to
ensure that the cd command is executed in the same shell session as the user
running the script.
▪ The trick is to source the script rather than running it. Sourcing the script will cause it
to run in the current shell session, so any changes to the environment (such as
changing directories) will persist even after the script finishes.
Example-1:
$ echo “hello how are you?” | tr ‘[:lower:]’ ‘[:upper:]’
HELLO HOW ARE YOU?
Example-2:
$ echo “LINUX IS AWESOME!” | tr ‘[:upper:]’ ‘[:lower:]’
Linux is awesome!
Number Comparison
String Comparison
$ sh myscript.sh
or
$ ./myscript.sh
if [ $a -eq $b ]
then
echo "a is equal to b!"
elif [ $a -gt $b ]
then
echo "a is greater than b!"
elif [ $a -lt $b ]
then
echo "a is less than b!"
fi
Prepared by- Amitabh Srivastava
Conditional Statements...contd.
Example- Example-
$ cat myscript.sh $ cat myscript.sh
Solution-
$ sh myscript.sh
or
$ ./myscript.sh
Prepared by- Amitabh Srivastava
Practice Question - 1
Q. Write a script that asks from user to enter an age. If age is less than 14 it should
print “Swimming not allowed” AND if age is greater than or equals to 14, then print
“Eligible for swimming!”
Solution-
read -p "Enter the age: " age
if [ $age -ge 14 ]
then
echo "Eligible for Swimming!"
else
echo "Swimming not allowed!"
fi
Prepared by- Amitabh Srivastava
Practice Question – 2 (and ‘-a’)
Q. Write a script that asks from user to enter an age. If age is greater than or equals to
18 AND less than or equals to 45 it should print “Eligible to Swim!”. Else it should print
“Swimming not allowed!”
Solution-
Solution-
read -p "Enter the age: " age
Solution-
read -p "Enter any number: " num
Solution-
read -p "Try your Guess: " num
if [ -s $fname ]
then
echo "File $fname exists!"
else
echo "File $fname does not exist!"
fi
if [ -d $dname ]
then
echo "Directory $dname exists!"
else
echo "Directory $dname does not
exists!"
fi
Prepared by- Amitabh Srivastava
Case Statement
▪ A case statement in shell script is used when a decision has to be made against multiple
choices.
▪ It is useful when an expression has the possibility to have multiple values.
Example-
3. If the file/directory does not exist, print: “File/Dir does not exist!.”
Syntax-
./scriptname arg1 arg2 arg3 …
▪ $0, $1, $2, $3, …, $n are known as positional parameters corresponding to the
./scriptname arg1 arg2 arg3, …, argN respectively.
▪ $# is used for total number of command line arguments except the scriptname.
$ cat myscript.sh
USAGE=" USAGE: ./scriptname <arg1> <arg2> <arg3> <arg4>"
if [ "$#" != 4 ]
then
echo $USAGE
exit 1
fi
✓ If the arguments are more than two, it should display the proper message to give only two
arguments.
✓ If only one argument is supplied, the 2nd argument should take the default number value.
✓ If provided filename exists, display top N lines from that file, if it does not exist display
proper message that “file does not exist!”.
Prepared by- Amitabh Srivastava
Practice Code – 1: Solution
if [ $# -lt 2 -a $# -gt 0 ] elif [ $# -gt 2 ]
then then
if [ -s $1 ] echo "There must be exactly two arguments!"
then exit 1
head -n 7 $1 elif [ -s $1 ]
else then
echo "File $1 does not exist!" echo "Displaying first $2 lines of $filename: "
fi head -n $2 $1
elif [ $# -eq 0 ] else
then echo "File $1 does not exist!"
head -n 7 /var/log/syslog fi
1. A number (num1)
2. Any of the arithmetic operators: plus(+), minus(-), multiplication(\*) or division(/).
3. Another number (num2)
✓ If the arguments are more than three or less than three, it should display the proper
message to the user “Usage ./scriptname <num1> <operator> <num2>”.
✓ The script should perform the calculation (num1 operator num2) and display the
result.
Example-
$ cat myscript.sh
declare -i x
x=10/5
echo $x
x=10*2
echo $x
Solution-
Example- Example-
(in seq, first number is START
point and second
number is END point)
Enter rows: 4 read -p "Enter rows: " rows for ((j=1; j<=i; j++))
Starting number: 5 read -p “Starting number: " start do
5 echo -n "$num "
7 9 num=$start num=$((num + 2))
11 13 15 done
17 19 21 23 if [ `expr $num % 2` -ne 0 ] echo
then done
for ((i=1; i<=rows; i++)) else
do echo "Please enter an ODD
number!"
exit 1
fi
Prepared by- Amitabh Srivastava
Practice Code-4 (while loop)
Q. write a shell script to print the number of digits in a number entered by the user.
diff command
▪ diff stands for difference.
▪ It is used to display the differences in the files by comparing the files line by line.
▪ It also tells which lines in one file is to be changed to make the two files identical.
Example-
$ cat names $ cat names2 $ diff names names2
▪ When changes are made to any one of them, the other reflects those changes.
▪ The permissions, link count, ownership, timestamps and file content are exactly same
in all of the links and the original file.
▪ Files having hard-links together share same i-node number (use ls –li to see the inode)
▪ If original file is deleted, the data still exists under the hard link. Data will only
remove when all the links will be deleted including original file.
▪ Observe that the letter “l” will be added to the permissions column.
▪ If the original file is deleted, the soft link is broken. This situation is known as a
dangling soft link.
▪ Syntax-
exec [COMMAND] [ARGUMENTS...]
▪ Example-
$ exec top
The above command replaces the current shell with top command. You’ll lose the
shell session— pressing ‘q’ key won’t return you to the shell because it was
replaced. You’ll have to open a new terminal.
Output-
“After banner” is never printed because banner replaces the shell running the script.
▪ The subnet mask is used by the TCP/IP protocol to determine whether a host is on
the local/same network or on a remote network.
▪ A router that is specified on a host, which links the host's subnet to other networks,
is called a default gateway.
▪ To send packets on remote host, it is the responsibility of the router to forward the
packets to the correct subnet.
$ hostname -f or --fqdn
Displays the system’s Fully Qualified Domain Name (FQDN).
$ hostname -h
Displays the help of hostname command.
to check if the alias name is set properly, test it with ping command.
$ ping MY-LAPTOP
❑ To set the Fully Qualified Domain Name (FQDN) hostname, open /etc/hosts file and
edit it in following format-
IP_ADDRESS FQDN HOSTNAME
127.0.0.1 MY-LAPTOP.example.com LAPTOP-8F40GMIU
to check if the FQDN name is set properly, test it with ping command.
$ ping MY-LAPTOP.example.com Prepared by- Amitabh Srivastava
ip command
▪ ip command is used for network configuration and management.
▪ Allows user to interact with various networking components like network interfaces, routing tables,
addresses, etc.
▪ Is a part of iproute2 package.
▪ Replacement of older commands- ifconfig and route.
Options and Examples-
$ ip route show
Shows all the network routes defined under routing table.
-a : Displays all active TCP & UDP connections and listening ports.
-t : Displays TCP (Transmission Control Protocol) connections.
-u : Displays UDP (User Datagram Protocol) connections.
-l : Displays only listening ports.
-n : Displays numerical addresses instead of resolving names.
-r : Displays the routing table information.
Prepared by- Amitabh Srivastava
traceroute command
▪ traceroute command prints the route that a packet takes to reach the host.
▪ This command is useful to know about the route and about all the hops (in between nodes) that a
packet takes.
▪ It sends three packets to each hop.
Options and Examples-
$ traceroute google.com
Displays the route information in different columns.
- First column is the hop count.
- Second column is the ip-address of that hop.
- Then the three times for three packets, respectively.
$ traceroute -f 10 google.com
Instead of first hop, it starts tracing route from the 10th hop.
$ traceroute -n google.com
Do not resolve the IP-addresses to their domain names.
network:
version: 2
ethernets:
DEVICE-NAME:
renderer: NetworkManager
match:
name: INTERFACE-NAME
dhcp4: YES/NO
addresses: [IP/NETMASK]
gateway4: GATEWAY-ADDRESS
nameservers:
addresses: [NAMESERVER,NAMESERVER]
Prepared by- Amitabh Srivastava
▪ Edit the above file to fit your networking needs. Save and close the file.
Applying netplan settings
▪ Configure and save the .yaml file.
network:
version: 2
ethernets:
NM-2f3e1107-becd-43d2-852a-eece2133d91a:
renderer: NetworkManager
match:
name: "eth0"
dhcp4: no
addresses: [172.30.16.188/20]
gateway4: 172.30.16.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]
▪ Before applying the changes, first test the configuration with the following command-
$ sudo netplan try
The above command will validate the configuration before applying it. If it succeeds, the configuration
accepted. If it fails, netplan will automatically revert to the previous configuration.
Prepared by- Amitabh Srivastava
nmcli command
▪ nmcli is a command-line tool used to-
➢ View network status
➢ Enable/disable network interfaces
➢ Connect to Wifi
➢ Configure static IP address
➢ Manage Ethernet and VPN connections
▪ Basic Syntax-
nmcli [OPTIONS] OBJECT { COMMAND | help }
Object: e.g. device, connection, network
Command: the action you want to perform
Prepared by- Amitabh Srivastava
nmcli command: Examples
▪ Example-1: to show all network interfaces/connections, their type and state.
$ nmcli device show
$ apt-get update
It will update the packages by downloading the package’s information.
$ gcc--version
It will show the version and copyright information of GCC compiler.
$ gcc prog1.c
It will compile the C program written inside prog1.c file. After the successful compilation, it will create an
executable file called a.out.
$ ./a.out
This will run the code just compiled in above step. Prepared by- Amitabh Srivastava
Extracting Substring
▪ Extracting a substring from a string is a basic and common operation of text
processing in Linux.
▪ Example:1-
$ str=“LinuxShell”
$ echo ${str:5} Output- Shell
▪ Example:2-
$ str=“LinuxShell”
$ echo ${var:5:3} Output- She
Prepared by- Amitabh Srivastava
Arrays in Shell Script
▪ Arrays in Shell Scripting allow us to store multiple values in a single
variable.
$ declare –a indexed_array
$ indexed_array[0]=value
if [[ -n "${marks["Geeta"]}" ]]
then
echo "Key exists!"
else
echo "Key not found!"
fi
declare -A days
read -p "Enter a day abbreviation
(e.g., Mon): " input
# Define mapping
days["Mon"]="Monday"
if [[ -n "${days[$input]}" ]]
days["Tue"]="Tuesday"
then
days["Wed"]="Wednesday"
echo "Full name: ${days[$input]}"
days["Thu"]="Thursday"
else
days["Fri"]="Friday"
echo "Invalid day abbreviation."
days["Sat"]="Saturday"
fi
days["Sun"]="Sunday"
▪ To login with this new user account, run the following command at
Ubuntu terminal-
$ sudo mysql -u amitabh -p
Prepared by- Amitabh Srivastava
MySQL: Creating a Database
▪ After login to your mySQL account, first we need to confirm if the
database is successfully created, give the following command-
if [ -z "$record" ]
then
echo "No student found!!"
else
Prepared by- Amitabh Srivastava
Shell Scripting: Functions
▪ Functions enables to break down the overall functionality of a script/code into
smaller, logical subsections, which can then be called upon to perform their
individual tasks when needed.
▪ Using functions to perform repetitive tasks is an excellent way to create code
reuse.
▪ Shell functions are similar to subroutines, procedures, and functions in other
programming languages.
▪ To declare a function, simply follow the below syntax-
function_name()
{
list_of_commands
}
Prepared by- Amitabh Srivastava
Function: Example
▪ Example-
# Function definition
Hello() {
echo "Hello World"
}
# Calling function
Hello
Output-
Hello World
▪ Example-
greet() {
echo "Welcome $1 $2"
}
▪ Output-
Welcome Alok Kumar
Example-1 Example-2
# Function definition # Function definition
add() { add() {
echo -n "Sum of $1 and $2 is: " echo -n "Sum of $1 and $2 is: "
return `expr $1 + $2` sum=`expr $1 + $2`
} return $sum
}
# Calling function with parameters
add 10 20 # Calling function with parameters
echo $? add 20 30
echo $sum
Prepared by- Amitabh Srivastava
Using Return Codes 0 and 1
Example-
is_even_odd() { is_even_odd 43
if (( $1 % 2 == 0 ))
then if [[ $? -eq 0 ]]
return 0 then
else echo "It's even."
return 1 else
fi echo "It's odd."
} fi
▪ OR, put the function definitions in any .sh script and source the script. When
we source the file, no output will be displayed but we can now use the
functions defined under the .sh file from the command prompt.
▪ func2.sh-
sum() $ . func2.sh To remove a function from
{ $ sum 4 5 current shell-
echo "`expr $1 + $2`"
9
} $ unset –f sum
Prepared by- Amitabh Srivastava
Nested Functions
▪ A function can call another function.
Example-
# Calling one function from another
number_one () {
echo "This is number_one function!"
number_two
}
number_two () {
echo "This is number_two function!"
}
# Calling number_one
number_one
Prepared by- Amitabh Srivastava
Example: Recursive Function
▪ When a function call itself is known as Recursive function.
Example- count=0
number_one () {
count=$((count + 1))
if [ $count -le 5 ]
then
echo "Count: $count"
number_one
fi
}
# Calling number_one
number_one
Prepared by- Amitabh Srivastava
‘local’ Keyword
▪ The local command/keyword can only be used within a function.
▪ It makes the variable name have a visible scope restricted to that function and its
children only.
Example- name="Alok"
show_name(){
local name=$1
echo "Inside show_name(): name is set to $name"
}
show_name "Ram"
▪ Solution- string_input() {
read -p "Enter String: " input
reverse() {
echo "$1" | rev
}
string_input
Prepared by- Amitabh Srivastava
fdisk command
▪ Short for ‘Format Disk’, a dialog driven utility used for creating and manipulating the
disk partition table.
▪ fdisk –l /dev/sda
will display all disk partitions of device /dev/sda.
To view all commands which are available for fdisk, use the below command by
mentioning the hard disk name-
▪ it can sort raw storage (hard disks) into logical volumes, making it easy to configure
and use.
➢ If the file exist edit it and if does not exist, create a new file as follows-
[automount] After performing all these steps all windows drives will
enabled = true mount correctly inside WSL Ubuntu OS.
options = "metadata"
mountFsTab = true To access your Windows drives under Ubuntu, give following
command-
➢ Restart WSL by giving following command- $ cd /mnt/
wsl –shutdown $ ls
And reopen Ubuntu. It will show the directories as ‘c’, ‘d’, ‘e’, etc. under Ubuntu
for Windows drives.
Prepared by- Amitabh Srivastava
Mount Specific Folder
▪ To mount a specific folder, we need to configure a file called /etc/fstab.
▪ Open /etc/fstab file and add following line at the end of this file-
/mnt/e/my-folder /home/yourhomedirectory/new-folder none bind 0 0
▪ After adding the above line, save the file and run the following command-
$ sudo mount –a
If no error comes, your folder is mounted.
▪ Replace new-folder with your directory name where you want it to appear inside Ubuntu.
Prepared by- Amitabh Srivastava
mount/umount command options
Examples-
mount –t type <device> <directory>
It will mount the filesystem of device at the specified directory. If the directory is not given, it will look for
the mount-point in /etc/fstab file. The /etc/fstab file contains information about which device should be
mounted where.
mount
It will display all currently mounted filesystems on a system.
mount –V or mount--version
It will display the version information of mount utility.
Umount <devicefile>
It will unmount (dettach) the filesystem of device.
▪ We define cron jobs using a crontab (cron table) file, which lists jobs in a
specific format.
▪ Crontab Syntax-
▪ Example-
▪ By default, cron jobs have no terminal and do not show output unless
explicitly redirected to the terminal (/dev/pts/0).
Prepared by- Amitabh Srivastava
Cron Jobs Examples
▪ To run a command every 5 minutes-
*/5 * * * * echo “Hello” > /dev/pts/0
Mostly used
▪ Example rule-
iptables -A INPUT -p tcp --dport 22 -j ACCEPT Prepared by- Amitabh Srivastava
iptables- rules:target
▪ Following are the targets we can use while writing rules to define what happens if a
packet is matches a rule-
➢ The above rules will block everything except SSH and existing/related
connections. Prepared by- Amitabh Srivastava
iptables- more examples
▪ Block specific IP Address-
$ sudo iptables -A INPUT -s 192.168.1.100 -j DROP
This rule will block all traffic from specified IP.
▪ Enabling ufw- sudo ufw enable Disabling ufw- sudo ufw disable
Prepared by- Amitabh Srivastava
ufw: Allowing/Denying Connections
▪ Allow a specific port-
$ sudo ufw allow <port>
▪ Allow a service-
$ sudo ufw allow <service_name>
example- $ sudo ufw allow ssh
▪ Deny a service-
$ sudo ufw deny <service_name>
Prepared by- Amitabh Srivastava
Secure Shell (SSH)
▪ SSH (Secure Shell) is used to securely access and manage remote systems over a
network. It encrypts the connection and allowing us to Log into the remote
system/server, execute commands remotely, transfer files securely, manage
automated tasks.
Example-
$ ssh [email protected]
OR
$ ssh student07@localhost
▪ It will ask for the user’s password. After entering the correct user’s
password, the user logs into the server remotely through client
machine.
Prepared by- Amitabh Srivastava
Docker
▪ Docker is a software program that creates containers.
▪ For example, if one computer contains the source code for a Word
Generator application, it could be distributed through other computers
by first converting the source code into an image and running it to make
a container to access the application.
▪ The image can be copy and load onto another system and run it.