Solving "Sudo Access "Error When User Does Not Exist in Passwd Database

At times, you may run into an error that says "sudo: user foo does not exist in the passwd database" while running a sudo command. In such a scenario, user access rights become compromised and it's important to troubleshoot the issue quickly and determine why the user cannot gain access to sudo. This guide will help you troubleshoot and fix the “sudo: user foo does not exist in the passwd database” error.

Step 1: Identify the User in Question

The first step in troubleshooting this issue is to identify the user that is not listed in the passwd database. The passwd database is a file which stores users’ authentication data. Specifically, it contains information about the user names, passwords, user ID and user group ID. The file is located in the /etc/passwd directory in a Linux system.

To view all users in the passwd database, execute the following based on your Linux distribution:

Centos/RHEL (Red Hat):

$ cat /etc/passwd

Ubuntu:

$ getent passwd

Look through the contents of the file to identify the user who is not listed.

Step 2: Check the User's Presence in the "shadow" File

Once you have identified the user name that is missing in the passwd database, go to the /etc/shadow file which contains the encrypted passwords associated with each user.

The greatest challenge lies in distinguishing a user that appears in the passwd database but not in the shadow file. In such a scenario, you will be unable to use the usual methods to reset the user's password.

Run the following command on the terminal to view the contents of the shadow file:

$ sudo cat /etc/shadow

Check the output of this command to know if the user exists in the shadow file.

Step 3: Fixing the Issue

If both the passwd and the shadow file do not contain the user, it means that the user was created by a third-party package or application and is not available in the passwd database.

In this scenario, you may have to reset the user account to regain access. To do this, execute the following command on the terminal:

$ sudo useradd -m <username>

where <username> is the name of the missing user.

This will add the user back to the passwd database. Once the user is added, the passwd file needs to be updated and the ‘shadow’ file needs to contain the encrypted password for the user.

To update the passwd file, run the following command:

$ sudo pwconv

This will update the user’s information in the passwd file.

Similarly, you will need to update the shadow file by running the following command:

$ sudo pwunconv

Finally, reset the password for the user to grant access. To do this, use the passwd command followed by the name of the user. Execute the following command on the terminal:

$ sudo passwd <username>

You can now login to the user with the credentials set in the shadow file.

FAQ

Q1: What Is the Location of the Passwd File?

The passwd file is located in the /etc/passwd directory in a Linux system.

Q2: How Can I Check the List of Users in the Passwd Database?

On a Centos/RHEL (Red Hat) system, use the cat command to view all users in the passwd database:

$ cat /etc/passwd

On an Ubuntu system, use the getent command to view all users in the passwd database:

$ getent passwd

Q3: Where Is the Shadow File Located?

The shadow file is located in the /etc/shadow directory in a Linux system.

Q4: How Can I View the Contents of the Shadow File?

Run the following command to view the contents of the shadow file:

$ sudo cat /etc/shadow

Q5: How Can I Reset the User Account?

To reset the user account, execute the following command on the terminal:

$ sudo useradd -m <username>

where <username> is the name of the missing user. This will add the user back to the passwd database. Then, update the passwd file using the pwconv command and the shadow file using the pwunconv command. Finally, use the passwd command followed by the name of the user to reset their password.

https://askubuntu.com/questions/1361115/sudo-you-do-not-exist-in-the-passwd-database

https://unix.stackexchange.com/questions/697382/ldconfig-sudo-you-do-not-exist-in-the-passwd-database

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Lxadm.com.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.