fbpx

Top 100 Linux System Administrator Interview Questions and Answers

Top 100 Linux System Administrator Interview Questions and Answers

Contents show

1. How do you check the current running processes in Linux?

Answer:
To view running processes, use the ps command:

ps -aux

Reference: ps command – Linux Man Pages


2. How can you find out how much free memory is available in Linux?

Answer:
Use the free command:

free -h

Reference: free command – Linux Man Pages


3. How do you check disk space usage in Linux?

Answer:
Use the df command to display disk space usage:

df -h

Reference: df command – Linux Man Pages


4. How do you list all files in a directory, including hidden files?

Answer:
Use ls with the -a option:

ls -a

Reference: ls command – Linux Man Pages


5. How can you find a specific string in files?

Answer:
Use grep:

grep 'search_string' file_name

Reference: grep command – Linux Man Pages


6. How do you change file permissions in Linux?

Answer:
Use chmod:

chmod permissions file_name

Reference: chmod command – Linux Man Pages


7. How can you find and kill a specific process in Linux?

Answer:
Find the process ID with pgrep and kill it with kill:

kill $(pgrep process_name)

Reference: pgrep command – Linux Man Pages and kill command – Linux Man Pages


8. How do you create a symbolic link in Linux?

Answer:
Use ln -s:

ln -s /path/to/original /path/to/link

Reference: ln command – Linux Man Pages


9. How can you schedule a task to run at a specific time using cron?

Answer:
Edit the crontab file using crontab -e and add an entry like:

* * * * * /path/to/command

Reference: cron and crontab – Linux Man Pages and crontab command – Linux Man Pages


10. How do you list open ports and their associated processes?

Answer:
Use netstat or ss:

netstat -tuln
# or
ss -tuln

Reference: netstat command – Linux Man Pages and ss command – Linux Man Pages


11. How can you monitor system resource usage in real-time?

Answer:
Use top or htop:

top
# or
htop

Reference: top command – Linux Man Pages


12. How do you check the status of a service in Linux?

Answer:
Use systemctl:

systemctl status service_name

Reference: systemctl command – Linux Man Pages


13. How can you add a user to a group in Linux?

Answer:
Use usermod:

usermod -aG group_name user_name

Reference: usermod command – Linux Man Pages


14. How do you check the version of installed Linux distribution?

Answer:
Use lsb_release or read /etc/os-release:

lsb_release -a
# or
cat /etc/os-release

Reference: lsb_release command – Linux Man Pages


15. How can you find all files modified within the last 24 hours?

Answer:
Use find:

find /path/to/search -mtime -1

Reference: find command – Linux Man Pages


16. How do you compress and extract files in Linux

?

Answer:
Use tar:

tar -cvzf archive.tar.gz /path/to/directory   # To compress
tar -xvzf archive.tar.gz                      # To extract

Reference: tar command – Linux Man Pages


17. How can you view the contents of a file without opening it?

Answer:
Use cat, less, or more:

cat file_name
# or
less file_name
# or
more file_name

Reference: cat command – Linux Man Pages, less command – Linux Man Pages, more command – Linux Man Pages


18. How do you find the IP address of a Linux system?

Answer:
Use ifconfig or ip:

ifconfig
# or
ip addr show

Reference: ifconfig command – Linux Man Pages, ip command – Linux Man Pages


19. How can you set up a static IP address in Linux?

Answer:
Edit the network configuration file, typically located at /etc/network/interfaces.

Reference: interfaces file – Ubuntu Manpages


20. How do you monitor log files in real-time?

Answer:
Use tail:

tail -f /var/log/file.log

Reference: tail command – Linux Man Pages


21. How can you find all files owned by a specific user?

Answer:
Use find with the -user option:

find / -user username

Reference: find command – Linux Man Pages


22. How do you check the integrity of a file using checksums?

Answer:
Use sha256sum or md5sum:

sha256sum file
# or
md5sum file

Reference: sha256sum command – Linux Man Pages, md5sum command – Linux Man Pages


23. How can you limit the resources a process can use?

Answer:
Use ulimit:

ulimit -c unlimited   # Example: Allow core dumps

Reference: ulimit command – Linux Man Pages


24. How do you find out which package provides a specific file in Linux?

Answer:
Use dpkg (for Debian-based systems) or rpm (for Red Hat-based systems):

dpkg -S /path/to/file   # Debian-based
# or
rpm -qf /path/to/file   # Red Hat-based

Reference: dpkg command – Linux Man Pages, rpm command – Linux Man Pages


25. How can you automate tasks in Linux?

Answer:
Use cron for scheduled tasks or bash scripting for more complex automation.

Reference: cron and crontab – Linux Man Pages


26. How do you find out the system’s uptime?

Answer:
Use uptime:

uptime

Reference: uptime command – Linux Man Pages


27. How can you securely copy files between servers?

Answer:
Use scp:

scp /path/to/file user@remote_host:/path/to/destination

Reference: scp command – Linux Man Pages


28. How do you change the hostname of a Linux system?

Answer:
Edit the /etc/hostname file and run hostnamectl set-hostname new_hostname.

Reference: hostnamectl command – Linux Man Pages


29. How can you find out which ports are listening on a Linux server?

Answer:
Use netstat or ss:

netstat -tuln
# or
ss -tuln

Reference: netstat command – Linux Man Pages, ss command – Linux Man Pages


30. How do you set up a firewall in Linux?

Answer:
Use iptables or a firewall management tool like ufw:

# Example using ufw
ufw enable
ufw allow 22     # Allow SSH

Reference: iptables command – Linux Man Pages, ufw documentation


31. How can you find out which services are set to start on boot?

Answer:
Use systemctl:

systemctl list-unit-files --type=service | grep enabled

Reference: systemctl command – Linux Man Pages


32. How do you check the status of a specific service in Linux?

Answer:
Use systemctl:

systemctl status service_name

Reference: systemctl command – Linux Man Pages


33. How can you mount a new disk in Linux?

Answer:
Use fdisk to partition, then mkfs to format, and mount to mount:

fdisk /dev/sdX
mkfs -t ext4 /dev/sdX1
mount /dev/sdX1 /mnt/point

Reference: fdisk command – Linux Man Pages, mkfs command – Linux Man Pages, mount command – Linux Man Pages


34. How do you add a new user in Linux?

Answer:
Use adduser or useradd:

adduser username
# or
useradd username

Reference: adduser command – Linux Man Pages, useradd command – Linux Man Pages


35. How can you check if a package is installed in Linux?

Answer:
Use dpkg (for Debian-based systems) or rpm (for Red Hat-based systems):

dpkg -l | grep package_name   # Debian-based
# or
rpm -q package_name          # Red Hat-based

Reference: dpkg command – Linux Man Pages, rpm command – Linux Man Pages


36. How do you create a swap file in Linux?

Answer:
Use dd to create an empty file, mkswap to set it up, and swapon to enable it:

dd if=/dev/zero of=/swapfile bs=1M count=1024
mkswap /swapfile
swapon /swapfile

Reference: dd command – Linux Man Pages, mkswap command – Linux Man Pages, swapon command – Linux Man Pages


37. How can you find the largest files in a directory?

Answer:
Use du and sort:

du -a /path/to/directory | sort -n -r | head -n 10

Reference: du command – Linux Man Pages, sort command – Linux Man Pages


38. How do you change the timezone in Linux?

Answer:
Use timedatectl:

timedatectl set-timezone America/New_York

Reference: timedatectl command – Linux Man Pages


39. How can you view a log file with the most recent entries?

Answer:
Use tail with the -f option:

tail -f /var/log/file.log

Reference: tail command – Linux Man Pages


40. How do you add a user to the sudoers file?

Answer:
Use visudo to edit the sudoers file:

visudo

Then add a line like:

username ALL=(ALL:ALL) ALL

Reference: visudo command – Linux Man Pages


41. How can you find all files with a specific extension?

Answer:
Use find:

find /path/to/search -type f -name "*.extension"

Reference: find command – Linux Man Pages


42. How do you check the size of a directory?

Answer:
Use du:

du -sh /path/to/directory

Reference: du command – Linux Man Pages


43. How can you monitor network traffic in Linux?

Answer:
Use tools like tcpdump or wireshark:

tcpdump -i eth0

Reference: tcpdump command – Linux Man Pages


44. How do you limit the resources a user can use in Linux?

Answer:
Use ulimit or cgroups for more fine-grained control.

Reference: ulimit command – Linux Man Pages, cgroups documentation


45. How can you check for open ports on a remote host?

Answer:
Use nmap:

nmap remote_host

Reference: nmap documentation


46. How

do you configure a static IP address in Linux?

Answer:
Edit the network configuration file, typically located at /etc/network/interfaces.

Reference: interfaces file – Ubuntu Manpages


47. How can you find out the kernel version in Linux?

Answer:
Use uname:

uname -r

Reference: uname command – Linux Man Pages


48. How do you kill a process in Linux?

Answer:
Use kill or killall:

kill process_id
# or
killall process_name

Reference: kill command – Linux Man Pages, killall command – Linux Man Pages


49. How can you find out the available disk space on a Linux system?

Answer:
Use df:

df -h

Reference: df command – Linux Man Pages


50. How do you check the current system load in Linux?

Answer:
Use uptime:

uptime

Reference: uptime command – Linux Man Pages


51. How do you check the file system type of a partition in Linux?

Answer:
Use blkid or lsblk:

blkid /dev/sdX1
# or
lsblk -f

Reference: blkid command – Linux Man Pages, lsblk command – Linux Man Pages


52. How can you create a symbolic link in Linux?

Answer:
Use ln:

ln -s /path/to/source /path/to/link

Reference: ln command – Linux Man Pages


53. How do you set up a firewall in Linux?

Answer:
Use iptables or ufw for a user-friendly interface:

iptables -A INPUT -p tcp --dport 80 -j ACCEPT

Reference: iptables documentation, ufw documentation


54. How can you find and replace text in a file using the command line?

Answer:
Use sed:

sed -i 's/old_text/new_text/g' filename

Reference: sed command – Linux Man Pages


55. How do you check for failed login attempts in Linux?

Answer:
Use grep with /var/log/auth.log:

grep "Failed password" /var/log/auth.log

Reference: auth.log documentation


56. How can you schedule a task to run at a specific time in Linux?

Answer:
Use cron:

* * * * * /path/to/command

Reference: cron documentation


57. How do you find out which process is using a specific port?

Answer:
Use netstat or ss:

netstat -tuln | grep port_number
# or
ss -tuln | grep port_number

Reference: netstat command – Linux Man Pages, ss command – Linux Man Pages


58. How can you check the health of a hard drive in Linux?

Answer:
Use smartctl:

smartctl -a /dev/sdX

Reference: smartctl documentation


59. How do you compress and decompress files in Linux?

Answer:
Use tar for compression and extraction:

tar -czvf archive.tar.gz /path/to/directory
tar -xzvf archive.tar.gz

Reference: tar command – Linux Man Pages


60. How can you change the ownership of a file in Linux?

Answer:
Use chown:

chown username:groupname filename

Reference: chown command – Linux Man Pages


61. How do you check the permissions of a file in Linux?

Answer:
Use ls with the -l option:

ls -l filename

Reference: ls command – Linux Man Pages


62. How can you list all processes running on a system?

Answer:
Use ps:

ps aux

Reference: ps command – Linux Man Pages


63. How do you enable and disable services on boot in Linux?

Answer:
Use systemctl:

systemctl enable service_name
systemctl disable service_name

Reference: systemctl command – Linux Man Pages


64. How can you find the IP address of a Linux system?

Answer:
Use ifconfig or ip:

ifconfig
# or
ip addr show

Reference: ifconfig command – Linux Man Pages, ip command – Linux Man Pages


65. How do you check the available memory on a Linux system?

Answer:
Use free:

free -h

Reference: free command – Linux Man Pages


66. How can you check the status of a service in Linux?

Answer:
Use systemctl:

systemctl status service_name

Reference: systemctl command – Linux Man Pages


67. How do you add a user in Linux?

Answer:
Use adduser or useradd:

adduser username
# or
useradd username

Reference: adduser command – Linux Man Pages, useradd command – Linux Man Pages


68. How can you grant sudo privileges to a user in Linux?

Answer:
Add the user to the sudoers file:

sudo visudo

Then, add the following line:

username ALL=(ALL:ALL) ALL

Reference: visudo command – Linux Man Pages


69. How do you check the current date and time in Linux?

Answer:
Use date:

date

Reference: date command – Linux Man Pages


70. How can you monitor system resource usage in real-time in Linux?

Answer:
Use top or htop:

top
# or
htop

Reference: top command – Linux Man Pages, htop documentation


71. How do you change the hostname of a Linux system?

Answer:
Edit /etc/hostname and /etc/hosts files, then restart the system or use the hostname command.

Reference: hostname command – Linux Man Pages


72. How can you find out the number of CPU cores in Linux?

Answer:
Use lscpu:

lscpu | grep "^CPU(s):"

Reference: lscpu command – Linux Man Pages


73. How do you search for files in Linux?

Answer:
Use find:

find /path/to/search -name "filename"

Reference: find command – Linux Man Pages


74. How can you check the integrity of a file in Linux?

Answer:
Use sha256sum or md5sum:

sha256sum filename
# or
md5sum filename

Reference: sha256sum command – Linux Man Pages, md5sum command – Linux Man Pages


75. How do you change the timezone in Linux?

Answer:
Use timedatectl:

sudo timedatectl set-timezone timezone

Reference: timedatectl command – Linux Man Pages


76. How can you view the contents of a file without opening it in Linux?

Answer:
Use cat, less, or more:

cat filename
# or
less filename
# or
more filename

Reference: cat command – Linux Man Pages, less command – Linux Man Pages, more command – Linux Man Pages


77. How do you check the version of a installed package in Linux?

Answer:
Use dpkg or rpm:

dpkg -l | grep package_name
# or
rpm -q package_name

Reference: dpkg command – Linux Man Pages, rpm command – Linux Man Pages


78. How can you find out the open ports on a Linux system?

Answer:
Use netstat or ss:

netstat -tuln
# or
ss -tuln

Reference: netstat command – Linux Man Pages, ss command – Linux Man Pages


79. How do you create a new directory in Linux?

Answer:
Use mkdir:

mkdir directory_name

Reference: mkdir command – Linux Man Pages


80. How can you list all installed packages on a Linux system?

Answer:
Use dpkg or rpm:

dpkg -l
# or
rpm -qa

Reference: dpkg command – Linux Man Pages, rpm command – Linux Man Pages


81. How do you check the disk space usage in Linux?

Answer:
Use df:

df -h

Reference: df command – Linux Man Pages


82. How can you add a user to a group in Linux?

Answer:
Use usermod:

usermod -aG groupname username

Reference: usermod command – Linux Man Pages


83. How do you compress and decompress files in Linux?

Answer:
Use tar for compression and decompression:

# Compression
tar -czvf archive.tar.gz files

# Decompression
tar -xzvf archive.tar.gz

Reference: tar command – Linux Man Pages


84. How can you find out the IP address of a Linux system?

Answer:
Use ifconfig or ip:

ifconfig
# or
ip addr show

Reference: ifconfig command – Linux Man Pages, ip command – Linux Man Pages


85. How do you schedule tasks in Linux?

Answer:
Use cron or at:

# For recurring tasks
crontab -e

# For one-time tasks
at -f script.sh now + 1 hour

Reference: cron command – Linux Man Pages, at command – Linux Man Pages


86. How can you monitor log files in real-time in Linux?

Answer:
Use tail or journalctl:

tail -f /var/log/syslog
# or
journalctl -f

Reference: tail command – Linux Man Pages, journalctl command – Linux Man Pages


87. How do you set up SSH key-based authentication in Linux?

Answer:

  1. Generate keys: ssh-keygen -t rsa
  2. Copy public key to remote: ssh-copy-id user@hostname

Reference: ssh-keygen command – Linux Man Pages, ssh-copy-id command – Linux Man Pages


88. How can you monitor system performance in Linux?

Answer:
Use tools like sar or vmstat:

sar
# or
vmstat 1

Reference: sar command – Linux Man Pages, vmstat command – Linux Man Pages


89. How do you change file permissions in Linux?

Answer:
Use chmod:

chmod permissions filename

Reference: chmod command – Linux Man Pages


90. How can you check the swap usage in Linux?

Answer:
Use free:

free -h

Reference: free command – Linux Man Pages


91. How do you monitor network activity in Linux?

Answer:
Use tools like iftop or tcpdump:

iftop
# or
tcpdump -i interface

Reference: iftop documentation, tcpdump documentation


92. How can you check the status of a network interface in Linux?

Answer:
Use ifconfig or ip:

ifconfig interface_name
# or
ip link show interface_name

Reference: ifconfig command – Linux Man Pages, ip command – Linux Man Pages


93. How do you monitor file system changes in real-time in Linux?

Answer:
Use inotifywait:

inotifywait -m /path/to/directory

Reference: inotifywait command – Linux Man Pages


94. How can you check the kernel version in Linux?

Answer:
Use uname:

uname -r

Reference: uname command – Linux Man Pages


95. How do you create a symbolic link in Linux?

Answer:
Use ln -s:

ln -s /path/to/source /path/to/link

Reference: ln command – Linux Man Pages


96. How can you check the status of a hardware component in Linux?

Answer:
Use specific commands like lspci, lsusb, etc.:

lspci
# or
lsusb

Reference: lspci command – Linux Man Pages, lsusb command – Linux Man Pages


97. How do you configure a static IP address in Linux?

Answer:
Edit the network configuration file, e.g., /etc/network/interfaces or use nmtui:

sudo nano /etc/network/interfaces

Reference: interfaces file – Ubuntu Man Pages, nmtui documentation


98. How can you check the status of a firewall in Linux?

Answer:
Use ufw, iptables, or firewalld:

ufw status
# or
iptables -L
# or
firewall-cmd --state

Reference: ufw documentation, iptables documentation, firewalld documentation


99. How do you find out the amount of free and used memory in Linux?

Answer:
Use free:

free -h

Reference: free command – Linux Man Pages


100. How can you list all running processes in Linux?

Answer:
Use ps:

ps aux

Reference: ps command – Linux Man Pages