Linux Commands

Troubleshooting Error: Usermod: A Process Currently Uses User

Sometimes, while using any Linux distribution, most of the users got the Error: “user is currently used by process”. This error could have occurred while changing the username or deleting a user. One of the reasons behind this error is that the user has been deleting or changing a user’s name while logging in. If you are looking for solutions for this particular error, this tutorial is for you. Make sure you have any of the Linux distribution installed on your system. In our case, it’s Ubuntu 20.04 Linux system.

Example 01

Firstly, you have to have a look at the error. Suppose you have more than one account in your Ubuntu 20.04 system, and you want to delete one of them. So, we have a user “Saeed” in our Ubuntu 20.04, and we want to delete it. Login from the user “saeed” and open the command terminal. Now, write the below command to delete the user “saeed”. The output in the snapshot shows that the user is already used by some process “3751”.

$ userdel –r saeed

Let’s kill this process to delete this user using the “pkill” command and the process id as below. This command will kill the process, and the user will be logged out, while this cannot delete the user.

$ pkill -9 3751

When we try the userdel command with the “if” flag to forcefully delete the user “saeed”, it doesn’t work either as follows:

$ userdel –f saeed

Let’s login from the other account to avoid this error. You can find the information regarding the process id “3751” by using the below “ps” command.

$ ps aux | grep 3751

Now you can kill all the processes that held the user “saeed” to delete it or change something in it. For this, execute the below “killall” query followed by the name of a user and the “-u” flag along with the “-TERM” keyword.

$ killall –TERM –u saeed

After the deletion of all the processes, we will delete the user from this account using the below sudo command followed by the keyword “userdel” while using the flag “-r” alongside a user’s username to be deleted. It may require your current account password to delete the particular user. Add your password and hit the Enter button from the keyboard. It will output that the user has been successfully deleted and not found anymore.

$ sudo userdel –r saeed

Let’s confirm the deletion of the user “saeed” using the simple “id” command. It will output that there is no user. Try it as follows:

$ id saeed

Example 02

Let’s have a look at another similar example to understand this concept properly. Let suppose you have another user account in the Ubuntu Linux system named “Rimsha,” and you want to delete this user. At the start, you will log in from the user account named “rimsha” and open the terminal in it. After that, you will try to delete the user “Rimsha” while using the “userdel” command followed by a “-r” flag as below.

$ userdel –r Rimsha

It will show you an error that the current user in which you are currently logged in is already used by a process having a process id 9566. This means you cannot delete this account before you kill that process while you are currently logged in from the same account.

You can have additional information regarding the troubleshoot error 9566 using the “ps” and “aux” commands as below. You have to provide the process id within this command.

$ ps aux | grep 9566

So, you have to switch to another account. We have been using “aqsayasin” to make changes this time. If you want to list all the current users of the Ubuntu Linux system, try the below getent command as follows:

$ getent passwd

You can see from the output that it has all the usernames mentioned that we were using or currently logged in.

Before deleting a user “Rimsha”, let’s make sure that this account exists in our Linux system. And to see that, try out the below simple Id instruction along with the username to be checked. You will get the information regarding the user if it exists, e.g., user id, groups, and group id.

$ id rimsha

You can also get some extra information regarding the user “Rimsha” by using the below grep command.

$ grep ^rimsha /etc/passwd

Now, it’s time to kill all those user “Rimsha” processes that were holding the user “Rimsha” to delete itself. To delete all processes, we will try and execute the below “killall” query followed by the flag “-TERM” and “-u”, along with the name of a user. Now all the processes have been killed because we are currently logged in from another account to do that.

$ killall –TERM –u Rimsha

After killing all those processes that hold back the process of deletion, we are now ready to delete the user. We have been using the same “userdel” command to delete the user with sudo privileges and the “-r” flag and username of the user to be deleted. It may require your currently logged-in user password to execute this process of deletion. Type the password and hit the Enter key. You can see it displays that the user “Rimsha” doesn’t found anymore.

$ sudo userdel – r Rimsha

Let’s confirm the deletion of a user “rimsha” using the same old “id” command in the shell as below. It displays the output that there is no user “rimsha” found in the Ubuntu 20.04 Linux system without the error.

$ id rimsha


Finally! We have solved the troubleshooting error: a process currently uses the user. Make sure to perform every step of this tutorial for a better understanding of the troubleshooting error.

About the author

Aqsa Yasin

I am a self-motivated information technology professional with a passion for writing. I am a technical writer and love to write for all Linux flavors and Windows.