Professional Documents
Culture Documents
Kashif Ali
Kashif Ali
Kashif Ali
Ans : Let’s say logs been created in the following path /var/log/security
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?
2. cat /etc/login.defs
4. What is command to create the user with predefined uid, shell and Home directory?
Ans: userdel -r user --- This will delete user with his home directory
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
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
Ans: last username - this will give you output of specific user login and logout details with
dates.
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
Ans: 1. Username
2. Encrypted password
3. user id
4. group id
5. Description
6. Home directory
7. Default login shell
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: w or who
The default package for DNS is “bind” and its default port number 53
DNS default configuration file is “/etc/named.conf”
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
Ans: hostname
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)
31. To improve performance how can you set limit process for user root.
Ans: ulimit -a
Ans: sysctl -a
35. How to view boot time parameters and which file is modified
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)
Ans: sar -u (It shows the cpu usage for current day)
Ans: Lets say if you want to kill cat then use pidof cat(This displays cat’s id) then use kill
44. How to list all created users and send them via file.
45. How would you list only 2nd column in a specific file?
Ans: du -S /var/log | sort -n (This displays all files in sorted numeric order by most occupied)
Ans: cd /var/log mkdir history ls -ltr history chmod 1755 history (Using stickybit we
can accomplish the above question)
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.
You can disable any unnecessary services and deamons. - Enable firewall and configure it
54. Which file is the most commonly know for checking for log messages.
Ans: /var/log/messages
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
Ans:
59. How to find all files /bin with the specific permissions (755)?
60. What is the default port and configuaration file of ssh server?
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: 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: SecureCopy- It uses SSH for data transfer and uses same authentication and provides same
security as SSH
Ans: ssh -V
ssh-keygen
ssh-copy-id -I ~/.ssh/id_rsa.pub Username@Servername For validation
ssh servername - This time it won’t ask for password
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)
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
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 )
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)
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)
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)
Ans:
Pvscan
Vgscan
Ans:
Lvscan
Ans:
Ans
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
85. How would you find all lines containing a character # in that file?
86. How would you display all lines in a file with line numbers?
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)
89. Which command can you run to find certain package installed?
90. How to find out total lines in a file without opening the file?
Ans: wc -l filename
95. What is the location of system configuration files that should be backed up regularly?
Ans: who or w
Ans:
Poweron Machine
BIOS or UEFI
MBR (Master Boot Record)
Boot Loader (GRUB or LILO)
Kernel and initramfs
Ans:
Ans:
Ans: top or ps -l
104. How to run a command at a higher priority with nice value of -10?
106.