Loading...
Linux Interview Questions

Linux scenario-based interview Questions & Answers Phase 2

1. How to set a username and password to NEVER EXPIRE?
Ans:

Command to check expiration date:

chage -l username

-l: Lists account aging information.
Command to set account to never expire:

chage -M -1 username

-M -1: Sets password to never expire.
Additional chage options:
– -E YYYY-MM-DD: Set expiration date.
– -w DAYS: Set warning days before password expiry.

2. Why are /etc/passwd and /etc/shadow not merged into one file?
Ans:

  • – /etc/passwd is readable by all users and is used by commands like finger, ls, etc.
  • – For security, password hashes are stored in /etc/shadow, which is only readable by root.

3. How to list all files opened by a particular PID?
Ans:
lsof -p <PID>
lsof: Lists open files.

4. Why can’t I unmount a file system?
Ans: Possible reasons:
– Current working directory is inside the file system (pwd).
– Other users or processes are accessing it (fuser -cu /dev/sda, lsof /dev/sda).

5. Why does the server take a long time to boot after a reboot?
Ans: – The file system may be corrupted.
– ext2 file system lacks journaling support, which may delay recovery.

6. Permission denied error when creating a file, but no disk space or permission issues?
Ans: Possible cause: Inode exhaustion
Check inode usage:

df -i

If 100% inodes are used:
– Delete or move unnecessary files.

7. How to check kernel routing table?
Ans:

 route -n
netstat -rn
ip route

8. What is a Sticky Bit, and what is the difference between s and S?
Ans:  Sticky bit: Only the file/directory owner or root can delete.
Setting sticky bit:

  • chmod +t /opt/dump
  • chmod 1757 /opt/dump
  • – s: setuid/setgid and executable.
  • – S: setuid/setgid but not executable.

9. Which file defines the default gateway?
Ans:

/etc/sysconfig/network

10. How to switch runlevels in RHEL 7?
Ans:

  • systemctl isolate multi-user.target
  • systemctl isolate graphical.target
  • systemctl set-default multi-user.target
  • systemctl get-default

11. What is NFS and how to configure it?
Ans: Port: 2049
NFS Server:
1. Install nfs-utils.
2. Create and export directory via /etc/exports.
3. Restart nfs-server.
NFS Client:
1. Install NFS utilities.
2. Use showmount to view exports.
3. Mount export and verify access.

12. What is Nice value and how is it set?
Ans: nice -n [value] <command>
Range: -20 (high priority) to +19 (low priority).

13. How to extend the file system in Linux?
Ans:

lvextend -L +1G /dev/vg_name/lv_name
resize2fs /dev/vg_name/lv_name

16. How to rollback a package after patching?
Ans:

yum history
yum history info <ID>
yum history undo <ID>

17. What is rsync and how is it used?
Ans:

rsync -rv -e ssh /source 192.168.10.95:/destination

– r: Recursive
– v: Verbose

18. How to reduce file system size (offline only)?
Ans:

umount /mount_point
e2fsck -f /dev/vg_name/lv_name
resize2fs /dev/vg_name/lv_name
lvreduce -L -200M /dev/vg_name/lv_name

19. What do the three load average values in `uptime` indicate?
Ans: They represent average system load over 1, 5, and 15 minutes.

20. How to number lines in vi editor?
Ans: :

set nu

21. How to scan for new disks in Linux?
Ans:

echo "- - -" > /sys/class/scsi_host/hostX/scan

22. Explain /etc/fstab fields
Ans:
1. Device name
2. Mount point
3. File system type
4. Mount options
5. Dump (backup)
6. fsck order

24. Can a soft link span partitions?
Ans: Yes, soft links can span partitions.

25. Location of NFS shared info?
Ans:

/etc/fstab

26. How to check if a port is listening?
Ans:

netstat -anp | grep <port>

28. What is journaling in filesystems?
Ans:
– Journaling logs metadata changes to prevent corruption.
– Pros: Increased reliability.
– Cons: Slightly slower performance.

29. Patch command failing due to dependency issues. What to do?
Ans:

rpm -ivh <package>.rpm --nodeps

–nodeps: Installs without checking dependencies (use with caution).

Leave a Reply

Your email address will not be published. Required fields are marked *