1. How to remove files older than 7 days by creating a cron job to run every night?
Ans : Let’s say logs been created in the following path /var/log/security
Find /var/log/security -type f -mtime +7 -exec rm -rf {} \;
Crontab -e – This opens an editor. Then type the below.
0 2 * * * /bin/find /var/log/security -type f -mtime +7 -exec rm -rf {} \;- This run every night 2 AM
and deletes the files which are 7 Days older.
2. Run a command that shows all lines except any lines that are starting with a character # in a file?
Ans: cat filename | grep -v ^#- This command displays all the lines except those
which starts with #
3. Which 2 files contains default values when creating a user with useradd command?
Ans: 1. cat /etc/default/useradd
2. cat /etc/login.defs
4. What is command to create the user with predefined uid, shell and Home directory?
Ans: useradd -m -d /home/user -s /bin/bash -u 9000 user
For validation please use the below command.
Grep user /etc/passwd
5. How to delete a user with his home directory.
Ans: userdel -r user --- This will delete user with his home directory
6. How to create the user with primary and secondary group?
Ans: useradd -g test -G wheel linux- This will create a user with primary group as test and
secondary group as wheel. For validation use the below command
Id linux-- uid=1003 gid=1000 groups=test(1000), wheel(10)
7. How to change primary group for any user.
Ans: usermod -g staff linux
8. How can you give normal users as root level permissions.
Ans: cat /etc/sudoers- We need to edit this file and give root level permissions
9. How can you give sudo access to any user without asking you to provide password every time he runs
a command?
Ans: cat /etc/sudoers- We need to edit this file and give root level permissions without
asking for password every time
10. How to view users login and logout details?
Ans: last username - this will give you output of specific user login and logout details with
dates.
11. How to lock and unlock user.
Ans: passwd -l username- To lock an account
Passwd -u username- To unlock an account
For validation purpose use following command - grep linux /etc/shadaow
12. What is the command to view and change the expiry date of the user.
Ans: chage -l username - This displays all password related info about user
Chage -E 2019-12-22 username - Helps us to change the expiry date
13. What are the fields of /etc/passwd
Ans: 1. Username
2. Encrypted password
3. user id
4. group id
5. Description
6. Home directory
7. Default login shell
14. What is the difference between .bash_profile and , .bashrc
Ans: When you login as specific user .bash_profile file will executed. But if you are already logged in
and opening a new terminal then .bashrc file will execute.
15. What are the details that you get using finger command?
Ans: finger username - This will displays the following Login, Name, Directory and Shell,
mail and Plan.
16. Name 3 files which are auto created when you create the user.
Ans: .bash_history, .bash_profile and .bashrc
17. what is the command to view all currently logged in users?
Ans: w or who
18. How to find an error in a file.
Ans: grep error /var/log/messages or grep -i error var/log/messages
19. List 3 types of filesystems
Ans: ext3, ext4 and xfs
20. How to check whether the package is installed.
Ans: rpm -qa | grep http
The default package for DNS is “bind” and its default port number 53
DNS default configuration file is “/etc/named.conf”
21. Where are zone files located in DNS.
Ans: ls /var/named
22. How to find where passwd command located.
Ans: To find location of any command use the following command which passwd
23. How to find Ip-address and mac address.
Ans: ifconfig or ifconfig -a
24. how to find hostname?
Ans: hostname
25. How create a group?
Ans: groupadd newgrp
26. How to check running processes in your system
Ans: ps -ef
27. How to view to all messages generated by the system since last reboot in rhel7?
Ans: journalctl or journalctl | grep ssh (This gives all messages which are related to SSH since
last reboot)
28. What are the different ways of showing kernel messages.
Ans: demsg or (demsg | less) or (journalctl -k)
29. Where can you find messages related to installation of Linux?
Ans: cat /var/log/anaconda/anaconda.log
30. Where are most log files located-- /var/log
31. To improve performance how can you set limit process for user root.
Ans: ulimit -a or ulimit -u
32. How can you set resource limits to users who logged in as PAM
Ans: cat /etc/security/limits.conf
33. How to check ulimit for the user
Ans: ulimit -a
34. How to view runtime kernel parameters
Ans: sysctl -a
35. How to view boot time parameters and which file is modified
Ans: cat /proc/cmdline and the file (cat /boot/grub2/grub.cfg)
36. How to check system load without top command?
Ans: uptime or w or top or htop or glances
37. By default load average shows in how many intervals.
Ans: 1, 5 and 15 mins interval
38. How can you get physical and virtual memory stats (Swap).
Ans: free (it shows in kb’s) or free -m (it shows in mb’s) or vmstat (for virtual memory stats)
39. How to check cpu utilization and other statics.
Ans: sar -u (It shows the cpu usage for current day)
Sar -r (To check memory utilization)
Sar -s (To check Swap utilization)
40. How to find process id and kill processes?
Ans: Lets say if you want to kill cat then use pidof cat(This displays cat’s id) then use kill
41. How to list all opened files by specified user.
Ans: lsof -u username
42. How to list all opened files by specified command.
Ans: lsof -c ls (This displays all files opened by ls command)
43. How to list all network connections by port 22?
Ans: lsof -i :22 (This gives all information about connections of port 22)
44. How to list all created users and send them via file.
Ans: cat /etc/passwd - cut -d: -f1 /etc/passwd > filename.txt
45. How would you list only 2nd column in a specific file?
Ans: awk ‘{print $2}’ filename.txt or cut -d ; -f2 filename.txt
46. How to broadcast a message to all logged in users?
Ans: wall -n “System is rebooting in another 5 mins”
47. How to create user with no login access?
Ans: useradd -s /sbin/nologin username
To validate use su – username—You will get an error message
48. How to schedule server reboot in 15 mins.
Ans: shutdown -r +15 or shutdown -r now or shutdown -r 23:00
49. How to find disk usage by the largest directories?
Ans: du -S /var/log | sort -n (This displays all files in sorted numeric order by most occupied)
50. How prevent users deleting files of other users.
Ans: cd /var/log mkdir history ls -ltr history chmod 1755 history (Using stickybit we
can accomplish the above question)
51. Print the 10th line of the file
Ans: head -10 filename | tail -1 (Head -10 will get results of 1st 10 lines and tail will print the
last line)
52. You server got hacked or server damaged. How would restore kernel system files or restoring server.
Ans: If I’m using VMware, It has a tool where it captures system state depending on which date it is
captured. You can restore it from that state.
If in case you are using a physical server, We cannot restore whole system but we can backup
configuaration files and user data from tape backup device.
53. What necessary steps taken to enhance security system of Server.
Ans: Update Kernal and package using - yum update
You can disable any unnecessary services and deamons. - Enable firewall and configure it
Service firewalld start
I would setup complex passwd policy and I would disable root login via ssh
54. Which file is the most commonly know for checking for log messages.
Ans: /var/log/messages
55. Why would you want to disable ping?
Ans: Let’s say your server is a Webserver and users starts pinging there is a possibility of hanging your
system.
56. Which command can tell how long system has been running?
Ans: uptime
57. How to check if the port is listening?
Ans: netstat -anp | grep 22
58. How to troubleshoot for Server down issue?
Ans:
Check website url or if it is just a server try login
Try pining the server or website
You can try to ssh into server
Traceroute servername
59. How to find all files /bin with the specific permissions (755)?
Ans: find /bin -perm 755
60. What is the default port and configuaration file of ssh server?
Ans: Port : 22, and the config file “/etc/ssh/sshd_config”
61. How to change the default ssh port in linux?
Ans: To change the port, first edit the file “/etc/ssh/sshd_config” change the value of Port 22 and
restart SSH service
62. How to change the maximum allowed sessions through SSH?
Ans: grep Maxsessions /etc/ssh/sshd_config- Then change the value.
63. What is the config file for SSH client?
Ans: “cat /etc/ssh/ssh_config” Is the client file
64. How to disable SSH root login in linux server?
Ans: Edit /etc/ssh/ssh_config and change the value “PermitRootLogin Yes” to “PermitRootLogin No”
and restart SSH service
65. How to allow only specific users to SSH into Linux Server?
Ans: Edit file /etc/ssh/sshd_config and enter the following entries at
AllowUsers user1 user2 - Restart SSH Service
66. What is SCP and How to use it?
Ans: SecureCopy- It uses SSH for data transfer and uses same authentication and provides same
security as SSH
CMD: scp file1 username@centos:/home/test
67. How to check the SSH Server version?
Ans: ssh -V
68. How to enable passwordless SSH authentication in Linux?
Ans: Use the following steps
ssh-keygen
ssh-copy-id -I ~/.ssh/id_rsa.pub Username@Servername For validation
ssh servername - This time it won’t ask for password
69. How to extend Swap space?
Ans:
lsblk
lvs
lvextend -L 900M /dev/centos/swap
For validation use ( swapon -s). It still shows existing size. To make it effect use below
Swapoff -v /dev/centos/swap
mkswap /dev/centos/swap
swapon -va
swapon -s (This is for validation. This time it will take effect)
70. How to extend logical volume?
Ans:
lsblk
vgs
lvs
lvextend -L 700M /dev/new_vg/test_lv
resize2fs /dev/new_vg/test_lv --- This is used to extend the existing filesystem after extending
LV
71. How to create Logical volume?
Ans:
lsblk
pvs
vgs
lvcreate -n test_lv -L 500M new_vg
mkfs.ext4 /dev/new_vg/test_lv
df -h (It will not appear because it is not mounted)
mkdir test
mount /dev/new_vg/test_lv /test/
df -h (This time it will show LV mounted to filesystem )
72. How to create a Volume group?
Ans:
lsblk
pvs
vgcreate test_vg /dev/sdb
vgs (for validation purpose)
73. How to create the Physical volume after disk space has been increased?
Ans:
lsblk
pvcreate /dev/sdb
pvs ( For validation)
74. IS it possible to increase the logical volume on fly?
Ans: Yes. LVM has feature to increase the volume without unmounting it.
Lvs
Lvextend -L 600M /dev/new_vg/test_lv
Lvs (For validation purpose)
75. How to reduce logical volume? Is it possible to reduce on fly?
Ans: No, We can’t reduce Logical volume on fly. Below are the steps to reduce Logical volume.
Lvs
Df -h (If it is mounted to filesystem then we need to unmount)
Umount /test/
E2fsck /dev/new_vg/test-lv
Resize2fs /dev/new_vg/test_lv
Lvreduce -L 400M /dev/new_vg/test_lv
Lvs (Now it will reduce from 500M to 400M)
Mount /dev/new_vg/test_lv /test/ ( You will get the error, Use below to fix)
Resize2fs /dev/new_vg/test_lv
Mount /dev/new_vg/test_lv /test/ (This time it will work)
76. How to scan disks for existing Volume group?
Ans:
Pvscan
Vgscan
77. How to scan logical volume for existing volume group
Ans:
Lvscan
78. How to stop or deactivate the Logical volume?
Ans:
Lvchange -an /dev/vgname/lvname
79. how to activate the logical volume?
Ans
Lvchange -ay /dev/vgname/lvname
80. How to disable and enable Volume group?
Ans:
Vgchange -an vgname / vgchange -ay vgname(This is to activate)
81. What is the default size of physical extent in LVM?
Ans: Physical volume is divided into several smaller logical pieces when it is added to VG.
These logical pieces are known as PE’s , Its default size 4MB
82. How to list the logical volumes in the LVM? How to list physical volumes in LVM?
Ans:
Lvs / lvdisplay
Pvs / pvdisplay
83. How to see detailed volume group information?
Ans: vgdisplay vgname
84. How to find files that are over 10MB in size?
Ans: find /var/log -size +10M
85. How would you find all lines containing a character # in that file?
Ans: cat /etc/resolv.conf | grep “#”
86. How would you display all lines in a file with line numbers?
Ans: cat -n filename
87. How to find current system information such as version or release info ?
Ans: uname -v (for version) or uname -r (for release version) or uname -a (To know all info)
88. Where is the file located for network interfaces?
Ans: cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
89. Which command can you run to find certain package installed?
Ans: rpm -qa | grep httpd
90. How to find out total lines in a file without opening the file?
Ans: wc -l filename
91. How to find the disk usage by the largest directories ?
Ans: du -S | sort -n
92. How to find all directories named conf under root?
Ans: find / -type d -name conf
93. How to find files not accessed in over 3 days?
Ans: find /etc -atime +3
94. How to view difference between two files?
Ans: diff filename1 filename2
95. What is the location of system configuration files that should be backed up regularly?
Ans: tar -cvf /dev/tape /etc/
96. What command is used to find currently logged in users?
Ans: who or w
97. Step by step boot process for RHEL6 and RHEL7?
Ans:
Poweron Machine
BIOS or UEFI
MBR (Master Boot Record)
Boot Loader (GRUB or LILO)
Kernel and initramfs
98. Details about Hostname?
Ans:
Hostname--- This command gives system name
Hostnamectl--- This command gives System name with OS information and Distro info and
Kernel info. This command is similar to uname with different switches
Hostnamectl set-hostname linux--- This changes your hostname to Linux
You can view and edit hostname file. Its location is /etc/hostname
99. To List all process owned by any user or any group.
Ans: ps -U username or ps -G groupname
100 Some important commands related to process.
Ans:
Pidof- Displays pid of process
Ps -ef | grep httpd - pgrep httpd (Both are same, Both displays pid of process http)
101. How to find default nice value?
Ans: nice
102. How to find priority or niceness of process
Ans: top or ps -l
103. How to change niceness of a process?
Ans: nice -2 top
104. How to run a command at a higher priority with nice value of -10?
Ans: nice --10 top
105. How to renice the running process?
Ans: renice 5 pid renice 5 642
106.