Remove a Linux user with only his UID

8,415

Solution 1

Just delete the appropriate lines in /etc/passwd and /etc/shadow, and the home directory.

Solution 2

The '?' needs to be escaped. I've verified that the following works:

root@panic:/# useradd test?test
root@panic:/# userdel test\?test
Share:
8,415

Related videos on Youtube

Cimm
Author by

Cimm

Intrigued by the web and its potential, convinced it will keep reinventing itself and happy to be part of that. Feels there is not enough time to build all the applications he comes up with.

Updated on September 17, 2022

Comments

  • Cimm
    Cimm almost 2 years

    I would like to remove (or rename) an Ubuntu user I created but the usual solutions don't work as there is a question mark in the username.

    $ sudo usermod -l myuser my?user
    usermod: user 'my?user' does not exist
    

    I tried with the usual quotes and/or a backslash before the question mark but to no avail.

    Is there a way to remove a user based on his UID? That would be a solution as I don't need to enter the username.

    Thanks!

  • Cimm
    Cimm almost 14 years
    Didn't think about the shadow file. Cool, this worked, thanks!
  • Cimm
    Cimm almost 14 years
    For future reference: It may be useful to check the /etc/group file as well, had the same typo there.
  • Cimm
    Cimm almost 14 years
    Thanks Scott, I think Sven's solution is nicer. His solution makes it possible to change the username without removing.