Complete List of Linux Interview Questions and Answers 2018
Linux interview questions and answers from troubleshooting, advanced, technical and SySAdmin levels including real time scenario topics to get that job.
Unix Interview Questions
What is the important aspect of a System Administrator Account?
Basically the root account have full unrestricted access in the system, for example, a root account can remove, add, or recover critical system files.
What are some mostly used System Tools?
Most admins have their different idea and implementation of tool, but if i look at overall usage, the System Tools are rsync, sar, iostat, setfacl, getfacl, curl and wget, iptables and who.
What you need to understand about the Shell?
i have to figure out how it passes the arguments, expands wildcards, and a session.
What are the different types of shells in Linux Distributions?
They are Bourne Shell, it was written by Stephen Bourne, it has a program name ‘sh’ which is located at /bin/sh and C shell, it was developed by Bill Joy, it has many interactive commands.
What is SWAP Partition?
Swap is like a “seperate Ram memory”, located on the disk, if the the system uses total RAM memory, then the SWAP space is used.
linux operating system interview questions
What are different Backup Techniques?
tar, cpio, mksysb and ufsdump
What is an INODE?
It is a data structure in unix file system, where all files have their description stored in a structure called ‘inode’. The inode usually contains the file-size, modification time, permission and more. This is basically the information of a file.
What is a Zombie?
Zombies are the premature process, whose mature parent process died with out retrieving its children. These processes cannot be killed by normal “kill” command.
Explain LVM?
Logical Volume Manage is used to mange the disk drives, and this enables the disk to be added or replaced without depending on the system downtime. Also we need LVM to resize the filesystem’s size.
What is Network Bonding?
Network Bonding is sorting of multiple LAN cards into a single bonded interface to produce high perforamnce and fault tolerance. It is also called as NIC Teaming.
How to upgrade kernal in Linux?
This process is not recommended, because upgrading the Kernal may cause boot problems to your Linux, instead you can install a new kernel using rpm command.
What is Puppet Server?
Puppet is a open-source, enterprise & IT automation software used to push configuration to its clients using puppet codes. It can do various tasks like checking file permissions, installing new softwares, updating accounts and more.
What is MX Record?
linux commands interview questions
What are the different modes of Network Bonding?
The binding supports 7 possible modes, they are
- Mode 0 (balance-rr):
This mode transmits packets in a sequential order from the first available slave through the last. - Mode 1 (active-backup)
This mode places one of the interfaces into a backup state and will only make it active if the link is lost by the active interface. - Mode 2 (balance-xor)
Transmits based on XOR formula. modula slave count. This selects the same slave for each destination MAC address and provides load balancing and fault tolerance. - Mode 3 (broadcast)
This mode transmits everything on all slave interfaces. This mode is least used and provides only fault tolerance. - Mode 4 (802.3ad)
This mode is known as Dynamic Link Aggregation mode. It creates aggregation groups that share the same speed and duplex settings. This mode requires a switch that supports IEEE 802.3ad Dynamic link. Slave selection for outgoing traffic is done according to the transmit hash policy, which may be changed from the default simple XOR policy via the xmit_hash_policy option. Note that not all transmit policies may be 802.3ad compliant, particularly inregards to the packet mis-ordering requirements of section 43.2.4 of the 802.3ad standard. - Mode 5 (balance-tlb)
This is called as Adaptive transmit load balancing. The outgoing traffic is distributed according to the current load and queue on each slave interface. Incoming traffic is received by the current slave. - Mode 6 (balance-alb)
This is Adaptive load balancing mode. This includes balance-tlb + receive load balancing (rlb) for IPV4 traffic. The receive load balancing is achieved by ARP negotiation.
What is the difference between Telnet and SSH?
what are the process states in Linux?
What are the two main MySQL storage engines, and how they differ?
What is the difference between Active and Passive FTP Sessions?
Active FTP | Passive FTP |
command channel : client port above1023 connects to server port 21 | command channel: client port above 1023 connects to server port 21 |
data channel: client port above 1023 is connected from server port 20 | data channel: client port above 1023 connects to server port above 1023 |
How you craft custom packets like TCP SYN and send them to remote host?
How do you pin a process to a specific CPU?
How to see a memory map of process with it’s memory usage?
what is the location of system configuration files?
what command is used to kill all instances of WebServer?
What is SeLinux?
Linux Log File Interview Questions And Answers
How do I view log files on Linux?
Open the Terminal or login as root user using ssh command. Go to /var/log directory using the following cd command:
# cd /var/log
To list files use the following ls command:
# ls
To view a common log file called /var/log/messages use any one of the following command:
# less /var/log/messages
# more -f /var/log/messages
# cat /var/log/messages
# tail -f /var/log/messages
# grep -i error /var/log/messages
What are Common Linux log files names and usage?
- /var/log/messages : General message and system related stuff
- /var/log/auth.log : Authenication logs
- /var/log/kern.log : Kernel logs
- /var/log/cron.log : Crond logs (cron job)
- /var/log/maillog : Mail server logs
- /var/log/qmail/ : Qmail log directory (more files inside this directory)
- /var/log/httpd/ : Apache access and error logs directory
- /var/log/lighttpd/ : Lighttpd access and error logs directory
- /var/log/boot.log : System boot log
- /var/log/mysqld.log : MySQL database server log file
- /var/log/secure or /var/log/auth.log : Authentication log
- /var/log/utmp or /var/log/wtmp : Login records file
- /var/log/yum.log : Yum command log file.
What is the GUI tool to view log files on Linux?
System Log Viewer is a graphical, menu-driven viewer that you can use to view and monitor your system logs. This tool is only useful on your Linux powered laptop or desktop system. Most server do not have X Window system installed. You can start System Log Viewer in the following ways:
Click on System menu > Choose Administration > System Log:
Linux System Admin Interview Questions And Answers
What Squid service do?
What is MTA?
Which ip address you should use for server?
What is the default Virtualization technology for RHEL6?
netstat -ar
what is daemon responsible for tracking events in a server?
syslogd
What is the difference between raid 0 and raid 1?
Raid 0, no redundancy
Raid 1, redundancy
What is ‘0’ procsee?
parent process id of ‘init’
How to dislay memory info?
cat /proc/meminfo
how to roll back application?
insert ‘ts_flags=repackage’ in /etc/yum.conf and create file /etc/rpm/macros with an entry’repackage’ parameter.
How to check which ports are working?
netstat cmd
What is GRUB?
Grand Unified Boot loader, it is a boot loader in Linux.
linux interview questions for experienced
How to check if an user account has been locked?
ANS:- Run the command “passwd -S <UserName>”, this would show if the password has been locked or not. Otherwise, grep for the username from /etc/shadow file and you could see “!” mark prefixed to the encrypted password field.
[root@server6 ~]# passwd -S smurthy
smurthy LK 1970-01-01 0 99999 7 -1 (Password locked.)
[root@server6 ~]# grep smurthy /etc/shadow
smurthy:!!$6$jZqvS4ju$k.o6o7OoL7EZ1Bn52uPKeI2gqA76A7qyTl2PM8192jF2mz4ssVTz/u8DfbY2zJ7xCjFymh5FuATWxW5RxFugM1:0:0:99999:7:::
If you notice a double exclamation mark here (“!!”) this indicates that the account got locked-up by running the command “passwd -l <UserName>” command (available only for root user). Otherwise, a single exclamation mark indicates that the account got locked with the command “usermod -L <UserName>”. Accounts locked with usermod command would record it in /var/log/secure file by default.
To “unlock” an user account, run this command “passwd -u <UserName”>. Otherwise, run “usermod -U <UserName” command twice to get rid off double exclamation marks in the encrypted password field.
Otherwise, “usermod -U <UserName” would unlock an account locked by the “usermod -L <UserName>” command.
EXAMPLE:-
[root@server6 ~]# grep smurthy /etc/shadow
smurthy:!!$6$jZqvS4ju$k.o6o7OoL7EZ1Bn52uPKeI2gqA76A7qyTl2PM8192jF2mz4ssVTz/u8DfbY2zJ7xCjFymh5FuATWxW5RxFugM1:0:0:99999:7:::
[root@server6 ~]# passwd -S smurthy
smurthy LK 1970-01-01 0 99999 7 -1 (Password locked.)
[root@server6 ~]# passwd -u smurthy
Unlocking password for user smurthy.
passwd: Success
[root@server6 ~]# grep smurthy /etc/shadow
smurthy:$6$jZqvS4ju$k.o6o7OoL7EZ1Bn52uPKeI2gqA76A7qyTl2PM8192jF2mz4ssVTz/u8DfbY2zJ7xCjFymh5FuATWxW5RxFugM1:0:0:99999:7:::
[root@server6 ~]# passwd -S smurthy
smurthy PS 1970-01-01 0 99999 7 -1 (Password set, SHA512 crypt.)
How to find out the shadow password encryption method being used in Linux? How could this be changed (example : from md5 to sha512)?
ANS:- We can find out the password encryption method being used for shadow passwords as shown below:
– Check in /etc/login.defs
[root@server8 ~]# grep -i crypt /etc/login.defs
# Use SHA512 to encrypt password.
ENCRYPT_METHOD MD5
MD5_CRYPT_ENAB yes
OR
– Check using “authconfig” command:
[root@server8 ~]# authconfig –test|grep hashing
password hashing algorithm is md5
OR
– Check the password beginning character in the second field of /etc/shadow file:
If it begins with = $6 > indicates sha512
$5 > sha256
$1 > md5
Examples:
ty2:$6$EyoeIHFK$L2PAXcXRo.Q5Y7zUweYkste8PtiL/CqYJ9Z/ydBvRIOqvsegpVtOU1hDfkFdUpTcmjEou4kzL/Ej5MF2HdAB7.:16378:3:100:7::16489:
ty3:$5$Bsv43yG6$/Oa4fhlKF65XW8ROohKnJaSxVIIEhUKFUEdiIcOEfY4:16378:0:99999:7:::
ty5:$1$5J4jzULD$dKGfhSIzXp50Y4mwZxcqB/:16379:0:99999:7:::
To Change Password Encryption Method to sha512:
#authconfig –passalgo=sha512 –update {this would change the password encryption method to sha512}
Verify if it got changed successfully:
[root@server8 ~]# grep -i crypt /etc/login.defs
# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512
MD5_CRYPT_ENAB no
[root@server8 ~]# authconfig –test|grep hashing
password hashing algorithm is sha512
What are the possible causes when an user failed to login into a Linux system (physical/remote console); despite providing proper credentials?
ANS:- Here are the possible reasons why an user fails to login into console:
– Account Locked.
When user tries to login via GUI receive an error “authentication failure” after entering password and it goes back to the user list prompt.
In CLI mode, after entering user password, it would fail with an error “incorrect password”. However, if user tries “su” from root account, access would get granted.
– Account Expired.
When account expired, an error notifying about the same would be shown up.
– Shell Disabled
After entering password in GUI, system shows a progress, however, could come back the login prompt. When this user attempts login via CLI, would receive an error “This account is currently not available”. For example, do disable shell of an user “test” : #usermod -s /sbin/nologin test (this only locks only terminal login, however, GUI login would work)
– Only Non-root Users Failed To Login.
If all non-root users are unable to login via GUI/CLI, however, root could login then this could be because of the file “/etc/nologin” presence on the system.
– Only Non-root Users Failed To Login in CLI.
If all non-root users are unable to login via CLI, however, can login via GUI then it would be because of /tmp space limitations. Need to check if /tmp is configured and mounted separately and check free space under /tmp.
– User login failed from GUI or from text console, however, could do su.
If an user fails to login from GUI/Console, however, could login from other user accounts by running ‘su’ then it could be due to pam restrictions. One could use “pam_access” module to restrict login. Need to add :
account required pam _access.so
to files : /etc/pam.d/login & /etc/pam.d/gdm-*
After this add ” – : <UserName> : ALL ” to /etc/security/access.conf file. For example to limit user “test”, we could add below line to access.conf file;
– : test : ALL
{{ there would an error “permission denied” in GUI when user is restricted to login via pam}}
– Only root user login failed from console, however, works in GUI.
This could be because of no terminals available or defined in /etc/securetty file.
If an user failed to login remotely via ssh then the reasons could be different. Here are the reasons:
– User Restricted.
If “AllowUsers” parameter is configured in /etc/ssh/sshd_config then need to add required user to this list to get access.
– Max Logins Set.
If “maxlogins” parameter is set in /etc/security/limits.conf then user would be allowed up to the parameter set and further connections would be denied. There could be “maxsyslogins” configured as well to limit concurrent access to a system.
How to manually add user without using “useradd/adduser” or “system-config-user” utilities?
ANS: Create required directory under /home (default home directory for all local users) and set permissions.
#mkdir /home/user1
#chmod 700 /home/user1
[root@host1 mail]# ls -ld /home/user1
drwx——. 4 user1 user1 4096 Jan 24 07:19 /home/user1
<> Now, edit /etc/passwd file to manually set required parameters for the new user “user1”:
#vipw (this command would block multiple edits of /etc/passwd file)
user1:x:2000:2000:local user:/home/user1:/bin/bash
[root@host1 ~]# grep user1 /etc/passwd
user1:x:2000:2000:local user:/home/user1:/bin/bash
<> Create required group by editing /etc/group file using command ‘vigr’:
#vigr
user1:x:2000:
<> Next step is to create the local profile files for the new user by copying from /etc/skel.
[root@host1 ~]# cp -arv /etc/skel/. /home/user1
`/etc/skel/./.bash_profile’ -> `/home/user1/./.bash_profile’
`/etc/skel/./.bash_logout’ -> `/home/user1/./.bash_logout’
`/etc/skel/./.mozilla’ -> `/home/user1/./.mozilla’
`/etc/skel/./.mozilla/extensions’ -> `/home/user1/./.mozilla/extensions’
`/etc/skel/./.mozilla/plugins’ -> `/home/user1/./.mozilla/plugins’
`/etc/skel/./.gnome2′ -> `/home/user1/./.gnome2′
`/etc/skel/./.bashrc’ -> `/home/user1/./.bashrc’
<> Change permissions of all the files under /home/user1 to be owned by new user:
#chown -R user1:user1 /home/user1
– Try logging in as new user and test.
For user mail requirement, need to create a proper file under /var/spool/mail (default mail box location) with username and permissions:
#cd /var/spool/mail
#touch user1
#chown user1:mail user1
#chmod 660 user1
linux technical interview questions
it is used to halt/shutdown system
How do you kill program using one port in Linux?
A. Use this command to kills the program using one port: sudo fuser -k 8000/tcp
How do you limit memory usage for commands?
A. ulimit -Sv 1000 # 1000 KBs = 1 MB
ulimit -Sv unlimited # Remove limit
How do you get full path of a file in Linux?
Use this command: readlink -f file.txt
How do you list contents of tar.gz and extract only one file?
Use these commands:
- tar tf file.tgz
- tar xf file.tgz filename
How do you find who is logged in?
Use this command to find who logged in: w
How do you check permissions of each directory to a file?
It is useful to detect permissions errors, for example when configuring a web server.
namei -l /path/to/file.txt
How do you run command every time a file is modified?
A. Use this command to do:
while inotifywait -e close_write document.tex
do
make
done
How to copy text to clipboard?
A. Use this command: cat file.txt | xclip -selection clipboard
How do you check resources usage?
A. Use this command to check resource usage: /usr/bin/time -v ls
How do you run a command for a limited time?
A. Use this command: timeout 10s ./script.sh
# Restart every 30 minutes
while true; do timeout 30m ./script.sh; done
How do you combine two lines from two sorted files in Linux?
A. Use this command: comm file1 file2.
List of Other Best Linux Courses:
Red Hat Certified Engineer | Linux Security Fundamentals |
Linux Networking | Linux Administration |
Linux Cluster | IBM LinuxONE |
Linux Shell Scripting Interview Questions And Answers
In the shell scripting interview questions, the interviewer may ask you the questions regarding the usage of shell script in the terminal. Regarding the syntax of declaring variables, performing arithmetic operations etc
How compare the strings in shell script ?
Ans: test command is used to compare the text strings. The test command compares text strings by comparing each character in each string.
What are the Special Variables set by Bourne shell for command line arguments ?
Ans: The following table lists the special variables set by the Bourne shell for command line arguments.
Special Variables | Holds |
$0 |
Name of the Script from the command line
|
$2 |
First Command-line argument
|
$9 | Ninth Command line argument |
$# | Number of Command line arguments |
$* | All Command-line arguments, separated with spaces |
How to test files in a shell script ?
Ans: test command is used to perform different test on the files. Basic test are listed below :
Test | Usage |
-d file_name | Returns true if the file exists and is a directory |
-e file_name | Returns true if the file exists |
-f file_name | Returns true if the file exists and is a regular file |
-r file_name | Returns true if the file exists and have read permissions |
-s file_name | Returns true if the file exists and is not empty |
-w file_name | Returns true if the file exists and have write permissions |
-x file_name | Returns true if the file exists and have execute permissions |
How to put comments in your shell script ?
Ans: Comments are the messages to yourself and for other users that describe what a script is supposed to do and how its works.To put comments in your script, start each comment line with a hash sign (#) . Example is shown below :
#!/bin/bash
# This is a command
echo “I am logged in as $USER”
shell scripting interview questions
check out a short video of the shell scripting interview questions:
How to get input from the terminal for shell script ?
Ans: ‘read’ command reads in data from the terminal (using keyboard). The read command takes in whatever the user types and places the text into the variable you name. Example is shown below :
# vi /tmp/test.sh
#!/bin/bash
echo ‘Please enter your name’
read name
echo “My Name is $name”
# ./test.sh
Please enter your name
LinuxTechi
My Name is LinuxTechi
How to unset or de-assign variables ?
Ans: ‘unset’ command is used to de-assign or unset a variable. Syntax is shown below :
# unset <Name_of_Variable>
How to perform arithmetic operation ?
Ans: There are two ways to perform arithmetic operations :
1. Using expr command (# expr 5 + 2 )
2. using a dollar sign and square brackets ( $[ operation ] ) Example : test=$[16 + 4] ; test=$[16 + 4]
Basic Syntax of do-while statement ?
Ans: The do-while statement is similar to the while statement but performs the statements before checking the condition statement. The following is the format for the do-while statement:
do
{
statements
} while (condition)
How to define functions in shell scripting ?
Ans: A function is simply a block of of code with a name. When we give a name to a block of code, we can then call that name in our script, and that block will be executed. Example is shown below :
$ diskusage () { df -h ; }
How to use bc (bash calculator) in a shell script ?
Ans: Use the below Syntax to use bc in shell script.
variable=`echo “options; expression” | bc`
How to make a shell script executable ?
Ans: Using the chmod command we can make a shell script executable. Example is shown below :
# chmod a+x myscript.sh
What is the use of “#!/bin/bash” ?
Ans: #!/bin/bash is the first of a shell script , known as shebang , where # symbol is called hash and ‘!’ is called as bang. It shows that command to be executed via /bin/bash.
What is the syntax of for loop in shell script ?
Ans: Basic Syntax of for loop is given below :
for variables in list_of_items
do
command1
command2
….
last_command
done
How to debug a shell script ?
Ans: A shell script can be debug if we execute the script with ‘-x’ option ( sh -x myscript.sh). Another way to debug a shell script is by using ‘-nv’ option ( sh -nv myscript.sh).
How compare the strings in shell script ?
Ans: test command is used to compare the text strings. The test command compares text strings by comparing each character in each string.
puppet interview questions
Check out a short Video of Puppet Interview Questions
What is Puppet ?
Puppet is a configuration Tool which is use to automate administration tasks.Puppet Agent(Client) sends request to Puppet Master (Server) and Puppet Master Push Configuration on Agent.
What is Manifests ?
Manifests, in Puppet, are the files in which the client configuration is specified.
What is Module and How it is different from Manifest ?
Whatever the manifests we defined in modules, can call or include into other manifests. Which makes easier management of Manifests.It helps you to push specific manifests on specific Node or Agent.
Command to check requests of Certificates ?
puppetca –list (2.6)
puppet ca list (3.0)
Command to sign Requested Certificates
puppetca –sign hostname-of-agent (2.6)
puppet ca sign hostname-of-agent (3.0)
Where Puppet Master Stores Certificates
/var/lib/puppet/ssl/ca/signed
What is Facter ?
Sometime you need to write manifests on conditional experession based on agent specific data which is available through Facter. Facter provides information like Kernel version,Dist release, IP Address, CPU info and etc.You can defined your facter also.
What is the use of etckeeper-commit-post and etckeeper-commit-pre on Puppet Agent ?
etckeeper-commit-post: In this configuration file you can define command and scripts which executes after pushing configuration on Agent
Etckeeper-commit-pre: In this configuration file you can define command and scripts which executes before pushing configuration on Agent
What is Puppet Kick ?
By default Puppet Agent request to Puppet Master after a periodic time which known as “runinterval”. Puppet Kick is a utility which allows you to trigger Puppet Agent from Puppet Master.
What is MCollective ?
MCollective is a powerful orchestration framework. Run actions on thousands of servers simultaneously, using existing plugins or writing your own.
Use this Linux interview questions and answers guide before you attend for an interview for best results, for your next dream job as Linux System Administrator.
4 thoughts on “Top Linux Interview Questions and Answers [UPDATED] 2018”
Wow. That is so elegant and logical and clearly explained. Brilliantly goes through what could be a complex process and makes it obvious.
great blog and thanks for sharing the post
thank you for sharing this post and this is the more useful and important blog for whoever preparing for linux system administrator jobs.