In this article, you may learn high Linux sysadmin queries and answers. it’s part2.
You Can read Linux SysAdmin Interview Questions 2021 Part 1
Q1. Which file stores the user min UID, max UID, password expiration settings, and password encryption method will be used.
Ans: The file name is /etc/login.defs
.
Q2. How do you make a file copied to a new user account automatically upon user account creation?
Ans: To make a file copied to a new user account automatically upon user account creation then you have to store that file in /etc/skel
directory.
Q3. What is the mean of the fields in /etc/passwd
file?
Ans: There are seven fields in /etc/passwd
file. So all the fields are separate from the colon. Also, you can read more after visiting /etc/passwd
nerds:x:1001:1001::/home/nerds:/bin/bash
UserName : EncryptedPassword : UserID : GroupID : Comments : HomeDirectory : LoginShell
Q4. How to lock a user account?
Ans: There are many ways to lock a user account. You can find it below.
Firstly, you can use the usermod
command along with -L
option in below format.
usermod -L username
For instance, if you want to block a user whose name is nerds
then the command will be as below.
usermod -L nerds
Once an account gets locked, there would be an exclamation mark
before the encrypted password files in /etc/shadow
as shown below:
nerds:!$6$6ddHi7a1mFlbPRPa$CWO.fTKiCVmGUXYAPELWKC59MAmaEACIRuL8d8PST8oX3C77jHEhOboZEoP33IrBYRy6Y49fIBfFLmSEzi3vs0:18472:0:99999:7:::
Secondly, you can also use the passwd
command along with -l
option in below format to lock a user account.Copy The Command
passwd -l username
For instance, if you want to block a user whose name is nerds
then the command will be as below.
passwd -l nerds
Once an account gets locked, there would be two exclamation mark
before the encrypted password files in /etc/shadow
as shown below:
nerds:!!$6$6ddHi7a1mFlbPRPa$CWO.fTKiCVmGUXYAPELWKC59MAmaEACIRuL8d8PST8oX3C77jHEhOboZEoP33IrBYRy6Y49fIBfFLmSEzi3vs0:18472:0:99999:7:::
Q5. How to unlock a user account?
Ans: To unlock a user account, you can use the below command.
Firstly, you can use the usermod
command along with -U
option to unlock the user account in the below format.
usermod -U username
Secondly, you can use the passwd
command along with -u
option in the below format.
passwd -u username
Q6. How to disable user login via terminals?
Ans: If you want to disable a user login via terminal then you have to modify the user login shell in /etc/passwd
file.
Add /sbin/nologin
field instead of /bin/bash
in /etc/passwd
file for that user.
Q7. Which commands are normally recommended to edit /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files?
Ans: If you want to edit the /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files then you can go as per below format.
- To edit the user password
/etc/passwd
file, you can usevipw
. - To edit the user group file
/etc/group
file, you can usevigr
. - You can edit the shadow password
/etc/shadow
file, you can usevipw -s
. - To edit the shadow group
/etc/gshadow
file, you can usevigr -s
These commands would normally lock the file while editing to avoid corruption.
Q8. How to check if a user account has been locked?
Ans: To check if a user account has been locked or not, so you can use the below method.
Firstly, you can use the passwd
command along with -S
option then you can get the output.Copy The Command
passwd -S username
For instance, if the user name is nerds
then the command will be as below.
passwd -S nerds
Secondly, you can look in /etc/ shadow and grep the username. If there’s one exclamation mark either the user account has been locked using usermod-L username command but if there’s two exclamation mark either the user account has been locked using the passwd-l username command.
cat /etc/shadow | grep nerds
Note: If a user account has been locked using the usermod command then you can find the record in /var/log/secure
file by default.
# You can read Q5. How to unlock a user account?
Q9. Whenever a user tries to login via terminal, the system would throw up the error “The account is currently not available”, otherwise, via GUI when a user enters the password, it looks to be logging in, however, comes back to the login prompt. How can you fix this issue?
When the shell field set as /sbin/nologin
in /etc/passwd
file then you get the error Permission denied, please try again
. To fix it change the value from /sbin/nologin
to /bin/bash
in /etc/passwd
file.
If the shell field is set as /bin/false
then whenever a user tries to log in there will be no any error or messages, it just comes back to the login prompt and same happens in GUI mode. So again change it /bin/bash
in /etc/passwd
file.
Q10. How do you make a new user reset his/her password upon his/her first login?
Ans: To make it happen you have to use chage
command. Also set the date for password expiration. The command will be as below.Copy The Command
chage -d 0 username
For example, if the user name is nerds
then the command will be.Copy The Command
chage -d 0 nerds
Note: You can check the detail using the command chage -l username
.
For example,Copy The Command
chage -l nerds
Q11. Create users home directory in /data/home directory instead of default /home directory. Also, it gets applied to any new users who get created i.e the home directory of that user should be /data/home/username.
Ans: So, There are mainly two ways to do it.
Firstly, Changing the value in /etc/default/useradd
file. So use the any file editor like vi, vim or any other to open this file. I’m using here vim editor.Copy The Command
vim /etc/default/useradd
Now look for the line Home=/home
and change it to Home=/data/home
Save the changes after pressing Esc
key and then typing :wq
and hit Enter
key. As a result, you can check now after adding a new user using useradd command.
Secondly, you can use the useradd
command along with -d
option and full path for the home directory.
useradd -d /location/username username
For example, I’m creating a user with name flatliner
and the home directory location will be /data/home/flatliner
. So the command will be as below.
useradd -d /data/home/flatliner flatliner
Conclusion
In this tutorial, you learned about top Linux sysadmin questions and answers. So, If you have any suggestions or you want to add any questions, please leave a dispatch along with the question in the comment section.
Also You Can Read:
How To Install and Setup Ansible in Ubuntu