1

If a user has an UID but no name, ie:

$ whoami
whoami: cannot find name for user ID 1001
$ id
uid=1001 gid=0(root) groups=0(root)

is it possible to change the UID but still leave the user name undefined?


System info:

$ cat /proc/version
Linux version 4.15.0-88-generic (buildd@lgw01-amd64-036) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.12)) #88~16.04.1-Ubuntu SMP Wed Feb 12 04:19:15 UTC 2020
3
  • The UID is a unique identifier for a user. To 'change' the UID of a user actually means to point a user database entry to a different UID. When you say that the user name isn't defined, you actually mean that the UID doesn't have an associated user database entry pointing to the UID.
    – Torin
    Commented May 15, 2020 at 19:41
  • @Torin Can we manually add the entry in to this database? If so, how can we do it? Commented May 16, 2020 at 1:38
  • Sure, you can create a user with adduser --uid 1001 username
    – Torin
    Commented May 16, 2020 at 13:28

1 Answer 1

0

It is possible to manually change both the user id and the user name (along with other user attributes) by using vipw. This opens an editor on the password file.

After running vipw you should run vipw -s and make equivalent changes to the shadow file.

The equivalent utility for editing groups is vigr.

If the user you are changing owns any files, you would likely then need to use chown to change ownership to the new user id. (You can use the username in the chown call, but the ownership is decided based on user id, not user name.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .