Linux Interview Questions

Linux Interview Questions


Linux Beginner

Question
What is your experience with Linux? When you can set up an application on multiple operating systems, on which one would you prefer to set it up and why?
                    

Question
Explain what each of the following commands does and give an example on how to use it: * ls * rm * rmdir (can you achieve the same result by using rm?) * grep * wc * curl * touch * man * nslookup or dig * df
                    

Question
Running the command df you get "command not found". What could be wrong and how to fix it?
                    

Question
How to make sure a service will start on a OS of your choice?
                    

Question
How do you schedule tasks periodically?
You can use the commands cron and at.
With cron, tasks are scheduled using the following format:

minute hour day of month month day of week command to execute

The tasks are stored in a cron file.
                    

Question
Have you scheduled tasks in the past? What kind of tasks?
Normally you will schedule batch jobs.
                    
Permissions

Question
How to change the permissions of a file?

Using the `chmod` command.
                    

Question
What does the following permissions mean?: * 777 * 644 * 750
777 - means you are lazy
644 - owner has read+write permissions and everyone else can only read
750 - owner can do anything, group can read and execute and others can do nothing
                    

Question
Explain what is setgid, setuid and sticky bit
                    

Question
You try to delete a file but it fails. Name at least three different reason as to why it could happen
                    

Question
What is systemd?
                    

Question
On a system which uses systemd, how would display the logs?
journalctl
                    
Debugging

Question
What are you using for troubleshooting and debugging network issues?

dstat -t is great for identifying network and disk issues.
netstat -tnlaup can be used to see which processes are running on which ports.
lsof -i -P can be used for the same purpose as netstat.
ngrep -d any metafilter for matching regex against payloads of packets.
tcpdump for capturing packets
wireshark same concept as tcpdump but with GUI (optional).
                    

Question
What are you using for troubleshooting and debugging disk & file system issues?

dstat -t is great for identifying network and disk issues.
opensnoop can be used to see which files are being opened on the system (in real time).
                    

Question
What are you using for troubleshooting and debugging process issues?

strace is great for understanding what your program does. It prints every system call your program executed.
                    

Question
What are you using for debugging CPU related issues?

top will show you how much CPU percentage each process consumes
perf is a great choice for sampling profiler and in general, figuring out what your CPU cycles are "wasted" on
flamegraphs is great for CPU consumption visualization (http://www.brendangregg.com/flamegraphs.html)
                    

Question
You get a call saying "my system is slow" - how would you deal with it?

1. Check with top if anything consumes your CPU or RAM.
2. Run dstat -t to check if it's related to disk or network.
3. Check I/O stats with iostat
                    

Question
How to debug binaries?
                    

Question
What is a Linux kernel module and how do you load a new module?
                    

Question
What is KVM?
                    

Question
What is the difference between SSH and SSL?
                    

Question
What is SSH port forwarding?
                    

Question
Explain redirection
                    

Question
What are wildcards? Can you give an example of how to use them?
                    

Question
What do we grep for in each of the following commands?: * grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' some_file * grep -E "error|failure" some_file * grep '[0-9]$' some_file
1. An IP address
2. The word "error" or "failure"
3. Lines which end with a number
                    

Question
Tell me everything you know about Linux boot process
                    

Question
What is an exit code? What exit codes are you familiar with?
An exit code (or return code) represents the code returned by a child process to its
parent process.

0 is an exit code which represents success while anything higher than 1 represents error.
Each number has different meaning, based on how the application was developed.

I consider this as a good blog post to read more about it: https://shapeshed.com/unix-exit-codes
                    

Question
What is the difference between a soft link and hard link?
Hard link is the same file, using the same inode.
Soft link is a shortcut to another file, using a different inode.

Soft links can be created between different file systems while.
Hard link can be created only within the same file system.
                    

Question
What happens when you delete the original file in case of soft link and hard link?
                    

Question
What is a swap partition? What is it used for?
                    

Question
You are trying to create a new file but you get "File system is full". You check with df for free space and you see you used only 20% of the space. What could be the problem?
                    

Question
What do you know about LVM?
                    

Question
Explain the following in regards to LVM: * PV * VG * LV
                    

Question
What is NFS? What is it used for?
                    

Question
What RAID is used for? Can you explain the differences between RAID 0, 1, 5 and 10?
                    

Question
What is lazy umount?
                    

Question
Fix the following commands: * sed "s/1/2/g' /tmp/myFile * find . -iname \*.yaml -exec sed -i "s/1/2/g" {} ;
                    

Question
Explain what is stored in each of the following paths and if there is anything unique about it: * /tmp * /var/log * /bin * /proc * /usr/local
                    

Question
What is chroot?
                    
Processes

Question
How to run a process in the background and why to do that in the first place?
You can achieve that by specifying & at end of the command.
As to why, since some commands/processes can take a lot of time to finish
execution or run forever
                    

Question
How can you find how much memory a specific process consumes?
                    

Question
What signal is used when you run 'kill process_id'?
The default signal is SIGTERM (15). This signal kills
process gracefully which means it allows it to save current
state configuration.
                    

Question
What signals are you familiar with?
SIGTERM - default signal for terminating a process
SIGHUP - common usage is for reloading configuration
SIGKILL - a signal which cannot caught or ignored

To view all available signals run `kill -l`
                    

Question
What is a trap?
                    

Question
What happens when you press ctrl + c?
                    

Question
What are daemons?
                    

Question
What are the possible states of a process in Linux?
Running Waiting Stopped Terminated Zombie
                    

Question
What is a zombie process? How do you get rid of it?
                    

Question
What is the init process?
                    

Question
How to change the priority of a process? Why would you want to do that?
                    

Question
Can you explain how network process/connection is established and how it's terminated?>
                    

Question
What are system calls? What system calls are you familiar with?
                    

Question
What strace does?
                    

Question
Find all the files which end with '.yml' and replace the number 1 in 2 in each file
find /some_dir -iname \*.yml -print0 | xargs -0 -r sed -i "s/1/2/g"



Question
How to check how much free memory a system has? How to check memory consumption by each process?
You can use the commands top and free

Question
How would you split a 50 lines file into 2 files of 25 lines each?

You can use the split command this way: split -l 25 some_file
                    

Question
What is a file descriptor? What file descriptors are you familiar with?
Kerberos
File descriptor, also known as file handler, is a unique number which identifies an open file in the operating system.

In Linux (and Unix) the first three file descriptors are:
  * 0 - the default data stream for input
  * 1 - the default data stream for output
  * 2 - the default data stream for output related to errors

This is a great article on the topic: https://www.computerhope.com/jargon/f/file-descriptor.htm
                    

Question
What's an inode?
For each file (and directory) in Linux there is an inode, a data structure which stores meta data
related to the file like its size, owner, permissions, etc.
                    

Question
How to list active connections?
                    

Question
What is NTP? What is it used for?
                    

Question
Explain Kernel OOM
                    

Question
What is SELiunx?
                    

Question
What is Kerberos?
                    

Question
What is nftables?
                    

Question
What firewalld daemon is responsible for?
                    

Network


Question
What is a network namespace? What is it used for?
                    

Question
How can you turn your Linux server into a router?
                    

Question
What is a virtual IP? In what situation would you use it?
                    

Question
Which port is used in each of the following protocols?: * SSH * HTTP * DNS * HTTPS
                    

Question
What is the routing table? How do you view it?
                    

Question
What are packet sniffers? Have you used one in the past? If yes, which packet sniffers have you used and for what purpose?
                    
DNS

Question
What is DNS? Why do we need it?
                    

Question
What the file /etc/resolv.conf is used for? What does it include?
                    

Question
What is a "A record"?
                    

Question
What is a PTR record?
While an A record points a domain name to an IP address, a PTR record does the opposite and resolves the IP address to a domain name.
                    

Question
What is a MX record?
                    

Question
Is DNS using TCP or UDP?
                    
Packaging

Question
Do you have experience with packaging? Can you explain how it works?
                    

Question
RPM: explain the spec format(what it should and can include)
                    

Question
How do you list the content of a package without actually installing it?
                    
Applications and Services

Question
What is a load balancer?
                    

Question
What load balancer algorithms are you familiar with?
                    

Question
What is a proxy?
                    

Question
What is a reverse proxy?
                    

Question
What can you find in /etc/services
                    

Question
You run ssh 127.0.0.1 but it fails with "connection refused". What could be the problem?
1. SSH server is not installed
2. SSH server is not running
                    

Question
How to print the shared libraries required by a certain program? What is it useful for?
                    

Question
How do you create users? Where user information is stored?
                    

Question
Do you know how to create a new user without using adduser/useradd command?
                    

Question
How to add a new user to the system without providing him the ability to log-in into the system?
  * adduser user_name --shell=/bin/false --no-create-home
                    

Question
What can you do if you lost/forogt the root password?

Re-install the OS IS NOT the right answer :)
                    

Question
What is sudo? How do you set it up?
                    
Advanced Linux

Question
What happens when you execute ls?. Provide a detailed answer
                    

Question
Can you describe how processes are being created?
                    

Question
What does the following block do?: ``` open("/my/file") = 5 read(5, "file content") ```
These system calls are reading the file /my/file and 5 is the file descriptor number.
                    

Question
What is the difference between a process and a thread?
                    
Linux Networking

Question
When you run ip a you see there is a device called 'lo'. What is it and why do we need it?
                    

Question
What traceroute command does? How it works?
                    

Question
What is network bonding? What types are you familiar with?
                    

Question
How to link two separate network namespaces so you can ping an interface on one namespace from the second one?
                    

Question
What are cgroups? In what scenario would you use them?
                    

Question
How to create a file of a certain size?
There are a couple of ways to do that:
  
  * dd if=/dev/urandom of=new_file.txt bs=2MB count=1
  * truncate -s 2M new_file.txt
  * fallocate -l 2097152 new_file.txt
                    

Question
What are the differences between the following system calls?: exec(), fork(), vfork() and clone()?
                    

Question
Explain Process Descriptor and Task Structure
                    

Question
What are the differences between threads and processes?
                    

Question
Explain Kernel Threads
                    

Question
What happens when socket system call is used?
This is a good article about the topic: https://ops.tips/blog/how-linux-creates-sockets
                    

Question
You executed a script and while still running, it got accidentally removed. Is it possible to restore the script while it's still running?