Skip to main content

Linux Interview Questions

Part #2: User Management, Storage, and Job Scheduling (29-49 Questions)

In this part of the Linux Interview Handbook, weโ€™ll dive into three critical areas every Linux administrator should master: user and group management, file system and storage, and job scheduling.

Welcome to Part 2 of our Linux Interview Questions Series. In the previous part, we covered the basics of Linux, common commands, and how to monitor system processes. Now, weโ€™re moving a step further into more practical and commonly asked topics in interviews.

In this part, weโ€™ll focus on three important areas: user and group management, file system and storage, and job scheduling and time management. Youโ€™ll learn how to manage users and permissions, check disk space, understand key system files, and automate tasks using tools like cron and at.

๐Ÿ‘ค User and Group Management

In this section, we share questions that show how to manage who can access your system by adding, editing, or removing users, and organizing them into groups for simpler, centralized control.

29. How do you list all users in a Linux system?

To list all users on a Linux system, you can use the following command, which extracts and displays all usernames from the /etc/passwd file.

cut -d: -f1 /etc/passwd

If you want to see which users are currently logged in, use the who command. For even more detailed information about current login sessions, including what each user is doing, the w command provides a comprehensive view.

who
w

30. How do you switch users in Linux?

To switch users in Linux, you can use the su command or the sudo command, depending on what you need. The su (substitute user) command lets you switch to another user account entirely.

For example, su - username will switch to the specified user and load their environment. If you want to run a specific command as another user without fully switching accounts, you can use sudo.

The syntax is sudo -u username command, which runs the command as that user, which is especially useful for executing a single task as another user without changing your current session.

31. What is the difference between โ€˜sudoโ€™ and โ€˜suโ€™?

The sudo and su commands are both used to perform tasks with elevated privileges in Unix-like systems, but they serve different purposes.

The sudo command allows a permitted user to run a specific command as another user, usually the superuser (root), without switching the current user session. Itโ€™s often used when you need to perform a single administrative task.

For example, sudo apt update will refresh the package list with root privileges while keeping the current user session intact.

On the other hand, the su command is used to switch to another user entirely, most commonly the root user.

For instance, su - root will prompt for the root password and log you into a root session with a new shell environment.

32. How do you change a user password in Linux?

In Linux, the passwd command is used to change user passwords, which is essential command for user account password management.

If you want to change your own password, simply type passwd in the terminal, which will prompt you to enter your current password followed by the new password twice for confirmation.

passwd

To change the password of another user, you need superuser (root) privileges. Use sudo followed by the passwd command and specify the username of the account whose password you want to change.