Thursday, 21 September 2017

Basic Linux Interview Question

Q.1: What is the core of Linux Operating System?

Shell
Kernel
Command
Script
Terminal
Answer : Kernel is the core of Linux Operating System. Shell is a command Line Interpreter, Command is user Instruction to Computer, Script is collection of commands stored in a file and Terminal is a command Line Interface
Q.2: What Linus Torvalds Created?

Fedora
Slackware
Debian
Gentoo
Linux
Answer : Linux Torvalds created Linux, which is the kernel (heart) of all of the above Operating System and all other Linux Operating System.
Q.3: Torvalds, Wrote most of the Linux Kernel in C++ programming Language, do you agree?

Answer : No! Linux Kernel contains 12,020,528 Lines of codes out of which 2,151,595 Lines are comments. So remaining 9,868,933 lines are codes and out of 9,868,933 Lines of codes 7,896,318 are written in C Programming Language.
The remaining Lines of code 1,972,615 is written in C++, Assembly, Perl, Shell Script, Python, Bash Script, HTML, awk, yacc, lex, sed, etc.



Note : The Number of Lines of codes varies on daily basis and an average of more than 3,509 lines are being added to Kernel.

Q.4: Linux initially was developed for intel X86 architecture but has been ported to other hardware platform than any other Operating System. Do you agree?.

Answer : Yes, I do agree. Linux was written for x86 machine, and has been ported to all kind of platform. Today’s more than 90% of supercomputers are using Linux. Linux made a very promising future in mobile phone, Tablets. In-fact we are surrounded by Linux in remote controls, space science, Research, Web, Desktop Computing. The list is endless.
Q.5: Is it legal to edit Linux Kernel?

Answer : Yes, Kernel is released under General Public Licence (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).
Q.6: What is the basic difference between UNIX and Linux Operating System.

Answer : Linux Operating System is Free and Open Source Software, the kernel of which is created by Linus Torvalds and community. Well you can not say UNIX Operating System doesn’t comes under the category of Free and Open Source Software, BSD, is a variant of UNIX which comes under the category of FOSS. Moreover Big companies like Apple, IBM, Oracle, HP, etc. are contributing to UNIX Kernel.
Q. 7: Choose the odd one out.

HP-UX
AIX
OSX
Slackware
Solaris
Answer : Slackware is the odd in the above list. HP-UX, AIX, OSX, Solaris are developed by HP, IBM, APPLE, Oracle respectively and all are UNIX variant. Slackware is a Linux Operating System.
Q.8: Is Linux Operating system Virus free?

Answer : No! There doesn’t exist any Operating System on this earth that is virus free. However Linux is known to have least number of Viruses, till date, yes even less than UNIX OS. Linux has had about 60-100 viruses listed till date. None of them actively spreading nowadays. A rough estimate of UNIX viruses is between 85 -120 viruses reported till date.
Q.9: Linux is which kind of Operating System?

Multi User
Multi Tasking
Multi Process
All of the above
None of the above
Answer : All of the Above. Linux is an Operating System which supports Multi User, Running a Number of Processes performing different tasks simultaneously.
Q.10: Syntax of any Linux command is:

command [options] [arguments]
command options [arguments]
command [options] [arguments]
command options arguments
Answer : The correct Syntax of Linux Command is Command [options] [arguments].
Q.11: Choose the odd one out.

Vi
vim
cd
nano
Answer : The odd one in the above list is cd. Vi, vim and nano are editors which is useful in editing files, while cd command is used for changing directory.
That’s all for now. How much you learned for the above questions? How it helped you in your Interview? We would like to hear all these from you in our comment section. Wait till the next weekend, for new set of questions. Till then stay healthy, tuned and connected to Tecmint.

Apache Interview Questions

Apache Interview Questions
Apache Job Interview Questions
In this section, we have covered some interesting 25 Apache Job Interview Questions along with their answers so that you can easily understand some new things about Apache that you might never known before.

Before you read this article, We strongly recommend you to don’t try to memorize the answers, always first try to understand the scenarios on a practical basis.

1. What is Apache web server?

Answer : Apache web server HTTP is a most popular, powerful and Open Source to host websites on the web server by serving web files on the networks. It works on HTTP as in Hypertext Transfer protocol, which provides a standard for servers and client side web browsers to communicate. It supports SSL, CGI files, Virtual hosting and many other features.
2. How to check Apache and it’s version?

Answer : First, use the rpm command to check whether Apache installed or not. If it’s installed, then use httpd -v command to check its version.
[root@tecmint ~]# rpm -qa | grep httpd
httpd-devel-2.2.15-29.el6.centos.i686
httpd-2.2.15-29.el6.centos.i686
httpd-tools-2.2.15-29.el6.centos.i686
[root@tecmint ~]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Aug 13 2013 17:27:11
3. Apache runs as which user? and location of main config file?.

Answer : Apache runs with the user “nobody” and httpd daemon. Apache main configuration file: /etc/httpd/conf/httpd.conf (CentOS/RHEL/Fedora) and /etc/apache2.conf (Ubuntu/Debian).
4. On which port Apache listens http and https both?

Answer : By default Apache runs on http port 80 and https port 443 (for SSL certificate). You can also use netstat command to check ports.
[root@tecmint ~]# netstat -antp | grep http
tcp        0      0 :::80                       :::*                        LISTEN      1076/httpd        
tcp        0      0 :::443                      :::*                        LISTEN      1076/httpd
5. How do you install Apache Server on your Linux machine?

Answer : Simply, you can use any package installer such as yum on (RHEL/CentOS/Fedora) and apt-get on (Debian/Ubuntu) to install Apache server on your Linux machine.
[root@tecmint ~]# yum install httpd
[root@tecmint ~]# apt-get install apache2
6. Where you can find all configuration directories of Apache Web Server?

Answer : By default Apache configuration directories installed under /etc/httpd/ on (RHEL/CentOS/Fedora) and /etc/apache2 on (Debian/Ubuntu).
[root@tecmint ~]# cd /etc/httpd/
[root@tecmint httpd]# ls -l
total 8
drwxr-xr-x. 2 root root 4096 Dec 24 21:44 conf
drwxr-xr-x. 2 root root 4096 Dec 25 02:09 conf.d
lrwxrwxrwx  1 root root   19 Oct 13 19:06 logs -> ../../var/log/httpd
lrwxrwxrwx  1 root root   27 Oct 13 19:06 modules -> ../../usr/lib/httpd/modules
lrwxrwxrwx  1 root root   19 Oct 13 19:06 run -> ../../var/run/httpd
[root@tecmint ~]# cd /etc/apache2
[root@tecmint apache2]# ls -l
total 84
-rw-r--r-- 1 root root  7113 Jul 24 16:15 apache2.conf
drwxr-xr-x 2 root root  4096 Dec 16 11:48 conf-available
drwxr-xr-x 2 root root  4096 Dec 16 11:45 conf.d
drwxr-xr-x 2 root root  4096 Dec 16 11:48 conf-enabled
-rw-r--r-- 1 root root  1782 Jul 21 02:14 envvars
-rw-r--r-- 1 root root 31063 Jul 21 02:14 magic
drwxr-xr-x 2 root root 12288 Dec 16 11:48 mods-available
drwxr-xr-x 2 root root  4096 Dec 16 11:48 mods-enabled
-rw-r--r-- 1 root root   315 Jul 21 02:14 ports.conf
drwxr-xr-x 2 root root  4096 Dec 16 11:48 sites-available
drwxr-xr-x 2 root root  4096 Dec  6 00:04 sites-enabled
7. Can Apache be secured with TCP wrappers?

Answer : No, It can’t be secured with the TCP wrappers since it doesn’t support libwrap.a library of Linux.
8. How to change default Apache Port and How Listen Directive works in Apache?

Answer : There is a directive “Listen” in httpd.conf file which allows us to change the default Apache port. With the help of Listen directive we can make Apache listen on different port as well as different interfaces.


Suppose you have multiple IPs assigned to your Linux machine and want Apache to receive HTTP requests on a special Ethernet port or Interface, even that can be done with Listen directive.

To change the Apache default port, please open your Apache main configuration file httpd.conf or apache2.conf file with VI editor.

[root@tecmint ~]# vi /etc/httpd/conf/httpd.conf
[root@tecmint ~]# vi /etc/apache2/apache2.conf
Search for the word ”Listen”, comment the original line and write your own directive below that line.

# Listen 80
Listen 8080
OR
Listen 172.16.16.1:8080
Save the file and restart the web server.

[root@tecmint ~]# service httpd restart
[root@tecmint ~]# service apache2 restart
9. Can we have two Apache Web servers on a single machine?

Answer : Yes, we can run two different Apache servers at one time on a Linux machine, but the condition for that is they should listen on different ports and we can change the ports with Listen directive of Apache.
10. What do you mean by DocumentRoot of Apache?

Answer : DocumentRoot in Apache means, it’s the location of web files are stored in the server, the default DocumentRoot of Apache is /var/www/html or /var/www. This can be changed to anything, by setting up “DocumentRoot” in a virtual host of configuration file of domain.
11. How to host files in different folder and what is Alias directive?

Answer : Yes, this can be achieved by Alias directive in the main Apache configuration file. Alias directive maps resources in File system, it takes a URL path and substitute it with a file or directory path on the system with is set up to redirect.
To use Alias directive, Its the part of mod_alias module of Apache. The default syntax of Alias directive is:

Alias /images /var/data/images/
Here in above example, /images url prefix to the /var/data/images prefix that mean clients will query for “http://www.example.com/images/sample-image.png” and Apache will pick up the “sample-image.png” file from /var/data/images/sample-image.png on the server. It’s also known as URL Mapping.

12. What do you understand by “DirectoryIndex”?

Answer : DirectoryIndex is the name of first file which Apache looks for when a request comes from a domain. For example: www.example.com is requested by the client, so Apache will go the document root of that website and looks for the index file (first file to display).
The default setting of DirectoryIndex is .html index.html index.php, if you have different names of your first file, you need to make the changes in httpd.conf or apache2.conf for DirectoryIndex value to display that to your client browser.

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents.  The MultiViews Option can be used for the
# same purpose, but it is much slower.
#
DirectoryIndex index.html index.html.var index.cgi .exe
13. How to disable Directory listing when an index file is missing?

Answer : If, the main index file is missing in the website root directory, then the Apache will lists all the contents like files and folder of the website on the browser instead of Main website pages.
To stop Apache directory listing, you can set the following rule in the main configuration file globally or in .htaccess file for a particular website.

<Directory /var/www/html>
Options -Indexes
</Directory>
14. What are different log files of Apache Web Server?

Answer : The default log files of Apache Web Server are access log “/var/log/httpd/access_log” and error log :/var/log/httpd/error_log”.
15. What do you understand by “connection reset by peer” in error logs?

Answer : When the server is serving any ongoing Apache request and end user terminates the connection in between, we see “connection reset by peer” in the Apache error logs.
16. What is Virtual Host in Apache?

Answer : The Virtual Host section contains the information like Website name, Document root, Directory Index, Server Admin Email, ErrorLog File location etc.
You are free to add as many directives you require for your domain, but the two minimal entries for a working website is the ServerName and DocumentRoot. We usually define our Virtual Host section at the bottom of httpd.conf file in Linux machines.

Sample VirtualHost

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>
ServerAdmin : Its usually the email address of the website owner, where the error or notification can be sent.
DocumentRoot : location where the web files are located in the server(Necessary).
ServerName : Its the domain name which you want to access from your web browser(Necessary).
ErrorLog : Its the location of the log file where all the domain related logs are being recorded.
17. What’s the difference between <Location> and <Directory>?

Answer :
<Location> is used to set element related to the URL / address bar of the web server.
<Directory> refers that the location of file system object on the server
18. What is Apache Virtual Hosting?

Answer : Apache Virtual hosting is the concept of hosting multiple website on a single web server. There are two types of Virtual hosts can be setup with Apache are Name Based Virtual hosting and IP based virtual hosting.
For more information, read on How to Create Name/IP based Virtual Hosts in Apache.

19. What do you understand by MPM in Apache?

Answer : MPM stands for Multi Processing Modules, actually Apache follows some mechanism to accept and complete web server requests.
20. What is the difference between Worker and Prefork MPM?

Answer : Both MPMs, Worker and prefork has their own mechanism to work with Apache. It totally depends on you that in which mode you want to start your Apache.
Basic difference between Worker and MPM is in their process of spawning the child process. In the Prefork MPM, a master httpd process is started and this master process starts manages all other child processes to serve client requests. Whereas, In the worker MPM one httpd process is active, and it uses different threads to serve client requests.
Prefork MPM uses multiple child processes with one thread each, where worker MPM uses multiple child processes with many threads each.
Connection handling in the Prefork MPM, each process handles one connection at a time, whereas in the Worker mpm each thread handles one connection at a time.
Memory footprints Prefork MPM Large memory footprints, where Worker has smaller memory footprints.
21. What’s the use of “LimitRequestBody” and how to put limit on your uploads?

Answer : LimitRequestBody directive is used to put a limit on the upload size.
For example: I want to put limits of 100000 Bytes in the folder /var/www/html/tecmin/uploads. So, you need to add following directive in Apache configuration file.

<Directory "/var/www/html/tecmint/uploads">
LimitRequestBody 100000
</Directory>
22. What is mod_perl and mod _php?

Answer :
mod_perl is an Apache module which is compiled with Apache for easy integration and to increase the performance of Perl scripts.
mod_php is used for easy integration of PHP scripts by the web server, it embeds the PHP interpreter inside the Apache process. Its forces Apache child process to use more memory and works with Apache only but still very popular.
23. What is Mod_evasive?

Answer : Its a third-party module which helps us to prevent your web server from the web attacks like DDOS because it performs only one task at a time and performs it very well.
For more information, read the article that guides you how to install and configure mod_evasive in Apache.

24. What is Loglevel debug in httpd.conf file?

Answer : With the help of Loglevel Debug option, we can get/log more information in the error logs which helps us to debug a problem.
25. What’s the use of mod_ssl and how SSL works with Apache?

Answer : Mod_ssl package is an Apache module, which allows Apache to establish its connection and transfer all the data in a secure encrypted environment. With the help of SSL certificates, all the Login details and other important secret details get transferred in an encrypted manner over the Internet, which prevents our data from Eavesdropping and IP spoofing.
How SSL works with Apache

Whenever an https requests comes, these three steps Apache follows:

Apache generates its private key and converts that private key to .CSR file (Certificate signing request).
Then Apache sends the .csr file to the CA (Certificate Authority).
CA will take the .csr file and convert it to .crt (certificate) and will send that .crt file back to Apache to secure and complete the https connection request.
These are just most popular 25 questions being asked these days by Interviewers, please provide some more interview questions which you have faced in your recent interview and help others via our Comment section below.