You are on page 1of 120

RHEL Interview Questions -

What is Linux and also explain the basic components of Linux?


Linux is themost commonly used operating system that is open source and free.
Forany computer, the operating system acts as the backbone, and it is mostimportant
software that is required for any computer.
Consists of 3 components which are:

- Kernel: Linux is a monolithic kernel that is free and opensource software that is
responsible for managing hardware resources forthe users.
- System Library: System Library plays a vital role because application programs
access Kernels feature using system library.
- System Utility: System Utility performs specific and individual level tasks.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are the differences between UNIX and Linux Operating System?
Linux is a UNIX clone, the Kernel of which iscreated by Linus Torvalds. There are
so many differences between Linuxand UNIX operating system which are as follows:
- Open Source Operating System:
- Free of Cost:
- Compatibility and Flexibility:

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe BASH.
BASH stands for Bourne Again Shell. BASH is the UNIX shell for the GNU operating
system. So, BASH is the commandlanguage interpreter that helps youto enter your
input, and thus youcan retrieve information. In a straightforward language, we can
say that it is a program that will understand the data entered by the user
andexecute the command and gives output.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the similarity and difference between cron and anacron? Which one would you
prefer to use?
Cron and Anacron are used to schedulethe tasks in cron jobs. Both of these are the
daemons that are used toschedule the execution of commands or tasks as per the
informationprovided by the user.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Differences between cron and anacron:


1.One of the main difference between cron and anacron jobs is thatcron works on the
system that are running continuously that means it isdesigned for the system that
is running247. While anacron is used forthe systems that are not running
continuously.
2.Other difference between the two is cron jobs can run every minute, but anacron
jobs can be run only once a day.
3.Any normal user can do the scheduling of cron jobs, but the scheduling of anacron
jobs can be done by the superuser only.
4.Cron should be used when you need to execute the job at a specifictime as per the
given time in cron, but anacron should be used in whenthere is no any restriction
for the timing and can be executed at anytime.
5. If we think about which one is ideal for servers or desktops, thencron should be
used for servers while anacron should be used fordesktops or laptops.
/var/spool/cron/crontabs.
There are six fields in the format for the crontab that is as below:
<Minute><Hour><Day_of_the_Month><Month_of_the_Year><Day_of_the_Week><command/
programto execute>

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What do you understand by CLI?


CLI is an acronym for Command Line Interface.We have to provide the information to
the computer so that it canperform the function accordingly. In Linux, CLI is the
interface thatprovides the user an interface so that user can type the commands and
it complete the tasks. CLI is very easy to use, but it should be typedvery
precisely.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a Swap Space or Swap Partition?


When we have insufficient RAM space in thesystem and we need more RAM to process
our applications then Linuxallows an extra allocation of RAM in the physical hard
disk which iscalled a swap space. It is used to hold current programs that
arecurrently running in the system.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What do you control with swapiness?


The Linux kernel provides a tweakable setting that controls how often the swap file
is used, called swappiness.
A swappiness setting of zero means that the disk will be avoided unless absolutely
necessary (you run out of memory), while a swappiness setting of 100 means that
programs will be swapped to disk almost instantly.

Swappiness = /proc/sys/vm/swappiness OR sysctl vm.swappiness


to change swappiness = vi /etc/sysctl.conf > vm.swappiness=10 > sysctl -p

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Increase Swap Space -


swapoff -a
lvextend -L +2G /dev/mapper/fedora_studentvm1-swap
mkswap /dev/mapper/fedora_studentvm1-swap
swapon -a
lsblk
swapon -s = to check exack swap size

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe the root account.


The root account resembles an administratoraccount and permits you to take full
control of the framework. Here youcan make and keep up client accounts, allocating
distinctive accountsfor each user. It is the default account that is created every
time youinstall Linux.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is LILO?
LILO or LinuxLoader is the default boot loader for Linux. It is independent of
aspecific file system and can boot operating system from hard disks.Various
parameters such as root device can be set independently usingLILO.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the maximum length for a filename allowed in Linux?


Any filename can have a most extreme of 255characters. This farthest point does
exclude the pathname, soaccordingly the whole pathname and filename could very much
surpass 255characters.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Why is it a bad idea to restore a DC last backed up seven months ago?


If you back up a DC seven months old, you could encounter lingering objects that
lead to inconsistent data. Backup files, as a general rule, shouldn't be over 180
days old

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain briefly about three popular Linux shells.


Bash Shell – Default shell in many Linux/Unix distribution. Has Features like
Edit command history
Shell functions and gives aliases to it
Unlimited command history
Array with unlimited size with index.

Tcsh/Csh Shell (Normally called C shell) – Tcsh is enhanced C shell,


Auto-completion of word and filename is programmable
Spell check
Job control

K Shell – It is called Korn Shell or Ksh.More than aninteractive Shell, K shell is


a complete, powerful, high-levelprogramming language. It has features like
Options and variables that give you more ways to customize your environment.
Advanced security features
Advanced regular expressions,- well-known utilities like grep and awk.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is RAID? What is RAID0, RAID1, RAID5, RAID10?


RAID (redundant array of independent disks; originally redundant arrayof
inexpensive disks) is a way of storing the same data in differentplaces on multiple
hard disks to protect data in the case of a drive failure. However, not all RAID
levels provide redundancy
Standard RAID levels
RAID 0: This configuration has striping, but no redundancy of data. It offers the
best performance, but no fault tolerance.
RAID 1: Also known as disk mirroring,this configuration consists of at least two
drives that duplicate thestorage of data. There is no striping. Read performance is
improvedsince either disk can be read at the same time. Write performance is
thesame as for single disk storage.
RAID 5: This level is based on
[block](https://searchsqlserver.techtarget.com/definition/block)-levelstriping with
parity. The parity information is striped across eachdrive, allowing the array to
function even if one drive were to fail.The array's architecture allows read and
write operations to spanmultiple drives. This results in performance that is
usually better thanthat of a single drive, but not as high as that of a RAID 0
array. RAID5 requires at least three disks, but it is often recommended to use
atleast five disks for performance reasons.
RAID 10:Combining RAID 1 and RAID 0, this level is often referred to as RAID10,
which offers higher performance than RAID 1, but at a much highercost. In RAID 1+0,
the data is mirrored and the mirrors are striped.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a level 0 backup? What is an incremental backup?


A level 0 incremental backup, which is the base for subsequent incremental backups,
copies all blocks containing data, backing the datafile up into a backup set just
as a full backup would.
Incremental backup, only stores the data that has changed since some point in time
(typically the previous backup)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is Virtual Memory?


Virtual memory is a memory management of an operating system (OS) that uses
hardware and software to allow a computer to compensate for physical memory
shortages by temporarily transferring data from random access memory ([RAM]
(https://searchstorage.techtarget.com/definition/RAM-random-access-memory)) to disk
storage. Virtual address increased using active memory in RAM and inactive memory
inhard disk drives (HDDs) to form contiguous addresses that hold both
theapplication and its data.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What does `& disown` after a command do?


- `&` puts the job in the background, that is, makes it block on attempting to read
input, and makes the shell not wait for itscompletion.
- `disown` removes the process from the shell's jobcontrol, but it still leaves it
connected to the terminal. One of theresults is that the shell won't send it a
`SIGHUP`. Obviously, it can only be applied to background jobs, because you cannot
enter it when a foreground job is running.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the sticky bit?


A sticky bit is a permission bit which is set on a file or folder,thereby
permitting only the owner or root user of the file or folder to modify, rename or
delete the concerned directory or file. No other user would be permitted to have
these privileges on a file whichhas a sticky bit. In Unix-like systems, without the
sticky bit on, anyuser can modify, rename or delete the directory or file
regardless ofthe owner of the file or folder.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
What does the immutable bit do to a file?
A file with an immutable attribute can not be:
- Modified
- Deleted
- Renamed
- No soft or hard link created by anyone including root user.
Onlythe root (superuser) or a process possessing the CAP_LINUX_IMMUTABLE capability
can set or clear this attribute. Use the lsattr command tolist file attributes on a
Linux second extended file system that you set with the chattr command.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How to force/trigger a file system check on next reboot?


The simplest way to force fsck filesystem check on a root partition eg.
/dev/sda1
is to create an empty file called `forcefsck` in the partition's root directory.
touch /forcefsck
This empty file will temporarily override any other settings and force `fsck` to
check the filesystem on the next system reboot. Once the filesystem is checked
the`forcefsck` file will be removed thus next time you reboot your filesystem will
NOT be checked again.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a runlevel and how to get the current runlevel?


A runlevel is one of the modes that a Unix-basedoperating system will run in. In
Linux Kernel, there are 7 runlevelsexists, starting from 0 to 6. The system can be
booted into only onerunlevel at a time. By default, a system boots either to
runlevel 3 orto runlevel 5. Runlevel 3 is CLI, and 5 is GUI. The default runlevel
isspecified in /etc/inittab file in most Linux operatingsystems. Using runlevel, we
can easily find out whether X is running, or network is operational, and so on. In
this brief guide, we will talkabout how to check the runlevel in Unix-like
operating systems.
Here is the list of runlevels in Linux distributions,which were distributed with
SysV init as default service manager.
- 0 – Halt
- 1 – Single-user text mode
- 2 – Not used (user-definable)
- 3 – Full multi-user text mode
- 4 – Not used (user-definable)
- 5 – Full multi-user graphical mode (with an X-based login screen)
- 6- Reboot
To find out the system runlevel, open your Terminal and run the following command:
$ runlevel OR systemctl get-default
Sample output for the above command would be:
N 3

To set a default target, run:


# systemctl set-default TARGET.target
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are the steps to add a user to a system without using useradd/adduser?

STEP-I(The system creates a directory with the name of ‘user’ in “/home” directory)
Now we create a user with a username techbrown. So start with the first step
[root@techbrown]mkdir /home/techbrown
Copy
It will create a home directory for user techbrown

STEP-II(Creates an entry in /etc/passwd file)


[root@techbrown]touch /var/spool/mail/techbrown
Copy
This command will create a file in the mail directory so that allmail’s come to the
user techbrown directly stores in this file.

STEP-III(Creates an entry in /etc/shadow file)


Now we create an entry in passwd file so that the getty script will discover a
information about the user.
[root@techbrown]vim /etc/passwd
Copy
Now it will show some users information which that are previously created.
So now just make an entry in it as following or simple way just copy oneof the
entry from it. By using “yy(yank or copy)” and “p(paste)” andthen edit it.
techbrown:x:501:501:Hello techbrown :/home/gopal:/bin/bash
1 :2 :3 :4 :5: 6 : 7
Copy
:wq
Here in “/etc/passwd“file you have to create 7 entries. Let’s discuss about it
shortly.
Username
It indicates that the password is encrypted and stores in a shadow file
User ID
Group ID
Comment
Home directory of the User
Last one shell prompt you can check it through “/etc/shells” file.

STEP-IV(Creates an entry in /etc/groups file)


Now we are going to make entry in the shadow file which stores the information
about an user with the encrypted password.
[root@techbrown]vim /etc/shadow
Copy
Now make entry in this file.
techbrown:! !:16244:0:99999:7: : :
1 :2 :3 :4:5 :6:7:8:9
Copy
:wq!
You will see 9 entries presently available in the /etc/shadow file so we will also
discuss about that.
Name of a user
Password in encrypted
The number of days since 1 January 1970 that the password last changed.
The number of days permitted before the password can be changed.
The number of days after which the password must be changed.
The number of days before the password expires that the user is warned.
The number of days after the password expires before the account is disabled.
The number of days since 1 January 1970 after which the account is disabled.
Reserved for the feature.
but in above we didn’t edit that so just do the following step
first go to the shell prompt and type following command
[root@techbrown]grub-md5-crypt
password:[type your password]
retype password : [type above password again]
$1$YgGpm1$hhDEbeY0mRpKccgyQsWQn0
Copy
Now copy and paste this password in this section.

STEP-V(Create a file for mail address so that the mail come to thatuser will be
shown in that file which is present in“/var/spool/mail/’username’”)
Now create a entry in the /etc/groups directory.
[root@techbrown]vim /etc/groups
techbrown :x : 501:
1 :2 : 3 :4
Copy
:wq
Here 1:2:3:4 as
Username
Password
Group ID
List of users, which are associated with the group.
STEP-VI(create the bash prompts in its home directory)
[root@techbrown]touch /var/spool/mail/techbrown
Copy
This will create a mail box for the user for techbrown so that the mail generated
for user techbrown comes to this file.
Now use this command to login into user techbrown.
[root@techbrown ~] su - techbrown
-bash-4.1$
Copy
[root@techbrown ~]
Copy
This shows the above error that is a bash error. Means to enter intothe user, you
should have some bash files into the home directory of theuser. So do the following
steps.
[root@techbrown ~] cd /etc/skel/
[root@techbrown skel] cp .bash /home/techbrown
[root@techbrown skel] su - techbrown
[techbrown@techbrown ~]$ [you are in user techbrown ]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is MAJOR and MINOR numbers of special files?


If you issue the ls -l command, you’ll see two numbers (separated by a comma) in
the device file entries before the date of last modification, where the file length
normally appears. These numbers are the major device number and minor device number
for the particular device. The following listing shows a few devices as they appear
on a typical system. Their major numbers are 1, 4, 7, and 10, while the minors are
1, 3, 5, 64, 65, and 129.
crw-rw-rw- 1 root root1, 3 Feb 23 1999null
crw------- 1 root root 10, 1 Feb 23 1999psaux
crw------- 1 rubini tty 4, 1 Aug 16 22:22 tty1
crw-rw-rw- 1 root dialout 4, 64Jun 30 11:19 ttyS0
crw-rw-rw- 1 root dialout 4, 65Aug 16 00:00 ttyS1
crw------- 1 root sys 7, 1 Feb 23 1999vcs1
crw------- 1 root sys 7, 129 Feb 23 1999vcsa1
crw-rw-rw- 1 root root1, 5 Feb 23 1999zero
The major number identifies the driver associated with the device. For example,
`/dev/null` and `/dev/zero` are both managed by driver 1, whereas virtual consoles
and serial terminals are managed by driver 4;

The minor number is used only by the driver specified by the major number; other
parts of the kernel don’t use it, and merely pass it along to the driver. It is
common for a driver to control several devices (as shown in the listing); the minor
number provides a way for the driver to differentiate among them.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe the mknod command and when you'd use it.


`mknod` was originally used to create the character and block devices that populate
`/dev/`. Nowadays software like `udev` automatically creates and removes device
nodes on the virtual filesystem when the corresponding hardware is detected by the
kernel,but originally `/dev` was just a directory in `/` that was populated during
install.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe a scenario when you get a "filesystem is full" error, but 'df' shows there
is free space.
It's possible that a process has opened a large file which has since been deleted.
You'll have to kill that process to free up the space. Youmay be able to identify
the process by using lsof. On Linux deleted yetopen files are known to lsof and
marked as (deleted) in lsof's output.

When all the inodes are consumed then eventhough you have free space, you will get
the error that filesystem isfull. So, to check whether there is space available, we
have to use thecommand df –i. Sometimes, it may happen file system or storage
unitcontains the substantial number of small files, and each of the filestakes 128
bytes of the inode structure then inode structure fills up,and we will not be able
to copy any more file to the disk. So, torectify the problem, you need to free the
space in inode storage, andyou will be able to save more files.
You can check this with `sudo lsof +L1`

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe a scenario when deleting a file, but 'df' not showing the space being
freed.
Deleting the file won't free the space until you delete the processes that have
open handles against that file.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe how 'ps' works.


On Linux, the `ps` command works by reading files in the proc filesystem The
directory `/proc/PID` contains various files that provide information about process
PID. The content of these files is generated on the fly by the kernel when a
process reads them.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What happens to a child process that dies and has no parent process to wait for it
and what’s bad about this?
It becomes a Zombie process.
Zombie processes don’t use up any system resources. (Actually, each one uses a very
tiny amount of system memory to store its process descriptor.) However, each zombie
process retains its process ID (PID).Linux systems have a finite number of process
IDs – 32767 by default on32-bit systems. If zombies are accumulating at a very
quick rate – for example, if improperly programmed server software is creating
zombie processes under load — the entire pool of available PIDs will eventually
become assigned to zombie processes, preventing other processes fromlaunching.

Zombie Process =
Identify zombie process -
pa -aux | grep defunct
OR
top -b1 -n1 | grep Z
find parent zombie -
ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }' | uniq | xargs ps -p
kill -9 pid
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain briefly each one of the process states.


In Linux a process can be in a number of states. It's easiest to observe it in
tools like `ps` or `top`: it's usually in the column named `S`. The documentation
of `ps` describes the possible values:
PROCESS STATE CODES
R running or runnable (on run queue)
D uninterruptible sleep (usually IO)
S interruptible sleep (waiting for an event to complete)
Z defunct/zombie, terminated but not reaped by its parent
T stopped, either by a job control signal or because
it is being traced
[...]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Which Linux file types do you know?


Linux file types and ls command identifiers:

- \- : regular file.
- d : directory.
- c : character device file.
- b : block device file.
- s : local socket file.
- p : named pipe.
- l : symbolic link.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between a process and a thread? And parent and child
processes after a fork system call?
Process:
A process is an instance of a program in execution. It represents a unit of work
within the operating system.
Each process has its own address space, which includes memory, resources, and a
unique process identifier (PID).
Processes are independent of each other and typically do not share memory, except
through explicit inter-process communication (IPC) mechanisms.

Thread:
A thread is the smallest unit of execution within a process. Threads share the same
memory space and resources within the process.
Threads within the same process can communicate directly through shared memory and
synchronization primitives.

When a fork system call is executed in Unix-like operating systems, a new process
(child process) is created as an exact copy of the calling process (parent
process).
After the fork call, both the parent and child processes continue executing from
the point immediately following the fork call.
The child process receives a new unique process ID (PID), while the parent process
retains its original PID.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between exec and fork?


fork():
fork() is a system call used to create a new process (child process) that is an
exact copy of the calling process (parent process).
After the fork() call, both the parent and child processes continue executing from
the point immediately following the fork() call.

exec():
exec() is a family of system calls used to replace the current process's memory
image with a new program.
When exec() is called, the current process is replaced by the new program, and the
new program starts executing from its entry point.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is "nohup" used for?


`nohup` disconnects the process from the terminal, redirects its output to
`nohup.out` and shields it from `SIGHUP`. One of the effects (the naming one) is
that the process won't receive any sent `SIGHUP`.It is completely independent from
job control and could in principle beused also for foreground jobs (although that's
not very useful).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can you get Host, Channel, ID, LUN of SCSI disk?

Using udevadm:
You can also use the udevadm command to get detailed information about SCSI disks =
udevadm info --query=all --name=/dev/xvda
P: /devices/vbd-768/block/xvda
M: xvda
U: block
T: disk
D: b 202:0
N: xvda
L: 0
S: disk/by-diskseq/1
Q: 1
E: DEVPATH=/devices/vbd-768/block/xvda
E: DEVNAME=/dev/xvda
E: DEVTYPE=disk
E: DISKSEQ=1
E: MAJOR=202
E: MINOR=0
E: SUBSYSTEM=block
E: USEC_INITIALIZED=7428161
E: ID_PART_TABLE_UUID=d209c89e-ea5e-4fbd-b161-b461cce297e0
E: ID_PART_TABLE_TYPE=gpt
E: DEVLINKS=/dev/disk/by-diskseq/1
E: TAGS=:systemd:
E: CURRENT_TAGS=:systemd:

bash
$ cat /proc/scsi/scsi
Host: scsi2 Channel: 00 Id: 00 Lun: 29
Vendor: EMCModel: SYMMETRIX

bash
$ ls -ld /sys/block/sd/device
lrwxrwxrwx 1 root root 0 Oct4 12:12 /sys/block/sdaz/device ->
../../devices/pci0000:20/0000:20:02.0/0000:27:00.0/host2/rport-2:0-0/
target2:0:0/2:0:0:29
lrwxrwxrwx 1 root root 0 Oct4 12:12 /sys/block/sdbi/device ->
../../devices/pci0000:20/0000:20:02.2/0000:24:00.0/host3/rport-3:0-0/
target3:0:0/3:0:0:29

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can you limit process memory usage?


`ulimit` allows you to limit the resources that a process can use

Displaying Current Limits: ulimit -a


Setting a Specific Limit = to set the maximum number of open files to 1000, you can
use: ulimit -n 1000

ulimit are typically temporary and only apply to the current shell session
To make them persistent = /etc/security/limits.conf
<domain> <type> <item> <value>

domain>: Specifies the user or group to which the limit applies. It can be:
A username (e.g., user)
A group name prefixed with @ (e.g., @group)
* to apply the limit to all users.

<type>: Specifies whether the limit is a soft or hard limit. It can be:
soft: Defines the soft limit for the resource. The soft limit can be adjusted by
the user within the constraints of the hard limit.
hard: Defines the hard limit for the resource. The hard limit acts as a maximum
value and cannot be exceeded.

<item>: Specifies the resource being limited. It can be various system resources
like:
core: Maximum size of core files created.
data: Maximum data size.
fsize: Maximum filesize.
memlock: Maximum locked-in-memory address space.
nofile: Maximum number of open files.
nproc: Maximum number of processes.

<value>: Specifies the value of the limit for the resource.

Example Values =
* soft core 0: Sets the soft limit for core file size to 0 (core files are disabled
for all users).
* hard rss 10000: Sets the hard limit for the resident set size to 10000 for all
users.
@student hard nproc 20: Sets the hard limit for the maximum number of processes to
20 for users in the student group.
@faculty soft nproc 20: Sets the soft limit for the maximum number of processes to
20 for users in the faculty group.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Can you explain to me the difference between block based, and object based storage?
Block-based Storage:
Structure: Data organized into fixed-sized blocks.
Access: Accessed at the block level, requires a file system.
Examples: HDDs, SSDs, SANs.
Advantages: Efficient for structured data, fine-grained control.
Disadvantages: Requires file system, lacks metadata.

Object-based Storage:
Structure: Data stored as objects with metadata.
Access: Accessed at the object level via unique identifiers.
Examples: Amazon S3, Google Cloud Storage.
Advantages: Scalable, metadata-rich, simplified management.
Disadvantages: Overhead for metadata, not ideal for all use cases.

In summary, block-based storage is about fixed-sized blocks with low-level access,


while object-based storage stores data as objects with associated metadata,
offering scalability and simplified management. The choice depends on the data's
structure and management requirements.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain Network Bonding and also explain the different types of Network bonding?
Network Bonding as the name implies that it is the process of bonding or joining
two or more than two network interfaces to create one interface. It helps
inimproving the network throughput, bandwidth, redundancy, load balancingas in case
any of the interfaces is down; the other one will continue towork. Several types of
Network Bonding are available that are based onthe kind of bonding method.
Below are the different bonding types in Linux:
- balance-rr or mode 0 – This is the default mode of network bonding that works on
the round-robin policy that means from the firstslave to the last, and it is used
for fault tolerance and loadbalancing.
- active-backup or mode 1 – This type of network bonding works on the active-backup
policy that means only one slave will be active andother will work just when
another slave fails. This mode is also usedfor fault tolerance.
- balance-xor or mode 2 –This type of network bonding sets anexclusive or mode that
means source MAC address is XOR’d with thedestination address, and thus it provides
fault tolerance and loadbalancing.
- broadcast or mode 3 –This mode sets a broadcast mode toprovide fault tolerance,
and it should be used for particular purposes.In this type of network bonding, all
transmissions are sent to all slaveinterfaces.
- 802.3ad or mode 4 –This mode will create the aggregationgroups, and all the
groups will share the same speed. For this, modesets an IEEE 802.3ad dynamic link
aggregation mode. It is done byparticular switch support that supports IEEE 802.3ad
dynamic link.
- balance-tlb or mode 5 –This mode sets a transmit load balancing mode for fault
tolerance and load balancing and does not require any switch support.
- balance-alb or mode 6 –This mode sets an active load balancing to achieve fault
tolerance and load balancing.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Where is password file located in Linux and how can you improve the security of
password file?
This is animportant question that is generally asked by the interviewers.
Userinformation along with the passwords in Linux is stored in/etc/passwdthat is a
compatible format. But this file is used to get the userinformation by several
tools. Here, security is at risk. So, we have tomake it secured.
To improve the security of the passwordfile, instead of using a compatible format
we can use shadow passwordformat. So, in shadow password format, the password will
be stored assingle “x” character which is not the same file (/etc/passwd).
Thisinformation is stored in another file instead with a file name/etc/shadow. So,
to enhance the security, the file is made word readableand also, this file is
readable only by the root user. Thus securityrisks are overcome to a great extent
by using the shadow passwordformat.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is Key-based authentication? Explain.


There arevarious methods to enter into the servers. One of the ways to log in
isusing password-based authentication, but that is not secure. So, we needa method
that is secured.
One of the ways to achieve the securityis to use Key-based authentication. To use
this type of authentication,we have to disable the password-based authentication.
So, there is aprocedure to set up this authentication which is as follows:
We have to get the SSH key pair using below command:
$ ssh-keygen -t rsa
It will generate the public/private rsa key pair.
Enter file where you want to save this generated key (/home/username/.ssh/id_rsa):
It will prompt you for the same location, i.e. ~/.ssh/id_rsafor the key pair. Press
enter if you want to confirm the same location.Else, if you want to provide any
other location, enter that and confirmthe same.
Now copy ~/.ssh/id_rsa.pub into the ~/.ssh/authorized_keys that will be located
where you have to connect.
Now, we have to provide the permissions to the file as per below command:
$ chmod 600 ~/.ssh/authorized_keys
Now try to sshthe machine you want to connect, and you will see that you are able
to login to the machine without a password.
If you are confirmed that key-based authentication is working fine, disable the
password-based authentication.
Go to the path /etc/ ssh/sshd_config
set the following property as no.
PasswordAuthentication no
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mention the steps to find out the memory usage by Linux.
You have to enter a command in the Linux shell called “Concatenate” to find out the
memory usage by Linux.
Syntax: cat/proc/meminfo.
When you will enter this command thenyou will see a list of memory usage like Total
Memory, Free Memory,Cache memory, and many other memory usages by Linux. Other
commands usedin Linux are:
- $ free –m // this is the simplest command where it will show the memory usage in
MB.
- $ vmstat –s //this command gives a report on virtual memory statistics
- top // this command checks the usage of memory and cpu usage
- htop // similar like top command

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What do you mean by an ext3 file system?


Ext3 file system is an upgraded version of ext2 and it also supports journaling.
When an unclean shutdown is performed ext2 file system performs a check on the
machine for errors which is a long process but it is not so in case of the ext3file
system.
In case of a hardware failure, an ext3 consistency check will occur without any
pause. The time of the recovery of the file system is independent of the number of
files. The time is dependent on the size of the journal which only takes a second
which depends on the speed of the hardware.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the level of Security that Linux provides in comparison to other Operating
Systems?
If an operating system is not secure then it is not successful. In comparison to
other operating systems, Linux is themost secure operating system as it consists of
Pluggable AuthenticationModules. A secure layer is created between the
authentication processand applications. It is because of PAM only by which an admin
can giveaccess to other users to log into the system. You can find
theconfiguration of PAM applications in the “/etc/pam.d” or “/etc/pam.conf”
directory.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are soft links? Describe some of the features of soft links.
Soft Links or Symbolic Link or Symlink are special files which are used as a
referencefor another directory. Some features of softlinks are:
- They have a different INODE number with respect to source files or original
files.
- If in case the original file is deleted then a soft link of that file is useless.
- We cannot update a soft link.
- Soft links are used to create links between directories.
- Soft links are independent of file system boundaries.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain INODE in Linux.


INODE is a structure which acts as an identity for all files and objects. Type
acommand in the shell “ls -i”. The numbers which are displayed at the adjacent of
files and folders, these are INODE numbers which areassigned to each file that
contains information about the file. Thesystem uses this number to identify the
file. Information like the sizeof the file, when the file was modified etc is
contained in an INODEnumber.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the routing table in Linux?


The routing table is a method in which how all the networks and devices are
interconnected with each other to efficiently establish communication with each
other.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is Puppet?
The Puppet is open source software which is [used for software configuration]
(https://www.educba.com/software-engineering-interview-questions/) management that
runs on systems similar to that of UNIX. It is secureand scalable to use. It
provides automation features in DevOps and Cloud environment.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is automounting in Linux?


The automounting is a process of automatically mounting all the partitions on a
hard disk on a Linux or [Unix System](https://www.educba.com/uses-of-unix/) while
booting the system. fstab property can be used to automount the hard drives on
Linux.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

List the fields in /etc/passwd file.


The fields that are present in /etc/passwd file are Username, Password,User ID,
Group ID, Comments, HomeDir and LoginShell. The /etc/passwdfile has contents as
below:
redhat:x:500:500:Redhat User:/home/redhat:/bin/bash
mssm:x:501:501:another user:/home/mssm:/bin/bash
– “x” in the password column indicates that the encrypted password is stored in
/etc/shadow file.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain each system call used for process management in Linux.


Fork(): This is used to create a new process from an existing one.
Exec(): This is used to execute a new program.
Wait(): This is used to wait until the given process finishes the execution.
Exit(): This is used to exit from the process.
Getpid(): This helps in getting the unique process id of a particular process.
Getppid(): This helps in getting a parent process unique id.
Nice(): This is used to bias the existing property of the process.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain the steps to increase the size of the LVM partition =

fdisk, lsblk, or pvdisplay to check the available space.


sudo lvextend -L +10G /dev/vg_name/lv_name
#sudo resize2fs /dev/vg_name/lv_name
sudo xfs_growfs /mount_point
lvdisplay, or lsblk = to check new size

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Which utility can be used to create the partition from a raw disk?
You can use tools like fdisk, lsblk, or lsscsi to identify the newly added disk
To scan= echo "- - -" > /sys/class/scsi_host/host0/scan
fdisk -l = to identity
fdisk /dev/sdX = to start partitioning
Type n and press Enter to create a new partition.
Choose the partition type:
For primary partition, type p.
For extended partition, type e.
Specify the partition number (e.g., 1) and press Enter.
Specify the starting sector (usually, press Enter to use the default).
Specify the ending sector or size of the partition. You can specify the size in
sectors, megabytes (e.g., +100M), gigabytes (e.g., +1G), etc.
Use the t command to set the partition type
use the w command to write the changes
lsblk = to check new partition

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a tunnel and how you can bypass a http proxy?


Refers to a communication channel established between two endpoints, allowing data
to be transmitted securely and privately over a public network. It encapsulates
data packets within other protocols, effectively creating a "tunnel" through which
data can travel securely.

Bypassing an HTTP proxy involves finding ways to access resources on the internet
without going through the proxy server =

Using a VPN (Virtual Private Network): VPNs encrypt your internet connection and
route it through a server located elsewhere, effectively bypassing the proxy
server.
Using SSH Tunneling: Secure Shell (SSH) tunneling involves creating an encrypted
connection between your computer and a remote server, then using that server as a
proxy to access the internet.
Using Proxy Websites: There are websites that act as proxies themselves, allowing
you to access internet resources indirectly through them.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between IDS and IPS?


Intrusion Detection System (IDS):
Functionality: IDS monitors network traffic or system activity for suspicious
patterns or anomalies that may indicate unauthorized access, misuse, or security
policy violations.

Intrusion Prevention System (IPS):


Functionality: IPS performs the same functions as IDS, but it also has the ability
to actively block or prevent detected threats in real-time.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Your freshly configured http server is not running after a restart, what can you
do?
Check Server Configuration
Check Log Files
Verify Port Availability
Restart the Server
Check System Resources
Check for Conflicting Services
Test Connectivity
Review Recent Changes
Check for Firewall Rules
Reinstall or Roll Back

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What kind of keys are in ~/.ssh/authorized_keys and what it is this file used for?
Authorized_keys File in SSH. The authorized_keys file in SSH specifies the SSH keys
that can be used for logging into the user account for which the file is
configured. It is a highly important configuration file, as it configures permanent
access using SSH keys and needs proper management.
I've added my public ssh key into authorized_keys but I'm still getting a password
prompt, what can be wrong?
Make sure the permissions on the ~/.ssh directory and its contents are proper. When
I first set up my ssh key auth, I didn't have the ~/.ssh folder properly set up,
and it yelled at me.
Your home directory ~, your ~/.ssh directory and the ~/.ssh/authorized_keys file on
the remote machine must be writable only by you: rwx------ and rwxr-xr-x are fine,
but rwxrwx--- is no good¹, even if you are the only user in your group (if you
prefer numeric modes: 700 or 755, not 775).
If ~/.ssh or authorized_keys is a symbolic link, the canonical path (with symbolic
links expanded) is checked.
Your ~/.ssh/authorized_keys file (on the remote machine) must be readable (at least
400), but you'll need it to be also writable (600) if you will add any more keys to
it.
Your private key file (on the local machine) must be readable and writable only by
you: rw-------, i.e. 600.
Also, if SELinux is set to enforcing, you may need to run restorecon -R -v ~/.ssh
(see e.g. Ubuntu bug 965663 and Debian bug report 658675; this is patched in CentOS
6).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How do you catch a Linux signal on a script?


trap sigusr1 USR1catch -USR1 signal

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Can you catch a SIGKILL?


You can't catch SIGKILL (and SIGSTOP ), so enabling your custom handler for SIGKILL
is moot.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What's a chroot jail?


A chroot jail is a way to isolate a process and its children from the rest of the
system. It should only be used for processes that don't run as root, as root users
can break out of the jail very easily.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

When trying to umount a directory it says it's busy, how to find out which PID
holds the directory?
open a terminal:
fuser -c /media/KINGSTON
It will output something like this:
/media/KINGSTON/: 3106c 11086
This will give you the pid of the processes using this volume. The extra character
at the end of pid will give some extra info. ( c in 3106c)
c - the process is using the file as its current working directory
m - the file is mapped with mmap
o - the process is using it as an open file
r - the file is the root directory of the process
t - the process is accessing the file as a text file
y - this file is the controlling terminal for the process
So to unmount just kill that pids and re-try the unmount
sudo kill -9 3106 11086
sudo umount /media/KINGSTON

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What's LD_PRELOAD and when it's used?


If you set LD_PRELOAD to the path of a shared object, that file will be loaded
before any other library (including the C runtime, libc.so). So to run ls with your
special malloc() implementation, do this:
$ LD_PRELOAD=/path/to/my/malloc.so /bin/ls

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

You ran a binary and nothing happened. How would you debug this?
gdb debugger or check the return code `echo $?`

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are cgroups? Can you specify a scenario where you could use them?

Cgroups Allocate resources: Limit and distribute CPU, memory, I/O bandwidth, and
other resources among groups of processes.
cpu, cpuset: CPU usage and scheduling
memory: Memory limits
blkio: Block device I/O limits
devices: Control access to hardware devices

cgcreate: Create cgroups


cgset: Modify cgroup parameters
cgexec: Run a process within a cgroup
cgdelete: Delete cgroups
systemd-cgls, systemd-cgtop: View cgroup hierarchy and resource usage

Create cgroup:
sudo cgcreate -g memory:/my_limited_group

Set memory limit:


sudo cgset -r memory.limit_in_bytes=100M my_limited_group
``` (Limits to 100MB)

Run process inside cgroup:


sudo cgexec -g memory:/my_limited_group /bin/my_program
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How can you remove/delete a file with file-name consisting of only
non-printable/non-type-able characters?
The file has a name, but it's made of non-printable characters. If you use ksh93,
bash, zsh, mksh or FreeBSD sh, you can try to remove it by specifying its non-
printable name. First ensure that the name is right with: ls -ld $'\177' If it
shows the right file, then use rm: rm $'\177'
Another (a bit more risky) approach is to use rm -i --. With the -i option rm
requires confirmation before removing a file, so you can skip all files you want to
keep but the one.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can you increase or decrease the priority of a process in Linux?


nice -n 10 apt-get upgrade

What are run-levels in Linux?


A runlevel is one of the modes that a [Unix -based operating
system](https://ww.liquidweb.com/products/dedicated)will run in. Each runlevel has
a certain number of services stopped orstarted, giving the user control over the
behavior of the machine.Conventionally, seven runlevels exist, numbered from zero
to six.
After the Linux kernel has booted, the init program reads the /etc/inittabfile to
determine the behavior for each runlevel. Unless the userspecifies another value as
a kernel boot parameter, the system willattempt to enter (start) the default
runlevel.

| Run Level | Mode| Action |


| --------- | ------------------------------- |
------------------------------------------------------------ |
| 0 | Halt| Shuts down system|
| 1 | Single-User Mode| Does not configure network interfaces, start daemons, or
allow non-root logins |
| 2 | Multi-User Mode | Does not configure network interfaces or start daemons.|
| 3 | Multi-User Mode with Networking | Starts the system normally.|
| 4 | Undefined | Not used/User-definable|
| 5 | X11 | As runlevel 3 + display manager(X) |
| 6 | Reboot| Reboots the system |

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are the default port numbers used for SMTP, FTP,DNS, DHCP, SSH?
ServicePort SMTP25
FTP 20 for data transfer and 21 for Connection established
DNS53
DHCP 67/UDP(for DHCP server, 68/UDPfor DHCP client
SSH22

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain all the fields in the/etc/passwd file?


/etc/passwdfile contains the useful information for all the system users who login.
We have many fields in /etc/passwd file such as username, password,user ID, group
ID, comment or user ID info, home directory, command/shell, etc. So, this file
contains sensitive information regarding allthe user accounts. There is a single
line per user in this file. Colon(:) separates the fields in /etc/passwd. Below is
the explanation of thefields.
- Username: First field is the username that contains the username which is 1 to 32
length characters.
- Password: This field does not show the actual password as thepassword is
encrypted. Here, x character shows that password isencrypted that is located in
/etc/shadow file.
- User ID (UID): All the users created in Linux is given a user IDwhenever the user
is created. UID 0 is fixed and reserved for the rootuser.
- Group ID (GID): This field specifies the name of the group to whichthe user
belongs. The group information is also stored in a file/etc/group.
- User ID Info: Here you can add comments and you can add any extrainformation
related to the users like full name, contact number, etc.
- Home directory: This field provides the path where the user is directed after the
login. For example, /home/smith.
- Command/shell: This field provides the path of a command/shell and denotes that
user has access to this shell i.e. /bin/bash.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can an administrator know whether a user account is locked or not?


To check if the user account is locked or not just run this command in the shell:
passwd –S <username>
Or search for the grep username in thelocation /etc/shadow file and it will show a
symbol ‘!’ prefix to theencrypted field in the password box.
To just unlock the password type this command:
passwd –u <username>
If there is a double exclamation mark then run this command two times:
usermod –U <username>

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What do you mean by SELinux?


SELinux is theabbreviation for Security Enhanced Linux. The access controls for the
users can be controlled using SELinux. For example, the users can bestopped from
running the scripts and accessing their own homedirectories. SELinux has the
capability to support the access controland security policies. It basically
operates on three different modes:
- Enforcing –to enforce its policies.
- Permissive –Polices want to apply but will be locked in case of violation.
- Disabled –SELinux will stay in disabled mode.
To check the status of SELinux, just type: getenfore OR sestatus

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

To change the edit level /etc/inittlab and edit the initdefault entry.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can we create a local Yum repository in the location /media with the use of
mounted Linux ISO image?
To create the local yum repository you have to create the files ending with
extension .repo in the location /etc/yum.repos.d
Syntax: [root@localhost yum.repos.d] cat local.repo
[local]
name=RHEL6.5
baseurl=file:///media
enabled=1
gpgcheck=1
gpgkey=file:///media/RPM-GPG-KEY-redhat-release

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Mention the methods to check whether using Yum, the package is installed
successfully or not.
There are several methods to check whether the package is installed or not. To
understand, just see the below steps.
Method 1 –If the command is executed successfully then after running the yum
command it will show ‘0’ on checking the exit status.
Method 2-You can run the rpm and –qa test.
Method 3–In the yum log, check if any entry is installed in the directory.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between Hard Link and Soft Link?


A soft link(Symbolic Link) points to another file by name. As it justcontains a
name, that name does not actually have to exist or exist on a different file
system. If you replace the file or change file contentwithout changing a name, then
the link still contains the same name andpoints to that file. A hard link points to
the file by inode number. Afile should actually exist in the same file system. A
file will only bedeleted from disk when the last link to its inode is removed.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

A running process gets `EAGAIN: Resource temporarily unavailable` on reading a


socket. How can you close this bad socket/file descriptor without killing the
process?
get the file descriptor of the socket, debug the process and manually call close on
the file descriptor.
On Linux systems:
Find the offending process: `netstat -np`
Find the socket file descriptor: `lsof -np $PID`
Debug the process: `gdb -p $PID`
Close the socket: `call close($FD)`
Close the debugger: `quit`
Profit.
From [here](http://superuser.com/a/668155).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How do you change TCP stack buffers? How do you calculate it?
TCP Tuninghttp://www.linux-admins.net/2010/09/linux-tcp-tuning.html

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is Huge Tables? Why isn't it enabled by default? Why and when use it?
HugePages feature enables the Linux kernel to manage large pages of memory in
addition to the standard 4KB (on x86 and x86_64) or 16KB (on IA64) page size. If
you have a system with more than 16GB of memory running Oracle databases with a
total System Global Area (SGA) larger than 8GB, you should enable the HugePages
feature to improve database performance.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is LUKS? How to use it?


LUKS is the standard for Linux hard disk encryption. By providing a standard on-
disk-format, it does not only facilitate compatibility among distributions, but
also provides secure management of multiple user passwords.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the advantage of executing the running processes in the background? How can
you do that?
The most significant advantage of executing the running process in the background
is that you can do any other tasksimultaneously while other processes are running
in the background. So,more processes can be completed in the background while you
are workingon different processes. It can be achieved by adding a special character
‘&’ at the end of the command.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

List the differences between BASH and DOS?


There are many differences between BASH and DOS that are as below:
Out of these two commands, BASH is case sensitive while DOS is not case sensitive.
In BASH ‘/’ acts the directory separator while in DOS ‘/’ acts as the command
argument delimiter.
In BASH ‘\’ is used as the escape character while in DOS ‘\’ acts as the directory
separator.
In BASH, there is a file convention used while in DOS, there is no any file
convention used.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

If a volume group already exists and we need to extend the volume group to some
extent. How will you achieve this?
Linux providethe facility to increase the size of a volume group even if it
alreadyexists. For this, we need to run a command.
First of all, we have to create a physical volume (/dev/sda1)
Size of the physical volume should be the size you want the size of the logical
volume.
Now, run the below command:
vgextend VG1 /dev/sda1
Here VG1 is the name of the volume group.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Why is “finger service” always kept disabled when not in use?


Finger Serviceacts as both the Web and FTP server. It is also known as Finger
UserInformation Protocol which contains the information of the user that canbe
viewed by the clients. It allows a remote user to see theinformation about the
admin such as login shell, login name and otherconfidential details. That is why,
the finger service should be keptdisabled when it’s not in use.
If it is not disabled, you have to modify and comment out the file
“/etc/inetd.conf”.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can we make a router with the help of Linux Computer?


Linuxmachine has the ability to turn it into a router with the help of
IPMasquerade. You may have seen the servers found in commercial firewalls.IP
Masquerade does the same function to one-to-many Network AddressTranslation
servers. If the internal computers do not have the IPaddress then in this case, IP
Masquerade can connect to the otherinternal computers which are connected to Linux
box to access theinternet.
Just follow these steps to enable IP Masquerade Linux:
- Connect your PC to LAN.
- This PC can be used as a default gateway for other systems for TCP/IP networking.
You can use the same DNS on all other systems.
- Go in the Kernel and enable IP forwarding. You can also enable IPforwarding using
the command: /etc/rc.d/rc.local file on rebooting thesystem.
- The last step is to run this command which sets up the rules to masquerade:
/sbin/iptables

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How we can enable ACL?


ACL is anacronym for Access Control List which is used to provide flexible
permission mechanism for the file systems. We can enable ACL byfollowing methods:
Type the code in the shell: /etc/fstab with a label=/home/ext3 acl
Now we have to remount this file system with the ACL partition: mount –t ext3 –o
acl /dev/sda3/home

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What do you mean by Redirection?


When the data is directed from one output toanother output even when the output
will serve the data as an input foranother process, this is called redirection.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is command grouping?


We can redirecta command from a file or to a file. It is usually done with the help
ofbraces or parenthesis. When the command is grouped then redirection isdone to the
whole group.
The command is executed by the currentshell when we use the braces () and in case
we have to execute a commandby a subshell then we use parenthesis {}.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain file permission in Linux. How to change it?


Permissions are established for all files and directories. Permissionsspecify who
can access a file or directory, and the types of access. All files and directories
are owned by a user.
Permissions are controlled at three levels:
Owner (called a user, or ‘u’)
Group (‘g’)
The rest users(called other, or ‘o’)
Level of access:
Read – Filet can be viewed or copied.
Write – File can be overwritten (e.g., using save as)
Execute – File can be executed
To change permission – chmod <permissions> < file(s)> is used. Here permissions can
be specified different approaches. The parameter file(s) is one or more files (or
directories). One approach to specifypermissions is to describe the changes to be
applied as a combination of u, g, o along with r, w, x. To add permission, use +
and to removepermission, use –.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the process in a Linux context?


A process is a running program. Processes can be started from the GUI orthe command
line. Processes can also start other processes. Whenever aprocess runs, Linux keeps
track of it through a process ID (PID). Afterbooting, the first process is an
initialization process called init. Itis given a PID ofFrom that point on, each new
process gets the nextavailable PID.
A process can only be created by another process. We refer to thecreating process
as the parent and the created process as the child. Theparent process spawns one or
more child processes. The spawning of aprocess can be accomplished in one of
several ways. Each requires asystem call (function call) to the Linux kernel. These
function callsare fork(), vfork(), clone(), wait(), and exec().

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What do you understand about Linux Kernel and can you edit it?
Linux Kernel is the component that manages the hardware resources for the user and
that provides essential services and interact with the user commands. Linux Kernel
is an open sourcesoftware and free, and it is released under General Public License
so we can edit it and it is legal.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are the different types of Kernels? Explain


We can buildkernels by many different types, but 3 of the types of kernels are
mostcommonly used: monolithic, microkernel and hybrid.
Microkernel: This type of kernelonly manages CPU, memory, and IPC. This kind of
kernel providesportability, small memory footprint and also security.
Monolithic Kernel: Linux is amonolithic kernel. So, this type of kernel provides
file management,system server calls, also manages CPU, IPC as well as device
drivers. Itprovides easier access to the process to communicate and as there isnot
any queue for processor time, so processes react faster.
Hybrid Kernel: In this type ofkernels, programmers can select what they want to run
in user mode andwhat in supervisor mode. So, this kernel provides more flexibility
thanany other kernel but it can have some latency problems.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain Linux Boot Sequence.?

BIOS/UEFI Initialization: The boot process begins with the system firmware (BIOS or
UEFI) initializing the hardware components such as CPU, memory, and storage devices
Boot Loader (GRUB): Once the hardware is initialized, the boot loader, usually GRUB
(Grand Unified Bootloader), is loaded into memory from the boot device. GRUB
presents the kernel versions to boot
Kernel Initialization: After the kernel version is selected, GRUB loads the Linux
kernel (vmlinuz) into memory. The kernel initializes system components, scheduler,
memory management, drivers and more
Initramfs: the kernel loads an initial RAM filesystem (initramfs) into memory. The
initramfs has modules and tools required for mounting the root filesystem
Root Filesystem Mounting: The kernel mounts the root filesystem mentioned in the
bootloader configuration. This filesystem has all the necessary files for the
operating system to function
Init Process: Once the root filesystem is mounted, the kernel executes the init
process, which is the user-space process. The init process initializes the rest of
the user-space environment, such as starting system services and daemons
System Initialization: The init process may be replaced by systemd. It brings up
the system services defined in the configuration files, sets up networking, mounts
additional filesystems, and performs other system setup tasks
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain Interrupts in Linux and also explain Interrupt handlers.


Interrupts means the processor is transferred temporarily to another program
orfunction. When that program is completed, the processor will be givenback to that
program to complete the task.
Interrupt handler is the function that the kernel runs for a specific interrupt. It
is also called InterruptService Routine. Interrupts handlers are the function that
matches aparticular prototype and enables the kernel to pass the handlerinformation
accurately.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is page frame?


A page frame is a block of RAM that is used for virtual memory. It has its page
frame number. The size of a page framemay vary from system to system, and it is in
the power of 2 in bytes.Also, it is the smallest length block of memory in which an
operatingsystem maps memory pages.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are the possible methods to deploy a module inside a kernel?

The Kernel modules are the set of programs or code which can be loadedas per the
requirement or demand which can be implemented without theprocess of rebooting the
system. Each and every kernel is a module andis easily loadable. There will also be
an automatic module handling.

To check themodules that are already installed inside the kernel, you have to
runthis code: lsmod. When the module has been built, now it is the stage toload it
in the kernel. You can load it by the command “Insmod” or“Modprobe”.
Syntax: Insmod[filename][module-options] //module-options are command line
arguments to kernel objects.
Insmod always accepts only one filename at a time.
Modprobe offers more features thanInsmod like it can decide which module is to be
loaded and is aware ofthe module dependencies.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Mention the case when we use “user virtual address” instead of “kernel virtual
address”?
When we run a program in userspace then we use“user virtual address” as we do not
have any access to kernel virtualmemory address. Normally when we are running our
program in kernel modethen we use kernel address but in case we have to run our
program inkernel mode and that program needs an interaction with a userspace thenwe
will use “user virtual address” and be careful to first translate itto user virtual
address.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Mention the ways to debug the kernel code.


We can debug a kernel code simply with the command printks. Else we can also use
KDB and kernel probes. Other methods are:
- UML (User Mode Linux) – It is the best method for debugging but it does not
support device drivers.
- KGDB (Kernel GNU Debugger)
- kdump tools which are used to dump kernel cores.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the device tree concept?


Device tree is a data structure which is used to remove the repetitive codes in
different boards. They are loaded in the memory with the helpof bootloader to a
binary file. Here the kernel is used to settle thestructure of the device tree on
the binary.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can we reduce the size of the kernel?


There are codes which areunnecessary and are not executed, we can find and disable
them to makethe processing faster in the project. The kernel comes with an editor
known as “kernel’s configuration editor” by which we can remove anddisable chunks
of code that are not required.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

There may be the codes for which the hardware is not present in the system and you
have to make your system understand about what are your system’s requirements.
Below are some guiding principles by which you can find the codes to be removed.
- Hardware Networking Drivers:Several ofsystem-on-chips have Wi-Fi drivers, serial
and other hardware that arenot used, you can remove those drivers that are built on
the kernel.
- File Systems:The system has the only requirement offew file systems but in the
kernel you will find many file systemsdrivers that are not in use e.g. Devices
which make use of flash filesystems do not require ext2 or ext3 file system so they
can be removed.Be cautious that do not remove the file systems that are essential
oryou may have the use of the systems in the future.
- Debugging and Profiling:All the systems which come under kernel hacking entry
could be disabled if not in use.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between “rm” and “rm –r”?


“rm”command is used to delete all the files while “rm –r” command is used todelete
all the files in a directory and also in subdirectories.
For Example,
rm file.txt: It will delete the file with name file.txt
rm –r directory: It will remove directories and subdirectories and also their
contents.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

You run a bash script and you want to see its output on your terminal and save it
to a file at the same time. How could you do it?
bash
user@unknown:~$ sudo command -option | tee log.txt

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain what echo "1" > /proc/sys/net/ipv4/ip_forward does.


Enable IP Forwarding on the fly

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain the command and method to change the file permissions in Linux.
chmod command is used to change the permissions of a file. There are three parts to
consider to set the file permissions.
User (or Owner)
2. Group
3. Other
3 types of file permission that is given to a file.
- r – Reading permission
- w – Writing permission
- x – Execution permission
For example, chmod 751 filename
Then, three number 751 describespermissions given to the user, group and other in
the order. Each numberis the sum of the values,i.e. 4 for reading, 2 for write, 1
forexecute.
Here 751 is the combination of (4+2+1), (4+0+1), (0+0+1).
So, chmod 751 filename will provideread, write and execute permission to the owner;
read and executepermission to the group and only execute permission to the others.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can we edit a file without opening in Linux?


sed command is used to edit a file without opening. sed is the acronym for
StreamEditor. The “sed” command is used to modify or change the contents of a file

Sed Command-

sed -n 3,5p /etc/passwd


sed 3,5d /etc/passwd - to see all except 3 and 5
sed -i s/old-text/new-text/g ~/myfile
sed -i s/u070228//g group
sed -i -e '2d' ~/myfile
sed -i -e '2d;2025d' ~/myfile
sed -i '/^HOSTNAME=/s/=.*/=pardhu/' /etc/sysconfig/network = to change hostname in
rhel 6

Remove entire line with keyword


sed --in-place '/dev/mapper/oracle_vg-ora_lv' /etc/fstab
sed -i '/oracle_vg-ora_lv/d' /etc/fstab
Replace word in file using sed
sed -i 's//dev/mapper/vg_prod-lv_production/production//dev/mapper/vg_prod-
lv_production /production/g' /etc/fstab
sed -i 's/$i/Hello/g' /tmp/ajit
Deleting last line from a file in linux with sed command
sed -i '$d' /etc/fstab
Deleting a line with a keyword -
sed -i '/woble/d' sherlock.txt
Deleting empty lines with sed -
sed -i '/^$/d' sherlock.txt
replacing comma with new line
sed 's//\n/g' /tmp/file1
sed 's/ //g' 44 = remove an empty blank/space
replacing tab with space -
sed -i 's/\t/ /g' sherlock.txt

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain grep command and its use.


grep command inLinux is used to search a specific pattern. Grep command will help
youto explore the string in a file or multiple files.
The syntax for grep command:
grep '\<pwpolicy\>' anaconda-ks.cfg = beginning of the line is pwpolicy\
grep '[[:digit:]]\{4\}' <file>

grep '\bpolicy\b' anaconda-ks.cfg


840 grep '\<pwpolicy\>' anaconda-ks.cfg
842 grep '[[:digit:]]\{2\}' anaconda-ks.cfg
857 grep [Ss]ome sherlock.txt
861 grep reali[zs]e sherlock.txt
862 grep realise sherlock.txt
864 grep 'wind' sherlock.txt
865 grep '\<wind\>' sherlock.txt
866 grep '\bwind\b' sherlock.txt
868 grep ' The' sherlock.txt
869 grep '^The\>' sherlock.txt
872 grep '[[:digit:]]\{4\}' sherlock.txt
875 grep fl..d sherlock.txt
877 grep 'die\?d' sherlock.txt
882 grep '[[:alpha:]]\{1617\}' sherlock.txt
878 egrep 'die?d' sherlock.txt
884 grep 'June\|July' sherlock.txt
886 egrep 'June|July' sherlock.txt

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain file content commands along with the description


There are many commands present in Linux which are used to look at the contents of
the file.
head: to check the starting of a file.
tail: to check the ending of the file. It is the reverse of head command.
cat: used to view, create, concatenate the files.
rrep: used to find the specific pattern or string in a file.
more: used to display the text in the terminal window in pager form.
less: used to view the text in the backward direction and also provides single line
movement.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain “cd” command in Linux.


In Linux, when a user needs to change the current directory then “cd” command is
input in the shell.
Syntax: $cd
The purpose that can be fulfilled by the current command are –
- Redirect to a new directory from the current directory.
- Change a directory using absolute path and relative path.
The following commands are under the cd:
- cd ~:Redirect to home directory.
- cd-:Redirect to previous directory.
- cd/: Redirect to entire system directory.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Mention some of the networking commands in Linux.


If you connect asystem to a network then you can easily troubleshoot the
connectionissues related to the system. Below are few of the networking
commandsused for configuration and troubleshooting.
- ifconfig(now is ip something)
- traceroute
- dig
- telnet
- nslookup

dmesg = gives error messages and info about hardware and kernel
iostat -xmt 1= this gives info on disks, if something been written iostat 1 - to
keep refreshing the disk usage
ss is the replacement utility for netstat
netstat -antup | grep 873
netstat -rvn = gives network information
netstat -tnlup = gives all active listening ports
netstat -i = shows packets information
nmap -A ip = to check the open ports on remote server
vmstat = virtual memory buffer
pidstat = shows all info regarding the pid's and user accessing
mtr ip or hostname = to see packets lost or sent and other network information
mpstat = cpu information that has nice value and idle state of CPU
sar -q = cpu load utilization
sar -r = memory utilization
sar -d = disk utilization
sar -n ALL or network interface = network utilizations

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Write the command to view an existing tar archive and how to extract it?
The command for viewing tar archive that is already existing: $ tar tvf
archive_name.tar
The command to extract an existing tar archive: $ tar xvf archive_name.tar
The command for the creation of new tar archive: $ tar cvf archive_name.tar
dirname/
You may be asked one or more commandbased interview questions in the linux
interview. You should prepareyourself with as many commands as you can. There are
several commandsthat are used for tar archive which are commonly asked in the
linuxinterview, so don’t miss to cover this question while going for thelinux
interview.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Write the steps to make a USB bootable device.


Followings are the steps to make a USB bootable device –
- You have to write efidisk.img from RHEL 6 DVD images/ subdirectory
to USB dd if=efidisk.img of=/dev/usb (name of the usb device)
- Now you have to disable ping to avoid network /ICMP flood
- Now set the following in/etc/sysctl.conf : net.ipv4.icmp_echo_ignore_all =1
- Then “sysctl -p”

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the command used to get a guide on how to use a command?


Manual pages are where an explanation of every command has stored.Manual pages for
a specific command will have all information about thatcommand and it can be called
as ‘man <command> eg: ‘man ls’.Manualpages are categorized into different sets of
user commands, systemcalls, library functions..etc..A general layout of a manual
page is –

NAME
The name of the command or function and simple explanation of it.
SYNOPSIS
For commands how to run it and parameters it takes. For functions, alist of the
parameters it takes and which header file contains itsdefinition.
DESCRIPTION
A detailed description of command or function we are searching for.
EXAMPLES
Some examples of usages.Most helpful section
SEE ALSO
This section will have a list of related commands or functions.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How to get a list of currently running processes and resource utilization in Linux?
The top is the command used for this. This will give all information about each
process running on a machine like –
Process ID (PID)
Owner of the process(USER)
Priority of process(PR)
Percentage of CPU (%CPU)
Percentage of memory
Total CPU time spends on the process.
Command used to start a process.

The popular option used with top command


top -u -> Process by a user.
top – i -> exclude idle tasks
top -p -> Show a particular process

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
What is a pipeline operator in Linux?
Pipeline operator in Linux is used to redirect the output of one program or command
to another program/command for further processing. Usuallytermed as redirection.
Vertical bars,’|’ (“pipes” in common [Unix
verbiage](https://www.educba.com/course/unix-1/)) are used for this. For example,
ls -l | grep key, will redirect the output of ls -l command to grep key command

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are Regular Expressions(regex)? What is the meaning of ,+,? In regular


expression?
A regular expression (regex) is a string that expresses a pattern usedto match
against other strings. The pattern will either match someportion of another string
or not. There is a list of predefinedmetacharacters used in a regex.
\ Used to match the preceding character if it appears 0 or more times
+Used to match the preceding character if it appears 1 or more times
? Used to match the preceding character if it appears 0 or 1 times

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is umask and what is its use in Linux?


The umask is a command which is often called as user file creation maskwhich is
used to create file mask for the user that determines whichfile or directory
permissions are available for the user based on theread or write or modify type.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain, in as much detail as you feel comfortable with, what is happening when you
access Google.com
You type maps.google.com into the address bar of your browser.
2. The browser checks the cache for a DNS record to find the corresponding IP
address of maps.google.com.
3. If the requested URL is not in the cache, ISP’s DNS server initiates a DNS query
to find the IP address of the server that hosts maps.google.com.
4. Browser initiates a TCP connection with the server.
5. The browser sends an HTTP request to the web server.
6. The server handles the request and sends back a response.
7. The server sends out an HTTP response.
8. The browser displays the HTML content (for HTML responses which is the most
common).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is SSH port forwarding?


SSH port forwarding is a mechanism in SSH for tunneling application ports from the
client machine to the server machine, or vice versa. It can be used for adding
encryption to legacy applications, going through firewalls, and some system
administrators and IT professionals use it for opening backdoorsinto the internal
network from their home machines. It can also beabused by hackers and malware to
open access from the Internet to theinternal network.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How to know which process listens on a specific port?


Using netstat Command:
Netstat (network statistics) command is used to display information concerning
network connections, routing tables, interface stats and beyond.
use it with grep command to find the process or service listening on a particular
port in Linux as follows (specify the port)
$ netstat -ltnp | grep -w ':80'
![Check Port Using netstat
Command](https://www.tecmint.com/wp-content/uploads/2017/07/Check-Port-Using-
netstat-Command.png)
Check Port Using netstat Command
In the above command, the flags.
- `l` – tells netstat to only show listening sockets.
- `t` – tells it to display tcp connections.
- `n` – instructs it show numerical addresses.
- `p` – enables showing of the process ID and the process name.
- `grep -w` – shows matching of exact string (:80).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between local and remote port forwarding?


Local Port Forwarding:
Local port forwarding allows you to forward a port from your local machine to a
remote server through an SSH connection.
This means that connections made to a specific port on your local machine are
forwarded to a specified port on a remote server via the SSH tunnel.

Remote Port Forwarding:


Remote port forwarding operates in the opposite direction of local port forwarding.
With remote port forwarding, you can forward a port from a remote server to your
local machine through an SSH connection.
This allows connections made to a specific port on the remote server to be
forwarded to a specified port on your local machine.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is DNS?
The Domain Name System resolves the names ofinternet sites with their underlying IP
addresses adding efficiency andeven security in the process.
DNS is a directory of names that match with numbers. The numbers, inthis case are
IP addresses, which computers use to communicate with each other.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is an A record, an NS record, a PTR record, a CNAME record, an MX record?


These are record types that are present inside a DNS server
DNS Resource Records (from: A, AAAA, CNAME, MX, NS, PTR, SOA, SRV, TXT
Zone DNS database is a collection of resource records and each of therecords
provides information about a specific object. A list of mostcommon records is
provided below:
- Address Mapping records (A)The record A specifies IP address (IPv4) for given
host. A recordsare used for conversion of domain names to corresponding IP
addresses. IP Version 6 Address records(AAAA)The record AAAA (also quad-A record)
specifies IPv6 address forgiven host. So it works the same way as the A record and
the differenceis the type of IP address.
- Canonical Name records(CNAME) The CNAME record specifies a domain name that has
to be queriedin order to resolve the original DNS query. Therefore CNAME records
areused for creating aliases of domain names. CNAME records are trulyuseful when we
want to alias our domain to an external domain. In othercases we can remove CNAME
records and replace them with A records andeven decrease performance overhead
- Host Information records(HINFO) are used to acquire general information about
ahost. The record specifies type of CPU and OS. The HINFO record dataprovides the
possibility to use operating system specific protocols when two hosts want to
communicate. For security reasons the HINFO recordsare not typically used on public
servers.
- Integrated Services Digital Network records (ISDN)The ISDN resource record
specifies ISDN address for a host. AnISDN address is a telephone number that
consists of a country code, anational destination code, a ISDN Subscriber number
and, optionally, aISDN sub address. The function of the record is only variation of
the Aresource record function.
- Mail exchanger record (MX)The MX resource record specifies a mail exchange server
for a DNSdomain name. The information is used by Simple Mail Transfer
Protocol(SMTP) to route emails to proper hosts. Typically, there are more thanone
mail exchange server for a DNS domain and each of them have setpriority.
- Name Server records (NS)The NS record specifies an authoritative name server for
given host.
- Reverse-lookup Pointer records (PTR)As opposed to forward DNS resolution (A and
AAAA DNS records), the PTR record is used to look up domain names based on an IP
address
- Start of Authority records (SOA) The record specifies core information about a
DNS zone, includingthe primary name server, the email of the domain administrator,
thedomain serial number, and several timers relating to refreshing thezone.
- Text records (TXT): The text record can hold arbitrary non-formatted text string.
Typically, the record is used by [ender Policy Framework (SPF) to prevent fake
emails to appear to be sent by you.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a Split-Horizon DNS?


Split-Brain DNS, Split-Horizon DNS, or Split DNS are terms used todescribe when two
zones for the same domain are created, one to be usedby the internal network, the
other used by the external network (usuallythe Internet).I prefer the term "Split
DNS" so we will just continue with that one.
A Split DNS infrastructure is used to direct internal hosts to aninternal domain
name server for name resolution and external hosts to anexternal domain name server
for name resolution.This type of DNSconfiguration is verycommon in networks that
have established an internal Active Directorydomain name which is the same as the
public external domain name.Let'sbegin by taking a look at an example where Split
DNS is not used.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is HTTP?
Stands for "Hypertext Transfer Protocol."HTTP is the protocol used to transfer data
over the web.It is part of the Internet protocol suite and defines commands and
services used for transmitting webpage data.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is an HTTP proxy and how does it work?


An HTTP Proxy serves two intermediary roles as an HTTP Client and anHTTP Server for
security, management, and caching functionality. TheHTTP Proxy routes HTTP Client
requests from a Web browser to theInternet, while supporting the caching of
Internet data.
Proxy server advantages include:
- Maintaining identity anonymity as a security precaution.
- Accelerating caching rates.
- Facilitating access to prohibited sites.
- Enforcing access policies on certain websites.
- Allowing a site to make external server requests.
- Avoiding security controls.
- Bypassing Internet filtering for access to prohibited content.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe briefly how HTTPS works.


HTTP uses a server-client model.
When you access a website, your
[browser](https://techterms.com/definition/web_browser) sends a request to the
corresponding web server and it responds with an HTTP status code.If the [URL]
(https://techterms.com/definition/url) is valid and the connection is granted, the
server will send your browser the webpage and related files.

Some common HTTP status codes include:


200 - successful request (the webpage exists)
2. 301 - moved permanently (often forwarded to a new URL)
3. 401 - unauthorized request (authorization required)
4. 403 - forbidden (access is not allowed to the page or directory)
5. 500 - internal server error (often caused by an incorrect server configuration)
HTTP also defines commands such as GET and POST, which are used to handle form
submissions on websites.The CONNECT command is used to facilitate a secure
connection that is [encrypted](https://techterms.com/definition/encryption) using
[SSL](https://techterms.com/definition/ssl).Encrypted HTTP connections take place
over [HTTPS](https://techterms.com/definition/https), an extension of HTTP designed
for secure data transmissions.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is SNMP and what is it used for?


SNMP (Simple Network Management Protocol isa widely used protocol for monitoring
the health and welfare of networkequipment (eg. routers), computer equipment and
even devices likeUPSs.
It is commonly used by network and system administrators to gatheroperational
statistics(such as measuring network bandwidth traffic, cpuusage, or available hard
drive space) as well as setting systemparameters.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is SMTP? Give the basic scenario of how a mail message is delivered via SMTP.
SMTP stands for Simple Transfer Email Protocol. Currently, the electronic mail (e-
mail) standard for the Internet isSMTP. SMTP is the Application Levelprotocol that
handlesmessage services over [TCP/IP]. SMTP uses TCP Well Known Port25.
Simple Mail Transfer Protocol (SMTP) is based onend-to-end message delivery. An
Simple Mail Transfer Protocol (SMTP)client contacts the destinationhost's Simple
Mail Transfer Protocol (SMTP) serveron well-known port 25, to deliver the mail. The
client then waitsfor theserver to send a 220 READYFOR MAIL message.
Uponreceiptofthe220 message, theclient sends a HELO command. The server then
responds with a "250Requested mail action okay" message.
After this, the mail transaction will begin with a MAILcommand that gives the
sender identificationas well as a FROM:field that contains the address to which
errors should bereported.
After asuccessful MAILcommand, the sender issues a series of RCPTcommands
thatidentifyrecipientsofthemailmessage.Thereceiver will the acknowledgeeach RCPT
command bysending 250 OK or bysending the error message 550 Nosuch user here.
Afterall RCPTcommands havebeenacknowledged,thesenderissuesa DATAcommand to inform
the receiver thatthe sender isreadytotransferacomplete mail message.The
receiverresponds with message 354Start mail command with an endingsequence that the
sender should use to terminate themessage data. The termination sequence consists
of 5 characters:carriage return, line feed, period, carriage return, and line
feed(<CRLF>.<CRLF>).
The client now sends the data line by line, ending with the 5-character sequence
<CRLF>.<CRLF> line, upon which the receiver will acknowledge with a 250 OK, or an
appropriate error message if anything went wrong.
After the sending is completed, the client can follow any of these actions.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is localhost and why would `ping localhost` fail?


In computer networking localhost is a hostname that means this computer. It is used
to access the network services that are running on the host via theloopback network
interface. Using the loopback interface bypasses any local network interface.
If ping localhost fail we should se if there is an interface configured with `lo0`
or any other interface with 127.0.0.1?Check the Rx packets/Tx packets count. Also,
check to see if lo0 is configured in /etc/network/interfaces.
bash
output of 'ifconfig'
loLink encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:16436Metric:1
RX packets:24 errors:0 dropped:0 overruns:0 frame:0
TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1440 (4 KB)TX bytes:1440 (4 KB)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the similarity between "ping" & "traceroute" ? How is traceroute able to
find the hops.
The main difference between the common Ping and Traceroute commands isthat Ping is
a quick and easy way to tell you if the destination serveris online and estimates
how long it takes to send and receive data tothe destination. Traceroute tells you
the exact route you take to reachthe server from your computer (ISP) and how long
each hop takes.
Traceroute makes use of a network mechanism called TTL, or "Time to Live" and
Probing the Hops: Traceroute makes sure that each hop on the way to a destination
device drops a packet, and sends back an ICMP error message.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the command used to show all open ports and/or socket connections on a
machine?
bash
ss -sList currently established, closed, orphaned and waiting TCP sockets
ss -ldisplay all open network ports
ss -plto see process named using open socket:
ss -lp | grep 4949Find out who is responsible for opening socket / port4949 using
the ss command and grep command

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Is 300.168.0.123 a valid IPv4 address?


A valid IP address must be in the form of xxx.xxx.xxx.xxx, where xxx is a number
from 0-255so no, this isn't a valid IPv4 address.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Which IP ranges/subnets are "private" or "non-routable" (RFC 1918)?


A private network is typically a network that uses private IP address space,
following the RFC 1918]standard

| 24-bit block | 10.0.0.0 – 10.255.255.255 | 16,777,216| single class A, 256


contiguous class Bs | 10.0.0.0/8 |
| 20-bit block | 172.16.0.0 – 172.3255.255 | 1,048,576 | 16 contiguous class Bs|
172.16.0.0/12|
| 16-bit block | 192.168.0.0 – 192.168.255.255 | 65,536| single class B, 256
contiguous class Cs | 192.168.0.0/16 |

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a VLAN?
A VLAN, or Virtual Local Area Network, is a technology used in networking to
logically segment a single physical network into multiple virtual networks. This
segmentation is achieved by assigning network devices, such as computers, servers,
or switches, to different VLANs based on criteria such as port numbers, MAC
addresses, or protocols.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is ARP and what is it used for?


The Address Resolution Protocol (ARP) is a communication protocol used for
discovering the link layer address, such as a MAC address, associated with a given
internet layer address, typically an IPv4 address. This mapping is a critical
function in the Internet protocol suite

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the purpose of a default gateway?


A default gateway serves as an access point or IP router that a networked computer
uses to send information to a computer in anothernetwork or the internet. Default
simply means that this gateway is usedby default, unless an application specifies
another gateway.
A default gateway lets devices in one network communicate with devices in another
network. If your computer, forexample, is requesting an internet web page, the
request first runsthrough your default gateway before exiting the local network to
reach the internet.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
What are the layers of the OSI model?
The seven layers of function are provided by a combination of applications,
operating systems,network card device drivers and networking hardware that enable
asystem to transmit a signal over a network Ethernet or fibber optic cableor
through Wi-Fi or other wireless protocols

The seven Open Systems Interconnection layers are:


Layer 7: The application layer.This is the layer at which communication partners
are identified -- Isthere someone to talk to? -- network capacity is assessed --
Will thenetwork let me talk to them right now? -- and where the data orapplication
is presented in a visual form the user can understand. Thislayer is not the
applicationitself, it is the set of services an application should be able to
makeuse of directly, although some applications may performapplication-layer
functions.
Layer 6: The presentation layer.This layer is usually part of an operating system
OS and converts incoming and outgoing data from one presentation [format to another
-- for example, from clear text to encrypted text at one end and back to clear text
at the other.
Layer 5: The session layer.This layer sets up, coordinates and terminates
conversations. Itsservices include authentication and reconnection after an
interruption.On the internet, Transmission Control Protocol TCP and User Datagram
Protocol UDP provide these services for most applications.
Layer 4: The transport layerThis layer manages packetization of data, then the
delivery of thepackets, including checking for errors in the data once it arrives.
Onthe internet, TCP and UDP provide these services for most applicationsas well.
Layer 3: The network layer. This layer handles addressing and routingthe data --
sending it in the right direction to the right destinationon outgoing transmissions
and receiving incoming transmissions at thepacket level. IP is the network layer
for the internet.
Layer 2: The data-link layer. This layer sets up links across the physical network,
putting packets into network frames. This layer has two sub-layers: the logical
link control layer and the media access control layer MAC. MAC layer types include
Ethernet and 802.11 wireless specifications.
Layer 1: The physical layer. This layer conveys the bit stream across the network
either electrically, mechanically or through radiowaves. The physical layer covers
a variety of devices and mediums, amongthem cabling, connectors, receivers,
transceivers and repeaters.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Can you have several HTTPS virtual hosts sharing the same IP?
Yes, you can have several HTTPS (HTTP over SSL/TLS) virtual hosts sharing the same
IP address. This is achieved through the use of Server Name Indication (SNI), which
is an extension to the TLS protocol

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a wildcard certificate?


A wildcard certificate is a type of SSL/TLS certificate that is issued to a domain
and all its subdomains, represented by a wildcard character (*). This wildcard
character typically replaces the subdomain portion of the domain name in the
certificate.

For example, a wildcard certificate for .(domainname).com, could beused for www.
(domainname).com, mail.(domainname).com,store.(domainname).com, in addition to any
additional sub domain name in the (domainname).com.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

A TCP connection on a network can be uniquely defined by 4 things. What are those
things?
A TCP connection on a network can be uniquely defined by the following four
elements:
Source IP address: The IP address of the sender or the source of the TCP
connection.
Source port number: The port number being used by the sender's device for the TCP
connection.
Destination IP address: The IP address of the receiver or the destination of the
TCP connection.
Destination port number: The port number being used by the receiver's device for
the TCP connection.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How do you add an IPv6 address to a specific interface?


Adding an IPv6 address is similar to the mechanism of "IP ALIAS" addresses in Linux
IPv4 addressed interfaces.
Usage:
/sbin/ip -6 addr add <ipv6address>/<prefixlength> dev <interface>
Example:
/sbin/ip -6 addr add 2001:0db8:0:f101::1/64 dev eth0

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

You have added an IPv4 and IPv6 address to interface eth0. A ping tothe v4 address
is working but a ping to the v6 address gives you theresponse `sendmsg: operation
not permitted`. What could be wrong?
bash
This means that your server is not allowed to send ICMP packets.
Check firewall rules:
$ ip6tables -P INPUT ACCEPT
$ ip6tables -P OUTPUT ACCEPT
$ ip6tables -P FORWARD ACCEPT

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How many NTP servers would you configure in your local ntp.conf?
It is NOT recommended to use only two NTP servers.
If more than one NTP server is required, four NTP servers is therecommended
minimum. Four servers protects against one incorrecttimesource, or "falseticker".

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What does the column 'reach' mean in `ntpq -p` output?


In the ntpq -p output, the "reach" column represents the reachability register of
each server.
If a bit is set (1), it means that a successful response was received from the
server during that polling interval.
If a bit is clear (0), it means that no successful response was received from the
server during that polling interval.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can you tell if the httpd package was already installed?
Try install it again? Or check it version httpd -v

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can you list the contents of a package?


dpkg -c (or --contents ) lists the contents of a .deb package file

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is SNAT and when should it be used?


Source NAT: Source Network Address Translation
Destination NAT: Destination Network Address Translation
Use-Case for Source NAT: A local client behind Firewall or NAT device wanted to
browse Internet.
Source NAT (SNAT) is the most common form of NAT. SNAT changes the source address
of the packets passing through the Router. SNAT is typically used when an internal
(private) host needs to initiate a session to an external (public) host; in this
case, the device that is performing NAT changes the private IP address of the
source host to some public IP address, as shown in the following figure. In
“masquerade” NAT (a common type of SNAT), the source address of the outgoing packet
is replaced with the primary IP address of the outbound interface. The destination
address of return packets is automatically translated back to the IP address of the
source host.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain how could you ssh login into a Linux system that DROPs all new incoming
packets using a SSH tunnel.
If the Linux system is configured to drop all new incoming packets, you won't be
able to SSH directly into it. However, you can establish an SSH tunnel from another
system that has outbound connectivity to the target Linux system

ssh -L <local_port>:localhost:<target_ssh_port> <username>@<target_ip>


ssh <username>@localhost -p <local_port>

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How do you stop a DDoS attack?


netfilter [iptables](https://netfilter.org/projects/iptables/) (soon to be replaced
by [nftables](https://netfilter.org/projects/nftables/)) is a user-space command
line utility to configure kernel packet filtering rules developed by netfilter.
It’sthe default firewall management utility on Linux systems – everyoneworking with
Linux systems should be familiar with it or have at leastheard of it.
iptables can be used to filter certain packets, blocksource or destination ports
and IP addresses, forward packets via NATand a lot of other things.
You can use it to block the ip or ip-ranges that are targetting your network.
You can also use commercial tools that do it for you like Cloudflare.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How can you see content of an ip packet?
` tcpdump -r /tmp/capture -A | grep '10.2.50'`
`-A` option to `tcpdump` gives the packet contents

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What will happen when you bind port 0?


Asking to bind TCP on port 0 indicates a request to dynamically generate an unused
port number. In other words, the port number you're actually listening on after
that request is not zero.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between a Hub and a switch?


A switch is used to connect various network segments. A network switch is a small
hardware device that joins multiple computers together within one local area
network (LAN). A Hub connects multiple Ethernet devices together, making them act
as a single segment.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Nmap command
Nmap is used to discover hosts and services on a computer network by sending
packets and analyzing the responses. Nmap provides a number of features for probing
computer networks, including host discovery and service and operating system
detection

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What function does DNS play on a network?


It's on the core for any environment, responsible to translate IP addresses into
names, DNS can also provides a load balancer layer using geolocation, service
discovery using SRV entry and a lot of others features, like domain ownership
confirmation using TXT entries ( useful to generate SSL certs, for example )

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is HTTP?
HTTP (hypertext transport protocol) it's a protocol that defines how messages are
formated and transmitted via web, and what actions webservers and browsers should
take in response of various commands.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are HTTP status codes?


HTTP status codes are predefined status of the task at the server
1xx - represents informational responses
2xx - represents succesful responses
3xx - represents redirect responses
4xx - represents client errors
5xx - represents server errors
The most commmons status codes are:
200 Success/OK
201 - CREATED - used by POST or PUT methods
304 - NOT MODIFIED - used in conditional GET Request to reduce bandwitdth use
400 - BAD REQUEST - This can be due to validation errors or missing input data
404 - NOT FOUND - Resource method is not available
500 - INTERNAL SERVER ERROR - server threw some exceptions while running the method
502 - BAD GATEWAY - Server was not able to get the response from another upstream
server

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe the most common HTTP methods/verbs, and give examples:


GET - Read only operation, used to fetch detail from the server, downloads
POST - This method is used for the creationg of new resources on the server
PUT - This method is used to update existing resource on the server or to replace
the resource, PUT it's indepotent, and POST isn't, with PUT you can update a
resource N times, but if you try with post you will create N resources. PUT can
create resources.
PATCH - Applies a partial update to a resource and doesn't create a new resource
DELETE - This method is used to delete the resource on the server
TRACE - Provides a loop back test along the path to the target resource providing a
useful debugging mechanism.
OPTIONS - Fetches the list of supported options of resources present on the server.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is an HTTP proxy and how does it work?


An HTTP proxy it's a service that forwards HTTP connections, for example a user A
want's to access a server www.b.com, but for security reasons the user cannot have
direct access on internet, so the user's browser will ask for the HTTP proxy to
access the website, the webserver from www.b.com will receive a HTTP message from
the proxy and will answer as usual, but in the http HEADER from the message will be
changed by the HTTP proxy server who will add or change some headers like User-
Agent, X-Forwarded-For, used a lot by companies that need to control their users
Internet access.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe briefly how HTTPS works.


HTTPS use the same HTTP protocol but creates a security layer(tunnel) using
SSL/TLS, on top of it, this prevents anyone modify or inspect what's happening
inside this tunnel and ensure the client it's communicating with the right server.
The SSL handshake is established and after that all HTTP responses are send by. The
SSL uses both types of encryption, symmetrical and assymetrical, first when the key
exchange happens, a assymetrical encriptions is put in place to the result of the
key exchange be a symmetrical encryption.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is SMTP? Give the basic scenario of how a mail message is delivered via SMTP.
SMTP ( Simple Mail transport protocol) works in the application layer, and uses a
process called "store and forward", working close to a MTA (Mail Tranfer Agent),
this MTA service sends via SMTP a package with the messages, when this message
arrives at the destination, the client will use POP3/IMAP to download it.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe the general file system hierarchy of a Linux system.


/ - root folder
/etc - configuration files provided by the package manager
/bin - binaries files
/sbin - system binaries files (important binaries for the OS)
/boot - Static files for boot processes ( boot loader)
/dev - Device files
/lib - Essential shared libraries and kernel modules
/usr - Secundary hierarchy
/mnt - Mounting point for temporary filesystem
/media - Mounting point for removable media
/opt - Add-on application software packages
/srv - Data service provided by this system

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What commands do you know that can be used to check DNS records?
dig +trace
nslookup
whois
host

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is in /etc/services?
A mapping for services and ports, when a service call a function getportbyname()
usually this function goes in this file to check.
Example the command netstat or ss without the -n parameter

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How to redirect STDOUT and STDERR in bash? (> /dev/null 2>&1)


1> redirect the STDOUT
1>> redirect the STDOUT in append mode
2> redirect the STDERR
2>> redirect the STDERR in append mode
&> redirect both STDERR and STDOUT
&>> redirect both STDERR and STDOUT in append mode
2>&1 redirect STDERR to STDOUT

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the diference between Telnet and SSH?


SSH it's encrypted and telnet isn't.
Telnet can ommit authentication
SSH adds overhead to the bandwidth

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

tee
copies the STDOUT to a file, but continues to show the STDOUT.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

awk
awk it's a programming language designed for text processing.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

tr
tr or translate, it's a command to substitute characters.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

cut
cut is a command for text processing and extracts a portion of a text

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

tac
tac it's a reverse cat, pritting the file bottom to up.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

curl
curl or cURL is a tool to transfer data from or to a server, using one of the
supported protocols. cURL can be called a CLI browser, you can use to authenticate,
change the HEADER, and do a lot of stuffs with it.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

wget
wget is a tool for retrieving files using HTTP, HTTPS , or FTP.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

watch
Watch it's a tool that runs a specified command repeatedly and displays the result
on standard output.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

head
It's a command that shows the first lines of a file, the default it's 10 lines

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

tail
It's a command that shows the last lines of a file, the default it's 10 lines

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
What does an & after a command do?
Makes the command run in a background sub shell, and becomes a job.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Packet filter it's the process of passing or blocking packets at a network


interface based on source and destination address, port or protocols. The packet
filter examines, the header of every packet who passed through and based in the
rules, ACCEPT, DROP or REJECT the packet, it's well know as firewall.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is Virtual Memory?


Virtual memory it's the amount of memory available for the system, physical memory
+ swap memory (hard disk memory).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is an A record, an NS record, a PTR record, a CNAME record, an MX record?


A record stands for address, indicates an IP address for a domain
NS stands for Name Server record indicates which DNS server is authoritative for
that domain ( Where the actual DNS entries are)
CNAME stands for canonical name and servers to make one domain to another domain
name.
MX stands for mail exchange, it's a list of mail exchange servers used by the
domain.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Are there any other RRs and what are they used for?
PRT record stands for pointer record and maps an IPV4 address to a CNAME
SOA record stands for State of Authority and is easily one of the most important
DNS records because stores information like when the domain was last updated.
SRV record stands for Service Record, is a record that specifies hostname and port
number for a specific service, it can be used for service discovery.
TXT record stands for Text Information, used by various purposes, as domain
ownership for example.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a Split-Horizon DNS?


It's the feature/configuration of the DNS server answer a different resolution to a
query based on the source of the query. A common use it's when the DNS server needs
to diferentiate internal and external queries, for the same domain. We can use
views to configure this.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Describe briefly the steps you need to take in order to create and install a valid
certificate for the site https://foo.example.com.
Create a key file
Uses this key file to create a csr file
Send this csr file to a ssl certificate provider
Get the crt from the certificate provider with the CA chain and configure into the
webserver
Or you can use certbot to simplify.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Can you have several HTTPS virtual hosts sharing the same IP?
Yes using virtualhosts, but the client needs to support http/1, to use name-based
virtual host configuration.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a tunnel and how you can bypass a http proxy?


We can create a ssh tunnel with ssh -R and redirect the http proxy to a server that
has access to the internet.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between IDS and IPS?


IDS detect the problem inspecting the packet header and payload and creates a log.
IPS detect the problem inspecting the packet header and payload and drops the
packet if finds something problematic, based in some pre defined rules.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What's happening when the Linux kernel is starting the OOM killer and how does it
choose which process to kill first?
OOM will kill the process that will free more memory and the least important for
the OS.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What's a chroot jail?


Chroot jail it's a way to isolate a process and its children from the rest of the
system. The idea is that you create a directory tree where you copy or link in all
the system files needed for a process to run, usually we use bind to mount some
folder inside a chroot.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are cgroups? Can you specify a scenario where you could use them?
Cgroups are a Linux kernel feature that allow limit the resource use for a group of
process(CPU, memory, disk I/O). A scenario to use could be to test a software in a
physical machine that has a big hardware, and make this software run a minimum
configuration, a very common sofware that uses cgroups it's in contairners
( docker, crio).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the similarity between "ping" & "traceroute" ? How is traceroute able to
find the hops.
Both use ICMP (Internet control message protocol) packets to archive their
proposes, but traceroute sends the packets gradually increasing the TTL value,
starting with TTLThe first router receives the packet, decrements the TTL value and
drops the packet because the TTL has zero. The router sends an ICMP Time Exceeded
message back to the source.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the command used to show all open ports and/or socket connections on a
machine?
lsof -i
netstat -a
ss -a

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Which IP ranges/subnets are "private" or "non-routable" (RFC 1918)?


0/8
0/16
0/16

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a VLAN?
It's a virtual lan created to separate networks inside a switch, making the
broadcast domain shorter, and for security proposes. Works in the network layer
(OSI Layer 2)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between TCP and UDP?


TCP ( Transmissions control protocol ) and UDP ( User Datagram Protocol ), both
works in the layer 3 of the OSI model, and are different methods to send
information across networks, or Internet. TCP is used in scenarios when reliability
is important, and is used by the majority of layer 7 protocols, like HTTP, FTP,
SMTP. TCP is connection-oriented ( after estabilishes the connection between two
devices, maintains until the transfer process finishes), and uses a process called
three-way handshake ( SYN, SYN-ACK, ACK)..
UDP it's a connectionless protocol ( doesn't estabilish a connection before hand)
it's much simple and used in situations when data loss is acceptable, because
doesn't guarantee all data is successfully transferred.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is command used to show the routing table on a Linux box?


route
netstat -r
ip route list
ip r

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

A TCP connection on a network can be uniquely defined by 4 things. What are those
things?
remote-ip-address
remote-port
source-ip-address
source-port
When a client running a web browser connects to a web server, what is the source
port and what is the destination port of the connection?
source port it's dynamic based on net.ipv4.ip_local_port_range defined between
32768 - 61000, destination port 80 or 443.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a tarpipe (or, how would you go about copying everything,including


hardlinks and special files, from one server to another)?
tarpipe (or, how would you go about copying everything,including hardlinks and
special files, from one server to another)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the equivalent of a file shortcut that we have a window on a Linux system?
Shortcuts are created using "links" on Linux. There are two types of links that can
be used namely "soft link" and "hard link".

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How will you pass and access arguments to a script in Linux?


Arguments can be passed as: scriptName "Arg1" "Arg2"…."Argn" and can be accessed
inside the script as $1 , $2 .. $n

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the significance of $?


$ shows the count of the arguments passed to the script.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between $\ and $@?


$@ treats each quoted arguments as separate arguments but $ willconsider the entire
set of positional parameters as a single string.
Use sed command to replace the content of the file (emulate tac command)

Eg:
if cat fille
ABCD
EFGH
Then O/p should be
EFGH
ABCD
sed '1! G; h;$!d' file1
Here G command appends to the pattern space,
h command copies pattern buffer to hold bufer
and d command deletes the current patternspace.
Given a file,replace all occurrence of wrd "ABC" with "DEF" from 5th line till end
in only those lines that contains word "MNO"
sed –n '5,$p' file1|sed '/MNO/s/ABC/DEF/'
Given a file, write a command sequence to find the count of each word.
tr –s"(backslash)040" <file1|tr –s"(backslash)011"|tr "(backslash)040
(backslash)011" "(backslash)012" |uniq –c
where "(backslash)040" is octal equivalent of "space"
"(backslash)011" is an octal equivalent of "tab character" and
"(backslash)012" is an octal equivalent of the newline character.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How will you find the 99th line of a file using only tail and head command?
tail +99 file1|head -1

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Print the 10th line without using tail and head command.
sed –n '10p' file1

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

In my bash shell I want my prompt to be of format '$"Present working


directory":"hostname">and load a file containinga list of user-defined functions as
soon as I log in, how will youautomate this?
In bash shell, we can create ".profile"file which automaticallygets invoked as soon
as I log in and write the following syntax intoit.
export PS1='$ `pwd`:`hostname`>' .File1
Here File1 is the file containing the user-defined functions and "." invokes this
file in current shell.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Explain about "s" permission bit in a file.


"s" bit is called "set user id" (SUID) bit.
"s" bit on a file causes the process to have the privileges of the owner of the
file during the instance of the program.
For example, executing "passwd" command to change currentpassword causes the user
to writes its new password to shadow file eventhough it has "root" as its owner.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

I want to create a directory such that anyone in thegroup can create a file and
access any person's file in it but noneshould be able to delete a file other than
the one created by himself.
We can create the directory giving read and execute access toeveryone in the group
and setting its sticky bit "t" on as follows:
mkdir direc1
chmod g+wx direc1
chmod +t direc1

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can you find out how long the system has been running?
We can find this by using the command "uptime".
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can any user find out all information about aspecific user like his default
shell, real-life name, default directory,when and how long he has been using the
system?
finger"loginName"…where loginName is the login name of the user whose information
is expected.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between $ and $!?


$$ gives the process id of the currently executing processwhereas $! Shows the
process id of the process that recently went intothe background.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How will you copy a file from one machine to other?


We can use utilities like "ftp," "scp" or "rsync" to copy a file from one machine
to other. E.g., Using ftp:
FTP hostname
\>put file1
\>bye
Above copies, file file1 from the local system to destination system whose hostname
is specified.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

I want to monitor a continuously updating log file, what command can be used to
most efficiently achieve this?
We can use tail –f filename. This will cause only the defaultlast 10 lines to be
displayed on std o/p which continuously shows theupdating part of the file.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

want to connect to a remote server and execute some commands, how can I achieve
this?
We can use ssh to do this:
ssh username@serverIP -p sshport
Example: ssh [root@122.52.25171](mailto:root@122.52.25171) -p 22
Once above command is executed, you will be asked to enter the password

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

I have 2 files and I want to print the records which are common to both.
We can use "comm" command as follows:
comm -12 file1 file2 ... 12 will suppress the content which are
unique to 1st and 2ndfile respectively.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Write a script to print the first 10 elements of Fibonacci series.


!/bin/sh
a=1
b=1
echo $a
echo $b
for I in 1 2 3 4 5 6 7 8
do
c=a
b=$a
b=$(($a+$c))
echo $b
done

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How will you connect to a database server from Linux?


We can use isql utility that comes with open client driveras follows:
isql –S serverName –U username –P password

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are the 3 standard streams in Linux?


0 - Standard Input1 - Standard Output2 - Standard Error
I want to read all input to the command from file1 direct all output to file2 and
error to file 3, how can I achieve this?
command <file1 1>file2 2>file3

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What will happen to my current process when I execute a command using exec?
"exec" overlays the newly forked process on the current process;so when I execute
the command using exec, the command gets executed onthe current shell without
creating any new processes.
E.g., Executing "execls"on command prompt will execute ls and once ls exits, the
process will shut down

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How will you emulate wc –l using awk?


awk 'END {print NR} fileName'

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Given a file find the count of lines containing the word "ABC".
grep –c"ABC" file1

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the difference between grep and egrep?


egrep is Extended grep that supports added grep features like "+"(1 or more
occurrence of a previous character),"?"(0 or 1 occurrence ofa previous character)
and "|" (alternate matching)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How will you print the login names of all users on a system?
/etc/shadow file has all the users listed.
awk –F ':' '{print $1} /etc/shadow'|uniq -u

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How to set an array in Linux?


Syntax in ksh:
Set –A arrayname= (element1 element2 ….. element)
In bash
A=(element1 element2 element3 …. elementn)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Write down the syntax of "for " loop


Syntax:
foriterator in (elements)
do
execute commands
done

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How will you find the total disk space used by a specific user?
du-s /home/user1 ....where user1 is the user for whom the total disk space needs to
be found.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Write the syntax for "if" conditionals in Linux?


Syntax
Ifcondition is successful
then
execute commands
else
execute commands
fi

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the significance of $?


The command $? gives the exit status of the last command that was executed.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How do we delete all blank lines in a file?


sed'^ [(backslash)011(backslash)040]$/d' file1
where (backslash)011 is an octal equivalent of space and
(backslash)040 is an octal equivalent of the tab
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How will I insert a line "ABCDEF" at every 100th line of a file?


sed '100i\ABCDEF' file1

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Write a command sequence to find all the files modified in less than 2 days and
print the record count of each.
find . –mtime -2 –exec wc –l {} \;

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can I set the default rwx permission to all users on every file which is
created in the current shell?
umask 777
This will set default rwx permission for every file which is created for every
user.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How can we find the process name from its process id?
We can use "ps –p ProcessId"

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are the four fundamental components of every file system on Linux?
Bootblock, super block, inode block andDatablock are found fundamental components
of every file system on Linux.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a boot block?


This block contains a small program called "Master Boot record"(MBR) which loads
the kernel during system boot up.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is a super block?


Super block contains all the information about the file systemlike the size of file
system, block size used by its number of free datablocks and list of free inodes
and data blocks.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is an inode block?


This block contains the inode for every file of the file system along with all the
file attributes except its name.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How can I send a mail with a compressed file as an attachment?
ip filezip file1|mailx –s "subject" Recipients email id
mail content
OF

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

How do we create command aliases in a shell?


alias Aliasname="Command whose alias is to be created".

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What are "c" and "b" permission fields of a file?


"c " and "b" permission fields are generally associated with adevice file. It
specifies whether a file is a special character file or ablock special file.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

What is the use of a shebang line?


Shebang line at the top of each script determines the location of the engine which
is to be used to execute the script.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Important Miscellaneous
Common TCP/IP Protocols and Ports
| Protocol | TCP/UDP | Port Number | Description|
| ------------------------------------------------------------ | ----------- |
--------------- | ------------------------------------------------------------ |
| File Transfer Protocol (FTP) (RFC 959) | TCP | 20/21 | FTP is one of the most
commonly used file transfer protocols on theInternet and within private networks.
An FTP server can easily be set upwith little networking knowledge and provides the
ability to easilyrelocate files from one system to another. FTP control is handled
on TCPport 21 and its data transfer can use TCP port 20 as well as dynamicports
depending on the specific configuration. |
| Secure Shell (SSH) (RFC 4250-4256) | TCP | 22| SSH is the primary method used to
manage network devices securely atthe command level. It is typically used as a
secure alternative toTelnet which does not support secure connections. |
| Telnet (RFC 854) | TCP | 23| Telnet is the primary method used to manage network
devices at thecommand level. Unlike SSH which provides a secure connection,
Telnetdoes not, it simply provides a basic unsecured connection. Many lowerlevel
network devices support Telnet and not SSH as it required someadditional
processing. Caution should be used when connecting to adevice using Telnet over a
public network as the login credentials willbe transmitted in the clear. |
| Simple Mail Transfer Protocol (SMTP) (RFC 5321)| TCP | 25| SMTP is used for two
primary functions, it is used to transfer mail(email) from source to destination
between mail servers and it is usedby end users to send email to a mail system. |
| Domain Name System (DNS) (RFC 1034-1035) | TCP/UDP | 53| The DNS is used widely
on the public internet and on private networksto translate domain names into IP
addresses, typically for networkrouting. DNS is hieratical with main root servers
that contain databasesthat list the managers of high level Top Level Domains (TLD)
(such as.com). These different TLD managers then contain information for thesecond
level domains that are typically used by individual users (forexample, cisco.com).A
DNS server can also be set up within a privatenetwork to private naming services
between the hosts of the internalnetwork without being part of the global system. |
| Dynamic Host Configuration Protocol (DHCP) (RFC 2131)| UDP | 67/68 | DHCP is used
on networks that do not use static IP address assignment(almost all of them). A
DHCP server can be set up by an administratoror engineer with a poll of addresses
that are available for assignment.When a client device is turned on it can request
an IP address from thelocal DHCP server, if there is an available address in the
pool it canbe assigned to the device. This assignment is not permanent and
expiresat a configurable interval; if an address renewal is not requested andthe
lease expires the address will be put back into the poll forassignment. |
| Trivial File Transfer Protocol (TFTP) (RFC 1350) | UDP | 69| TFTP offers a method
of file transfer without the sessionestablishment requirements that FTP uses.
Because TFTP uses UDP insteadof TCP it has no way of ensuring the file has been
properly transferred,the end device must be able to check the file to ensure
propertransfer. TFTP is typically used by devices to upgrade software andfirmware;
this includes Cisco and other network vendors’ equipment. |
| Hypertext Transfer Protocol (HTTP) (RFC 2616)| TCP | 80| HTTP is one of the most
commonly used protocols on most networks.HTTP is the main protocol that is used by
web browsers and is thus usedby any client that uses files located on these
servers. |
| Post Office Protocol (POP) version 3 (RFC 1939)| TCP | 110 | POP version 3 is one
of the two main protocols used to retrieve mailfrom a server. POP was designed to
be very simple by allowing a clientto retrieve the complete contents of a server
mailbox and then deletingthe contents from the server. |
| Network Time Protocol (NTP) (RFC 5905) | UDP | 123 | One of the most overlooked
protocols is NTP. NTP is used tosynchronize the devices on the Internet. Even most
modern operatingsystems support NTP as a basis for keeping an accurate clock. The
use ofNTP is vital on networking systems as it provides an ability to
easilyinterrelate troubles from one device to another as the clocks areprecisely
accurate. |
| NetBIOS (RFC 1001-1002)| TCP/UDP | 137/138/139 | NetBIOS itself is not a protocol
but is typically used in combinationwith IP with the NetBIOS over TCP/IP (NBT)
protocol. NBT has long beenthe central protocol used to interconnect Microsoft
Windows machines. |
| Internet Message Access Protocol (IMAP) (RFC 3501) | TCP | 143 | IMAP version3 is
the second of the main protocols used to retrievemail from a server. While POP has
wider support, IMAP supports a widerarray of remote mailbox operations which can be
helpful to users. |
| Simple Network Management Protocol (SNMP) (RFC 1901-1908, 3411-3418) | TCP/UDP |
161/162 | SNMP is used by network administrators as a method of networkmanagement.
SNMP has a number of different abilities including theability to monitor, configure
and control network devices. SNMP trapscan also be configured on network devices to
notify a central serverwhen specific actions are occurring. Typically, these are
configured tobe used when an alerting condition is happening.In this situation,
thedevice will send a trap to network management stating that an event hasoccurred
and that the device should be looked at further for a sourceto the event. |
| Border Gateway Protocol (BGP) (RFC 4271) | TCP | 179 | BGP version 4 is widely
used on the public internet and by InternetService Providers (ISP) to maintain very
large routing tables andtraffic processing. BGP is one of the few protocols that
have beendesigned to deal with the astronomically large routing tables that
mustexist on the public Internet. |
| Lightweight Directory Access Protocol (LDAP) (RFC 4510)| TCP/UDP | 389 | LDAP
provides a mechanism of accessing and maintaining distributeddirectory information.
LDAP is based on the ITU-T X.500 standard but hasbeen simplified and altered to
work over TCP/IP networks. |
| Hypertext Transfer Protocol over SSL/TLS (HTTPS) (RFC 2818)| TCP | 443 | HTTPS is
used in conjunction with HTTP to provide the same servicesbut doing it using a
secure connection which is provided by either SSLor TLS. |
| Lightweight Directory Access Protocol over TLS/SSL (LDAPS) (RFC 4513) | TCP/UDP |
636 | Just like HTTPS, LDAPS provides the same function as LDAP but over a secure
connection which is provided by either SSL or TLS. |
| FTP over TLS/SSL (RFC 4217)| TCP | 989/990 | Again, just like the previous two
entries, FTP over TLS/SSL uses the FTP protocol which is then secured using either
SSL or TLS. |

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Compiling a Kernel and Building Modules =


Development tools like gcc, make, and flex.
Kernel development packages like kernel-devel.
https://www.kernel.org/) and download the desired kernel version. Alternatively,
you can use yum to install the kernel source package
tar xvf linux-x.x.x.tar.gz
cd linux-x.x.x
make menuconfig
make -j $(nproc)
sudo make modules_install install
sudo nano /etc/default/grub
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
cat /boot/grub2/grub.cfg
sudo reboot

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Adding or removing kernel modules =


lsmod or modinfo = to search for available modules
sudo modprobe usb-storage
lsmod | grep usb-storage = to verify
sudo rmmod usb-storage
sudo echo "usb-storage" > /etc/modules-load.d/usb-storage.conf = to remove module
permanently

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Identifying Boot Failures =


rm -rf /boot/grub2/grub.cfg - Removes the GRUB configuration file.
lvscan - Scans for logical volumes (LVM).
vgchange -ay - Activates volume groups (LVM).
mount - Mounts a filesystem.
chroot /mnt/sysimage - Changes the root directory to the mounted filesystem.
grub2-mkconfig > /boot/grub2/grub.cfg - Generates a new GRUB configuration file.
exit - Exits the chroot environment.
Reboot command (not explicitly shown) - Reboots the system

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Hardware Issues =
lscpu - Displays CPU information such as the number of CPUs, vendor, and model
number.
lsblk - Shows block device or disk information, including partitions.
lsscsi - Provides information about SCSI devices.
lspci - Lists PCI devices connected to the system.
lsusb - Displays USB devices connected to the system.
dmidecode - Provides BIOS information, including memory information with the -t
memory flag.
dmesg - Shows kernel buffer messages, including hardware-related messages.
yum or dnf - Package managers used to install software packages.
systemctl enable --now mcelog - Enables and starts the mcelog service, which tracks
hardware information.
journalctl -f -u mcelog.service - Views logs related to the mcelog service.
memtest-setup - Sets up memtest86+ for running memory tests.
grub2-mkconfig - Regenerates the GRUB configuration to include memtest86+ as a boot
option.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Recovering Corrupt File Systems =


lsblk: This command is used to list all block devices attached to the system. It
provides information about block devices such as their names, sizes, and types.
fdisk: This command is a disk partitioning utility used for creating and managing
disk partitions on Linux systems. In the context of the text, it is used to set up
the file systems on the specified device (/dev/nvme1n1).
mkfs.xfs: This command is used to create an XFS file system on a disk partition.
XFS is a high-performance journaling file system known for its scalability and
reliability.
mkfs.ext4: This command is used to create an ext4 file system on a disk partition.
Ext4 is the default file system for many Linux distributions and offers features
such as journaling, scalability, and support for large file sizes.
mkdir: This command is used to create directories (folders) on the file system. In
the text, it is used to create mount points for the newly created file systems.
mount: This command is used to mount file systems to specified mount points in the
Linux file system hierarchy. It attaches the file system residing on a device to
the directory structure, making its contents accessible.
umount: This command is used to unmount (detach) file systems from the file system
hierarchy. It is important to unmount file systems before making changes to them or
before removing the underlying devices.
dd: This command is used for low-level copying and conversion of data. In the
context of the text, it is used to write random data to specific disk partitions,
simulating corruption of the file systems.
mkswap: This command is used to set up a Linux swap area on a device or a file. It
initializes the designated space to be used as swap space, which is a type of
virtual memory used when physical RAM is fully utilized.
xfs_repair: This command is used to repair corrupt XFS file systems. It scans the
file system for inconsistencies, attempts to correct them, and recover as much data
as possible.
e2fsck: This command is used to check the ext2, ext3, or ext4 file systems for
errors and repair any inconsistencies found. It is similar to xfs_repair but for
ext-based file systems.
dump2efs: This command is used to display information about the ext2, ext3, or ext4
file systems, including details about the file system's superblock, which is
crucial for recovery operations

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Troubleshooting LVM Configurations =


pvcreate: This command is used to initialize a physical volume for use by LVM
(Logical Volume Manager). It prepares a disk or partition to be used as a physical
volume within an LVM volume group.
vgcreate: This command is used to create a new volume group, which is a collection
of physical volumes managed by LVM. It allows you to group multiple physical
volumes into a single logical storage pool.
lvcreate: This command is used to create a logical volume within an existing volume
group. It allocates space from the volume group for the new logical volume and
allows you to specify parameters such as size and name.
mkfs.xfs: This command is used to create an XFS file system on a disk partition or
logical volume. XFS is a high-performance file system known for its scalability and
reliability.
mkdir: This command is used to create directories (folders) on the file system. In
the context of the text, it is used to create a mount point for the newly created
file system.
blkid: This command is used to locate/print block device attributes such as UUID
(Universally Unique Identifier) and filesystem type. In the text, it is used to
obtain the UUID of the logical volume.
Editing /etc/fstab: This involves manually editing the /etc/fstab file to configure
automatic mounting of filesystems during system boot. The UUID obtained from blkid
is added to /etc/fstab along with mount point, filesystem type, and other options.
mount: This command is used to mount file systems to specified mount points in the
Linux file system hierarchy. It attaches the file system residing on a device to
the directory structure, making its contents accessible.
vgcfgrestore: This command is used to restore volume group metadata from an LVM
archive. It helps in recovering a volume group to a previous state using archived
configuration information.
lvresize: This command is used to resize a logical volume within an existing volume
group. It allows you to increase or decrease the size of the logical volume as
needed.
lvchange: This command is used to change the attributes of a logical volume, such
as enabling or disabling it. In the text, it is used to disable and then re-enable
the logical volume after resizing.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
In a production-grade environment, there are multiple methods to update kernel
parameters in RHEL 7 and 8 to make them persistent on boot. Here are four commonly
used methods:

Modifying the kernel parameter file directly:


a. Edit the `/etc/sysctl.conf` file in a text editor with root privileges.
b. Add or modify the desired kernel parameters in the format `parameter=value`.
c. Save the file and exit the editor.
d. Run the command `sysctl -p` to reload the kernel parameters from the file.
e. Reboot the system for the changes to take effect.

Creating a kernel parameter file:


a. Create a new file in the `/etc/sysctl.d/` directory with a `.conf` extension,
such as `/etc/sysctl.d/my-kernel-params.conf`.
b. Edit the file and add the desired kernel parameters in the format
`vm.swappiness=10`. OR kernel.pid_max=65536OR fs.file-max=100000OR
net.ipv4.ip_forward=1
c. Save the file and exit the editor.
d. Reboot the system for the changes to take effect.

Using the GRUB configuration:


a. Open the `/etc/default/grub` file in a text editor with root privileges.
b. Locate the line starting with `GRUB_CMDLINE_LINUX` and append or modify the
kernel parameters as needed.
c. Save the changes and exit the editor.
d. Run the command `grub2-mkconfig -o /boot/grub2/grub.cfg` (for RHEL 7) or `grub2-
mkconfig -o /boot/efi/EFI/redhat/grub.cfg` (for RHEL 8) to regenerate the GRUB
configuration file.
e. Reboot the system for the changes to take effect.
Using the grubby tool:
a. Open a terminal and execute the command `grubby --default-kernel` to identify
the default kernel.
b. Use the following command to update the kernel parameters for the default
kernel:

grubby --update-kernel=DEFAULT --args=<kernel_parameters>

Replace `<kernel_parameters>` with the desired parameters.


c. Reboot the system for the changes to take effect.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NIC Bonding -

NIC (Network Interface Card) bonding, also known as NIC teaming or link
aggregation, is a technique used to combine multiple physical network interfaces
into a single logical interface. The purpose of NIC bonding is to increase network
bandwidth, provide redundancy, and improve network reliability.

For example, if you have eth0 and eth1 interfaces, you can bond them together.
Install bonding
/etc/sysconfig/network-scripts/ifcfg-bondX - configure bonding interface -
DEVICE=bondX
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
BONDING_OPTS="mode=balance-rr miimon=100"

/etc/sysconfig/network-scripts/ifcfg-eth0 and enth1 -


DEVICE=ethX
BOOTPROTO=none
ONBOOT=yes
MASTER=bondX
SLAVE=yes

sudo systemctl restart network


cat /proc/net/bonding/bondX

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IP Link Show -

The ip link show command is used to display information about the network
interfaces (links) on a Linux system. It provides detailed information about the
status, configuration, and characteristics of each network interface.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode


DEFAULT group default qlen 1000
link/ether 01:23:45:67:89:ab brd ff:ff:ff:ff:ff:ff

3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group
default qlen 1000
link/ether cd:ef:12:34:56:78 brd ff:ff:ff:ff:ff:ff
The first column represents the interface index number.
The second column shows the interface name (e.g., lo, eth0, wlan0).
The third column provides flags that indicate the interface's current state, such
as UP (interface is operational), DOWN (interface is inactive), LOOPBACK (loopback
interface), BROADCAST (supports broadcast), and MULTICAST (supports multicast).
The fourth column displays the Maximum Transfer Unit (MTU), which represents the
maximum size of a packet that can be transmitted over the interface without
fragmentation.
The fifth column specifies the queuing discipline (qdisc) used by the interface for
traffic control.
The sixth column indicates the current administrative and operational state of the
interface (e.g., state UP or state DOWN).
The seventh column shows the interface mode and group.
The eighth column provides the queue length (qlen) of the interface.
The last column displays the interface's link layer address (MAC address) and the
broadcast address (brd).

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I/O Redirection -

STDOUT >
STDOUT with appending >>
STDERR 2>

">" is the output redirection operator. ">>" appends output to an existing file
"<" is the input redirection operator
">&"re-directs output of one file to another.
2>&1 Redirects STDERR to the same destination as STDOUT
You can re-direct error using its corresponding File Descriptor 2.
cat brahma | sort | tr [:upper:] [:lower:]
cat brahma | sort | tr [a-z] [A-Z]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Globbing

ls host*
ls ?ost
ls [hm]ost
ls [!hm]ost
ls script[0-9][0-9]
ls script[0-9][0-9]

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Finding Files -
find / -iname file/dir
find / -type f -size +100M
find / -xdev -size +100M -exec ls -lh {} \;
find / -xdev -size +100M -exec ls -lh {} \; -exec cp {} /tmp \;
find /etc/ -exec grep -l fyre {} \; 2> /dev/null
find / -user anna
find / -type f -size +100M
find / -name most -type f
find / -type f -perm 664
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Copy -
Use cp -a to copy files with the exact permissions and other properties
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Soft link and hard link -

ls -il = showing the inode number


ln = generates a hard link = ln /etc/hosts /tmp
ln -s generates a symbolix link = ln -s /etc/hosts symhosts
ln -s /etc/hosts /tmp
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TAR -

tar cvf= create verbose and file name


tar tvf= t option to show the contents of the file
tar xvf= to extract an archive

Create tar archive


tar -cvf myArchive.tar /tmp/dir/

Create compressed tar.gz archive


tar -cvzf myCompressedArchive.tar.gz /tmp/dir/# gz compression
tar -cvfj myCompressedArchive.tar.bz2 /tmp/dir/ # bz2 compression

Untar archive
tar -xvf myArchive.tar.gz
tar -xvf myArchive.tar.bz2

List archive content


tar -tvf myArchive.tar

Extract files from archive


tar -extract --file=myArchive.tar theFile.txt # extract single file
tar -xvf myArchive.tar "theFiletxt" "theFile2.log"# extract multiple files
tar -xvf myArchive.tar --wildcards txt# extract by wildcard

Add files or directories to archive


tar -rvf myArchive.tar newFile.txt# add file
tar -rvf myArchive.tar dir# add directory

extract single file from tar -


tar --extract --file=archive.tar filetxt

multiple files -
tar -xvf Archive.tar "file 1" "file 2"

Using wildcards -
tar -xvf Archive.tar --wildcards txt'

To add files or directories to existing tar file -


# tar -rvf Archive.tar xyz.txt#add file
or
# tar -rvf Archive.tar php# add directory

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comression -
tar czvf homesz.tgz /home

dd if=/dev/zero of=100Mfile bs=1M count=100

Compress the file - gzip 100Mfile


Compress and keep the original file - gzip -k <file> this keeps the original file
and creates a compressed file
Compress and keep the original file - gzip -c file > file.gz
Uncompress the file - gunzip 100Mfile.gz OR gzip -d 100Mfile.gz

Compress the file - bzip2 100Mfile


Compress and keep the original file - bzip2 -k <file> this keeps the original file
and creates a compressed file
Uncompress the file - bunzip2 100Mfile.bz2 OR bzip2 -d 100Mfile.gz

xz <file>
xz -d -v <file> - to decompress

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Working with Text files -

tail -f /var/ /messages = -f refreshes the page and keep it open


head -n 11 /etc/passwd | tail -n 1 = this would print the last ine of the first
command output

cut -f 1 -d : /etc/passwd
cut -d -s " " -f1 <file> = -s says that ignore any line that doesn't have a space
OR delimiter and still give results

cut -f 1 -d : /etc/passwd | sort& cut -f 1 -d : /etc/passwd | sort -n to sort


numberically

cut -b 123 <file> = this will cut the first 3 charcters of the content of the file
cut -b 1-35-7 <file> = this will cut char's 1 to 3 leaves 4th char and again
displays from 5 to 7

cut -c 12 <file> = will cut the file and displays only these 2 char's/
cut -c 1-5 <file> = will cut and displays char's from 1 to 5 chars

du -h | sort -rn = lists the biggest file in that directory first


du -sh * | sort -n

^text line starts with text


text$ line ends with text
. wildcards
[abc] matches abcat

Type grep '^#' /etc/sysconfig/sshd. This shows that the file /etc/sysconfig/sshd
contains a number of lines that start with the comment sign #.

To view the configuration lines that really matter type grep -v '^#'
/etc/sysconfig/sshd. This shows only lines that do not start with a #.

Now type grep -v '^#' /etc/sysconfig/sshd -B 5. This shows lines that are not
starting with a # sign but also the five lines that are directly before that line
which is useful because in these lines you’ll typically find comments on how to use
the specific parameters. However you’ll also see that many blank lines are
displayed.

Type grep -v -e '^#' -e '^$' /etc/sysconfig/sshd. This excludes all blank lines and
lines that start with #.

sort 1 2 | uniq = gives uniq values but removes duplicates completely


grep -xvf 1 2 = removes duplicates but not both and just lists unique values

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Awk -

awk -F : '{ print $4 }' /etc/passwd


awk -F : '/user/ { print $4 }' /etc/passwd
awk -F: '{print $1}' /etc/passwd
awk -F: '/root/ {print $1}' /etc/passwd
awk -F: 'BEGIN { print "uid"} { print $1 }' /etc/passwd
awk -F: '{print $1} END { print "-done-"}' /etc/passwd
awk -F " " '{ print $2 }' 33
cut -c1-5 /etc/passwd
cut -c1-4,6-9 /etc/passwd
cut -d : -f 6-7 /etc/passwd

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sed Command-

sed -n 3,5p /etc/passwd


sed 3,5d /etc/passwd - to see all except 3 and 5
sed -i s/old-text/new-text/g ~/myfile
sed -i s/u070228//g group
sed -i -e '2d' ~/myfile
sed -i -e '2d;2025d' ~/myfile
sed -i '/^HOSTNAME=/s/=.*/=pardhu/' /etc/sysconfig/network = to change hostname in
rhel 6

Remove entire line with keyword


sed --in-place '/dev/mapper/oracle_vg-ora_lv' /etc/fstab
sed -i '/oracle_vg-ora_lv/d' /etc/fstab
Replace word in file using sed
sed -i 's//dev/mapper/vg_prod-lv_production/production//dev/mapper/vg_prod-
lv_production /production/g' /etc/fstab
sed -i 's/$i/Hello/g' /tmp/ajit
Deleting last line from a file in linux with sed command
sed -i '$d' /etc/fstab
Deleting a line with a keyword -
sed -i '/woble/d' sherlock.txt
Deleting empty lines with sed -
sed -i '/^$/d' sherlock.txt
replacing comma with new line
sed 's//\n/g' /tmp/file1
sed 's/ //g' 44 = remove an empty blank/space
replacing tab with space -
sed -i 's/\t/ /g' sherlock.txt

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Grep -
grep '\<pwpolicy\>' anaconda-ks.cfg = beginning of the line is pwpolicy\
grep '[[:digit:]]\{4\}' <file>

grep '\bpolicy\b' anaconda-ks.cfg


840grep '\<pwpolicy\>' anaconda-ks.cfg
842grep '[[:digit:]]\{2\}' anaconda-ks.cfg
857grep [Ss]ome sherlock.txt
861grep reali[zs]e sherlock.txt
862grep realise sherlock.txt
864grep 'wind' sherlock.txt
865grep '\<wind\>' sherlock.txt
866grep '\bwind\b' sherlock.txt
868grep ' The' sherlock.txt
869grep '^The\>' sherlock.txt
872grep '[[:digit:]]\{4\}' sherlock.txt
875grep fl..d sherlock.txt
877grep 'die\?d' sherlock.txt
882grep '[[:alpha:]]\{1617\}' sherlock.txt
878egrep 'die?d' sherlock.txt
884grep 'June\|July' sherlock.txt
886egrep 'June|July' sherlock.txt

grep -n 'string' file = gives line number information


grep -c 'string' file = gives count of the string repeated in the file

# Output all lines that contain 'target string' in filename.log


grep 'target string' /var/log/filename.log

# Output all lines that contain 'target string' in multiple files


grep 'target string' filename1 filename2 filename3

# Return lines containing 'David' 'david' 'DAVID' etc


grep -i 'david' /var/log/auth.log

# Search all apache log files for example.com/about


grep -r "example.com/about" /var/log/apache2

# Sample Output:
/var/log/apache2/example.com.access.log.1:88.87.168.109 - - [12/Oct/2016:21:33:16
+0100] "GET /uploads/2015/08/example.jpg HTTP/1" 200 628726
"http://example.com/about/" "Mozilla/5.0 (Linux; Android 6.0.1; SM-G920F
Build/MMB29K) AppleWebKit/537.36 (KHTML like Gecko) Chrome/53.0.2785.124 Mobile
Safari/537.36"

To suppress the filename. use the -h option. This example shows suppressed
filenames and sends the result output to a file:
grep -h -r "example.com/about" /var/log/apache2 > ~/about-log

# Return lines containing 'example' as a distinct word


grep -w 'example' /var/log/logfile.log

# Returns lines that contain either specified word using egrep


egrep -w "david|elaine" /var/log/auth.log

# Same:
grep -w "david\|elaine" /var/log/auth.log
# Recursively search apache logs for either specified string:
egrep -Rwi --color 'example.com/about|example.com/contact' /var/log/apache2

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo Friday@123 | passwd --stdin <user>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Usermod Examples -
usermod -c Admin bill - to change comment for user
usermod -d /home/bill bill - to change home dir
usermod -s /bin/nologin bill - to change shell
usermod -aG wheel bill - to add user to secondary group without removing the older
secondary groups
/etc/default/useradd - to check and change user default settings
/etc/login.defs - where password properties are seen
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Permissions -

mkdir -p /data/sales /data/account


ls -l -R /home/linda/
clear
id linda
clear
groupadd sales account
groupadd sales
groupadd account
clear
chown linda:sales /data/sales/
chown linda:account /data/account/
chmod 770 /data/sales/ /data/account/
clear
ls -ld /data/ *
ls -ld /data/*
clear
useradd -c "laura" -d /home/laura -m laura
su - laura
usermod -aG sales laura
usermod -aG account laura
clear
id laura
clear
su - laura
cd /data/account/
touch 11
ls
ls -lrt
chmod g+so+t /data/sales/
ls -ld /data/sales/
su - linda
su - laura

ACL's -

setfacl -m g:account:rx /data/sales/


setfacl -m g:sales:rx /data/account/
ls -ld /data/sales/ /data/account/
getfacl /data/
getfacl /data/sales/
getfacl /data/account/
clear
d option is to have the new files come with acl permissions
setfacl -m d:g:account:rxg:sales:rwx /data/sales/
getfacl /data/sales/
setfacl -m d:g:sales:rxg:account:rwx /data/account
clear
touch /data/sales/newfile
getfacl setfacl -m d:g:sales:rxg:account:rwx /data/account
getfacl /data/sales/newfile
remove acl permission - setfacl -x u:users <file>

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Network -

ip addr show - shows the ip addresses information that are connected to the devices
- ip address configuration
ip link show - shows the devices linked
ip -s link - to show statistics
ip route show - showing the routing table
ip route add default via 10.0.0.1 = to add a default routing
ping -c 1 google.com

Network Manager =
NetworkManager stores new network profiles in keyfile format in the
/etc/NetworkManager/system-connections/ directory.

Previously, NetworkManager stored network profiles in ifcfg format


in this directory (/etc/sysconfig/network-scripts/). However, the ifcfg
format is deprecated. By default, NetworkManager no longer creates
new profiles in this format.

cat ens160.nmconnection -
[connection]
id=ens160
uuid=396cac44-f7d8-3832-bbc7-05ffd58a80a4
type=ethernet
autoconnect-priority=-999
interface-name=ens160
timestamp=1704735144

[ethernet]

[ipv4]
method=auto

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]

nmcli = NetworkManager Command Line Interface

nmcli general status


STATECONNECTIVITYWIFI-HWWIFI WWAN-HWWWAN
connectedfullmissingenabledmissingenabled
nmcli general permissions
PERMISSIONVALUE
org.freedesktop.NetworkManager.checkpoint-rollbackauth
org.freedesktop.NetworkManager.enable-disable-connectivity-checkyes

nmcli connection show


NAMEUUIDTYPEDEVICE
ens160396cac44-f7d8-3832-bbc7-05ffd58a80a4ethernetens160

nmcli device status


DEVICETYPESTATE CONNECTION
ens160ethernetconnected ens160

Manually add connection with nmcli =


nmcli connection add con-name mycon ifname ens160 ipv4.addresses 192.168.198.22/24
ipv4.gateway 192.168.198.2 ipv4.method manual type ethernet
nmcli connectionshow
nmcli connection up mycon
nmcli connection show

nmcli connection modify = to modify existing connection configuration

nmtui =
NetworkManager Text User Interface

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Managing Processes -

sleep 3600 &


dd if=/dev/zero of=/dev/null &
sleep 7200
jobs = to check what jobs are running
bg 3
jobs
fg 1

ps -fU sa700011 - processes started by a specific user


ps aux - overall processes
ps -fax - shows hierarchy processes
ps -f --forest -C sshd = shows a process tree for specific process
ps -ef | grep -i sshd - gives you the pid of that service
ps -u sa700011 - to see processes run by that specific user
ps -u root - same as above
ps -ef | grep 7323 - gives you the service name

USER PID %CPU %MEMVSZ RSS TTYSTAT START TIME COMMAND


root 10.00.1 107532 16712 ?Ss 10:17 0:04 /usr/lib/systemd/systemd rhgb --switched-
root --sys

VSZ: The Virtual Memory Size


RSS: The Resident Set Size is the portion of a process's memory that is held in RAM
STAT: This column provides information about the process status. For example, if
the process is running (R), sleeping (S), stopped (T), or zombie (Z).
START: The start time of the process

[root@trvlapp5000 ~]# uptime


07:27:08 up1:26,1 user,load average: 0.00-load in last 1 mins 0.20-5mins 0.47-15
mins
lscpu - shows cpu information

Zombie Process =
Identify zombie process -
pa -aux | grep defunct
OR
top -b1 -n1 | grep Z
find parent zombie -
ps -A -ostat,ppid | grep -e '[zZ]'| awk '{ print $2 }' | uniq | xargs ps -p
kill -9 pid
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Combining and Splitting files -

split -l 2 <file> newfilename


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Monitor Users -
who - shows who is logged in
last | awk '{ print $1 }' | sort | uniq - this shows print 1st line of last command
and sort it with only unique values removing duplicates
w - same as who a little more information
finger - this is also a command

wall - this command can be used to broadcast message to all who logged in
write - this command can be used to broadcast a message to a single person
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Some useful commands -
cal 4 1989 - gives the calendar of that time
cal 2020 - gives full calendar of that year
bc - will open calculator
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Systemd -
systemctl restart sshd
systemctl status sshd.service
systemctl stop sshd
systemctl start sshd - this will just start the service but won't enable it at
server boot
systemctl enable sshd - to have this service start everytime the server boots up
systemctl disable sshd - to have this service disable everytime the server boots up

OR

service status sshd

systemctl list-units - to list all active services


systemctl list-units --all - to list all services on server
systemctl poweroff, halt, reboot
systemctl mask httpd = this will mask the service to be /dev/null which means is
the service is started after masking it would say failed to start as it's masked
systemctl umask httpd will change the above

Default systemd space - /usr/lib/systemd/systemd


If we want to make changes do not edit the above but create a custom file in the
above location
systemctl cat sshd.service
# /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.target
Wants=sshd-keygen.target

[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Kill -
kill -15 PID - kill gracefully
kill -9 PID - kill forcefully
killall <process name>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Crontab -
crontab -e = to edit
crontab -l = to list the crontabs
crontab -r = to remove crontabs
crond = crontab daemon/service
systemctl status crond

Example cronjob -
2403 *01 * echo "This is my first crontab entry" > crontab-entry
min hour day of month month dayoftheweek command

@hourly echo "hello world"


@reboot echo "hello world" = on every reboot of the server that message is echoed
crontab -u sa70001 -e = to edit the crontab for a different user

ls -l cron.* - this shows everything with cron under /etc


ls -l | grep cron - same as above
cd /etc = ls -l | grep cron to see all crons running daily, weekly, monthly
write your cron job and move it to that specified weekly, monthly folder
/etc/anacrontab = is where default time is set for daily, weekly, monthly cronjobs

In cron if a machine is not running on time of a scheduled job then it will skip
it, but anacron is a bit different as it first checks for timestamp of the job then
decides whether to run it or not
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Process Management -
background - cntl-z
foreground - fg
kill a process by name - pkill <process name>
process priority - nice -n 5 process name OR -5 to prioritize soon(is the command)
list processes - ps
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Network Debug tools -
dmesg = gives error messages and info about hardware and kernel
iostat -xmt 1= this gives info on disks, if something been written iostat 1 - to
keep refreshing the disk usage
ss is the replacement utility for netstat
netstat -antup|grep 873
netstat -rvn = gives network information
netstat -tnlup = gives all active listening ports
netstat -i = shows packets information
nmap -A ip = to check the open ports on remote server
vmstat = virtual memory buffer
pidstat = shows all info regarding the pid's and user accessing
mtr ip or hostname = to see packets lost or sent and other network information
mpstat = cpu information that has nice value and idle state of CPU
sar -q = cpu load utilization
sar -r = memory utilization
sar -d = disk utilization
sar -n ALL or network interface = network utilization
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Sticky Bit -
chmod +t /path

The sticky bit is a permission bit that can be set on a directory in Unix-based
operating systems. When the sticky bit is set on a directory, it restricts deletion
of files within that directory to only the owner of the file, the owner of the
directory, or the root user
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SUID (Set User ID) is a permission that allows a user to execute a file with the
permissions of its owner, rather than the permissions of the user who is executing
it. This is commonly used for programs that need to perform tasks that require root
privileges, but which cannot be run as the root user for security reasons. When a
user executes a SUID file, it runs with the same privileges as the owner of the
file.
chmod u+s </path/to/the/file>

SGID (Set Group ID) is similar to SUID, but it applies to groups rather than
individual users. When a file is given the SGID permission, it inherits the group
ID of the parent directory. This means that any user who accesses the file becomes
a member of the group associated with the parent directory. This is commonly used
in shared directories where multiple users need access to the same files.
chmod g+s </path/to/the/file>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Logs Monitoring -
var/log/secure - gives login and logout info of each user
var/log/messages - gives info of all hardware software processes application
messages
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Control Keys -
ctrl+w - deletes 1 word behind
ctrl+u - deletes the complete line on CLI
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Changing root password in single user mode -
reboot the server
edit grub
go to line where i says ro - which means read only line OR add rd.break at the end
of the line that starts with linux
replace ro with rw init=/sysroot/bin/sh
mount -o remount,rw /sysroot
ctrl+x
chroot /sysroot
passwd root
touch /.autorelabel = to update SELinux information
exit
reboot
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SOS Report
sosreport --batch OR sosreport
redhat-support-tool addattachment -c CASE_NUMBER /path/to/sosreport
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
wget <url> = to get the external files from website or packages
curl <url> = to see if you are able to connect to website
curl -O <url> = to download from website
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
FTP -
vsftpd package is needed to be installed
ftp client is supposed to be installed on dest. server
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SCP
scp <file> id@ip:/tmp
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rsync - to send files from your machine to another
rsync -avzh <file/dir> id@ip:/tmp
rsync -aAvzrp <file/dir> id@ip:/tmp

rsync -aAvzrp /cms/* id@ip:dest

to bring file remote machine to current


rsync -avzh id@ip:/tmp/file current dir in your current server
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Managing Software -
rpm & yum =
rpm -qa | grep <package> = to see if package exists
rpm -ivh = to install a package that locally exists
rpm -qi = package information
rpm -qc = package related configuration files
rpm -qf /bin/pwd = this gives info on this command belongs to which package
rpm -e = to remove a package
rpm -qPR = lists the dependencies of the package
rpm2cpio <package> | cpio -tv
yum list available = List all available packages
yum list installed = List all installed packages
yum list all = List installed and available packages
yum list kernel = List installed and available kernel packages
yum info vsftpd = List info about vsftpd package
yum deplist nfs-utils = List dependencies and packages providing them
yum search samba = Find packages with samba in name or description
dnf group info = to check group installation information
yum updateinfo security = Get info on available security updates
yum history list = List all yum install, update and erase actions
yum history info 3 = Show details of yum transaction
yum history undo 3 = Undo the yum action from transaction 3
yum history redo 3 = Redo the undone yum action from transaction 3
yum clean packages = Delete packages saved in cache
yum clean all = Clean out all packages and meta data from cache
yum repoinfo rhel-7-server-rpms = See info on rhel-7-server-rpms repo
yum downgrade abc = Downgrade the abc package to an earlier version
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rollback a package =
yum history undo id
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NTP =
systemctl status ntpd
/etc/ntp.conf = this is where we add ntp server info
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Chronyd =
same as ntp
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
timedatectl
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
systemctl -a = gives all services that are active and inactive
sestatus = to see if selinux is enabled
stat platform-ansible = this command gives complete information about file/dir
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
traceroute <ip> = gives the router information that's passing
ps axo pid,comm,nice,cls --sort=-nice
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
System Run Level -
init 0 = complete shut down
init 6 = reboot the server
init 5 = multiuser mode with networking
who -r = gives info on which run level we are in
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Boot Process -
BIOS > MBR > GRUB > Kernel > init > runlevel

BIOS
BIOS for Basic Input/Output System. The BIOS searches and executes the boot loader
program, which is found in the Master Boot Record (MBR).Once the boot loader
program is detected, it's then loaded into memory.
MBR
MBR stands for Master Boot Record, and is responsible for executing the GRUB boot
loader.
The MBR is located in the 1st sector of the bootable disk. The MBR also contains
information about GRUB, or LILO.
The screen will wait a few seconds to select desired kernel. post that, it will
load the default kernel image.
In many systems we see GRUB configuration file at /boot/grub/grub.conf or
/etc/grub.conf.
Now, the kernel that selected by GRUB first mounts the root file system and it
executes the /sbin/init program
Init - At this point, server executes runlevel programs. It looks for an init file,
usually found at /etc/inittab to decide the Linux run level.
Runlevel programs
Depending on which Linux distribution you have installed, you may be able to see
different services getting starte
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cat /etc/motd = display message when logged in to server
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LVM's -
pvcreate /dev/sdb
vgcreate rootvg /dev/sdc
lvcreate -L 40G -n lv_production vg_apps
If you want to use 100% disk space then use - lvcrete -l 100%FREE -n lv_production
vg_app
mkfs.xfs /dev/mapper/vg_app-lv_production
vi /etc/fstab >> /dev/mapper/datavg-data
mkdir /applications
mount -a

pvcreate /dev/sdc
vgextend rootvg /dev/sdc
lvextend -L 20G /dev/mapper/rootvg-root
resize2fs /dev/mapper/rootvg-root

pvcreate /dev/sde
vgextend appvg /dev/sde
lvextend -L +2G /dev/mapper/rootvg-var
xfs_growfs /dev/mapper/rootvg-var

The /etc/exports file controls which file systems are exported to remote hosts

fdisk -
Disk Partition -

fdisk /dev/sda
p to print the current partition table
n for new partition
select primary or extended
define size +100M and w for write and exit
sync
partprobe -s /dev/sdas to show the output

Format partition -
mkfs.xfs /dev/mapper/root-

Stale File Handle =


cat /proc/fs/nfs/exports = if there is stale entry for the client then
exportfs -ua
cat /proc/fs/nfs/exports
exportfs -a
mount -t nfs

showmount -a | grep nfs ip


cat /proc/mounts | grep nfs = check if export if actually mounted

umount -l = lazy unmount


umount -f = force umount

Another process -
To check nfs stale mounts
#grep -i 'stale' /proc/mounts
to fix the issue if any server have stale mounts . you can follow below steps .
we have activity on 04/29 . Network team will reach you
#!/bin/bash
# Find NFS-mounted file systems that are in a stale state
STALE_FS_LIST=$(grep -i 'stale' /proc/mounts | awk '{print $2}')
# Remount each stale file system to refresh its file handles
for FS in $STALE_FS_LIST; do
umount -l $FS
mount $FS
done
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Memory -
free -m
cat /proc/meminfo

CPU -
uptime
lscpu
cat /proc/cpuinfo
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TOP Command -

top -u sa700011 - to search processes with particular user


top and press c - to see absolute path of process that is running
top and press k - kill a process from top command with pid
top and press M - to sort processes with high memory usage at top
top and press P - to sort processes with cpu usage at top
top and press W - to save new display settings
f - to show and select from available display fields

CPU - 17.8 us (user space), 79.6 (system space) kernel processes, 0.0 ni (nice),
0.0 id (idle time), 0.0 wa (waiting)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How do you limit memory usage for commands?
ulimit -Sv 1000 # 1000 KBs = 1 MB
ulimit -Sv unlimited# Remove limit
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cat /etclogin.defs = to change UID GID umask information
cat /etc/default/useradd = to change default home or shell directory for users
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Change Date - date -s "2 OCT 2006 18:00:00"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
restart service if it is only running -
systemctl try-restart httpd.service
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
which rpm is responsible for /etc/hosts
setup-2.8.71-1el7.noarch for hosts and other rpm for other files
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The remote web server supports the TRACE and/or TRACK methods
TRACE and TRACK are HTTP methods that are used to debug web server connections
echo TraceEnable off >>/etc/httpd/conf/httpd.conf ~]#
service httpd reload
Reloading httpd:

The remote host is running a Telnet server over an unencrypted channel


For disabling the telnet server, edit/etc/xinetd.d/telnetand change the
fielddisabletoyes.
vi /etc/xinetd.d/telnet
service telnet
{
flags = REUSE
socket_type = stream
wait= no
user= root
server= /usr/sbin/in.telnetd
log_on_failure+= USERID
disable = yes
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How to switch between run levels -
systemctl isolate multi-user.target
how to set default -
systemctl set-default multi-user.target
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
System Calls -
system call is the way in which a computer program requests a service from the
kernel of the operating system it is executed on
Process control
File Management
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Strace =
strace pwd
strace records all the syscalls made by pwd

fork starts a new process which is a copy of the one that calls it, exec replaces
the current process with another
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D state process or uninterruptible sleep state are usually waiting on I/O, can't be
killed and need a reboot
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Boot issues on linux -
cat /var/log/boot.log
check if server is using swap space
swapon -s
cat /var/log/messages
dmesg
journalctl
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Cgroups =
cgroups is a feature that limits, accounts for, and isolates the resource usage
(CPU, memory and others
cgcreate, cgexec, and cgclassify are tools that can be used
sudo cgcreate -g cpu:my_cgroup
sudo cgset -r cpu.shares=512 my_cgroup
sudo cgexec -g cpu:my_cgroup ls
sudo cgclassify -g cpu:my_cgroup 1234
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Resource Limits for user -
The /etc/security/limits.conf file is used in Linux systems to set resource limits
for user accounts. It allows system administrators to define specific limits for
different system resources such as the maximum number of open files, maximum memory
usage, CPU time, etc. These limits are applied to individual users or groups

<domain> <type> <item> <value>

<domain>: Specifies the domain to which the limit applies. It can be either a user
name, a group name, the wildcard @group, or the wildcard * to apply the limit to
all users.
<type>: Specifies the type of resource being limited. It can be soft, hard, or
both.
<item>: Indicates the specific resource being limited, such as core, nofile (number
of open files), cpu, data (maximum data segment size), stack (maximum stack size),
etc.
<value>: Specifies the value of the limit for the resource. It can be a numerical
value or one of the special values like unlimited, infinity, or hard, depending on
the resource type.

Soft Limit: The soft limit is the initial limit set for a resource. It can be
modified by the user within the range of the hard limit. The soft limit acts as a
warning threshold, and the system can generate warnings when it is reached.
Hard Limit: The hard limit is the maximum value that a user can set the soft limit
to. It acts as an absolute limit that cannot be exceeded by the user.

* softnofile1000
* hardnofile1000
l
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LUKS =
LUKS provides a generic key store on the dedicated area on a disk, with the ability
to use multiple passphrases to unlock a stored key
yum install cryptsetup-luks
Configure LUKS - fdisk -l blkid
cryptsetup -y -v luksFormat /dev/xvdc
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
What is localhost and why would ping localhost fail?
Yes, iptables can firewall localhost from itself.
iptables -L -n can give us that information
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ping and traceroute =
Ping: It is a tool that helps one to check if a particular IP address is
accessible. ping sends a packet to the given IP address and waits for a reply.
Traceroute: It is a tool that traces a packet from our computer to the host, and
will also show the number of (hops) required to reach there, along with the time
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Telnet and ssh -
SSH or Secure SHell is a protocol to access the network devices and servers over
the internet and uses pub key authentication
Telnet transfers the data in simple plain text.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A chroot jail is a way to isolate a process and its children from the rest of the
system
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Private IP's =
0 – 10.255.255.255
0 – 172.3255.255
0 – 192.168.255.255
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
VLAN is a custom network which is created from one or more local area networks. It
enables a group of devices available in multiple networks to be combined into one
logical network
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Address Resolution Protocol (ARP)
Computers use logical address (IP address) to send/receive messages, however, the
actual communication happens over the physical address (MAC address)
ARP functionality is to translate IP address to physical addresses
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
What is the purpose of a default gateway?
Default Gateway is a point of a Network, through which your network can communicate
with Internet/Other Network.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ext2 =
mke2fs /dev/sda1
mkfs.ext3 /dev/sda1
Ext2 does not have journaling feature.
Maximum individual file size can be from 16 GB to 2 TB
Overall ext2 file system size can be from 2 TB to 32 TB

Ext3 -
mkfs.ext4 /dev/sda1
journaling is there in this
Maximum individual file size can be from 16 GB to 2 TB
Overall ext3 file system size can be from 2 TB to 32 TB

Ext4 =

Maximum individual file size can be from 16 GB to 16 TB


Overall maximum ext4 file system size is 1 EB (exabyte). 1 EB = 1024 PB (petabyte).
1 PB = 1024 TB (terabyte).

xfs =
XFS supports maximum file system size of 8 exbibytes
this is the default for RHEL 7
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A journaling filesystem keeps a journal or log of the changes that are being made
to the filesystem during disk writing'
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How to add IPv6 to a specific interface -
/sbin/ip -6 addr add 2001:0db8:0:f101::1/64 dev eth0
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
What will happen when you bind port 0?
Port 0 is a wildcard port that tells the system to find a suitable port number.
Alternatively, it can provide port 0 to bind() as its connection parameter. That
triggers the operating system to automatically search for and return a suitable
available port in the TCP/IP dynamic port number range
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Can you still SSH to a Linux server if its default gateway is set incorrectly? How?

Hints =>
a). You can SSH in, but only from another device in the same subnet, or in a
network to which the "broken"
server has a static route defined.
b).some static route is there which can route to destination network.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Disk Issues -
Check disk space usage = df
Check disk health = smartctl
Check disk I/O perf = iostat
Check disk errors = dmesg
Check filesystem consistency = fsck
Check disk partitioning = fdisk
So you can use blktrace to trace out the I/O on the machine.
blktrace -d /dev/sda -o -|blkparse -i -
At the same time, on another console launch the following command to generate some
I/O for testing purpose.
dd if=/dev/zero of=/mnt/test1 bs=1M count=1
From the blktrace console you will get an output which will end up as follows
CPU0 (8,0):
Reads Queued: 2, 60KiB Writes Queued: 5,132, 20,524KiB
Read Dispatches:2, 60KiB Write Dispatches: 61, 20,524KiB
Reads Requeued: 0 Writes Requeued: 0
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
mount point usage is 99% however did not find any large files to delete, how did
you clear up the / usage and bring back to normal usage?

lsof | grep deleted


lsof | grep deleted | grep ".TMP" | awk '{ print $2 }' | xargs kill -9
lsof | grep deleted | grep ".TMP" | awk '{ print $9 }' | xargs rm -rf
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
ssh login issue -
check the permission of the .pem issue
check the port #
Check permitrootlogin
DenyUsers and AllowUsers
if logging in without username and password - check pubkey authentication and
permission of it
cd /var/empty - sshd folder permissions need to be 711 if this is changed that can
cause too
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Connection reset by peer error =
Check the hosts.deny and hosts.allow
check iptables is blocking
check sshd_config
restart sshd service
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
NFS Server -
nfs-util package
systemctl start nfs-server.service
vi /etc/exports >> /exports/backup 10.0.0.0/255.255.255.0(rw,no_subtree_check)
systemctl restart nfs-utils.service
rpcbind service need to be active for nfs to start - The rpcbind service redirects
the client to the proper port number so it can communicate with the requested
service

create a dir and add data


export the directory to /etc/exports using exportfs command and exportfs -avr to
see exporting information
mount -t nfs -o sync ip:/nfsserver /brahma
restart the service and make it permanent in /etc/fstab - ip:/nfsserver /brahma nfs
defaults 0 0
mount -a

NFS Client -
nfs-util package
showmount -e nfs-server-ip = to see if nfs connection is established
create the dir.'s that we want to get from nfs-server
mount 10.10.10.6:/exports/backup /tmp/nfs/backup
df -h = shall show the mount

NFS Autofs -
NFS autofs (also known as autofs or automount) is a feature in Unix-like operating
systems that allows for automatic mounting and unmounting of network file systems
(NFS) on-demand
Autofs works by dynamically mounting NFS shares when they are accessed and
unmounting them when they are no longer in use

Install autofs: Ensure that autofs is installed on your system. The package name
may vary depending on your operating system and distribution.
Configure the autofs master configuration file: The master configuration file for
autofs is typically located at /etc/auto.master or /etc/auto_master. Edit this file
to define the mount points for your NFS shares.
/mnt/nfs/etc/auto.nfs
data-rw,softnfs.example.com:/export/data
sudo service autofs restart # SysV init
sudo systemctl restart autofs # systemd

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SNMP -
SNMP stands for Simple Network Management Protocol, and it is a widely used
protocol for network management and monitoring. SNMP allows network administrators
to manage and monitor network devices, such as routers, switches, servers, and
printers, from a central management system

yum install -y net-snmp


/etc/snmp/snmp.conf
systemctl enable snmpd
systemctl restart snmpd
firewall-cmd --permanent --add-port=161/udp
162/upd
firewall-cmd --reload
snmpget -v 2c -c testing localhost
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SELinux -

Access Control: SELinux enables granular access control policies by defining rules
for processes, files, directories, ports, and other system resources. It uses the
principle of least privilege, allowing only authorized actions and denying
everything else by default. This helps prevent unauthorized access or modification
of critical files and resources.

Security Enhanced Linux


Enforcing, Permissive, Disabled
getenforce - to check the status of selinux
sestatus - does the same

To change the mode from enforcing to permissive type:


sudo setenforce 0
To turn the enforcing mode back on, enter:
sudo setenforce 1
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
t3.2xlarge master nodes - 4
t3.2x large worker nodes - 12
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Memory Issues -
grep -i -r 'out of memory' /var/log/
top = Check the %MEM column of the output and identify the processes which show
consistent high memory usage
sar -r = command to see exact memory usage
/var/log/kern. log
/var/log/syslog
sysctl -a | grep vm.overcommit_memory
vmstat
add more memory is the last resort
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Q. There are many times a root user just leaves it session open which is kind of
breach of security as any session for any user (specially root) if left idle for
certain amount of time must be closed so that no one can use it for some wrong
purpose. How can this be achieved?

A. We can introduce TMOUT variable in the profile of the user which should do the
job.
edit .bsh_profile
export TMOUT=SECONDS
export TMOUT=120
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Q. I created a password less authentication between two linux box but still every
time I try to do ssh, it still prompts me for password, what wrong could I have
done? What all I should check?

A. Assuming private and public key were successfully created


Make sure the public key you generated is same as what is copied to the target
node's authorised key file. In such case I always prefer to use ssh-copy-id rather
than manually copying the public key to client node.
The permission of .ssh directory, the generated keys and authorized keys must not
be world readable, writable or executable
Analyse the /var/log/sshd, /var/log/secure, /var/log/messages or any other relevant
file which contains the logs for ssh as the error what appears will help debug
further
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Q. After upgrading kernel the machine fails to boot, what will you do?

A. The very first thing to be done here is to edit the grub menu at boot stage and
make the system boot with alternative kernel (assuming the last kernel is still
installed) or else try booting the system with using the rescue option from the
grub menu.
Once the node is UP then you can analyse the issue of why the node is failing to
boot from new kernel. Many times the kernel is not properly installed and all the
libraries are not available which leads to this problem. or the GRUB can be
corrupted so you can regerate the initramfs using grub2-mkconfig

# grub2-mkconfig -o /boot/grub2/grub.cfg
If there is a kernel panic observed then boot the system with alternate kernel or
rescue and then enable kdump. Share the kdump with the support engineers as they
can then further try to debug the source of the problem
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Q. How do I make sure that the swap memory used by my application is not flushed
away by any other process?
A. To lock memory for application then the application must be running in a cgroup
for which you can assign a low value swappiness so that it's memory is not swapped
out when the system goes out of memory or else in general if you do not wish your
memory to be swapped out then reduce the swappiness via sysctl to a lower value.

For more details on memory, virtual memory and swapping follow below linksWhat is
swappiness and how do we change its value?
4GB of RAM or lessa minimum of 2GB of swap space
4GB to 16GB of RAMa minimum of 4GB of swap space
16GB to 64GB of RAMa minimum of 8GB of swap space
64GB to 256GB of RAMa minimum of 16GB of swap space
256GB to 512GB of RAMa minimum of 32GB of swap space
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
CPU Affinity -

CPUAffinity is commonly used in scenarios where you want to optimize the


performance of specific applications by dedicating certain CPU cores exclusively to
them

taskset -p 0x03 1234

vim /etc/systemd/system/test.service
CPUAffinity=13
Type=forking
Restart=no
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Q. I have a physical hardware with 10 CPU processors but I want to use only 6 of
them and I do not my application to see the other 4 CPU processor, is it possible?

A. We can use "maxcpus" or "nr_cpus" for this purpose. This will help limit the
number of CPU processor which is visible to the kernel or any other application
running on the system.
use maxcpus=Nin /boot/grub2/grub.cfg
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Port Number Usage
20 - (FTP) Data Transfer
21 - FTP) Command Control
22 - (SSH)
23 - Telnet - Remote login service, unencrypted text messages
25 - Simple Mail Transfer Protocol (SMTP) E-mail Routing
53 - Domain Name System (DNS) service
80 - Hypertext Transfer Protocol (HTTP) used in World Wide Web
110 - Post Office Protocol (POP3) used by e-mail clients to retrieve e-mail from a
server
119 - Network News Transfer Protocol (NNTP)
123 - Network Time Protocol (NTP)
143 - Internet Message Access Protocol (IMAP) Management of Digital Mail
161 - Simple Network Management Protocol (SNMP)
194 - Internet Relay Chat (IRC)
443 - HTTP Secure (HTTPS) HTTP over TLS/SSL
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How will you restrict IP so that the restricted IP’s may not use the FTP Server?
Answer: We can block suspicious IP by integrating tcp_wrapper. We need to enable
the parameter “tcp_wrapper=YES” in the configuration file at ‘/etc/vsftpd.conf’.
And then add the suspicious IP in the ‘host.deny’ file at location
‘/etc/host.deny’.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Network Troubleshooting -
If server seems offline, login to the console
ping a public dns server or dig
ip addr show
if down and if up
tcdump - to check and analyze network traffic
check /etc/sysconfig/network-scripts and the network file
check cat /etc/resolv.conf to see if dns records exists
restart network service
check traceroute and mtr maybe to see if there is a loss in the data packets
check iptables firewall might be blocking
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Server hardening Linux -

BIOS Protection - password protected


Disable Booting from external media devices.
Boot Loader Protection - Grub - protect with password
Keep the OS updated (only from trusted sources) - patching
Check the installed packages and remove the unnecessary ones - this is part of
patching
Check for Open Ports and stop unnecessary services
Enforce Password Policy - 90 days or 60 days forceful password change
Audit Passwords
Eliminate unused and well-known accounts that are not needed.
Give users limited administrative access.
Do not use the root account on a q basis and do not allow direct root login.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Securing openssh -
change the port
Prohibit root login
Enable pub key auth
use a firewall
update openssh
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
TCP
TCP is a connection-oriented protocol. Connection-orientation means that the
communicating devices should establish a connection before transmitting data and
should close the connection after transmitting the data
Reliability - TCP is reliable as it guarantees the delivery of data to the
destination router
Error checking mechanism - TCP provides extensive error-checking mechanisms. It is
because it provides flow control and acknowledgment of data
Acknowledgment - An acknowledgment segment is present.
Sequence - Sequencing of data is a feature of Transmission Control Protocol (TCP).
this means that packets arrive in order at the receiver.
Speed - TCP is comparatively slower than UDP.
Handshaking Techniques - Uses handshakes such as SYN, ACK, SYN-ACK
Protocols - TCP is used by HTTP, HTTPs, FTP, SMTP and Telnet.

TCP - 115 or 119


UDP - 123

UDP -
UDP is the Datagram-oriented protocol. This is because there is no overhead for
opening a connection, maintaining a connection, and terminating a connection. UDP
is efficient for broadcast and multicast types of network transmission.
Reliability - The delivery of data to the destination cannot be guaranteed in UDP.
Error checking mechanism - UDP has only the basic error checking mechanism using
checksums.
Acknowledgment - No acknowledgment segment.
Sequence - There is no sequencing of data in UDP. If the order is required, it has
to be managed by the application layer.
Speed - UDP is faster, simpler, and more efficient than TCP.
Handshaking Techniques - It’s a connectionless protocol i.e. No handshake
Protocols - UDP is used by DNS, DHCP, TFTP, SNMP, RIP, and VoIP.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Performance Tuning -
Performance tuning on Red Hat Enterprise Linux 7.9 has strategies, depending on the
needs of our system and the applications running on it -
Monitor system performance: before starting tuning performance, we need to know
where the bottlenecks are. we can use monitoring tools like top, sar, iostat, and
vmstat to identify resource usage on our system.
Update system packages: Ensure that the system is up-to-date with the latest
software updates and patches. You can use the "yum update" command to update all
packages.
Optimize disk I/O: Disk I/O can be a big bottleneck on Linux systems. we can use
tools like iostat to monitor disk activity and identify any performance issues.
disk partitioning can be implemented
Adjust CPU scheduling
Optimize memory usage - consider adjusting swappiness
Optimize application settings - adjusting aplication cache to improve performance
Disable unnecessary services
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Securing Linux in Large Environments -
Strong Password Policy
Access controls like ACL's, sticky bits
Harden the OS
Up to date with the packages and kernel
Server logs to be monitored regularly and perform vulnerability audits
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Automating Linux Deployments -

We use Ansible as the CM tool to automate linux deploy's


Include server config's in the yaml, which includes package installation, user
management, network configuration, and more.
Write configuration scripts or files in the yaml
Create a deployment playbook. This playbook defines the steps needed to deploy the
server configurations to one or more servers.
Test the deployment process
Deploy to production
Regularly update the configurations using the configuration management tool to
ensure that servers are up-to-date and in compliance
Document the deployment process
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Upgrade Linux RHEL 7.9 server -
Check server requirements, if there is enough space and cache is cleared in yum
Take a backup
Run pre-upgrade checks: Run the pre-upgrade checks to ensure that the system is
ready for the upgrade. This can be done using the "redhat-upgrade-tool" command.
4 .Register the system: Register the system with Red Hat Network using the
subscription manager.
Download the upgrade packages: Download the upgrade packages for RHEL 7.10 using
the Red Hat Network.
Start the upgrade process: Start the upgrade process using the "redhat-upgrade-
tool" command. This will download and install the necessary packages.
Reboot the system: After the upgrade process is complete, reboot the system to
ensure that all changes are applied.
Verify the upgrade: After the system has rebooted, verify that the upgrade was
successful by checking the version of RHEL using the "cat /etc/redhat-release"
command.
Update configurations: Update any configurations or applications that may have been
affected by the upgrade.
Test the system: Test the system to ensure that all applications and services are
running correctly.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Migration -
Plan the migration
Take a backup
Install the new system
Configure the new system
Copy data and configuration files
Update DNS and network settings: Update the DNS and network settings to ensure that
the new system is accessible on the network.
Switch over to the new system: Switch over to the new system by shutting down the
old system and starting up the new system.
Verify the migration: Verify that the migration was successful by checking that all
applications and services are running correctly on the new system.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
To configure a static IP address in Linux -
/etc/sysconfig/network-scripts/ifcfg-eth0
iface eth0 inet static
address 192.168.100
netmask 255.255.255.0
gateway 192.168.1
dns-nameservers 8.8.8.8 8.8.4.4
systemctl restart networking
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Diff between a daemon and a service -
A daemon is a background process that performs specific tasks.
A service is a type of daemon that provides a specific functionality or set of
functionalities to users or other programs.
A service can have one or more daemons running in the background to provide the
required functionality.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How do you configure a firewall in Linux?
For example, the following command allows incoming traffic on port 80 (HTTP):
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

To block incoming traffic on a specific port, you can use the following command:
sudo iptables -A INPUT -p tcp --dport 22 -j DROP

Save the firewall rules using the command sudo iptables-save. This command saves
the current firewall rules to a file, which is typically located in the
/etc/sysconfig/iptables directory.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How do you configure a network bridge in Linux?
sudo yum install bridge-utils
sudo ifconfig eth0 down
sudo brctl addbr br0
sudo brctl addif br0 eth0
sudo ifconfig br0 192.168.100 netmask 255.255.255.0 up
sudo ifconfig eth0 up
sudo ifconfig br0 up
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
After patching unable to see new kernel =

Check the boot order: Make sure that the new kernel is set as the default boot
option in the bootloader configuration file. On RHEL systems, this is typically
GRUB2. You can edit the /etc/default/grub file to set the default kernel.
Regenerate the GRUB configuration file: After editing the /etc/default/grub file,
you need to regenerate the GRUB configuration file by running the command grub2-
mkconfig -o /boot/grub2/grub.cfg.
Check for errors during installation: Check the output of the patching process to
see if there were any errors during the installation of the new kernel. If there
were errors, you may need to troubleshoot them before the new kernel can be used.
Check the kernel version: Make sure that the new kernel version is higher than the
currently installed kernel. You can check the installed kernel version by running
the command uname -r.
Check the kernel package: Make sure that the new kernel package was installed
correctly and is not corrupted. You can check the integrity of the package by
running the command rpm -V kernel.
If none of these steps resolve the issue, you may need to seek further assistance
from the RHEL support team or a qualified Linux system administrator.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Kernel panic =

Reboot in single-user mode: Restart the system and interrupt the boot process by
pressing any key. Then edit the kernel line and append "single" or "1" to the end
of the line. Press Enter to boot into single-user mode. This mode provides a
minimal environment and allows you to perform troubleshooting steps.
Review the kernel panic message: When the system boots into single-user mode, it
might display a kernel panic message on the console. The error message provides
valuable information about the cause of the panic. Look for any specific error
codes, module names, or other relevant details.
Check boot logs: Use the command dmesg to review the system boot logs and look for
any errors or warnings related to the kernel panic. Additionally, check the
contents of the file /var/log/messages for any relevant information.
Inspect previous kernel versions: If the new kernel version is not visible in the
kernel list, it suggests that the patching process might not have completed
successfully. Reboot the system and select an older kernel version from the boot
menu. Once the system boots, you can investigate the cause of the issue with the
new kernel.
Roll back the patch: If you determine that the new kernel is causing the panic, you
can try rolling back the patch. To do this, reboot into single-user mode and use
the package management tool (e.g., yum or dnf) to remove the recently installed
kernel package. For example, if the new kernel version is 4.18.0-10, you can use
the command yum remove kernel-4.18.0-10 to uninstall it.
Check hardware compatibility: Ensure that the patched kernel is compatible with
your hardware. Verify if any hardware-specific modules are causing the panic. You
can try booting the system with specific kernel parameters, such as disabling
certain modules or enabling specific hardware-related options

Kernel Panic -
Reboot the server and boot with the recover mode kernel
check on which partition root is
$ sudo mount /dev/sda2 /mnt
$ sudo mount --bind /dev /mnt/dev
$ sudo mount --bind /dev/pts /mnt/dev/pts
$ sudo mount --bind /proc /mnt/proc
$ sudo mount --bind /sys /mnt/sys
$ sudo chroot /mnt
update-initramfs -u -k 4.15.0-54-generic
update-grub

we can even create a new grub file with dracut initramfs......


+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Unable to write on disk -

Check file permissions: Make sure that you have permission to write to the
directory or file you are trying to write to. Check the ownership and permissions
of the file or directory using the ls -l command. If necessary, change the
ownership or permissions using the chown or chmod commands.
Check for df -i if the inodes are full in number
Check disk quotas: If disk quotas are enabled on the filesystem, you may have
exceeded your quota limit. Check the disk quota limits using the quota command. If
necessary, adjust the quota limits using the edquota command.
Check filesystem integrity: If the filesystem has become corrupted, it may prevent
you from writing to it. Run a filesystem check using the fsck command to check and
repair any errors on the filesystem.
Check for disk errors: If there are errors on the disk itself, it may prevent you
from writing to it. Check the disk for errors using the smartctl command or other
disk checking tools.
Check for full filesystems: Make sure that the filesystem is not full or nearly
full. Even if there is space available on the filesystem, individual directories or
partitions may have filled up. Use the df command to check disk usage.
Mount and re-mount
Check for read-only filesystems: If the filesystem has been mounted as read-only,
you will not be able to write to it. Check the mount options using the mount
command and make sure that the filesystem is mounted as read-write.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
If there is enough disk space, but a user is unable to write to the disk on a Red
Hat Enterprise Linux (RHEL) server
Check Disk Permissions: Ensure that the user has the necessary permissions to write
to the disk. Use the ls -ld
Check User Quota = quota -u username
Check Filesystem Mount Options = mount | grep /mount/point
Check Disk Ownership = chown username:groupname /path/to/directory
Check SELinux Contexts: If SELinux is enabled, check if the file or directory has
the correct SELinux context that allows writing = ls -Z /path/to/file_or_directory

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How do you troubleshoot network connectivity issues in Linux?
Use the ifconfig, ip addr, route, cat /etc/resolv.conf, and ping commands to check
the network configuration.
Use the systemctl status, systemctl start, and systemctl enable commands to check
the status and start/enable the network services.
Use the iptables, ufw, firewalld, or shorewall commands to check the firewall
configuration.
Use the journalctl, dmesg, and /var/log/messages commands to check the system logs.
Use the tcpdump command to capture and analyze network traffic
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How do you configure RAID in Linux?
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
mount /dev/md0 /mnt/data

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
User space and kernel space are two distinct areas of memory in an operating
system, with different levels of privilege and access to system resources.

User space is the area of memory where user-level applications and programs
execute. Applications in the user space do not have direct access to the hardware
and other low-level system resources. Instead, they rely on system calls to request
services from the kernel. The system calls are the interface between the user space
and kernel space. Applications running in user space have limited permissions and
are not allowed to access the kernel's memory or execute privileged instructions.

Kernel space, on the other hand, is the area of memory where the kernel of the
operating system executes. It has complete access to the hardware and other system
resources, and can execute privileged instructions. The kernel space provides
services to the user space, such as memory management, process management, file
systems, and device drivers. The kernel space is a highly privileged area, and only
the kernel and certain trusted system processes are allowed to access it.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Kernel Module =
In the Linux kernel, a module is a piece of code that can be dynamically loaded and
unloaded into the kernel at runtime. Modules are a way of adding functionality to
the kernel without the need to recompile the entire kernel.

Modules are typically implemented as object files that can be compiled separately
from the main kernel code. When a module is loaded into the kernel, it becomes part
of the running kernel and can interact with other parts of the kernel, including
device drivers, file systems, and networking protocols.

Loading a module into the kernel is typically done using a command such as insmod
or modprobe. The kernel checks the module's dependencies and verifies that it is
compatible with the running kernel before loading it. Once the module is loaded, it
becomes part of the kernel and can be used like any other kernel component.

Modules can be unloaded from the kernel using the rmmod command. When a module is
unloaded, its memory and resources are released, and any dependent modules are also
unloaded if they are no longer needed.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/proc filesystem =
/proc is a virtual filesystem that provides a way for the kernel to show
information about the system and running processes

The /proc filesystem has directories and files, each representing a different
information of the system. The files and directories in /proc are created
dynamically by the kernel when a user requests access to them. Each file in /proc
is a virtual file that contains information about a specific aspect of the system
or a running process.

Here are some examples of the files and directories available in /proc:

/proc/cpuinfo: Contains information about the CPU(s) in the system, such as the
model, clock speed, and cache size.
/proc/meminfo: Contains information about the system's memory usage, including
total memory, free memory, and used memory.
/proc/net: Contains information about the system's network interfaces and
connections.
/proc/PID: Contains information about a specific process with the process ID (PID)
specified in the directory name. Each process directory contains files with
information about the process, such as its memory usage, open files, and command
line arguments.
Accessing files in /proc is similar to accessing regular files in the file system,
but the contents of the files are dynamically generated by the kernel. Applications
can read from and write to files in /proc to retrieve information about the system
or modify kernel parameters.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Can you explain the difference between a journaled and a non-journaled filesystem?
In a non-journaled filesystem, file changes are written directly to the disk
without any additional record-keeping. When the system crashes or loses power, the
filesystem may be left in an inconsistent state with incomplete or corrupted files.
To recover from such situations, the filesystem must perform a lengthy and
resource-intensive file system check (fsck) to scan the entire disk and repair any
errors.

In contrast, a journaled filesystem keeps a log or journal of all changes made to


the filesystem. When a change is made, it is first written to the journal before
being written to the disk. The journal records the metadata associated with each
change, such as the file name and location. This allows the filesystem to quickly
and efficiently recover from system crashes or power outages by replaying the
journal and applying any changes that were not completed before the crash.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you had to troubleshoot a critical issue on a Linux


server under high load. How did you approach it?
Scenario: I was managing a production e-commerce web server that suddenly
experienced severe performance degradation. Users complained about slow page loads,
and orders were stalled. This was a critical issue, as it directly impacted
revenue.

Approach:
Identify the Bottleneck: I started by using tools like top, htop, vmstat, and
iostat to quickly assess which resource was the limiting factor: CPU, memory, disk
I/O, or network. In this case, iostat showed extremely high disk wait times.
Pinpoint the Process: I used iotop to identify the specific processes generating
heavy disk activity. It turned out that a recently deployed log rotation script had
a bug, causing it to write massive amounts of data to disk without proper
compression.
Resolve: I immediately stopped the faulty log rotation script. Then, I investigated
and fixed the buggy script, implementing compression and more efficient log
management.
Monitor: I closely monitored the server's disk I/O performance over time to ensure
the issue was truly resolved and that no similar problems arose.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain how you would set up a high availability cluster using Linux for
mission-critical applications.
Approach:
Choose a Clustering Technology: Select a suitable high availability (HA) technology
like Corosync/Pacemaker, or Linux-HA. This choice depends on factors like
application requirements, complexity, and existing infrastructure.
Design Architecture: Plan the cluster configuration – number of nodes (at least two
for redundancy), resource failover strategy (active/passive or active/active),
shared storage (iSCSI, SAN, or distributed storage), and a virtual IP address for
clients to connect to.
Hardware and Network Setup: Configure the required hardware and ensure robust
network connectivity between the nodes. This often includes redundant network paths
and heartbeat mechanisms to detect node failures.
Install and Configure HA Software: Install the chosen cluster software on all
nodes. Configure cluster resources (services, IP addresses, storage) and define
failover rules and policies.
Implement Shared Storage: Set up shared storage accessible by all the cluster
nodes.
Thorough Testing: Rigorously test failover scenarios by simulating node failures
and ensuring that services seamlessly switch to healthy nodes, minimizing downtime.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Walk me through the process of optimizing disk I/O performance on a Linux


server.
Approach:
Identify the Bottleneck: Use tools like iostat, vmstat, and sar to analyze disk
metrics: utilization, wait times, IOPS (Input/Output Operations per Second),
throughput, queue size. This pinpoints if the issue is with the disks themselves,
the controllers, or workload patterns.
Hardware Checks: If hardware appears to be the issue, check RAID configuration,
disk health (SMART data), and cabling. Replace failing disks as needed.
I/O Scheduler: Choose an appropriate I/O scheduler (deadline, noop, CFQ) based on
the workload using the cat /sys/block/<device>/queue/scheduler command. Experiment
to find what works best for your specific application.
Filesystem Optimization: Select the right filesystem (ext4, XFS, Btrfs) considering
features like journaling modes, block sizes, and use case. Use tune2fs to adjust
filesystem parameters.
Application Tuning: If possible, identify and optimize applications causing
excessive disk I/O. This might involve reducing database writes, caching, or load
balancing.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you implemented security hardening measures on a Linux


system. What tools and techniques did you use?
Scenario: A client's Linux server needed enhanced security before hosting sensitive
data.

Approach:
Baseline Audit: Assessed the current security posture using tools like Lynis or
OpenSCAP to identify potential vulnerabilities and misconfigurations.
Firewall: Configured iptables or nftables for strong network filtering, allowing
only essential ports and services.
SSH Hardening: Enforced key-based authentication, disabled password logins, changed
the default SSH port, and implemented Fail2ban for brute-force protection.
Updates: Installed all security patches and updates.
Access Control: Strict user account management. Enforced least privilege principles
and strong password policies. Implemented sudo with granular permissions.
File Integrity Monitoring: Used tools like AIDE or Tripwire for file integrity
checks.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. How would you handle a situation where a Linux server is running out of disk
space?
Approach:

Identify Space Consumers: Use tools like df (filesystem overview) and du (directory
usage) to drill down into which directories and files are consuming the most space.
Example: du -sh /var/* to check usage under /var.
Temporary Cleanup: Delete unnecessary log files, clear old package caches (apt-get
clean or yum clean all), and empty user trash directories.
Analyze Application Data: Inspect application directories for excessive log
generation, temporary files, or old backups that might be taking up space.
Find Large Files: Use the find command to locate large files that might be
unnecessary. For example: find /home -type f -size +100M to find files larger than
100MB in /home.
Consider Expansion: If cleanup is insufficient, explore options to add more storage
capacity or move data to external storage or cloud-based solutions.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you had to configure a Linux server to act as a


firewall using iptables or nftables.
Scenario: A small business needed a firewall to protect its internal network and
internet-facing server.

Approach:

Choose Firewall Framework: I selected iptables due to familiarity and its


widespread use. For newer systems, nftables offers a more modern approach.
Develop Rule Set: Carefully designed firewall rules based on the following:
Default Policy: Deny all incoming traffic by default.
Allow Established/Related: Allow traffic for established connections.
Open Necessary Ports: Permit only essential services (e.g., port 80/443 for web
traffic, port 22 for SSH).
Logging: Log denied traffic for security analysis.
Implement Rules: Use the appropriate commands (iptables or nft) to create the
firewall rules. I prefer to store these rules in a script for ease of management
and restoration.
Test Thoroughly: Verify firewall functionality from both internal and external
networks. Use tools like nmap for port scanning.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain the process of setting up and configuring SELinux or AppArmor on a Linux


system.
Approach (I'll focus on SELinux):

Understand SELinux: SELinux is a Mandatory Access Control (MAC) system. It works on


labels and policies, adding security beyond traditional permissions.
Installation: Ensure SELinux packages are installed (selinux-policy, etc.).
Set Mode: Choose 'enforcing' for active protection, 'permissive' for logging, or
'disabled' to turn it off. Use setenforce 1 (enforcing) or setenforce 0
(permissive). Monitor /var/log/audit/audit.log in permissive mode.
Manage Policies: Use tools like semanage, audit2allow, and sepolicy to view,
modify, and create policies. Troubleshoot denials reported in the audit log.
Context Labeling: Ensure files and processes have correct SELinux labels. Use
restorecon to fix mislabeling.
Note: AppArmor follows a similar approach but focuses on defining profiles for
applications.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you had to troubleshoot network connectivity issues on


a Linux server.
Scenario: A production web server suddenly became inaccessible to clients on the
network.
Approach:

Physical Check: Verify cabling and link lights on the server and network switches.
Basic Network Tools: Use ping to test connectivity to the gateway, then external
targets (like 8.8.8.8) to isolate the issue.
Check IP Configuration: Use ip addr or ifconfig (older) to ensure the server has
the correct IP address, subnet mask, and default gateway.
Route Verification: Examine the routing table with ip route or route -n. Address
misconfigured routes if needed.
DNS Troubleshooting: Use nslookup or dig to check if the server can resolve domain
names. Verify /etc/resolv.conf for correct DNS settings.
Firewall: Check iptables or nftables rules to ensure firewall policies are not
blocking access.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. How would you automate repetitive tasks on Linux using shell scripting or
configuration management tools like Ansible?
Approach:

Shell Scripting (e.g., Bash):

Simple Tasks: Excellent for automating sequences of commands, file manipulation, or


tasks within a single server.
Write Script: Develop the script using loops, conditionals, and functions for logic
and flexibility.
Scheduling: Use cron or at to schedule the script's execution.
Configuration Management (e.g., Ansible):

Complex, Orchestrated Tasks: Ideal for managing multiple servers, enforcing desired
states, and infrastructure as code.
Create Playbooks: Write YAML playbooks to define tasks, modules, and variables.
Execution: Run ansible-playbook to execute playbooks against a defined inventory of
hosts.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain the steps you would take to secure SSH access to a Linux server.
Approach:

Disable Root Login: Edit /etc/ssh/sshd_config and set PermitRootLogin no. Enforce
user-based logins for better auditing.
Key-Based Authentication: Generate SSH key pairs for users. Disable password-based
authentication by setting PasswordAuthentication no in sshd_config. Enforce strong
key management.
Change Default Port: Modify the SSH port in sshd_config to a non-standard value to
reduce the visibility of the SSH service to automated port scans.
Firewall: Use iptables or nftables to limit SSH access to only trusted IP addresses
or networks. Reduce the attack surface.
Fail2ban: Install and configure Fail2ban to automatically ban IP addresses that
exhibit brute-force attempts. Mitigate automated password guessing attacks.
Strong Password: Enforce strong password policies if password-based authentication
cannot be completely disabled.
Regular Updates: Keep the OpenSSH server software updated with the latest security
patches.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you had to upgrade a critical application running on a


Linux server without causing downtime.
Scenario: A critical web application required a major upgrade, but minimizing
downtime was essential.

Approach:

Testing Environment: Set up a staging environment that mirrors production as


closely as possible. Thoroughly test the upgrade process and identify any potential
issues early on.
Choose Strategy: Consider strategies like:
Blue/Green Deployment: Provision a new server with the updated application. Switch
traffic to the new server seamlessly using DNS or load-balancer changes.
Rolling Updates: If the application supports it, update nodes behind a load
balancer one by one, maintaining capacity during the process.
Database Migrations: Carefully plan any required schema changes or data migrations
for the upgrade. Test database compatibility and migration scripts.
Backup and Rollback Plan: Have a comprehensive backup of the application and
database. Define a clear rollback procedure in case unexpected issues arise.
Communication: Notify users about planned maintenance and potential downtime
windows.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. How would you monitor system performance and resource utilization on a Linux
server? What tools would you use?
Approach:

Real-time Monitoring:
top or htop: Interactive views of processes, CPU, memory, load average.
vmstat: System-wide overview of memory, swap, CPU, I/O.
iostat: Disk input/output statistics.
sar: Collect and report historical system activity data.
Network Monitoring:
netstat: Network connections, routing table, interface statistics.
iftop or nethogs: Per-process network bandwidth usage
Logging and Visualization:
Centralized Logging: Tools like rsyslog or syslog-ng to aggregate logs.
Visualization: Grafana with datasources like Telegraf or InfluxDB to build custom
dashboards, graph metrics, and set alerts.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you had to recover a corrupted filesystem on a Linux


server.
Scenario: A critical file server experienced a power outage, leading to filesystem
corruption.

Approach:

Avoid Further Writes: If possible, unmount the affected filesystem immediately to


prevent further damage.
Backup: If feasible, attempt to create a full backup of the corrupted filesystem
before any repairs, for a fallback option.
Identify Filesystem: Use fdisk -l or blkid to determine the type of filesystem
(ext4, XFS, etc.).
Run fsck: Use the appropriate file system check tool (e.g., fsck.ext4, fsck.xfs)
for recovery attempts. Follow prompts and carefully analyze output.
Advanced Recovery: In complex cases, consider specialized data recovery tools or
professional services if critical data is at risk.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain how you would set up and configure a Linux server to host a web
application securely.
Approach:

Server Hardening: Follow basic security hardening practices (firewall, SSH


hardening, updates, access control) as outlined in previous answers.
Web Server Choice: Select a web server (Apache, Nginx) considering performance,
security track record, and application requirements.
Secure Configuration: Configure the web server to disallow directory listings,
restrict access to sensitive files, and enforce strong TLS settings.
HTTPS: Obtain and install a valid TLS certificate from a trusted Certificate
Authority (e.g., Let's Encrypt). Redirect all traffic to HTTPS.
Application Security: Secure the application itself using input validation, output
sanitization, session management best practices, protection against SQL injection,
XSS, and other OWASP Top 10 vulnerabilities.
WAF (Optional): Consider a Web Application Firewall (WAF) like ModSecurity for an
added layer of protection against common web attacks.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you had to implement user management and access
control on a Linux server.
Scenario: A new development team needed access to a Linux server, with individual
user accounts and restrictions based on their roles.

Approach:

User Creation: Add user accounts with useradd, setting appropriate home directories
and default shells. Enforce strong password policies.
Group Management: Create groups (groupadd) for different roles (e.g., 'developers',
'admins'). Assign users to their respective groups.
File Permissions: Use chown and chmod to set ownership and permissions on files and
directories. Apply the principle of least privilege:
Developers: Grant read/write access in project directories.
Admins: Allow broader access for system management.
sudo: Configure the /etc/sudoers file (using visudo) to provide granular sudo
permissions for specific commands to specific groups, for administrative tasks
where needed.
Logging: Ensure user logins and sudo activity are logged for auditing purposes.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. How would you handle a situation where a Linux server is experiencing a high CPU
usage spike?
Scenario: A production server suddenly experiences sustained high CPU utilization,
impacting performance.

Approach:
Top or htop: Quickly identify the processes responsible for the high CPU
consumption.
System Metrics: Use vmstat to check if high CPU usage is related to system-wide
issues (high I/O wait, excessive context switching).
Profiling (if needed): For deeper analysis, use tools like perf or strace to
profile the misbehaving processes and pinpoint code-level bottlenecks.
Application Issue: If caused by a specific application, address the issue within
the application (bugs, inefficient code, runaway processes). May need developer
involvement.
Resource Limits: Consider using cgroups or ulimit to temporarily limit resources
available to resource-intensive processes, mitigating the impact on the entire
system.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you had to deploy and manage Docker containers on a
Linux server.
Scenario: A web application with multiple dependencies needed to be packaged in a
portable way for deployment across different development and production
environments.

Approach:

Docker Installation: Install the Docker engine on the Linux server.


Dockerfile: Create a Dockerfile to define the steps to build a container image for
the application, including base OS, application dependencies, and instructions to
copy the app code.
Build Image: Use docker build to build the image.
Containerize: Run the image using docker run with appropriate options for port
mapping, volume mounts, and network configuration.
Repository: Optionally, push the image to a Docker registry (Docker Hub, private
registry) for sharing and versioning.
Orchestration (Optional): For complex multi-container setups, consider
orchestration tools like Kubernetes or Docker Swarm.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain the process of setting up a VPN server on a Linux system.


Approach (I'll focus on OpenVPN as an example):

Installation: Install the OpenVPN server and related packages.


Certificate Authority: Set up a certificate authority (CA) to manage server and
client certificates for authentication. Generate the necessary server certificate
and keys.
OpenVPN Server Configuration: Create the server configuration file
(/etc/openvpn/server.conf), specifying network settings, encryption protocols, and
client configuration options.
Firewall: Adjust firewall rules (iptables or nftables) to allow VPN traffic to the
server on the configured port (usually UDP 1194).
Client Configuration: Generate client certificates and create client configuration
files, distributing them securely to users.
Start OpenVPN: Start the OpenVPN service (systemctl start openvpn@server) and
ensure it starts on boot.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Q. Describe a scenario where you had to configure and manage a MySQL or PostgreSQL
database server on Linux.
Scenario: A new web application required a relational database backend to store
data.

Approach (I'll use MySQL as an example):

Installation: Install the MySQL server packages (mysql-server).


Secure Installation: Run mysql_secure_installation script to improve security: set
a root password, remove anonymous users, and disable remote root logins.
Database and User Creation: Create a database for the application and a dedicated
user account with the necessary permissions.
Firewall: Adjust firewall rules to allow connections only from the web server if
they reside on separate machines.
Remote Access (If needed): Configure MySQL to listen on the appropriate network
interface for remote connections. Consider implementing SSL/TLS for secure
communication.
Performance Tuning: Optimize MySQL settings based on workload and available
hardware. Adjust memory usage (buffer pool), use appropriate storage engines
(InnoDB), and configure indexing.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. How would you ensure data integrity and reliability on a Linux server hosting
critical data?
Approach:

RAID: Implement a Redundant Array of Independent Disks (RAID) configuration


suitable for your performance and redundancy needs (RAID 1, RAID 5, RAID 6, RAID
10) to protect against disk failures.
Regular Backups: Establish a comprehensive backup strategy involving regular full
and incremental backups. Test and verify backup restoration procedures.
Offsite Backups: Store backups offsite or use a cloud-based backup service for
disaster recovery in case of localized failures.
File System with Integrity Features: Consider file systems like ZFS or Btrfs, which
offer self-healing capabilities and checksumming to detect data corruption.
Data Validation: Implement integrity checks in your applications during data input
and output and regularly verify backup data integrity.
Access Control: Strict access controls (file permissions, ACLs) to prevent
unauthorized modification.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you had to patch and update a Linux server while
minimizing downtime.
Scenario: Critical security patches were released for a production web server.
Applying them while minimizing service disruption was crucial.

Approach:

Testing Environment: Test patches in a staging environment that mirrors production


as closely as possible to identify any potential issues before deployment.
Maintenance Window: Communicate a scheduled maintenance window to users.
Change Management: Follow established change management procedures. Document steps
and have a rollback plan.
Approach Options:
Rolling Updates: If possible, update servers behind a load balancer one at a time,
maintaining service availability.
Hot Patching: For kernel updates, consider live patching solutions (e.g., kpatch,
livepatch), which may avoid full reboots, depending on the vulnerability.
Post-Update Testing: Thoroughly test functionality on the updated servers before
returning them to production.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain the steps you would take to secure Apache or Nginx web servers on Linux.
Approach:

Regular Updates: Keep the web server software updated with the latest security
patches.
Least Privilege: Run the web server process as a non-root user with limited
permissions.
Secure Configuration:
Disable directory listings.
Restrict access to sensitive configuration files.
Enable strong TLS configurations and enforce HTTPS.
Hide web server version information.
Set appropriate HTTP security headers (X-Frame-Options, X-Content-Type-Options,
etc.).
Firewall: Use iptables or nftables to restrict incoming traffic to only necessary
ports (usually 80 and 443).
File Permissions: Ensure strict file and directory permissions to prevent
unauthorized modifications.
Input Validation: Implement input validation in web applications residing on the
server to mitigate XSS and SQL injection vulnerabilities.
Logging and Monitoring: Enable access and error logging. Consider intrusion
detection systems (IDS) or file integrity monitoring solutions.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you had to configure and troubleshoot a mail server
(e.g., Postfix, Sendmail) on Linux.
Scenario: A company needed to set up an internal mail server for employee emails.

Approach:

Choice of MTA: Choose a Mail Transfer Agent (MTA) like Postfix or Sendmail based on
familiarity and features required.
Installation and Basic Configuration: Install and configure the MTA with domain
name and hostname information.
DNS Setup: Configure DNS records (MX records) to point to the mail server for
domain-based email routing.
Firewall: Adjust firewall rules to allow SMTP traffic (port 25), and potentially
IMAP/POP3 for mail clients.
Authentication: Implement authentication mechanisms (SASL) to prevent unauthorized
relaying.
Spam Filtering: Install and configure spam filtering solutions like SpamAssassin or
Rspamd.
Testing: Thoroughly test sending and receiving email internally and externally.
Troubleshoot using mail logs.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Q. How would you set up and configure a backup solution for Linux servers? What
factors would you consider?
Approach:

Factors:
Data Criticality: How important is the data and what's the impact of its loss?
RPO and RTO: Recovery Point Objective (how much data loss is acceptable) and
Recovery Time Objective (how fast the systems need to be restored).
Budget and Resources: Available budget and IT personnel expertise.
Backup Tools:
rsync: For simple file-level backups with flexibility.
tar: Archive type backups.
Bareos / Bacula: Enterprise-level backup solutions with scheduling, client
management, and various backup types.
Strategy:
Backup Types: Full, incremental, differential backups.
Location: Local, external drives, cloud-based (AWS S3, etc.).
Encryption: Ensure backup data is encrypted for security.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you had to scale infrastructure horizontally to


accommodate increased workload on Linux servers.
Scenario: A popular website experienced a surge in traffic, straining existing
servers and impacting user experience.

Approach:

Identify Bottleneck: Analyze performance metrics (CPU, memory, disk I/O, network)
to determine the primary bottleneck.
Load Balancer: Introduce a load balancer (software like HAProxy, Nginx, or a
hardware appliance) to distribute requests across multiple web servers.
Provision Additional Servers: Add identical web server instances either on-premises
or in the cloud (depending on your infrastructure). Configure them identically to
existing servers.
Application Optimization: Ensure the application itself is optimized and can handle
distributed workloads.
Database Scaling: If the database is the bottleneck, consider replication (master-
slave) or sharding strategies for scaling databases.
Caching: Implement caching layers (e.g., Redis, Memcached) in front of the web
servers to reduce load on the backend.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain how you would configure and manage RAID arrays for data redundancy and
performance on Linux.
Approach:

RAID Level Choice: Select RAID level based on redundancy, performance, and capacity
needs:
RAID 0: Striping for performance (no redundancy)
RAID 1: Mirroring for redundancy
RAID 5: Striping with parity for redundancy and read performance
RAID 6: Striping with double parity for enhanced redundancy
RAID 10: Combination of mirroring and striping for both redundancy and performance
Tools:
mdadm: Software RAID management tool. Use commands like mdadm --create to create
arrays, mdadm --assemble to assemble existing arrays, and mdadm --detail to view
the array status.
Hardware RAID: If using a hardware RAID controller, its dedicated configuration
utility.
File System Creation: Create a file system on the assembled RAID device using tools
like mkfs.
Monitoring: Regularly monitor RAID array health and address any reported issues.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you implemented log rotation and retention policies
for a Linux server.
Scenario: Log files on a busy web server were consuming excessive disk space and
becoming difficult to manage.

Approach:

logrotate: Configure logrotate (usually in /etc/logrotate.d/) to manage log


rotation.
Retention Policy: Define how long to keep logs and how many rotated copies to
maintain (based on storage and compliance needs).
Compression: Enable log compression within logrotate configuration to save disk
space.
Specific Application Logs: Configure log rotation for individual applications if
they manage logs independently.
Centralized Logging (Optional): For large infrastructure, consider sending logs to
a centralized log management system for easier analysis and more robust retention
policies.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. How would you set up and configure a Linux server to host a secure FTP service?
Approach (I'll focus on VSFTPD as an example):

Installation: Install the VSFTPD package (vsftpd).


Secure Configuration: Edit /etc/vsftpd.conf:
Disable Anonymous Login: Set anonymous_enable=NO.
Chroot Jails (Optional): Confine users to their home directories for enhanced
security (consider chroot_local_user=YES).
SSL/TLS: Enable SSL/TLS support for encrypted transmissions. Generate certificates.
Firewall: Adjust firewall rules to allow FTP traffic on selected ports, consider
limiting access to specific IPs in the firewall.
User Management: Create dedicated FTP user accounts with necessary permissions.
Ensure the use of strong passwords.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you had to configure and manage network bonding or
teaming on a Linux server.
Scenario: A server required increased network throughput and redundancy for
critical network links.

Approach:

Verify Hardware Compatibility: Ensure network cards support bonding and provide
compatible drivers.
Bonding Mode: Choose a bonding mode (active-backup, round-robin, load balancing)
based on requirements.
Configuration:
Distribution Tools: Use ip link, ifenslave (older), or distribution-specific tools
to create and configure the bond interface (check your Linux distribution's
documentation).
Network Settings: Assign IP addresses, network configuration to the bond interface.
Testing: Thoroughly test network connectivity and failover scenarios by simulating
cable disconnections.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain the process of setting up and configuring a load balancer (e.g.,


HAProxy) on Linux.
Approach:

Installation: Install the HAProxy package.


Configuration: Edit the HAProxy configuration file (usually
/etc/haproxy/haproxy.cfg):
Global Section: Set up general parameters like logging and timeouts.
Frontend: Define how to receive traffic (IP address, port, protocols).
Backend: Define the pool of backend servers to which traffic will be distributed.
Health Checks: Configure health checks to monitor backend server availability.
Load Balancing Algorithm: Choose the algorithm (round-robin, least connections,
etc.).
Firewall: Adjust firewall rules to allow incoming traffic to the load balancer's
listening port(s).
Start HAProxy: Start the HAProxy service and configure it to start on boot.
Testing: Verify load balancer functionality using testing tools or by directing
real traffic.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you had to recover from a compromised Linux server.
What steps did you take?
Scenario: A web server was hacked due to an unpatched vulnerability, and the
attacker gained access.

Approach:

Contain the Breach: Immediately isolate the compromised server from the network to
prevent further spread.
Preserve Evidence: If possible, make a forensic image of the system before further
changes, for potential legal or investigative purposes.
Identify the Attack Vector: Analyze logs, system files, and network traffic to
determine how the attacker gained access and the extent of the compromise.
Remediate:
Patch the vulnerability that allowed the intrusion.
Change all passwords (root, user accounts, SSH keys).
Carefully examine system configuration files for modifications.
Review installed packages for malware.
Clean Install (If Necessary): In severe compromise, a full system reinstall from
trusted backups might be the safest option.
Monitoring: Implement enhanced logging and monitoring to identify future intrusion
attempts.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. How would you automate server provisioning and configuration management using
tools like Puppet, Chef, or SaltStack?
Approach (I'll use Puppet as an example):

Master-Agent Setup: Install Puppet Server (master) and Puppet agent on nodes to be
managed.
Manifests: Write Puppet manifests (code files) that define the desired state of the
servers:
Packages: Define what packages should be installed or removed.
Services: Manage services (running, stopped, configuration).
Files: Manage file contents and permissions.
Modules: Organize your manifests into reusable modules for easier management.
Node Classification: Assign nodes to specific roles by creating node definitions
within Puppet.
Apply Changes: The Puppet agent on each node regularly communicates with the master
to fetch its configuration and enforce the desired state.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you implemented disk encryption for data-at-rest


protection on a Linux server.
Scenario: A server handling sensitive client information needed data encryption to
safeguard it even if the physical disks were compromised.

Approach:

Encryption Choice: Select an appropriate encryption solution:


Full Disk Encryption: LUKS for encrypting entire disks/partitions.
File-level Encryption: Tools like eCryptfs for encrypting specific directories.
Partitioning (if necessary): Repartition disks if needed to create separate
partitions for encryption.
LUKS Setup (Example): Use cryptsetup luksFormat to format partitions for LUKS
encryption. Set strong passphrases.
Key Management: Securely store and manage the encryption keys. Consider a Key
Management System (KMS) for larger environments.
Unlock at Boot: Configure the system to unlock encrypted partitions at boot, either
by manual passphrase entry or by storing keys in an encrypted and protected manner.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain how you would configure and manage DNS services (e.g., BIND) on a Linux
server.
Approach (using BIND as an example):

Installation: Install the BIND package (bind9).


Main Configuration: Edit /etc/named.conf or /etc/bind/named.conf. This includes:
Zone Files: Define the DNS zones the server is authoritative for.
Zone File Configuration: Create zone files to hold DNS records (A, MX, CNAME, etc.)
within the zones defined.
Firewall: Adjust firewall rules to allow DNS traffic (UDP/TCP port 53).
Start BIND: Start the BIND service (named) and enable it on boot.
Testing: Use tools like dig or nslookup to test and query your DNS server.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you had to optimize memory usage and manage swap space
on a Linux server.
Scenario: A Linux server with limited RAM was experiencing performance issues due
to excessive swapping.

Approach:

Identify Memory-Intensive Processes: Use tools like top, htop, or free -m to check
memory usage and pinpoint the processes consuming the most memory.
Optimize Applications: If possible, address memory leaks or excessive usage within
applications causing the high memory consumption.
Add Swap (If Necessary): If you can't reduce memory usage, increase the swap space
to provide temporary relief but be aware this can degrade performance if overused.
Adjust Swappiness: Configure the kernel's swappiness parameter (e.g., in
/etc/sysctl.conf) to control how aggressively the system uses swap (lower values
favor keeping more data in memory).
Consider More RAM: If optimizing applications and managing swap proves
insufficient, the best long-term solution might be to add more physical RAM to the
server.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. How would you set up and configure a Linux server to support IPv6 networking?
Approach:

Kernel Support: Ensure your Linux kernel has IPv6 support compiled in (most modern
kernels do).
Interface Configuration:
Static: Assign IPv6 addresses to your interfaces manually using ip addr add or by
editing network configuration files.
DHCPv6: If your network provides DHCPv6, configure the client to obtain an IPv6
address automatically.
Routing: Ensure IPv6 routing is configured if the server needs to forward IPv6
traffic. Update your routing table using ip -6 route.
Firewall: Adjust firewall rules (iptables or ip6tables) to allow necessary IPv6
traffic.
DNS: Configure DNS so that your systems can resolve IPv6 addresses (AAAA records).
Testing: Verify IPv6 connectivity using ping6 and other network tools.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you had to troubleshoot kernel panic or system crashes
on a Linux server.
Scenario: A critical server periodically experienced kernel panics, leading to
downtime.

Approach:

Gather Information: Examine kernel logs (usually in /var/log/messages or using


dmesg) to look for any error messages or clues about the cause prior to the crash.
Recent Changes: Consider any recent hardware changes, software updates, or
configuration modifications that might be related.
Hardware Issues: Check for hardware errors (bad RAM, overheating, etc.) using
hardware diagnostics.
Kernel Bugs: Search online to see if the kernel panic messages point to known bugs
or if there are relevant kernel updates available.
Troubleshooting Tools: If necessary, use advanced tools like crash, kdump, and
system debuggers to gather more information.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain the steps you would take to secure containerized applications running on
Linux (e.g., Kubernetes).
Approach:

Secure Base Images: Start with hardened and minimal base images for containers.
Regularly update them with security patches.
Least Privilege: Run containers with the least privileges required. Avoid running
containers as root.
Image Scanning: Scan container images for vulnerabilities using tools like Clair or
Trivy.
Network Segmentation: Use network policies (e.g., in Kubernetes) to control
communication between containers and external networks.
Secrets Management: Use a secrets management solution (like Vault) to securely
store and distribute sensitive data (passwords, tokens) to containers.
RBAC: Implement Role-Based Access Control (RBAC) within Kubernetes to enforce
permissions for interacting with the Kubernetes API and resources.
Pod Security Policies: Apply Kubernetes Pod Security Policies to restrict
containers' capabilities.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you implemented automated monitoring and alerting for
Linux servers.
Scenario: An organization needed to proactively monitor servers and get alerted
about critical issues.

Approach:

Monitoring Tools: Select a monitoring solution like Nagios, Zabbix, Sensu, or


Prometheus, considering your infrastructure and needs.
Define Metrics: Identify critical metrics to monitor (CPU, memory, disk, network,
service health, etc.).
Configure Monitoring: Configure the tool to monitor your servers, set thresholds
for alerts, and define notification channels (email, SMS, webhooks).
Dashboards: Create visualizations (e.g., with Grafana) for easy monitoring and
historical data analysis.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you had to configure and manage a software-defined


storage solution (e.g., Ceph) on Linux.
Scenario: A growing organization needed scalable and resilient storage for its
mixed-workload environment.

Approach:

Hardware and Network: Plan hardware (number of nodes, disks, network) considering
performance, redundancy, and capacity needs. Ensure robust networking for Ceph's
communication.
Installation: Install Ceph packages on the selected nodes that will act as storage
nodes (OSDs).
Ceph Configuration: Create the Ceph configuration file (ceph.conf):
Monitor Nodes: Set up monitor nodes for cluster management.
OSD Creation: Prepare and add OSDs (disks or partitions) to the Ceph cluster.
Pools: Define storage pools with tailored replication or erasure coding levels
based on workload requirements.
Client Access: Provide access methods for clients:
Block Devices (RBD): For use as virtual machine block storage.
CephFS: For a distributed file system.
Object Storage (RADOSGW): For S3/Swift compatible object storage.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain how you would set up and configure a reverse proxy (e.g., Apache or
Nginx) on Linux.
Approach (using Nginx as an example):

Installation: Install the Nginx package.


Configuration: Edit the Nginx configuration file (usually /etc/nginx/nginx.conf):
Virtual Server: Define a server block to listen for incoming requests.
proxy_pass: Use the proxy_pass directive to forward requests to the backend server
(e.g., proxy_pass http://backend_server;).
Additional Settings: Configure options like caching, load balancing, and SSL/TLS
termination on the reverse proxy.
Firewall: Adjust firewall rules to allow traffic to the reverse proxy's listening
ports.
Start Nginx: Start the Nginx service and enable it on boot.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you had to configure and manage SSL/TLS certificates
for secure communication on Linux.
Scenario: A company website needed to implement HTTPS to secure user traffic and
improve search engine rankings.

Approach:

Certificate Type: Decide on the type of certificate:


Domain Validation (DV): Simplest, verifies domain ownership.
Organization Validation (OV): Verifies organizational identity.
Extended Validation (EV): Highest level of validation (may display green address
bar).
Obtain Certificate:
Purchase from a Certificate Authority (CA): For OV or EV certificates.
Use Let's Encrypt: A popular free option for DV certificates.
Certificate Generation: Generate a Certificate Signing Request (CSR) and private
key.
Web Server Configuration: Configure your web server (Apache, Nginx) to use the
certificate and private key. Enable HTTPS and enforce redirects (HTTP to HTTPS).
Test: Test your HTTPS configuration thoroughly using SSL testing tools or by
visiting your website with HTTPS in the browser.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. How would you implement and manage kernel upgrades on Linux servers?
Approach:
Check Compatibility: Verify that the new kernel is compatible with your hardware
and software. Look for changelogs, release notes, and vendor information.
Backup: Create a full system backup before making any major kernel changes.
Installation Method:
Package Updates: Use your Linux distribution's package manager (apt, yum) to
install the latest kernel package.
Manual: If needed, download, compile, and install a kernel directly from the
source.
Update Bootloader: Update your bootloader configuration (e.g., GRUB) to include the
new kernel.
Reboot: Reboot the server to load the new kernel.
Testing: Thoroughly test the server under the new kernel to identify any
compatibility issues or regressions.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you had to set up and configure a Linux server as a
caching DNS resolver (e.g., using dnsmasq).
Scenario: A small office network wanted to improve DNS lookup speeds and reduce
external DNS traffic.

Approach:

Installation: Install the dnsmasq package.


Configuration: Edit /etc/dnsmasq.conf to configure:
Upstream DNS Servers: Specify the servers to forward queries to.
Caching: Enable DNS caching.
Local DNS: Configure the network configuration of the clients to use the local
caching DNS server.
Firewall: If necessary, adjust firewall rules to allow DNS traffic (UDP/TCP port
53) to the server.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Explain the process of setting up and configuring network file sharing (e.g.,
NFS or Samba) on Linux.
Approach (I'll focus on NFS):

Installation: Install the necessary NFS server packages (nfs-utils or nfs-kernel-


server).
Exports: Edit the /etc/exports file to define directories to be shared via NFS,
along with allowed clients and permissions.
Firewall: Adjust firewall rules (iptables or nftables) to allow NFS traffic
(usually through port 2049).
Start Services: Start and enable the NFS server services (usually rpcbind and nfs-
server).
Client-side: On client machines, mount the NFS shares using the mount command.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Describe a scenario where you had to migrate data and applications from one
Linux server to another?
Scenario: A company needed to upgrade their primary web server to a newer, more
powerful machine, while minimizing downtime for their website.
Approach:

Planning:
Inventory: Thoroughly document the applications, configurations, and dependencies
on the existing server.
Migration Method: Choose between live migration (minimal downtime) or downtime-
based migration.
Compatibility: Ensure applications can run on the new server's OS and software
versions.
Data Migration:
rsync: For efficient file-level synchronization. Best for live migrations to keep
data updated in real-time.
Database Replication: If substantial database changes occur during the migration,
set up replication to the new database server in advance.
Application Migration:
Packaging: If possible, package applications and their dependencies for easy
redeployment.
Configuration Files: Carefully migrate configuration files, adjusting paths and
settings as needed.
Testing: Rigorously test all migrated applications and services on the new server
in a staging environment.
Cutover:
DNS Updates: Switch DNS records to point to the new server's IP address for a
seamless transition.
Monitoring: Closely monitor the new server post-migration for performance issues.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. How would you handle a situation where a Linux server is experiencing memory
leaks?
Scenario: A production server was gradually slowing down, and investigations
pointed towards increasing memory usage over time, indicating a potential memory
leak.

Approach:

Identify the Leaking Process: Use tools like top, htop, or ps to observe processes
over time to identify those with steadily increasing memory usage.
Profiling Tools: Use memory profiling tools for deeper analysis:
Valgrind: Detects memory leaks and errors within applications.
Heaptrack: Analyzes heap memory usage in applications over time.
Application-Level Fix: If the leak is in application code, work with developers to
identify the faulty code sections and implement fixes.
Restarting Services: Temporarily mitigate the impact by restarting the leaky
process. However, this is not a permanent solution.
Resource Limits (Temporary): Use tools like ulimit or cgroups to limit memory
available to a leaky process. This prevents it from consuming all server memory but
doesn't fix the root cause.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Q. Discuss a scenario where you had to implement role-based access control (RBAC)
using sudo or other tools on Linux servers?
Scenario: A development company needed to enforce separation of duties by providing
developers with elevated permissions to manage specific web applications without
granting them full root access.
Approach:

Groups: Create Linux groups representing the roles (e.g., "webdevs"). Add users to
their respective groups.
Sudoers Configuration: Edit the /etc/sudoers file (using visudo for safe editing)
to configure granular permissions:
Allow Groups: Grant the "webdevs" group permission to execute specific commands
with sudo.
Command Restrictions: Limit which commands they can run, and potentially which
paths those commands can operate on.
Alternative Tools (if needed): For finer-grained RBAC, consider:
SELinux: For mandatory access controls, if your environment supports it.
RBAC Systems: Tools like FreeIPA provide centralized RBAC management.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Bash cheat sheet


Example

!/usr/bin/env bash

NAME="John"
echo "Hello $NAME!"

Variables

NAME="John"
echo $NAME
echo "$NAME"
echo "${NAME}!"

String quotes

NAME="John"
echo "Hi $NAME"=> Hi John
echo 'Hi $NAME'=> Hi $NAME

Shell execution

echo "I'm in $(pwd)"


echo "I'm in `pwd`"
Same

Conditional execution

git commit && git push


git commit || echo "Commit failed"
Functions

get_name() {
echo "John"
}

echo "You are $(get_name)"

Conditionals

if [[ -z "$string" ]]; then


echo "String is empty"
elif [[ -n "$string" ]]; then
echo "String is not empty"
fi

Strict mode

set -euo pipefail


IFS=$'\n\t'

Brace expansion

echo {A,B}.js

| `{A,B}`| Same as `A B` |
| ---------- | ------------------- |
| `{A,B}.js` | Same as `A.js B.js` |
| `{.5}` | Same as `1 2 3 4 5` |

Parameter expansions

Basics

name="John"
echo ${name}
echo ${name/J/j}=> "john" (substitution)
echo ${name:0:2}=> "Jo" (slicing)
echo ${name::2} => "Jo" (slicing)
echo ${name::-1}=> "Joh" (slicing)
echo ${name:(-1)} => "n" (slicing from right)
echo ${name:(-2):1} => "h" (slicing from right)
echo ${food:-Cake}=> $food or "Cake"

length=2
echo ${name:0:length}=> "Jo"
STR="/path/to/foo.cpp"
echo ${STR%.cpp} /path/to/foo
echo ${STR%.cpp}.o /path/to/foo.o

echo ${STR.}cpp (extension)


echo ${STR/}foo.cpp (basepath)

echo ${STR/} path/to/foo.cpp


echo ${STR/}foo.cpp

echo ${STR/foo/bar}/path/to/bar.cpp

STR="Hello world"
echo ${STR:6:5}"world"
echo ${STR:-5:5} "world"

SRC="/path/to/foo.cpp"
BASE=${SRC/} => "foo.cpp" (basepath)
DIR=${SRC%$BASE}=> "/path/to/" (dirpath)

Substitution

| `${FOO%suffix}` | Remove suffix |


| ----------------- | ------------------- |
| `${FOOprefix}` | Remove prefix |
| `${FOO%%suffix}`| Remove long suffix|
| `${FOOprefix}`| Remove long prefix|
| `${FOO/from/to}`| Replace first match |
| `${FOO//from/to}` | Replace all |
| `${FOO/%from/to}` | Replace suffix|
| `${FOO/from/to}` | Replace prefix|

Comments

Single line comment

: '
This is a
multi line
comment
'

Substrings

| `${FOO:0:3}`| Substring (position, length) |


| ------------- | ------------------------------ |
| `${FOO:-3:3}` | Substring from the right |

Length
| `${FOO}` | Length of `$FOO` |
| --------- | ---------------- |
| ||

Default values

| `${FOO:-val}` | `$FOO`, or `val` if not set|


| ----------------- | ------------------------------------------------ |
| `${FOO:=val}` | Set `$FOO` to `val` if not set |
| `${FOO:+val}` | `val` if `$FOO` is set |
| `${FOO:?message}` | Show error message and exit if `$FOO` is not set |

The `:` is optional (eg, `${FOO=word}` works)

Loops

Basic for loop

for i in /etc/rc.; do
echo $i
done

C-like for loop

for ((i = 0 ; i < 100 ; i++)); do


echo $i
done

Ranges

for i in {.5}; do
echo "Welcome $i"
done

With step size

for i in {5..50..5}; do
echo "Welcome $i"
done

Reading lines

< file.txt | while read line; do


echo $line
done

Forever
while true; do
···
done

Functions

Defining functions

myfunc() {
echo "hello $1"
}

Same as above (alternate syntax)


function myfunc() {
echo "hello $1"
}

myfunc "John"

Returning values

myfunc() {
local myresult='some value'
echo $myresult
}

result="$(myfunc)"

Raising errors

myfunc() {
return 1
}

if myfunc; then
echo "success"
else
echo "failure"
fi

Arguments

| `$` | Number of arguments|


| ---- | ---------------------------------- |
| `$` | All arguments|
| `$@` | All arguments, starting from first |
| `$1` | First argument |

Conditionals

Conditions

Note that `[[` is actually a command/program that returns either `0` (true) or `1`
(false). Any program that obeys the same logic (like all base utils, such as
`grep(1)` or `ping(1)`) can be used as condition, see examples.

| `[[ -z STRING ]]`| Empty string|


| ------------------------ | --------------------- |
| `[[ -n STRING ]]`| Not empty string|
| `[[ STRING == STRING ]]` | Equal |
| `[[ STRING != STRING ]]` | Not Equal |
| `[[ NUM -eq NUM ]]`| Equal |
| `[[ NUM -ne NUM ]]`| Not equal |
| `[[ NUM -lt NUM ]]`| Less than |
| `[[ NUM -le NUM ]]`| Less than or equal|
| `[[ NUM -gt NUM ]]`| Greater than|
| `[[ NUM -ge NUM ]]`| Greater than or equal |
| `[[ STRING =~ STRING ]]` | Regexp|
| `(( NUM < NUM ))`| Numeric conditions|

| `[[ -o noclobber ]]` | If OPTIONNAME is enabled |


| -------------------- | ------------------------ |
| `[[ ! EXPR ]]` | Not|
| `[[ X ]] && [[ Y ]]` | And|
| `[[ X ]] || [[ Y ]]` | Or |

File conditions

| `[[ -e FILE ]]` | Exists|


| ----------------------- | ----------------------- |
| `[[ -r FILE ]]` | Readable|
| `[[ -h FILE ]]` | Symlink |
| `[[ -d FILE ]]` | Directory |
| `[[ -w FILE ]]` | Writable|
| `[[ -s FILE ]]` | Size is > 0 bytes |
| `[[ -f FILE ]]` | File|
| `[[ -x FILE ]]` | Executable|
| `[[ FILE1 -nt FILE2 ]]` | 1 is more recent than 2 |
| `[[ FILE1 -ot FILE2 ]]` | 2 is more recent than 1 |
| `[[ FILE1 -ef FILE2 ]]` | Same files|

Example

if ping -c 1 google.com; then


echo "It appears you have a working internet connection"
fi

if grep -q 'foo' ~/.bash_history; then


echo "You appear to have typed 'foo' in the past"
fi

String
if [[ -z "$string" ]]; then
echo "String is empty"
elif [[ -n "$string" ]]; then
echo "String is not empty"
fi

Combinations
if [[ X ]] && [[ Y ]]; then
...
fi

Equal
if [[ "$A" == "$B" ]]

Regex
if [[ "A" =~ "." ]]

if (( $a < $b )); then


echo "$a is smaller than $b"
fi

if [[ -e "file.txt" ]]; then


echo "file exists"
fi

Arrays

Defining arrays

Fruits=('Apple' 'Banana' 'Orange')

Fruits[0]="Apple"
Fruits[1]="Banana"
Fruits[2]="Orange"

Working with arrays


echo ${Fruits[0]}Element 0
echo ${Fruits[@]}All elements, space-separated
echo ${Fruits[@]} Number of elements
echo ${Fruits}String length of the 1st element
echo ${Fruits[3]} String length of the Nth element
echo ${Fruits[@]:3:2}Range (from position 3, length 2)

Operations

Fruits=("${Fruits[@]}" "Watermelon") Push


Fruits+=('Watermelon') Also Push
Fruits=( ${Fruits[@]/Ap/} ) Remove by regex match
unset Fruits[2]Remove one item
Fruits=("${Fruits[@]}")Duplicate
Fruits=("${Fruits[@]}" "${Veggies[@]}")Concatenate
lines=(`cat "logfile"`)Read from file

Iteration

for i in "${arrayName[@]}"; do
echo $i
done

Dictionaries

Defining

declare -A sounds

sounds[dog]="bark"
sounds[cow]="moo"
sounds[bird]="tweet"
sounds[wolf]="howl"

Declares `sound` as a Dictionary object (aka associative array).

Working with dictionaries

echo ${sounds[dog]}Dog's sound


echo ${sounds[@]}All values
echo ${!sounds[@]} All keys
echo ${sounds[@]} Number of elements
unset sounds[dog]Delete dog

Iteration

Iterate over values


for val in "${sounds[@]}"; do
echo $val
done

Iterate over keys

for key in "${!sounds[@]}"; do


echo $key
done

Options

Options

set -o noclobber Avoid overlay files (echo "hi" > foo)


set -o errexit Used to exit upon error, avoiding cascading errors
set -o pipefailUnveils hidden failures
set -o nounset Exposes unset variables

Glob options

set -o nullglob Non-matching globs are removed('.foo' => '')


set -o failglob Non-matching globs throw errors
set -o nocaseglob Case insensitive globs
set -o globdots Wildcards match dotfiles (".sh" => ".foo.sh")
set -o globstar Allowfor recursive matches ('lib//.rb' => 'lib/a/b/c.rb')

Set `GLOBIGNORE` as a colon-separated list of patterns to be removed from glob


matches.

History

Commands

| `history` | Show history|


| --------------------- | ----------------------------------------- |
| `shopt -s histverify` | Don’t execute expanded result immediately |

Expansions

| `!$` | Expand last parameter of most recent command |


| ------------ | ---------------------------------------------------- |
| `!` | Expand all parameters of most recent command |
| `!-n`| Expand `n`th most recent command |
| `!n` | Expand `n`th command in history|
| `!<command>` | Expand most recent invocation of command `<command>` |

Operations

| `!!` | Execute last command again |


| -------------------- |
------------------------------------------------------------ |
| `!!:s/<FROM>/<TO>/`| Replace first occurrence of `<FROM>` to `<TO>` in most
recent command |
| `!!:gs/<FROM>/<TO>/` | Replace all occurrences of `<FROM>` to `<TO>` in most
recent command |
| `!$:t` | Expand only basename from last parameter of most recent command |
| `!$:h` | Expand only directory from last parameter of most recent command |

`!!` and `!$` can be replaced with any valid expansion.

Slices

| `!!:n` | Expand only `n`th token from most recent command (command is `0`; first
argument is `1`) |
| -------- | ------------------------------------------------------------ |
| `!^` | Expand first argument from most recent command |
| `!$` | Expand last token from most recent command |
| `!!:n-m` | Expand range of tokens from most recent command|
| `!!:n-$` | Expand `n`th token to last from most recent command|

`!!` can be replaced with any valid expansion i.e. `!cat`, `!-2`, `!42`, etc.

Miscellaneous

Numeric calculations

$((a + 200)) Add 200 to $a

$((RANDOM%=200)) Random number 0..200

Subshells

(cd somedir; echo "I'm now in $PWD")


pwdstill in first directory

Redirection

python hello.py > output.txtstdout to (file)


python hello.py >> output.txt stdout to (file), append
python hello.py 2> error.logstderr to (file)
python hello.py 2>&1stderr to stdout
python hello.py 2>/dev/null stderr to (null)
python hello.py &>/dev/null stdout and stderr to (null)

python hello.py < foo.txt feed foo.txt to stdin for python

Inspecting commands
command -V cd
=> "cd is a function/alias/whatever"

Trap errors

trap 'echo Error at about $LINENO' ERR

or

traperr() {
echo "ERROR: ${BASH_SOURCE[1]} at about ${BASH_LINENO[0]}"
}

set -o errtrace
trap traperr ERR

Case/switch

case "$1" in
start | up)
vagrant up
;;

)
echo "Usage: $0 {start|stop|ssh}"
;;
esac

Source relative

source "${0%/}/../share/foo.sh"

printf

printf "Hello %s, I'm %s" Sven Olga


=> "Hello Sven, I'm Olga

Directory of script

DIR="${0%/}"

Getting options

while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in


-V | --version )
echo $version
exit
;;
-s | --string )
shift; string=$1
;;
-f | --flag )
flag=1
;;
esac; shift; done
if [[ "$1" == '--' ]]; then shift; fi

Heredoc

cat <<END
hello world
END

Reading input

echo -n "Proceed? [y/n]: "


read ans
echo $ans

read -n 1 ans Just one character

Special variables

| `$?` | Exit status of last task|


| ---- | --------------------------- |
| `$!` | PID of last background task |
| `$$` | PID of shell|

Go to previous directory

pwd/home/user/foo
cd bar/
pwd/home/user/foo/bar
cd -
pwd/home/user/foo

3. Linux Commands:

File Commands

| Command | Description|
| --------------- | ------------------------------------------------------------ |
| ls| directory listing|
| ls -al| formated listing with hidden files |
| cd dir| change directory to dir|
| cd| change to home |
| pwd | show current directory |
| mkdir dir | create directory dir |
| rm file | delete file|
| rm -r dir | delete directory dir |
| rm -f file| force remove file|
| rm -rf dir| force remove directory dir |
| cp file1 file2| copy file1 to file2|
| cp -r dir1 dir2 | copy dir1 to dir2; create dir2 if it doesn't exist |
| mv file1 file2| rename or move file1 to file2 if file is an existing directory,
moves file1 to sirectory file2 |
| ln -s file link | create symbolic link to file |
| touch file| create or update file|
| cat > file| places standard input into file|
| more file | output the contents of file|
| head file | output the first 10 lines of file|
| tail file | output the last 10 lines of file |
| tail -f file| output the contents of file as it grows starting with the last 10
lines |

System Info

| Command | Description |
| ----------------- | ------------------------------------- |
| date| show the current date and time|
| cal | show this month's calendar|
| uptime| show current uptime |
| w | display who is online |
| whoami| who you are logged in as|
| finger user | display info about user |
| uname -a| show kernel info|
| cat /proc/cpuinfo | cpu info|
| cat /proc/meminfo | memory info |
| man command | show the manual for command |
| df| show disk usage |
| du| show directory space usage|
| free| show memory and swap usage|
| whereis app | show possible locations of app|
| which app | show which app will be run by default |

File permissions commands

| Command| Description|
| ---------------- | ------------------------------------------------------------ |
| chmod octal file | change the permissions of file to octal, which can be found
separately for user, group, and world by adding: 4 – read (r), 2- write(w), execute
(x) |
| chmod 777| read, write execute for all|
| chmod 755| rwx for owner, rx for group and world|

Process management commands

| Command| Description|
| ------------ | ------------------------------------------------------------ |
| ps | display currently active processes |
| top| display all running processes|
| kill pid | kill process id pid|
| killall proc | kill al processes named proc |
| bg | lists stopped or background jobs; resume a stopped job in the background |
| fg | brings the most recent job to the foreground |
| fg n | brings job n to the foreground |

SSH commands

| Command | Description|
| --------------------- |
------------------------------------------------------------ |
| ssh user@host | connect to host as user|
| ssh -p port user@host | connect to host on port as user|
| ssh-copy-id user@host | add your key to host for user to enable a keyed
passwordless login |

Searching Commands

| Command | Description |
| ----------------------- | ------------------------------------------- |
| grep pattern files| search for pattern in files |
| greo -r pattern dir | search recursively for pattern in dir |
| command \| grep pattern | search for pattern in the output of command |
| locate file | find all instances of file|

Compression commands:

| Command | Description |
| ------------------------- | --------------------------------------------- |
| tar cf file.tar files | created a tar named file.tar containing files |
| tar xf file.tar | extract the files from file.tar |
| tar czf file.tar.gz files | create a tar with Gzip compression|
| tar xzf file.tar.gz | extract a tar using Gzip|
| tar cjf file.tar.bz2| create a tar with Bzip2 compression |
| tar xjf file.tar.bz2| extract a tar using Bzip2 |
| gzip file | compresses file and renames it to file.gz |
| gzip -d file.gz | decompresses file.gz back to file |

Networking commands

| Command| Description|
| ---------------------------- |
------------------------------------------------------------ |
| ping host| ping host and output results |
| whois domain | get whois information for domain |
| dig domain | get DNS information for domain |
| dig -x host| reverse lookup host|
| wget file| download file|
| wget -c file | continue a stopped download|
| Nmap Scan TypeOptionstarget. | scan a host|
| ifconfig ||
| traceroute domain/ip | traceroute prints the route packets take to network host.|
| telnet host <port> | talk to “hosts” at the given port number. By default, the
telnet port is port 23. |
| netstat –r | Print routing tables.|
| route add| Used for setting a static (non-dynamic by hand route) route path in
the route tables |
| nslookupdomain | Makes queries to the DNS server to translate IP to a name, or
vice versa. |

Installation Commands

| Command | Description|
| --------------------------------------- | -------------------------- |
| make<br />./configure<br />make install | Install from source|
| dpkg -i pkg.deb | install a package (Debian) |
| rpm -Uvh pkg.rpm| install a package(RPM) |

Shortcuts

| Command | Description|
| ------- | ------------------------------------------------------------ |
| Ctrl+C| halts the current command|
| Ctrl+Z| stops the current command, resume with fg in the foreground or bg in the
background |
| Ctrl+D| log out of current session, similar to exit|
| Ctrl+W| erases one word in the current line|
| Ctrl+U| erases the whole line|
| Ctrl+R| type to bring up a recent command|
| !!| repeats the last command |
| exit| log out of current session |

You might also like