Linux Interview Question and Answers


What is the core of Linux Operating System?

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

What Linus Torvalds Created?

Linus Torvalds created Linux, which is the kernel (heart) of all of the above Operating System and all other Linux Operating System.

What is the basic difference between UNIX and Linux Operating System.

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.

Is Linux Operating system Virus free?

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.

What kind of Operating System is Linux?

·         Multi User
·         Multi Tasking
·         Multi Process
Linux is an Operating System which supports Multi User, Running a Number of Processes performing different tasks simultaneously.

What command allows you to set a processor-intensive job to use less CPU time?

The nice command is used to change a job's priority level, so that it runs slower or faster.

Syntax: nice [OPTION] [COMMAND [ARG]...]

Range of priority goes from -20 (highest priority) to 19 (lowest).Priority is given to a job so that the most important job is executed first by the kernel and then the other least important jobs. This takes less CPU times as the jobs are scheduled and are given priorities so the CPU executes fast. The priority is given by numbers like -20 describe the highest priority and 19 describe the least priority.

While logged on as a regular user, ur boss calls up and wants you to create a new user account immediately. How can you do this without first having to close ur work, log off and logon as root?

U can use the su command to imitate any user including root. U will be prompted for the password for the root account. Once u have provided it U are logged in as root and can do any administration duties including creation of new user account, etc.

Ram, who has a username of Ramu, calls to tell U that he forgot his password. What command should U use to reset his password?

passwd Ramu

The passwd command is used to change Ur password. If U do not specify a username, Ur password will be changed.

The top utility can be used to change the priority of a running process? Another utility that can also be used to change priority is -----?

nice

Both top and nice commands provide the capability to change the priority of a running process.

What command should U type to see all the files with an extension of 'py' listed in reverse alphabetical order in the /home/fs4/python directory?

ls -r  /home.fs4/python/*.py

The -c option used with 'ls' results in the files being listed in chronological order. U can use wildcards with the 'ls' command to specify a pattern of filenames.

What command is used to remove the password assigned to a group?

gpasswd -r

The 'gpasswd' command is used to change the password assigned to a group. Use the -r option to remove the password from the group.

What command can you type at the command line to determine which shell U are using?

echo  $SHELL            --> display the name of the Shell ur using

The name and pathh to the shell U are using is saved to the SHELL environment variable. U can use the 'echo' command to print the value of any variable by preceding the variables name with '$'.

U need to see the last fifteen lines of the files f1, f2, f3. What command should U use?

 Tail  -15 f1 f2 f3

The 'tail' command displays the end of a file. The -15 tells tail to display the last fifteen lines of each specified file.


U locate a command in the /bin directory but do not know what it does. What command can U use to determine its purpose?

 whatis

'whatis' command displays a summary line from the man page for the specified command.

What command can you use to show a dynamic listing of running processes?

 top

'top' command shows a listing of all the running processes that is dynamically updated.

Where is standard output usually directed?
 
 by default ur shell directs standard output to ur screen or display.

U have  a file called sample that is almost 4,000 lines long. What text filter can U use to split into four pieces each 1,000 lines long?

 split

'split' text filter will divide files into equally sized pieces. The default length of each piece is 1,000 lines.

What account is created when u install Linux?

 root

whenever U install Linux, only one user account is created. This is the superuser account also known as 'root'.


What command should u use to check the no of files and disk space used and each user's defined quotas?

  repquota

'repquota' command is used to get a report on the status of the quotas U have set including the amount of allocated space and amount of used space.

Basic Commands

mkdir — For creating folders( use -p option to create multiple folders at a time)
ls –List folders/files( check what ls -1 do)

top — To monitor system activities

lsof –To check whats happening on the server and which process open which file.

netstat -tcp –Gives you complete picture about network connection details.

vnstat –Gives you Network band width statics

sh –For running shell scripts

history –For monitoring the commands executed by users

cd –For changing directories

chmod –To change permissions of folders and files.

mount –For mounting formated partitions.

service –For start/restart/stop a service. Eg: sudo service  mysql start

chkconfig –For permanent on/off a service.

fdisk -l –To list all the partitions

Q) Give me some commands for user management.

last, chage, chsh, lsof, chown, chmod, useradd, userdel, newusers.


Q) What is the command to do password less logins to other machines.

    ssh-keygen

Q) Give me some security monitoring related commands.

    lsof, netstat, top, ps -ef, tail, last, tcpdump, history.

Q) What is the difference between man, info, whatis commands and a –help option for a command?

whatis gives you one line answer.

–help option for a command gives you one line answers for each option supported by a command

man command gives you medium size info.

info command gives full details about a commands, lots and lots of information about a command.

What are virtual machines and explain their advantages?
It is the concept by which an operating syatem can create an illusion that a process has its own processor with its own (virtual) memory.  The operating system implements virtual machine concept by using CPU scheduling and virtual memory.

·         it provides robust level of security as each virtual machine is isolated from all other VM. Hence the system resources are completely protected.
·         System development can be done without disrupting normal operation. System programmers are giventheir own VM, and as system development is done on the VM instead on the VM instead of on the physical machine.
·         It solves the compatibility problem

Q) What is the difference between home directory and working directory?

Home directory: Each user will have a home directory and will have complete control over it. On login, home is the default working directory for the user. It contains configuration files and responsible for login and logout of the user.
Working directory: is the directory in which the user is working currently. The home may also be the working directory, if the user is working in it.

Q) What is the difference between internal and external commands?

Internal commands are the commands that are already loaded in the system and they are executed by the shell. No process is there to run them.
External commands are the commands that are executed by the kernel. Each command has its unique process id.

Q) What is the file server in Linux server?

 File server is dedicated for persisting files ina location from which the networked system can access. 'samba' is a file server of linux and is used for file sharing.

Q) What is NFS? Q) What is its purpose?

NFS is Network File system. It is a file system used for sharing of files over a network. It is also used to partition a disk on a remote machine disk.

Q) Explain RPM (Red Hat Package Manager) features.

RPM is a powerful s/w management tool for installing, uninstalling, verifying, querying and updating s/w packages. It is a s/w pkg manager. It is available with Fedora, Suse, centOs, etc.

Q) What is Kernel? Q) Explain the task it performs.

Kernel is used in UNIX like systems and is considered to be the heart of the operating system. It is responsible for communication between h/w and s/w components. It is primarily used for managing the systems resources as well.

Q) What is Linux Shell? Q) What is Shell Script?

Linux shell is a user interface used for executing the commands. Shell is a program the user uses for executing the commands. In Unix, any program can be the users shell. Shell categories in Linux are: Bourne shell compatible, C shell compatible, nontraditional, and historical.

Q) What are Pipes? Q) Explain use of pipes.

A pipe is a chain of processes so that output of one process (stdout) is fed an input (stdin) to another. The commands are written in sequence seperated by |.

Q) Explain some network monitoring tools.
 They are used to monitor the network, systems present on the network, traffic, etc.
They are:
 ping – ping command is used to check if the system is in the network or not. To check if the host is operating.
    ping ip_address

tcpdump -  commonly used to monitor network traffic


Q) What is Bash Shell?

Bash is a free shell for UNIX. It is the default shell for most UNIX systems. It has a combination of the C and Korn shell features.

Q) How does the linux file system work?

Linux file structure is a tree like structure. It starts from the root directory, represented by '/', and then expands into sub-directories. All the partitions are under the root directory. If a partition is mounted (The mount point defines the place of a particular data set in the file system) anywhere apart from a “device”, the system is not aware of the existence of that partition or device. Directories that are only one level below the root directory are often preceded by a slash, to indicate their position. 


Q) Explain file system of linux. The root "/" filesystem, /usr filesystem, /var filesystem, /home filesystem, /proc filesystem.

Root "/" file system: The kernel needs a root file system to mount at start up. The root file system is generally small and should not be changed often as it may interrupt in booting. The root directory usually does not have the critical files. Instead sub directories are created. E.g. /bin (commands needed during bootup), /etc (config files) , /lib(shared libraries).

/usr filesystem : this file system is generally large as it contains the executable files to be shared amongst different machines. Files are usually the ones installed while installing Linux. This makes it possible to update the system from a new version of the distribution, or even a completely new distribution, without having to install all programs again. Sub directories include /bin, /include, /lib, /local (for local executables)

/var filesystem : this file system is specific to local systems. It is called as var because the data keeps changing. The sub directories include /cache/man (A cache for man pages), /games (any variable data belong to games), /lib (files that change), /log (log from different programs), /tmp (for temporary files)

/home filesystem: - this file system differs from host to host. User specific configuration files for applications are stored in the user's home directory in a file. UNIX creates directories for all users directory. E.g /home/my_name. Once the user is logged in ; he is placed in his home directory.

/proc filesystem : this file system does not exist on the hard disk. It is created by the kernel in its memory to provide information about the system. This information is usually about the processes. Contains a hierarchy of special files which represent the current state of the kernel. Few of the Directories include /1 (directory with information about process num 1, where 1 is the identification number), /cpuinfo (information about cpu), /devices (information about devices installed), /filesystem (file systems configured), /net (information about network protocols), /mem (memory usage)

Q) What are the process states in Linux?

Process states in Linux:

·         Running: Process is either running or ready to run
·         Interruptible: a Blocked state of a process and waiting for an event or signal from another process
·         Uninterruptible: a blocked state. Process waits for a hardware condition and cannot handle any signal
·          Stopped: Process is stopped or halted and can be restarted by some other process
·          Zombie: process terminated, but information is still there in the process table. 
Q) What is a zombie?

Zombie is a process state when the child dies before the parent process. In this case the structural information of the process is still in the process table. Since this process is not alive, it cannot react to signals. Zombie state can finish when the parent dies. All resources of the zombie state process are cleared by the kernel 

Q) Explain each system calls used for process management in linux.

1. To create a new process – fork () is used.
2. To run a new program = exec () is used.
3. To make the process to wait = wait () is used.
4. To terminate the process – exit () is used.
5. To find the unique process id – getpid () is used.
6. To find the parent process id – getppid () is used.
7. To bias the currently running process property – nice () is used.      



Q) What is the name and path of the main system log?

By default the main system log is /var/log/messages. This file contains all the messages and the script written by the user. By default all scripts are saved in this file. This is the standard system log file, which contains messages from all system software, non-kernel boot issues, and messages that go to 'dmesg'. dmesg is a system file that is written upon system boot.

Q) How secured is Linux? Explain.

Security is the most important aspect of an operating system. Due to its unique authentication module, Linux is considered as more secured than other operating systems. Linux consists of PAM. PAM is Pluggable Authentication Modules. It provides a layer between applications and actual authentication mechanism. It is a library of loadable modules which are called by the application for authentication. It also allows the administrator to control when a user can log in. All PAM applications are configured in the directory "/etc/pam.d" or in a file "/etc/pam.conf". PAM is controlled using the configuration file or the configuration directory.

Q) Can Linux computer be made a router so that several machines may share a single Internet connection? How?

Yes a Linux machine can be made a router. This is called "IP Masquerade." IP Masquerade is a networking function in Linux similar to the one-to-many (1: Many) NAT (Network Address Translation) servers found in many commercial firewalls and network routers. The IP Masquerade feature allows other "internal" computers connected to this Linux box (via PPP, Ethernet, etc.) to also reach the Internet as well. Linux IP Masquerading allows this functionality even if the internal computers do not have IP addresses.
The IP masquerading can be done by the following steps:

1. The Linux PC must have an internet connection and a connection to LAN. Typically, the Linux PC has two network interfaces-an Ethernet card for the LAN and a dial-up PPP connection to the Internet (through an ISP).

2. All other systems on your LAN use the Linux PC as the default gateway for TCP/IP networking. Use the same ISP-provided DNS addresses on all systems.

3. Enable IP forwarding in the kernel. By default the IP forwarding is not enabled. To ensure that IP forwarding is enabled when you reboot your system, place this command in the /etc/rc.d/rc.local file.

4. Run /sbin/iptables-the IP packet filter administration program-to set up the rules that enable the Linux PC to masquerade for your LAN.

Q) What is the minimum number of partitions you need to install Linux?

Minimum 2 partitions are needed for installing Linux. The one is / or root which contains all the files and the other is swap. Linux file system is function specific which means that files and folders are organized according to their functionality. For example, all executables are in one folder, all devices in another, all libraries in another and so on. / or ‘root’ is the base of this file system. All the other folders are under this one. / can be consider as C: .Swap is a partition that will be used as virtual memory. If there is no more available RAM a Linux computer will use an area of the hard disk, called swap, to temporarily store data. In other words it is a way of expanding your computers RAM.

Q) What are the fields in the/etc/passwd file?

It contains all the information of the users who log into the system. It contains a list of the system's accounts, giving for each account some useful information like user ID, group ID, home directory, shell, etc. It should have general read permission as many utilities, like ls use it to map user IDs to user names, but write access only for the superuser (root). The main fields of /etc/passwd file are:
1. Username: It is used when user logs in. It should be between 1 and 32 characters in length.
2. Password: An x character indicates that encrypted password is stored in /etc/shadow file.
3. User ID (UID): Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1-99 are reserved for other predefined accounts. Further UID 100-999 are reserved by system for administrative and system accounts/groups.
4. Group ID (GID): The primary group ID (stored in /etc/group file)
5. User ID Info: The comment field. It allow you to add extra information about the users such as user's full name, phone number etc. This field use by finger command.
6. Home directory: The absolute path to the directory the user will be in when they log in. If this directory does not exists then users directory becomes /
7. Command/shell: The absolute path of a command or shell (/bin/bash). Typically, this is a shell.


Q) How do you create a new user account?

Useradd or adduser command is used for creating a new user account. When invoked without the
-D option, the useradd command creates a new user account using the values specified on the command line and the default values from the system. The new user account will be entered into the system files as needed, and initial files copied, depending on the command line options. This command uses the system default as home directory. If –m option is given then the home directory is made.

Q) Which password package is installed for the security of central password?

Shadow password packages are used for security of central passwords. Security is the most important aspect of every operating system. When this package is not installed the user information including passwords is stored in the /etc/passwd file. The password is stored in an encoded format. These encoded forms can be easily identified by the System crackers by randomly encoding the passwords from dictionaries. The Shadow Package solves the problem by relocating the passwords to another file (usually /etc/shadow). The /etc/shadow file is set so that it cannot be read by just anyone. Only root will be able to read and write to the /etc/shadow file.


Q) Which daemon is responsible for tracking events on Linux system?

syslogd is responsible for tracking system information and save it to the desired log files. It provides two system utilities which provide system logging and kernel message trapping. Internet and UNIX domain sockets support enable this utility package to support both local and remote logging. Every logged message contains at least a time and a hostname field, normally a program name field, too. So to track these information this daemon is used. syslogd mainly reacts to the set of signals given by the user. These are the signals given to syslogd: SIGHUP: This lets syslogd perform a re-initialization. All open files are closed, the configuration file (default is /etc/syslog.conf) will be reread and the syslog facility is started again. SIGTERM: The syslogd will die. SIGINT, SIGQUIT: If debugging is enabled these are ignored, otherwise syslogd will die. SIGUSR1: Switch debugging on/off. This option can only be used if syslogd is started with the - d debug option. SIGCHLD: Wait for Childs if some were born, because of waiting messages.

Q) Which daemon is used for scheduling of the commands?

The crontab command is used for scheduling of the commands to run at a later time.
SYNTAX
crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }

Options
-l List - display the current crontab entries.

-r Remove the current crontab.

-e Edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.
When user exits from the editor, the modified crontab will be installed automatically. Each user can have their own crontab, and though these are files in /var, they are not intended to be edited directly. If the –u option is given than the crontab gives the name of the user whose crontab is to be tweaked. If it is given without this then it will display the crontab of the user who is executing the command.

Q) How environment variable is set so that the file permission can be automatically set to the newly created files?

umask command is used to set file permission on newly created files automatically.

Syntax
umask [-p] [-S] [mode]

It is represented in octal numbers. We can simply use this command without arguments to see the current file permissions. To change the permissions, mode is given in the arguments. The default umask used for normal user is 0002. The default umask for the root user is 0022. For calculating the original values, the values shown by the umask must be subtracted by the default values. It is mainly used for masking of the file and directory permission. The /etc/profile script is where the umask command is usually set for all users. The –S option can be used to see the current default permissions displayed in the alpha symbolic format.
For example, umask 022 ensures that new files will have at most 755 permissions (777 NAND 022).
The permissions can be calculated by taking the NAND of original value with the default values of files and directories.    




Comments