Linux Questions
Linux Questions
Type:Silver
User Administration
1. What the fields of /etc/passwd file?
Ans:-
deepak:x:512:512:User:/home/deepak:/bin/bash
1st field: username
2nd field: x tells that an encrypted password is stored in /etc/shadow
3rd field: uid
4th field: gid
5th field: Description
6th field: home directory
7th field: default login shell
# vi /etc/passwd
user:x:501:501:test user:/home/user:/bin/bash
Step 2
You will have to create a group with same name. So add a new entry in /etc/group
# vi /etc/group
user:x:501:
Step 3
Assign a password to the user
# passwd user
Changing password for user user.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Now let us try to login with our newly created user
Ans:-
# su - user
-bash-4.1$
7. What is the command to create a user with a pre-defined uid, shell and home
directory?
Ans:-
useradd -m -d /path/to/home -s /bin/bash -u 550 deepak
9. If I delete a user, does it's home directory gets deleted? If not then what is the
command to delete the home directory of user along with the user
Ans:-
No.
# userdel -r username
10. Name any 3 files which are automatically created inside any user's home directory
when a user is added
Ans:-
.bashrc
.bash_profile
.bash_history
11. What is the command to view all the currently logged in users?
Ans:-
w
12. What is the command to change and view the expiry date for any user?
Ans:-
chage
13. What are the details you get with finger command?
Ans:-
Login Details
Mail
Home directory
Last login
14. How can you give a normal user all the root level privileges?
Ans:-
Add the user to wheel group and uncomment the wheel group line in sudoers file
Give the user all command permission in sudoers
Method 1
# visudo
Add an extra line in the last and make this entry
deepak ALL=(ALL) ALL
Using this above line you are telling your Linux box to give full permission for user deepak on all
the hosts and all the commands
[deepak@test ~]$ sudo /etc/init.d/network restart
[sudo] password for test:
Shutting down interface eth0: Device state: 3 (disconnected)
[ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Active connection state: activated
Sanjeevi Machina
Type:Silver
Method 2
Add the user to wheel group
# usermod -G wheel deepak
Verify the same
# cat /etc/group | grep wheel
wheel:x:10:root,deepak
Now uncomment this line from sudoers file
# visudo
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
The reason we did this because be default root is a member of wheel group so in case you want
to give root level permission to any
normal user then add him/her in wheel group.
$ sudo /etc/init.d/vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
16. How can you give sudo access to any user without asking him to provide password
every time he runs a command?
Ans:-
Add an extra parameter NOPASSWD in sudoers file while giving the user permission to run root
level commands
17. Why should I use visudo command instead of directly editing the file with vi or any
other editor?
Ans:-
Well the answer is in case you are editing the sudoers file using vi editor and you use any wrong
syntax and save and exit the file then it might even become hard for the root user to log back in
and edit the file again. As vi editor would not check for any syntax error inside the file.
That is the reason you should always prefer to use visudo because even in case you make any
syntax error then visudo will prompt you before making and changes and exiting.
# visudo
Suppose you want to give your user permission to run network and apache server restart
permission
# visudo
%test 192.168.0.100=(root) /etc/init.d/network, /etc/init.d/httpd
Sanjeevi Machina
Type:Silver
24. How do we set force passwd change for User's first login ?
Sanjeevi Machina
Type:Silver
Ans:-
Chage –d 0
# passwd -f <UserID>
bash-3.00# passwd -s unixrock
unixrock PS 12/11/13 7 91 7
bash-3.00#
bash-3.00# passwd -f unixrock
passwd: password information changed for unixrock
bash-3.00#
bash-3.00# passwd -s unixrock
unixrock PS 00/00/00 7 91 7
bash-3.00#
25. How to delete the User ID ?
Ans:-
# userdel <UserID> or # userdel -r <UserID>
-r option will delete the User's Home directory too.
Permissions in Linux
1.What is the difference between SUID and SGID?
Set UID – help to run the program as if the owner is running.
SGID – help to the program as if the group owner is running – Additionally when enabled on
directories, the group ownership is inherited by child directories.
2. What is Sticky Bit permission?
When sticky bit is enabled of directories, only the owner of the file is allowed to delete the files
and rest of the users cant delete though they have write permission on the directory. Example is
/tmp.
3. What is umask?
Ans:-
In computing, umask is a command that determines the settings of a mask that controls which
file permissions are set for files and directories when they are created. It also refers to a
function that sets the mask, and to the mask itself, which is formally known as the file mode
creation mask.
4. What is the default umask value for useradd command and where is it defined?
Ans:-
Default umask value for useradd: 077
/etc/login.defs
5. Will you be able to cd into a directory with only read permission?
Ans:-
No, we need execute permission along with read to cd into directory
6. What is -R argument used for along with chmod command?
Ans:-
To recursively apply the permission to all the directories including sub directories and files
7. How can you restrict a normal as well as root user from making any changes as well as
deleting any file?
Ans:-
chattr command
8. What is the difference between small t and capital T when applying sticky bit
permission?
Ans:-
Before applying Sticky Bit with executable permission
# chmod 775 /statusupdate
# ls -l
Sanjeevi Machina
Type:Silver
Display crontab
crontab -l
crontab -v
LVM
1.How many volume groups can be created in Linux ?
Answer :256.
Sanjeevi Machina
Type:Silver
21.What is lvmdump ?
Answer: “lvmdump” is tool for LVM2 to collect the various information for diagnostic purposes.
By default, it creates a tarball suitable for submission along with a problem report
22.How to replace the failed hard disk in LVM ?
23.How to create a mirrored logical volume ?
24.How to create a striped Logical volume ?
25.How to convert the linear volume to mirror volume ?
26.How are snapshots in LVM2 different from LVM1 in Redhat Linux?
Answer:LVM1 snapshots are readonly by default where LVM2 snapshots were read/write.
27.What are the steps involved to create the logical volume from scratch ?
Answer:
i.Create a physical volume using pvcreate command.
#pvcreate /dev/sdc
ii.Create a volume group using “vgcreate” command
#vgcreate vg02 /dev/sdc
iii.Create a logical volume using “lvcreate” command
#lvcreate -L 100M -n vol1 vg02
iv.Create a filesystem on logical volume using mkfs command.
#mkfs -t ext4 /dev/vg02/vol1
v.Mount the filesystem using mount command for use.
#mount -t ext4 /dev/vg02/vol1 /vol1
28.How to extent the volume group ?
Answer:Using “vgextend” we can increase the volume group.
29.Assume Volume group “vg02” is already exists.How do you extend the volume group
with 50GB ? Provide all the steps with commands.
Answer:
1.Get the 50GB lun from SAN team.(/dev/sdd)
2.Create physcical volume ( # pvcreate /dev/sdd )
2.Extend the volume group (# vgextend vg02 /dev/sdd)
30.If the vg02 has two physical volumes called /dev/sdc/ & /dev/sdd. How do you
remove /dev/sdd from vg02.
Answer: “vgreduce vg02 /dev/sdd/”
31.How to decommission/remove LVM completely from the host ?
Answer:
1.Un-mount all the logical filesystems
2.Remove the logical volumes using “lvremove” command.
3.Destroy the volume group using “vgremove” command.
4.Use “pvremove” command remove the physical volumes from the system.
Networking
1. How do you perform NIC teaming & its benefits?
http://www.golinuxhub.com/2014/01/how-to-do-ethernetnic-bondingteaming-in.html
Load balancing
Fault Tolerance
Failover
3. Mention all the network configuration files you would check to configure your ethernet
card
/etc/sysconfig/network-scripts/ifcfg-eth*
/etc/sysconfig/network
/etc/resolv.conf
/etc/nsswitch.conf
6. What is the command to check all the open ports of your machine?
Ans:- nmap localhost
7. What is the command to check all the listening ports and services of your machine?
Ans:- netstat -ntlp
10. What are the possible ways to check if your system is listening to port 67
# nmap localhost | grep 67
# netstat -ntlp | grep 67
Block IP Address
# vi /etc/hosts.deny
Sanjeevi Machina
Type:Silver
Add the IP address that you want to block at the bottom of the file.
#
# hosts.deny This file contains access rules which are used to
# deny connections to network services that either use
# the tcp_wrappers library or that have been
# started through a tcp_wrappers-enabled xinetd.
#
# The rules in this file can also be set up in
# /etc/hosts.allow with a 'deny' option instead.
#
# See 'man 5 hosts_options' and 'man 5 hosts_access'
# for information on rule syntax.
# See 'man tcpd' for information on tcp_wrappers
#
vsftpd:172.16.16.1
Answer : Telnet and SSH both are communication protocol which are used to manage remote
system. SSH is Secured, which requires exchanging of key opposite of telnet which transmit
data in plain text, which means telnet is less secure than SSH.
Rescue mode will try to mount all local file systems and start some important system services, but it
does not activate network interfaces neither allow multiple users to be logged in.
Emergency mode
Emergency mode provides the most minimal environment possible and allows you to repair your
system even in situations when the system is unable to enter rescue mode. In emergency mode, the
system mounts the root file system as read-only, does not attempt to mount any other local file
systems, does not activate network interfaces.
6.When it is required to boot the Linux box in the rescue mode and how will you boot the server in
rescue mode?
7.What is the default port and configuration file for ssh server