LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Is there any possibility to delete an user using uid?? (https://www.linuxquestions.org/questions/linux-newbie-8/is-there-any-possibility-to-delete-an-user-using-uid-4175636350/)

ruben_shah_j 08-14-2018 09:23 AM

Is there any possibility to delete an user using uid??
 
I was trying to remove some user from my linux system and I checked is there any possibility to delete user using user id but i couldn't find anything related to that.....

rtmistler 08-14-2018 10:14 AM

The command to delete a user is userdel(8).

ruben_shah_j 08-14-2018 10:17 AM

Quote:

Originally Posted by rtmistler (Post 5891638)
The command to delete a user is userdel(8).

is there any way i can use the user id with this command

rtmistler 08-14-2018 10:23 AM

Quote:

Originally Posted by ruben_shah_j (Post 5891640)
is there any way i can use the user id with this command

Please read the manual page for the command. It tells you the requirements and limitations for the command. It is the only way I'm aware of to delete a user, excepting a radical thing like reinstalling the OS (not recommended).

lougavulin 08-14-2018 11:32 AM

To use userdel, you need to be root. So, the only way I see is to do a script which use /etc/passwd to get the username from the uid. Then call userdel with the username found.
But I don't understand the requirement of UID use.

MadeInGermany 08-14-2018 03:07 PM

An example script
Code:

lookup=4711
username=`getent passwd "$lookup" | cut -f1 -d:`
if [ -n "$username" ]
then
  echo "running 'deluser $username'"
  deluser "$username"
else
  echo "$lookup not found"
fi



All times are GMT -5. The time now is 03:16 PM.