Sunday, 5 July 2020

How many characters can a file name have?


101. How many characters can a file name have?

The maximum amount of characters that a file name in Linux may have is 255.

102. What is the similarity and difference between cron and anacron? Which one would you prefer to use?

Cron and Anacron are used to schedule the tasks in cron jobs. Both of these are the daemons that are used to schedule the execution of commands or tasks as per the information provided by the user.

Differences between cron and anacron:

cron works on the system that are running continuously that means it is designed for the system that is running24*7. While anacron is used for the systems that are not running continuously.

jobs can run every minute, but anacron jobs can be run only once a day.
Any normal user can do the scheduling of cron jobs, but the scheduling of anacron jobs can be done by the superuser only.

Cron should be used when you need to execute the job at a specific time as per the given time in cron, but anacron should be used in when there is no any restriction for the timing and can be executed at any time.

If we think about which one is ideal for servers or desktops, then cron should be used for servers while anacron should be used for desktops or laptops.

103. What are the default port numbers used for SMTP, FTP,DNS, DHCP, SSH?

Service      Port

SMTP 25
FTP         20 for data transfer and 21 for Connection established
DNS          53
DHCP 67 (UDP for DHCP server), 68  (UDP for DHCP client)
SSH         22

104. 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.

105. 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.

106. How will you check if the two files are hard-linked to each other?

# ls –i, check the inode numbers are same or not.

107. What is the command that displays the settings for all services and run-levels?

# chkconfig --list # This output shows SysV services only
# systemctl list-unit-files #list systemd services

108. What is the command to list the hidden files in your HOME directory?

# ls -la ~/

108. Explain system calls used for process management?

System call provides additional control over the system. Processes are the most basic unit on Linux System and process management need some system calls in Linux, some of them are:-

System calls Explanation

Fork         Creates a new process
Exec         Execute the program
Wait         Force process to wait
Exit         Exit/terminate the process
Clone Creates Child Process
Exit_Group Exit/terminate all threads in the process
Nice         Change the priority of the running process
Getppid Find parent ID of the process
Vfork Create Child Process and block parent

109. 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 frame may 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 operating system maps memory pages.

110. What is the difference between rm and rm –r?

The rm command is used to delete all the files while rm –r command is used to delete 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.

111. 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

For example, 

# cat test.txt
one six three four five

to replace the content of the file and we want to replace "six"  with “two”. So, we will use below command for this.

# sed 's/six/two/' test.txt > out.txt

# cat out.txt
one two three four five
So, "six" is replaced with "two" in the text.

112. What are shared, slave, private, and unbindable mountpoints?

A mount point that is shared may be replicated as many times as needed, and each copy will continue to be the exact same. Other mount points that appear under a shared mount point in some subdirectory will appear in all the other replicated mount points as it is.

A slave mount point is similar to a shared mount point with the small exception that the “sharing” of mount point information happens in one direction. A mount point that is slave will only receive mount and unmount events. Anything that is mounted under this replicated mount point will not move towards the original mount point.

A private mount point is exactly what the name implies: private. Mount points that appear under a private mount point will not be shown elsewhere in the other replicated mount points unless they are explicitly mounted there as well.

An unbindable mount point, which by definition is also private, cannot be replicated elsewhere through the use of the bind flag of the mount system call or command.

113. What are some basic measures that you would take to harden a server’s SSH service?

There are a some very simple steps that can be taken to initially harden the SSH service, such as:

Forcing the service to use only version 2 of the protocol will introduce both security and feature enhancement.

Disabling root login, and even password-based logins, will further reinforce the security of the server.

The whitelist approach can be taken, where only the users that belong to a certain list can login via SSH to the server.

Disabling password-based login will require you to then allow key based logins, which is secure, but can be taken further by restricting their use from only certain IP addresses.

Changing the port to something other than 22 significantly decreases random brute force attempts from the internet.

Sometimes the use of having an SSH service on a server may just be transferring files to and from the server (typically using tools like scp). In such a case, it is possible to change the shell of the user to something restrictive, such as rssh.

Finally it is often desirable to know exactly what is going on while you are not logged into the server. The logging verbosity may be increased if needed. Often, it is the logs that allow one to figure out if a key has indeed been stolen and is being abused.

114. What would be a simple way to continuously monitor the log file for a service that is running?

Probably the simplest and most common way to do this would be by using the command:
tail -f $LOGFILE

where $LOGFILE is an environment variable corresponding to the path to the log file to be monitored.
By default, the Linux tail command prints the last 10 lines of a given file to standard output. The -F option causes additional file content to be displayed in realtime as the file continues to grow. This yields a simple mechanism for monitoring services via their log files in close to realtime.

Two other specific command line options of interest in this context are:

The -s option causes tail to sleep for a specified number of seconds between updates (e.g., tail -F -s 10 will update the displayed file contents roughly every 10 seconds rather than in close to realtime as the file is updated).

The -n option can be used to specify a number of lines other than 10 to initially display (e.g., tail -n 20 -F will first display the last 20 lines of the file and will then continue updating the output in realtime).

115. How to check the default route and routing table?

To display the default route and routing table, we use the following commands.

$ route -n
 
$ netstat -rn
 
$ ip

116. How to check which ports are listening in my Linux Server?

To check which ports are in listening in Linux Server, 

# netstat --listen
# netstat -l

117. What are the different modes of Network bonding in Linux?

Mode-0(balance-rr): It is a default mode and based on Round-Robin policy. It offers fault tolerance and load balancing features. It used round-robin fashion to transmit the packets.

Mode-1(active-backup): It is based on Active Backup policy and only one slave will act in the band and another one will act when the others fail in the band. It also provides fault tolerance.

Mode-2(balance-xor): It sets a xor mode between the source Mac address and destination Mac address to provide fault tolerance.

Mode-3(broadcast): It is based on broadcast policy and transmitted everything in the slave interface. It also provides fault tolerance and it can be used only for a particular purpose.

Mode-4(802.3ad): It is a dynamic aggregation mode, it created aggregation groups which is having the same speed. It uses transmit hashing method to select the slaves for outgoing traffic.

Mode-5(balance-tlb): The outgoing traffic is according to the current load on the slave, and the incoming traffic is received by the slave. It is called an adaptive transmit load balancing mode. 

Mode-6(balance-alb): It is an adaptive load balancing mode. It does not require any switch support. 

118. Why we use LINUX? 

We are some many reasons, in that few important reasons are listed out. Following are

High Stability: It is very stable and does not lead to crashes, it runs fastly as it is when it installed first. 

Security: It is a dependable server, that offers high security to the user. Using Linux on your system it is easy to avoid virus and malware. The attacker cannot change any changes in the system until the user logged in at as root user.

Easy to Operate: Linux is easy to operate and we can install easily on to the system because all the variants of the Linux have there owned software repositories. You can update the system periodically with just a few clicks or you can set automatic updation.

Hardware Compatibility: Linux can use on any hardware, it doesn’t have any hardware restrictions. It uses efficiently all system resources.

Open Source: The source code is available as it is under Free and Open Source Software(FOSS).
119. Why is Linux considered more secure than other operating systems?

Linux is an open-source operating system, nowadays it is rapidly growing in the technology market. A few reasons why Linux is more secure than other OS.

The perk of accounts: Linux allows only a few users to access the system. Thus, the virus cannot attack the whole system, it may cause only a few files in the system. 

Strong Community: Linux users first accomplished the files before they open. So they can save their systems from vulnerabilities. 

Iptables: Iptables used by the Linux because it checks the security circle of the system. 

Different Working Environment: Linux system has different working environments like Linux Mint, Debian, Arch and many more, these working environments protect from the virus.

Recording in Linux: It maintains log history because later it can view the details of the system files easily. 

Few User: Linux users are less compared to others, due to this security will be more.

120. How can you setup Password Aging?

In Linux, the system administrators use chage command to apply password ageing. This command is used to modify the number of days among resets of a mandatory password. 
The /etc/login.defs file is accountable for managing the configuration in the system. It can be edited for:
PASS_MIN_DAYS – States the minimum days allowed between password reset.
PASS_MAX_DAYS – States the maximum days to use a password.
PASS_WARN_AGE – States the days to give warning before a password expires.

121. Name some troubleshooting and Linux networking commands?

All computers are linked to network externally or internally for the aim of information exchange. Network configuration and troubleshooting are some of the essential elements of network administration. The networking commands allow you to rapidly troubleshoot issues related to the connection with another system; check another host response, etc.

A network administrator upholds network of a system including network troubleshooting and configuration. Some commands with their description are mentioned below:

Hostname: This command is used to view the machine hostname (IP address and domain) and for hostname setting.

ifconfig: used to manipulate and display network and route interfaces. It shows the configuration of the network. ‘IP’ is the ifconfig command replacement.

Traceroute: It is a utility of network troubleshooting, used to find the hops needed for a packet for accessing the destination.

Dig:  used for DNS name servers query for any job related to the DNS lookup.

Route: It displays the route table details and operates the IP routing table.

Ifplugstatus: it tells if the network cable is plugged in or not.

Ping: this command is used to identify if the remote server is accessible or not.

netstat: It shows network links, interface statistics, routing tables. ‘ss’ is the netstat command replacement, used to get more data.

Tracepath: It like a traceroute with a change that it does not need root rights.

nslookup: This command is used to find query related to DNS.

mtr: it combines track path and ping into a single command.

122. 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 help of bootloader to a binary file. Here the kernel is used to settle the structure of the device tree on the binary.

123. How can we reduce the size of the kernel?

There are codes which are unnecessary and are not executed, we can find and disable them to make the processing faster in the project. The kernel comes with an editor known as “kernel’s configuration editor” by which we can remove and disable 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 of system-on-chips have Wi-Fi drivers, serial and other hardware that are not used, you can remove those drivers that are built on the kernel.

File Systems: The system has the only requirement of few file systems but in the kernel you will find many file systems drivers that are not in use e.g. Devices which make use of flash file systems 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 or you 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.

124. 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)
Group
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 describes permissions given to the user, group and other in the order. Each number is the sum of the values,i.e. 4 for reading, 2 for write, 1 for execute.
Here 751 is the combination of (4+2+1), (4+0+1), (0+0+1).

So, chmod 751 filename will provide read, write and execute permission to the owner; read and execute permission to the group and only execute permission to the others.

125. Where is the target path of a symlink stored? How are permission settings for symlinks handled?

The target path of a symlink is stored in an inode - the data structure used to store file information on disk.

Typically, the permission settings of the symlink itself only control the renaming and removal operations performed on the symlink itself. Any operation that deals with the contents of the file linked to are controlled by the permission settings of the target file.

                                                                                           MENU         PREVIOUS | NEXT

What is the difference between Linux and Unix?


76. What is the difference between Linux and Unix?

Linux Unix

Both paid and free distributions are available. Different paid structures for different levels of Unix.

Linux primarily uses GUI with an optional            Unix uses the command-line interface
command-line interface

Portable and can be executed in                        Not portable.
different hard drives

Developed by a worldwide Linux community. Developed by AT&T developers.

Bug Fix Speed is Faster because            Bug Fix Speed is Slow
Linux is Community driven.

Linux is used at home-based PC's, phones, etc. Unix is used mainly as Internet Server, Workstations, Mainframes.

File System Support: Ext2, Ext3, Ext4,     File System Support: jfs, gpfs, hfs, hfs+, 
Jfs, ReiserFS, Xfs, Btrfs, FAT, FAT32, NTFS.           ufs, xfs, zfs,vxfs.

Examples:Ubuntu, Fedora, Red Hat, Examples:OS X, Solaris, All Linux
Kali Linux, Debian, Archlinux, Android, etc. 

Linux comes with open source Netfilter and   UNIX operating systems comes with its own firewall 
IPTables based firewall tool to protect server         products. 
and desktop from the crackers and hackers. 

Viruses listed: 60-100 Viruses listed: 80-120

77. 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 reference for 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.
78. Explain the linux directory commands?

The linux directory commands are :

pwd: It is a built-in command which stands for ‘print working directory’. It displays the current working location, working path starting with a / and directory of the user. Basically, it displays the full path to the directory you are currently in.

Is: This command lists out all the files in the directed folder.

cd: This stands for ‘change directory’. This command is used to change to the directory you want to work from the present directory. 

mkdir: This command is used to create an entirely new directory.

rmdir: This command is used to remove a directory from the system.
79. Which is the first process started by the kernel and what is itsprocess id?

‘init’ is the first process in linux which is started by the kernel and its process id is 1.
80. Is it legal to edit Linux Kernel?

Yes , it is absolutely legal to edit Linux Kernel. Kernel is released under General Public License(GPL) , and anyone can edit Linux Kernel to the extent permitted under GPL. Linux Kernel comes under the category of Free and Open Source Software(FOSS).
 
81. Explain /bin, /usr, /sbin, /user/bin and /user/sbin Linux directories?

/bin: Its critical directory used to bring the system online in single-user mode to repair it. This contains executable programs(can say scripts) for this.

/sbin: This directory holds commands needed to boot the system in normal condition but not executed or used by normal users.

/usr: This is one of the largest directories in the Linux system, mostly mounted from a separate partition. Birnies and files all programs are installed reside here.

/usr/bin: This directory contains programs, executables and scripts not used for boot process but used by users to execute. Most of the programs or executable executed by users rather than root

/usr/sbin: Program binaries or executables required for a system administrator is kept under this directory. This program binaries or executables are not required for boot process or normal users.

82. What are filenames that are preceded by a dot?

Generally, all the hidden files are preceded by a dot. These files hold important or setup info as they can be configuration files. Keeping these files as hidden makes them secure from being accidentally deleted.

83. What does Sar provide? Where are Sar logs stored?
SAR is an abbreviation for System Activity Report. This command is used to collect data, report and save the usage of CPU, a Memory unit, input, and output in Linux. 

84. What is the full form of grep?

Grep stands for global regulation expression point. The command-line utility, grep, is used for searching data sets in plain-text for lines that match an expression which is used regularly. 

85. Explain Window Manager in Linux?

Window Manager is client software that controls icons, placement of icons, the appearance of the window after login to the system. This is desktop management software. LINUX is an open-source operating system and it have a long list of WM software available in the market. The system administrator can install and configure it as per user or environment requirements. One thing before using WM software, they will consume additional resources on the system.

The/etc/.xinitrc file is hidden system files allows you to change the window manager while login from any or particular user account. The prefix of “.” In the file, the name shows that it is hidden file and you will not be able to view it with the normal ls command.  WM gives enhance user experience or add-on features.

Some of the popular command for WM or desktop management are:-

The KDE = startkde
The Gnome = gnome-session
The Blackbox = Blackbox
The FVWM = fvwm
The Window Maker = wmaker
The IceWM = icewm

86. What is the FTP Server?

FTP is the simplest file transfer protocol to exchange files to and from a remote computer or network system. Similar to Windows, Linux, and UNIX operating systems they also have built-in command-line prompts that can be used as FTP clients to establish FTP connection. FTP works in Client-Server architecture to communicate and transfer the file during an established FTP session. 

When the Client initiates a connection to the server, it’s called Passive Connection. Whereas when Server initiates a connection to the client, it’s called Active Connection.

In Phase 1, When Connection initiated with the server, User credentials are passed for authentication. This is the control connection phase. In Phase 2, When actual data is transferred between client & server, This is data connection phase.

87. Differences between Softlink and Hardlink?

Hard Links 

  •   Gets created using same I-node number with a different name.
  •   Can only be created within same file system.
  •   Remains even if original file is removed.
  •   Can’t be created for directories.
  •   Created using ln command

Soft Links

  •   Gets created using alias name referring the original file name, but uses different I-node.
  •   Can be created across file systems.
  •   Dies after original file is removed, otherwise exists as a dead link.
  •   Can be used to create links to directories.
  •   Created using ln -s command

88. What is the difference between umask and ulimit?

unmask stands for user file creation mode. When the user creates any file, it has default file permissions. So unmask will specify few restrictions to the newly created file (it controls the file permissions).

umask [-S] [mask]

You can limit user to specific range by editing /etc/security/limits.conf at the same time system wide settings can be updated in /etc/sysctl.conf


89. Your server is using a lot of cached memory. How do you free it up short of rebooting?

Kernels 2.6.16 and newer provide a mechanism to have the kernel drop the page cache and/or inode and dentry caches on command, which can help free up a lot of memory.
To free page cache, dentries and inodes: echo 3 > /proc/sys/vm/drop_caches

90. What is the difference between /dev/random and /dev/urandom for generating random data?

The Random Number Generator gathers noise of environment from the device drivers and other sources into the entropy pool. It also keeps an estimate of the number of bits of the noise in an entropy pool. It is from this entropy pool and will generate random numbers.

/dev/random will only be returning Random bytes from the entropy pool. If the entropy pool is empty, reads to /dev/random will be blocked until the additional environmental noise will be gathered. This is suited to high-quality randomnesses, such as the one-time pad or key generation.

/dev/urandom will return as many random bytes requested. But if the entropy pool is empty, this will generate data using SHA, MD5 or any other available algorithm. It never blocks the operations. Due to which, the values are vulnerable to the theoretical cryptographic attack, though no known methods will exist.

For cryptographic purposes, we should really use the /dev/random because of the nature of data it returns. Possible waiting should be considered as an acceptable tradeoff for the sake of the security, IMO. When we need random data fast, we should use the /dev/urandom of course.

Both /dev/urandom and the /dev/random are using exact same CSPRNG (a cryptographically secure pseudorandom number generator). They can only differ in very few ways that have nothing to do with the “true” randomness and then /dev/urandom is the preferred source of cryptographic randomness on the UNIX-like systems.

91. What is Samba Share?

Samba is an open-source software suite that runs on the Unix/Linux based platforms but it is able to communicate with the Windows clients like a native application. So Samba is able to provide the service by employing the Common Internet File System (CIFS).

At the heart of the CIFS is the Server Message Block (SMB) protocol.  Samba does this by performing the four key things –

The File & print services
The Authentication and Authorization
The Name resolution
The Service announcement (browsing)

Samba can be run on many different platforms including Linux, Unix, OpenVMS and the operating systems other than the Windows and allows users to interact with a Windows client or server natively. It can basically be described as Standard Windows interoperability suite of the programs for Linux and Unix.

92. What is IRIX Mode in top command?

In Irix Mode, System considers all processors as a whole and CPU usage can vary from 0 to 100 only. IRIX feature was introduced in Solaris and adopted by Linux later.

93. If you have a file with 2000 IP's. How do you ping them all using bash in parallel?

# echo $(cat iplistfile) | xargs -n 1 -P0 ping -w 1 -c 1

94. What command can you use to send unsolicited ARP updates to the neighboring servers caches.

# arping -U -c 1 -I eth0 0.0.0.0 -s IP_ADDRESS

95. Write command to list all the links from a directory?

# ls -lrt | grep "^l"

96. What Linux utility can craft custom packets, like TCP SYN packets and send them to a remote host?

# hping3 -S 192.168.1.1 -p 80 -i u1

97. Create a read-only file in your home directory?

create a file and change its parameter to read-only by using chmod command you can also change your umask to create read only file.

$ touch file
$ chmod 400 file

98. How will you run a process in background? How will you bring that into foreground and how will you kill that process?

For running a process in background use "&" in command line. For bringing it back in foreground use command "fg jobid" and for getting job id you use command jobs, for killing that process find PID and use kill -9 PID command.

99. How to search files in linux?

To search files in Linux, use the locate  or find command.

100. How to remote login to another linux computer?

You can log in to a remote Linux computer using SSH protocol or using the VNC service.

                                                                                           MENU         PREVIOUS | NEXT

How to create and delete a directory in Linux?


51. How to create and delete a directory in Linux?

To create a directory use the mkdir command as shown;
mkdir directory_name

For example to create a directory called 'data' run the command:
# mkdir data

To delete a directory in Linux, use either the rm or rmdir command.
The rmdir command is used for removing empty directories.
The rm command is mostly used with the -R flag for recursively removing directories.

52. How to list and mount devices in Linux?

To list mount points run the command:
# df  -aTh

To find more information about the mount points on your system, execute the command:
# findmnt

Additionally, you can use the cat command below
# cat /proc/self/mounts

Also, you can use the mount command as shown
# mount -l

53. How to schedule a task in Linux? What is crontab and explain the fields in a crontab?

The cron is a deamon that executes commands at specific dates and times in Linux. You can use this to schedule activities, either as one-time events or as recurring tasks. Crontab is the program used to install, deinstall or list the tables used to drive the cron daemon in a server. Each user can have their own crontab, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly. 

Here are few of the command line options for crontab.

# crontab -e #Edit your crontab file.
# crontab -l #Show your crontab file.
# crontab -r #Remove your crontab file.

Traditional cron format consists of six fields separated by white spaces:

<Minute> <Hour> <Day_of_the_Month> <Month_of_the_Year> <Day_of_the_Week> <command/program to execute>

The format is explained as follows:

* * * * * *
| | | | | |
| | | | | +-- Year (range: 1900-3000)
| | | | +---- Day of the Week (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month (range: 1-31)
| +---------- Hour (range: 0-23)
+------------ Minute (range: 0-59)

54. What are the basic Vim commands you know?

a) Save
To save a file, press ESC button and press :wq! OR :ZZ

b) Exit
To exit from a file without making changes, run the command :q

c) Jump to a particular line in a file
Press ESC and press j to move down by one line.
To move up by one line press k on the keyboard
Move the cursor to the beginning of a line Press ^
Move the cursor to the end of a line Press $
Move the cursor to the beginning of a file 1G
Move the cursor to the end of a file G
Moves the cursor to the start of line number “n” in the file nG

d) Copy text
Move the cursor to the beginning of the string or text. Next hit v on your keyboard and press cursor forward to highlight text. Once you get to the end of text that you wish to copy, hit y short for yank, to copy the text.
To copy text from current position to the end of the line - y$
To copy the entire line - yy
To copy 4 lines below - 4yy

e) Paste text
To paste text, simply press p on the keyboard

f) Delete text
To delete a line, move to the beginning of a line. Press the ESC button and press dd
To delete a single word, place the cursor in front of the word and hit dw
To delete text from the current word to the end of the line hit d$
To delete 3 lines below run 3dd

55. Explain are different process states in Linux?

When we execute “ps aux”  in Linux terminal console, we can see multiple states of processes running in the system under the STAT column.

R: Process is running with CPU or waiting for CPU (Running or Runnable)

S: Process is waiting for the set event to complete, Like an input from terminal (SLEEP)

D: Process is with uninterruptible sleep stats which cannot be changed or killed \ rollback. The only way to go away is the reboot system.

Z: Process in Zombie status means the process is already killed but process information and data still exist in the process table.

T: Process either completed or terminated by the operating system or user. This is also known as Terminated /  Completed.

56. What are inodes in Linux? How to find the inode associated with a file?

The inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. When a file is created, it is assigned both a name and an inode number, which is an integer that is unique within the filesystem.

Explanation,
File systems have two parts: the metadata or the “data” about the data and the data. Metadata consist of information about the data. It includes information such as the Access Control List (ACL), the date the file was modified, file owner, file permissions, size of file, device ID, uid of the file, etc. inodes store this metadata information and typically they also store information about where the data is located on the storage media.

In a file system, inodes consist roughly of 1% of the total disk space, whether it is a whole storage unit (hard disk, thumb drive, etc.) or a partition on a storage unit. The inode space is used to track the files stored on the hard disk. The inode entries only points to these structures rather than storing the data. Each entry is 128 bytes in size. Space for inodes is allocated when the operating system or a new file system is installed and when it does its initial structuring. So this way we can see that in a file system, the maximum number of inodes and hence maximum number of files are set. Now, the above concept brings up another interesting fact. 

A file system can run out of space in two ways:

No space for adding new data is left
All the inodes are consumed.

To get a listing of an inode number, use ls -i command.

# ls -li or # ls -li file_name 

# find /root -inum inode_number

57. Explain file permission in Linux?

In Linux, there are 3 main types of file permissions: read, write and execute. These permissions can be assigned to either a file or a directory recursively.  Being a multi-user system, you can assign these permissions to the root user, groups or even to other users using the system.

Read: The read permission grant uses the ability to open and read a file.

Write: Write permission allows a user to open and modify or edit the file's contents and save the changes.

Execute: This allows a user to execute or run the file or a program or shell script which is executable.

Decimal Permission Representation

0 No Permission - - -
1 Execute - - x
2 Write - w -
3 Write + Execute - w x
4 Read r - -
5 Read + Execute r - x
6 Read + Write r w –
7 Read + Write + Execute r w x

58. What basics measures could you take to secure an ssh connection? For Linux users, it is frequent to access servers by ssh. But are we sure that the communication established is really good secured?

Linux has secured shell services used to connect a Linux system in a secured manner. SSH is is the most common tool for a system administrator for better system management and security. SSH gives some advance features that need proper knowledge and expertise to use. SSH gives more features to the user.

Steps to secure ssh services as below:-

1. Disable/enable Root User
2. Reset Root user password
3. Disable password-based login and enable key-based logins
4. Change standard ports of the system and assign random ports
5. Restricted network access from the system
6. Use a white list approach to allow only authorized IPs to connect

59. Describe what happens when you run the rm command?

The rm command removes a filename from a directory list, decrements the link count of the corresponding i-node by 1, and, if the link count thereby falls to 0, deallocates the i-node and the data blocks to which it refers.

60. What is a process?

A process is an instance of an executing program. When a program is executed, the kernel loads the code of the program into virtual memory, allocates space for program variables, and sets up kernel bookkeeping data structures to record various information (such as process ID, termination status, user IDs, and group IDs) about the process. From a kernel point of view, processes are the entities among which the kernel must share the various resources of the computer.

61. What are the logically divided parts of a process?

A process is logically divided into the following parts, known as segments:
* Text: the read-only machine-language instructions of the program run by the process.
* Data: initialized/uninitialized global and static variables used by the program;
* Heap: an area from which memory (for variables) can be dynamically allocated at run time. The top end of the heap is called the program break;
* Stack: a piece of memory that grows and shrinks as functions are called and return and that is used to allocate storage for local variables and function call linkage information;

62. How are threads different from processes?

Like processes, threads are a mechanism that permits an application to perform multiple tasks concurrently. A single process can contain multiple threads. All threads are independently executing the same program, and they all share the same global memory, including the initialized data, uninitialized data, and heap segments.

Sharing information between threads is easy and fast. It is just a matter of copying data into shared (global or heap) variables. However, in order to avoid the problems that can occur when multiple threads try to update the same information, we must employ some synchronization techniques.
Thread creation is faster than process creation—typically, ten times faster or better. On Linux, threads are implemented using the clone() system call.

63.  What is a Signal in Linux, and what signal is invoked when you use the kill command? What is the difference between kill and kill -9?

A. A signal is a limited form of inter-process communication used in Unix, Unix-like, and other POSIX-compliant operating systems. It is an asynchronous notification sent to a process or to a specific thread within the same process in order to notify it of an event that occurred. When a signal is sent, the operating system interrupts the target process's normal flow of execution.

The difference between invoking kill with no signal specified (which uses SIGTERM, number 15) and kill -9 is that the latter tries to kill the process without consideration to open files and resources in use.

64. How do you debug a running process or a library that is being called?

# strace -p PID
# ltrace libraryfile

65. How to see a memory map of a process, along with how much memory a process uses?

# pmap -x PID

66. What is Huge Pages in Linux and what use is there for them?

Hugepages is a mechanism that allows the Linux kernel to utilize the multiple page size capabilities of modern hardware architectures. Linux uses pages as the basic unit of memory, where physical memory is partitioned and accessed using the basic page unit. The default page size is 4096 Bytes in the x86 architecture. Hugepages allows large amounts of memory to be utilized with a reduced overhead.

To check: # cat /proc/sys/vm/nr_hugepages.
To set: # echo 5 > /proc/sys/vm/nr_hugepages

67. What symbol represents that ACLs have been set on a file?

+

68. How would you continuously display memory usage every 5 seconds?

# free -s 5

69. How to stop a running process in Linux?

To stop a running process, use the kill command followed by the PID of the process.

to stop a process with PID 3836, run the command
# kill 3836

70. What is the difference between name based virtual hosting and IP based virtual hosting?

Virtual hosts are used to host multiple domains on a single apache instance. You can have one virtual host for each IP your server has, or the same IP but different ports, or the same IP, the same port but different host names. The latter is called "name based vhosts".

On IP-based virtual hosting, we can run more than one web site on the same server machine, but each web site has its own IP address while In Name-based virtual hosting, we host multiple websites on the same IP address. But for this to succeed, you have to put more than one DNS record for your IP address in the DNS database.

71. What is the advantage of Network Bonding?

Network Bonding(also known as NIC Teaming) is a Linux kernel feature that allows aggregating multiple network interfaces into a single virtual link. This is a great way to achieve redundant links, fault tolerance or load balancing networks in the production system. If one of the physical NIC is down or unplugged, it will automatically move traffic to the other NIC card. Similar way the bonding will increase the interface throughput to handle the traffic it is configured in active-active mode.

72. Where is password file located in Linux and how can you improve the security of password file?

User information along with the passwords in Linux is stored in /etc/passwd that is a compatible format. But this file is used to get the user information by several tools. Here, security is at risk. So, we have to make it secured.
To improve the security of the password file, instead of using a compatible format we can use shadow password format. So, in shadow password format, the password will be stored as single “x” character which is not the same file (/etc/passwd). This information is stored in another file instead with a file name /etc/shadow. So, to enhance the security, the file is made word readable and also, this file is readable only by the root user. Thus security risks are overcome to a great extent by using the shadow password format.

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

/etc/passwd file contains the useful information for all the system users who log in. 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 all the user accounts. There is a single line per user in this file. Colon (:) separates the fields in /etc/passwd. 

Below is the explanation of the fields.

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 the password is encrypted. Here, x character shows that password is encrypted that is located in /etc/shadow file.

User ID (UID): All the users created in Linux is given a user ID whenever the user is created. UID 0 is fixed and reserved for the root user.

Group ID (GID): This field specifies the name of the group to which the 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 extra information 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.

74. What is a Master boot Record and how do you back it up and restore it?

The MBR  is a 512 byte segment on the very first sector of your hard drive composed of three parts: 
 the boot code which is 446 bytes long, 
 the partiton table which is 64 bytes long, and 
 the boot code signature which is 2 bytes long.

To backup: # dd if=/dev/sda of=/tmp/mbr.img_backup bs=512 count=1
To restore: # dd if=/tmp/mbr.img of=/dev/sda bs=512 count=1

75. You are using iSCSI or a virtual machine with attached block device. Due to high IO or network latencies the FS goes in read only mode from time to time. What can you do to increase the write time out on the block device?

To increase the write time out on a block device in real time use the sys fs:
echo 60 > /sys/block/sdk/device/timeout
        
                                                                                           MENU         PREVIOUS | NEXT 

What is Linux shell?


26. What is Linux shell? How to check current shell?

A Linux shell is a command interpreter or a program that accepts commands and passes them to the operating system for execution. To check the shell that you are using, run # echo $0.

27. What command to find memory and swap usage?

# free -m
              total        used        free      shared  buff/cache   available
Mem:            972         347         460           7         164         481
Swap:          2047           0        2047

28. Mention the steps to find out the memory usage by Linux?

# cat /proc/meminfo

When you will enter this command then you will see a list of memory usage like Total Memory, Free Memory, Cache memory, and many other memory usages by Linux. 

Other commands used in 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.

29. How to rename file and directory in Linux?

To rename files, use the mv command. Note that for this to work, the path of the file to be renamed needs to be the same. 

For example, to rename the file file1.doc in /data/files directory to file2.doc 
execute the command: mv /data/files/file1.doc /data/files/file2.doc

30. What is Input/output Redirection?

Directing input & outputs data to and from processes is called Input/Output Redirection. Input / Output redirection is a required feature for good programming and shell scripting. It’s used for taking input and showing results as per requirement. Input from user and passing to other process is called input redirection whereas if process further pass its output to another process or function that will be output redirection for that and input redirection for receiving one.

three redirections available as below: -

Input Redirection: ‘<’ symbol is used for input redirection to the new process.
Output Redirection: ‘>’ symbol is used for output redirection to a new process or log file.
Error Redirection: It is denoted as STDERR(2). This is very useful for error handling.

31. How to copy files and directory in Linux?

To copy files in Linux, use the cp command. The syntax is quite simple
# cp  /source/of/the/file  /destination/of/the/file

32. How to create empty file in Linux?

To create an empty file in Linux, use the touch command as shown:
touch new_file

33. Briefly define ls command and options?

This is one of the most basic and useful commands. This command (“ls”) is used by a normal user or system administrator on a regular basis. This command is used to list down files and directories in the present working directory. 

“ls” Command comes up with multiple options:-

-l This option will show file & directory permissions in rwxrwxrwx format for user, group & others
-a This option allows you to view hidden & system files
-i This option gives you inode details of files
-s Helps you to list down file size

“ls” without any options will list down all files & directories in plain text. This command gives more desired outputs after clubbing it with grep & less command that allows your filter the list or highlights the required file. This command is also compatible with input-output redirection option which is very helpful for logging.

34. What is the difference between ctrl+z and ctrl+c?

When we have a process in progress which handle your prompt, there were some signals (orders) that we can send to theses process to indicate what we need:

Control+C sends SIGINT which interrupts the application. Usually causing it to abort, but a process is able to intercept the signal and do whatever it likes: for instance, from the Bash prompt, try Ctrl-C. In Bash, it cancels whatever you've typed and gives you a blank prompt (as opposed to the quitting Bash)

Control+Z sends SIGTSTP to foreground application, effectively putting in the background on suspended mode. This is very much useful when we want the application to continue its process while we are doing another job in the current shell. When we finish the job, we can go back into the application by running FG (or %x where x is the job number as shown in jobs).

35. How to create files in Linux?

To create files, use the touch command. For example to create a file file1.doc run the command:
# touch file1.doc

Also use cat command followed by the redirection operator or greater than sign >
# cat > file1.doc
Type the file contents and hit CTRL + D

Using the vi command,
# vi file1.doc
Type the file contents and hit ESC and save :wq

36. What is a Socket?

A Socket is a form of Interprocess Communication and Synchronization that can be used to transfer data from one process to another, either on the same host computer or on different hosts connected by a network; Network sockets are identified by source IP address source port and destination IP address and port.

37. What is the difference between the tar, gz, and zip?

Tar & ZIP are two most commonly used utilities in Linux system

TAR is archiver utility which will archive the selected files or directories. Extension of TAR is .tar.

gz is known as gunzip used compress files only. Extension of gz is .gz. You can use gz on TAR to compression directories achieved by TAR.

ZIP is archiver and compression utility for files and directory. Extension of ZIP is .zip.

The benefit of TAR can be applied on directories. Sometimes, you do not want to compress the filer but want to bundle them, TAR is perfect for it. TAR with GZIP is the best combination. Like GZIP, we also have bzip2 which use a completely new algorithm to compress files has given less size in compare to gzip.

38. Briefly explain the process of sending an email?

The basic steps of this process are mentioned below for your convenience.

Step 1: After composing a message and send, your email client - whether it's Outlook Express or Gmail - connect to the domain's SMTP server. This server can name many things; a standard example would be smtp.local.com.

Step 2: In this step, the email client communicates with the SMTP server by giving your email address, the recipient's email address, the message body, and any attachments.

Step 3: Now SMTP server has complete details to processes the recipient's email address - especially its domain. If the domain name is the same as the sender's, the message is routed directly over to the domain's POP3 or IMAP server - no routing between servers needed. If the domain is different, though, the SMTP server will have to communicate with the other domain's server.

Step 4: To deliver email and to find the recipient's server, the sender's SMTP server has to communicate with the DNS or Domain Name Server. The DNS will take the recipient's email domain name and translates this into an IP address. The sender's server cannot route an email properly with a domain name alone; an IP address is a unique number that is assigned to every computer that is connected to the Internet. By knowing information, an outgoing mail server can perform its work more efficiently.

Step 5: Once SMTP server got the recipient's IP address, it can connect to its SMTP server. This isn't done directly, though; instead, the message is routed along with a series of unrelated SMTP servers until it arrives at its destination.

Step 6: The recipient's SMTP server scans the incoming message. If the domain and user name are valid, it forwards the message along to the domain's POP3 or IMAP server. From there, it is placed in a send mail queue until the recipient's email client allows it to download. At that point, the message can read by the recipient.

39. What is the difference between the mail client and the mail server?

Email client primarily is a desktop or mobile application that enables users to receive and send emails directly on the desktop or mobile. Typically, email client requires an email address to be set up, mail server details & connectivity to the mail server to configure and use email service. These configuration and settings include email address, password, POP3/IMAP and SMTP address, port number, email aliases, and other related preferences.

A mail server or an email server is a server that supports email function in network and support clients to handles and delivers e-mail over a network. This can be over intranet or internet. Email server receives emails from client computers and delivers them to other mail servers after proper authentication and authorization. Mail servers use MTA (Mail transfer agent) with SMTP (Simple Mail Transfer Protocol) to support email transmission. You have used any open source free MTA or any paid version the basis of your requirements and security policies.

40. What are network zones?

Network Zone explains the trust level of a network connection. Creating Zones helps in identifying the secure network or unsecured network. This helps Network administrators to plan the level of monitoring for different networks.

The network zone example,

Trusted:                 Fully trusted connections. All the incoming traffic is allowed.
home work internal:         Partly trusted connections. User/administrator defines open services.
DMZ:                 Mostly untrusted connections, the demilitarized zone.
Public external:         Mostly untrusted connections. User/administrator defines the open services.
Block:         Fully untrusted connections. No incoming traffic is allowed.
Drop:         Fully untrusted connections. All packets are dropped immediately.

41. How to check if a particular service in running?

To check if a service is running, use the syntax:
# systemctl status service_name

For instance, to check is Postfix is running, run the command:
# systemctl status postfix

42. How to start a service on reboot?

To start a service on reboot run use the syntax:
# systemctl enable service_name

For example, to start httpd web server upon a reboot, run
# systemctl enable httpd

43. How do you start and stop a service?

To start a service in a systemd system, run the command:
# systemctl start service_name

For example, to start ssh service, run the command:
# systemctl start sshd

To stop the service, run:
# systemctl stop service_name

To stop ssh run:
# systemctl stop sshd

44. How do you check disk usage?

Use the df command to check the space used on your hard drive and the space remaining / free space.
Additionally, use the du command to check usage by specific files and directories.

45. What is initrd image?

The initial RAM disk (initrd) is an initial root file system that is mounted prior to when the real root file system is available. The initrd is bound to the kernel and loaded as part of the kernel boot procedure. The kernel then mounts this initrd as part of the two-stage boot process to load the modules to make the real file systems available and get at the real root file system. Thus initrd image plays a vital role in linux booting process.

46. Explain the terms suid, sgid and sticky bit?

In addition to the basic file permissions in Linux, there are few special permissions that are available for executable files and directories.

SUID: If setuid bit is set, when the file is executed by a user, the process will have the same rights as the owner of the file being executed.

SGID: Same as above, but inherits group privileges of the file on execution, not user privileges. Similar way when you create a file within the directory, it will inherit the group ownership of the directories.

Sticky bit: Sticky bit was used on executables in linux so that they would remain in the memory more time after the initial execution, hoping they would be needed in the near future. But mainly it is on folders, to imply that a file or folder created inside a stickybit enabled folder could only be deleted by the owner. A very good implementation of sticky bit is /tmp , where every user has write permission but only users who own a file can delete them.

47. Which one is the default sticky bit directory?

/tmp

48. Explain /proc filesystem?

/proc is a virtual file system that provides detailed information about the Linux kernel, hardware, and running processes. /prod is a generic file available in all flavors of Linux. Files under /proc directory named as Virtual files. These files are created when the system boots up and dissolve on shutdown. It contains information about running processes and works as an information zone for the kernel.

/proc is also a hidden tool for a system administrator for analyzed and troubleshooting performance and system bottleneck related issues.
These virtual files have unique qualities. Most of them are listed as zero bytes in size as they reside in memory, not on disk. Virtual files such as the /proc/interrupts, /proc/meminfo, /proc/mounts, and the /proc/partitions provide an up-to-the-moment glimpse of system’s hardware. Others: /proc/filesystems file and /proc/sys/ directories provide system configuration information and interfaces. These are tools for a system administrator to troubleshoot and analyze the issues.

49. What are the run levels in linux and how to change them?

A run level is a state of init and the whole system that defines what system services are operating and they are identified by numbers. There are 7 different run levels present (run level 0-6) in a Linux system for the different purpose. 

The descriptions are given below.

0: Halt System (To shutdown the system)
1: Single user mode
2: Basic multi user mode without NFS
3: Full multi user mode (text based)
4: unused
5: Multi user mode with Graphical User Interface
6: Reboot System

To change the run level, edit the file “/etc/inittab” and change initdefault entry ( id:5:initdefault:). If we want to change the run level on the fly, it can be done using ‘init’ command.
For example, when we type ‘init 3' in the command line, this will move the system from current runlevel to runlevl 3. Current level can be listed by typing the command 'who -r'

50. How can multiple machines share a single internet connection in Linux?

Linux machine can be made as a router so that multiple devices can share a single internet connection. For this, we have to use a feature called “IP Masquerade.” This functionality will help to connect multiple computers to connect to the Linux machine as well as internet. This functionality will also allow those internal computers to connect who do not have IP addresses.

                                                                                        MENU       PREVIOUS          NEXT 

300 Linux interview questions and answers


The set of below mentioned 300 Linux interview questions and answers would act as a last minute interview preparation guide for you. These questions are useful for the fresher as well as the experienced candidates.


The answers were curated from multiple sources and one can read more on the web about each topic if they are unfamiliar with it. These questions are not mandatory but just an example of what may come in the interview. Hope they are helpful to you for your interview. The key is not to go in-depth but to explain the concept. Good preparation and a smart approach may help you get through this interview. All the best!!

Ref :-

Who invented Linux?


1. Who invented Linux? Explain the history of Linux?

Linus Torvalds created Linux. He was a student at the University of Helsinki, Finland in 1991. He started writing code on his own to get the academic version of Unix for free. Later on, it became popular as Linux Kernel.

2. What is the Linux Kernel?

A Linux kernel is the core of the Linux system. It interfaces the underlying hardware with the operating system.

3. What are the Linux basic components?

Kernel: This is the core of the Linux system. It's responsible for interacting with the hardware components and ensuring the operating system communicates with hardware devices.

Shell: A shell is an interface between the Linux user and the kernel. 

System libraries: These are special programs or functions which are responsible for implementing a majority of the functionalities of the operating system without relying on the kernel modules code access rights.

System Utilities: These are specific programs that executed certain tasks. e.g LibreOffice, Brasero, Gparted.

4. What is BASH?

Bash is a Unix shell and command processor written by Brian Fox for the GNU project. It is free software and acts as a replacement for Bourne Shell. It is an interpreted and not compiled process which can also be run in the terminal window. This allows users to write commands and cause actions. Bash is capable of reading commands from shell scripts.

5. How many types of Shells are there in Linux?

They are five Shells in Linux:

C Shell (csh): It is like C syntax and provides spelling checking and job control.

Korn Shell (ksh): Is a high-level programming language shell.

Z Shell (Zsh): It provides some unique nature like it observes login/logout watching, file name generating, startup files, closing comments. 

Bourne Again Shell (bash): It is the default to Linux distributions.

Friendly Interactive Shell (Fish): It provides web-based configuration,  auto-suggestions, etc. 

6. Explain Root and it’s significance in the Linux system?

The root is the most privileged account in Linux for the system administrator. The root user has you full access to the system to perform all kind of access. The root is default account of Linux, created with Linux installation only. The root user is also known as the Root account or superuser. Due to uncontrolled access of Root account, this account needs to be secured and used crucially and carefully.

Some of the functions can be performed by the Root account:-

    •  The root can create/delete/ modify any user, user group, files, directory and permissions.
    •  The root can connect by using any user without password
    •  System / Library / function calls
    •  Managing hidden & config files
    •  System administrator commands

7. List down some of major Linux distributions?

Linux is an open-source operating system which allows users to modify kernel as per their requirement. This facilitates the different part of Linux to be deployed, modified and tested by a different organization. This result in multiple flavors of Linux available in the market and each has its own feature.

Major Linux distributions are as below:-

Ubuntu: It’s the most common and well-known distribution. It has lots of free installed apps for user’s easiness. It’s very easy to use and available in the command line and GUI both.

Red Hat Enterprise: Red Hat Enterprise Linux or RHEL is commercial Linux distribution. It stale, tested, user-friendly and most important NOT free to use.

Debian: Debian is one of the fastest and user-friendly Linux version.

Linux Mint: Its a special type of distribution works on the windows system as well. This for beginners to get hands-on the Linux system.

Fedora: Fedora is not in use on high numbers due to less stability. It supports a GNOME3 desktop environment by default.

8. What is the minimum requirement for Linux installation?

With newer Linux distributions being launched every other week or month, there's no clear cut minimum requirement. Newer versions will demand higher minimum requirements than older versions due to revamped GUI features and architecture. Nevertheless, any Linux distribution should work with a PC with the following minimum requirements:
25 GB of hard disk space
2 GB RAM
2 Ghz dual core processor
A screen resolution of 1024x768
A CD/DVD ROM or USB port for inserting installation media

9. Explain Command Line Interface?

Command Line Interface is also known as CLI. This is an interface for users to interact and instruct system in command line fashion. CLI is the basis on text-based interact to accept user request and response. While comparing with GUI, CLI is lightweight and consume less CPU & Memory resources.
considering the GUI of different versions and flavour, User needs to change there way of working and need additional learning. Whereas CLI is independent of this and allows the user to use any Linux system in the same manner. CLI also comes up with help option so that users need not remember all commands and option and they can refer help or man page for details options and definitions.

Advantages

Easy, Fast & Flexible
Very less load on CPU or Memory

Disadvantages

Commands syntax is a bit tricky and tough to learn
Long Text inputs can be problematic
In Compare of GUI, bit tuff to use

10. What is LILO?

LILO is a boot loader for Linux. LILO stands for Linux Loader that is used to load Linux into memory.
It is used mainly to load the Linux operating system into main memory so as to begin operation.

Lilo handles some tasks such as locating the kernel, identifying other supporting programs, load memory and starts the kernel. The configuration file of lilo is located at “/etc/lilo.conf”. Lilo reads this configuration file and it tells Lilo where to place the bootloader.

11. What is GNU project?

The GNU Linux project was created for the development of a Unix-like operating system that comes with source code that can be copied, modified, and redistributed. Richard Stallman announced the GNU Linux project in 1983 and, with others, formed the Free Software Foundation in 1985.

According to the GNU Linux project, there is no independent GNU operating system. Furthermore, they claim that there is no independent Linux operating system either. The OS known as Linux is based on the Linux kernel but all other components are GNU. As such, many believe that the OS should be known as GNU/Linux or GNU Linux.

GNU stands for GNU's not Unix, which makes the term a recursive acronym (an acronym in which one of the letters stands for the acronym itself).

12. Explain the importance of the GNU project?

The GNU project was begun to make a working framework which will be free for clients. The clients would have the opportunity to run, share, circulate, study, change, and enhance or roll out new improvements to the product.

The point of this task was to construct a working framework that is free and furthermore “everything valuable that typically accompanies a UNIX framework so one could get along with no product that isn’t free”.

13. What is the level of Security that Linux provides in comparison to other Operating Systems?

In comparison to other operating systems, Linux is the most secure operating system as it consists of Pluggable Authentication Modules. A secure layer is created between the authentication process and applications. It is because of PAM only by which an admin can give access to other users to log into the system.  You can find the configuration of PAM applications in the “/etc/pam.d” or “/etc/pam.conf” directory.

14. What do you mean by SELinux?

SELinux is the abbreviation for Security Enhanced Linux. It is designed to protect the server against misconfigurations and/or compromised daemons. It is an access control implementation and security feature for the Linux kernel. For example, the users can be stopped from running the scripts and accessing their own home directories. SELinux has the capability to support the access control and 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

15. List the differences between BASH and DOS?

There are many differences between BASH and DOS that are as below:

    •  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 no any file convention used. DOS follows the naming convention under which a file must have an 8-character filename followed by a dot and 3-character extension.

16. What are the different file system types in Linux?

In Linux, there are many file systems:

Ext, Ext2, Ext3, Ext4, JFS, XFS, btrfs, ufs, autofs, devpts, ntfs and swap.

17. What are the different types of Kernels? Explain.

We can build kernels by many different types, but 3 of the types of kernels are most commonly used: monolithic, microkernel and hybrid.

Microkernel: This type of kernel only manages CPU, memory, and IPC. This kind of kernel provides portability, small memory footprint and also security.

Monolithic Kernel: Linux is a monolithic kernel. So, this type of kernel provides file management, system server calls, also manages CPU, IPC as well as device drivers. It provides easier access to the process to communicate and as there is not any queue for processor time, so processes react faster.

Hybrid Kernel: In this type of kernels, programmers can select what they want to run in user mode and what in supervisor mode. So, this kernel provides more flexibility than any other kernel but it can have some latency problems.

18. Explain Linux Boot Sequence?

There are six levels of a Linux Boot Sequence. These are as follows:

BIOS: Full form of BIOS is Basic Input or Output System that performs integrity checks and it will search and load and then it will execute the bootloader.

MBR: MBR means Master Boot Record. MBR contains the information regarding GRUB and executes and loads this bootloader.

GRUB: GRUB means Grand Unified Bootloader. In case, many kernel images are installed on your system then you can select which one you want to execute.

Kernel: Root file system is mounted by Kernel and executes the /sbin/init program.

Init: Init checks the file /etc/inittab and decides the run level. There are seven-run levels available from 0-6. It will identify the default init level and will load the program.

Runlevel programs: As per your default settings for the run level, the system will execute the programs.

19. Explain Interrupts in Linux and also explain Interrupt handlers?

Interrupts means the processor is transferred temporarily to another program or function. When that program is completed, the processor will be given back to that program to complete the task.

Interrupt handler is the function that the kernel runs for a specific interrupt. It is also called Interrupt Service Routine. Interrupts handlers are the function that matches a particular prototype and enables the kernel to pass the handler information accurately.

20. Where the kernel modules are located?

lib/modules/kernel-version/, this directory stores all the information about the compiled drives under the Linux system. Using lsmod command also we can see the installed kernel modules. 

21. Where are the log files stored usually in Linux?

The log files are stored in /var/log.

22. How do you check the boot messages (kernel ring buffer)?

Check the boot messages using # dmesg or # cat /var/log/dmesg.

23. what is kernel ring buffer linux?

A ring buffer is a circular data architecture that is often used to hold data that is produced and exhaust by different processes without synchronization. The information is produced by the kernel foreign of any specific process background, but the customer is in user space. The kernel needs to grip out pages from the head of the ring intermediary to user space for expenditure, while ensuring that it doesn't overwrite that data as it create to the butt of the buffer.

24. How to increase size of ‘kernel ring buffer’ file (dmesg)?

By default the kernel ring buffer size is 512 bytes. So, to increase this space add “log_buf_len=4M” to the kernel stanza in grub.conf file.

25. What is the difference between YUM and rpm?

Rpm: need local rpm file and dependencies.
Yum: need repository (collections of rpm) local or internet.

                                                                                           MENU                  | NEXT

Tuesday, 5 May 2020

A simple animation bash script

Animation bash script

$ cat frame1

    =========
  =                  =
 =      -     -      =
 =         ^         =
 =         -         =
   \_________/
           ##
         ####
        # ## #
           | |
         _| |_

$ cat frame2

    =========
  =                  =
 =      o     o     =
 =         ^         =
 =         -        =
   \_________/
           ##
         ####
        # ## #
           | |
         _| |_

$ cat frame3

    =========
  =                  =
 =      0     0     =
 =         ^         =
 =      @@@      =
   \_________/
           ##
         ####
        # ## #
           | |
         _| |_

$ cat animation.sh
for ((i; i<=10; i++))
do

clear
cat frame1
sleep .5
clear
cat frame2
sleep .1
clear
cat frame3
sleep .5
done

$ chmod +x animation.sh
$ ./animation.sh



Sunday, 3 May 2020

Bash scrip to check internet speed frequently in Linux

Check internet speed frequently

$ crontab -l
   # set frequency
   20,50 * * * * sh /usr/local/src/internet_speed_test.sh

$ vim internet_speed.sh
   #!/bin/bash
   # run python to get speed
   python speedtest.py > /var/log/speed_test.log

   # process speed_test.log file
   date=$(date "+%d %B %Y %H:%M")
   echo -n "$date" >> /var/log/speed.log
 
   while IFS= read -r line
   do
     if [[ "$line" == *"Download"* ]] || [[ \n\t"$line" == *"Upload"* ]] ; then
           echo -n  '   ' "$line" >> /var/log/speed.log
     fi
   done < /var/log/speed_test.log
 
   echo -e "\n" >> /var/log/speed.log'

$ tail -f /var/log/speed.log
   03 May 2020 18:05    Download: 9.40 Mbit/s    Upload: 6.34 Mbit/s
   03 May 2020 18:22    Download: 11.34 Mbit/s    Upload: 6.12 Mbit/s

Friday, 1 May 2020

Internet Speed Test in Linux Terminal

speedtest using python and fast

  python
$ python3 --version
  Python 3.8.2
$ cat /etc/redhat-release
  CentOS Linux release 7.7.1908 (Core)

$ git clone https://github.com/jpmolekunnel/Speed.git
$ cd Speed/
$ python speedtest.py
  Retrieving speedtest.net configuration...
  Testing from Comcast Cable (71.214.251.133)...
  Retrieving speedtest.net server list...
  Selecting best server based on ping...
  Hosted by Sprint (Fairfax, SC) [114.89 km]: 75.946 ms
  Testing download speed................................................................................
  Download: 8.19 Mbit/s
  Testing upload speed.....................................................................................................
  .Upload: 5.94 Mbit/s

  fast
$ wget https://github.com/ddo/fast/releases/download/v0.0.4/fast_linux_amd64 -O fast
$ chmod +x fast
$ ./fast
   -> 11.64 Mbps

Ref:- addictivetips.com tecmint.com