Linux sysadmin interview questions and answers part 2

In this article, you will learn Top Linux sysadmin questions and answers. It is part2. You can read Linux system admin interview questions and answers for beginners part1.

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

sahil:x:1001:1001::/home/sahil:/bin/bash

UserName : EncrptedPassword : 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 sahil then the command will be as below.

usermod -L sahil

Once an account gets locked, there would be an exclamation mark before the encrypted password files in /etc/shadow as shown below:

sahil:!$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.

passwd -l username

For instance, if you want to block a user whose name is sahil then the command will be as below.

passwd -l sahil
linux sysadmin questions answers
locking a user account using passwd -l command

Once an account gets locked, there would be two exclamation mark before the encrypted password files in /etc/shadow as shown below:

sahil:!!$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 use vipw.
  • To edit the user group file /etc/group file, you can use vigr.
  • You can edit the shadow password /etc/shadow file, you can use vipw -s.
  • To edit the shadow group /etc/gshadow file, you can use vigr -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.

passwd -S username

For instance, if the user name is sahil then the command will be as below.

passwd -S sahil
linux sysadmin questions answers
confirming a user account status

Secondly, you can look in /etc/shadow and grep the username. If there is one exclamation mark then the user account has been locked using usermod -L username command but if there is two exclamation mark then the user account has been locked using the passwd -l username command.

cat /etc/shadow | grep sahil

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?

Ans: 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.

chage -d 0 username

For example, if the user name is sahil then the command will be.

chage -d 0 sahil

Note: You can check the detail using the command chage -l username.

For example,

chage -l sahil
Output of the chage command using -l option for the user sahil

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.

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 david and the home directory location will be /data/home/david. So the command will be as below.

useradd -d /data/home/david david
Checking the home direcotry of the user david in /etc/passwd file.

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 message along with the question in the comment section.

Linux sysadmin interview questions and answers

6 Comments

  1. Excellent post. I absolutely love this site. Continue the good work!

  2. Marie Sinclair Tess
    Marie Sinclair Tess

    I think everything published made a great deal of sense.

  3. Nice

  4. I got it useful for me.

  5. nice collection.

  6. Krishna Prabhat
    Krishna Prabhat

    The list of the questions and answers are very good. I got three question from this list in my interview. thanks

Leave a Reply