1. Overview
In Linux, it’s essential for a system administrator to know how to manage users. Additionally, it’s beneficial to have the knowledge to find and interpret user account information.
In this tutorial, we’ll get to learn these concepts while solving the Linux error “No passwd entry for user”.
2. Understanding the Error
When we run commands associated with user information like passwords and usernames, the system turns to the /etc/passwd file. This file stores registered users’ account information.
However, if we run a user-related task and there is no entry for that user in the /etc/passwd file, we get the error in question:
$ sudo su - john
No passwd entry for user 'john'
Depending on the Linux distribution and version, we may receive this error instead:
su: user john does not exist or the user entry does not contain all the required fields
Let’s take a closer look at what we’re trying to do with the above command. Essentially, we’re trying to switch our current user to user john using the su command. However, we get an error informing us that user john’s information cannot be found in the /etc/passwd file. So, if we register this person as a user in our system, we’ll resolve the issue.
3. Solving the Error
Let’s make john a user:
$ sudo adduser john
Adding user `john' ...
Adding new group `john' (1003) ...
Adding new user `john' (1003) with group `john' ...
...
Is the information correct? [Y/n] Y
Great, we’ve registered john as a user in our system. Next, let’s make sure that this is the case:
$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
...
john:x:1003:1003:john,,,:/home/john:/bin/bash
Here, we see an entry with john’s information: username, encrypted password, user’s ID*,* user’s group ID, user’s full name, user’s home directory, and the login shell, respectively. Furthermore, a colon (:) distinguishes one piece of information from another.
Now, we’ll try and run the previous command again:
$ sudo su - john
With the whoami command, we can confirm if the current user has been switched to john. It displays the name of the user logged into our system currently:
$ whoami
john
The output displays john as the currently logged-in user.
4. Conclusion
In this tutorial, we’ve learned that before performing any user-related commands, it’s important to make sure that the specified user exists. Also, we got to solve the Linux error in question and have a glimpse of the /etc/passwd file.