How can I change my own user ID?
You can change it in /etc/passwd
, /etc/group
and /etc/shadow
or you use one of the preferred possibilties above. But - most important - you have to change the ownership of all files belonging to the user.
For instance, if the old user id is 1000 and the new one is 5000:
find / -uid 1000 -exec chown -h 5000 {} +
And the same for the group id (if you change it as well).
find / -gid 1000 -exec chgrp -h 5000 {} +
The problem is that, like you mentioned, you cannot change your user's UID when it is logged in a session. You have to use another user account to proceed.
But you don't have to create a new user account, promote it to admin, log out, log in to the new admin account, change your primary account's UID, log out, log in to your primary account then delete the new admin user just change your UID. ;)
You can boot into recovery mode (it's an option that appears when you start up your computer, or hold shift right after the BIOS messages complete; Use ESC on Dell machines running OEM-Ubuntu). This will log you in a root session. Being logged in root and not your usual user account, you will be able to modify your UID.
Because the recovery mode only works in command line interface, once logged into a root session, you will have to:
Use BubbaJ's instructions to remount the root file system in read-write mode:
mount -o remount,rw /
.Use Luis Alvarado's command:
usermod -u NEW_UID your_username
.- Follow ddeimeke's instructions to update file permissions.
- Then, reboot your computer (
reboot
), so you can boot in normal mode.
Complete solution based on @AlexandreP. and @ddeimeke + official documentation. No reboot necessary.
The Debian/Ubuntu policy is that if there is a user jim
with user ID 1001
, there is also a group jim
with group ID 1001
. This solution also updates those group IDs.
Enable the root account:
sudo passwd root
- If the user is logged in, then log out (also on virtual terminals)
- Go to VT1: Ctrl-Alt-F1
Log in as root and run this with the user name and old/new UID supplied:
# put the information we need in variables username=... old_uid=`id -u $username` # looks up current (old) uid new_uid=... # update the user ID and group ID for $username usermod -u $new_uid $username groupmod -g $new_uid $username # update the file ownerships # NB: you cannot combine the next two chowns, or files where # only the uid xor the gid matches won't be updated chown -Rhc --from=$old_uid $new_uid / # change the user IDs chown -Rhc --from=:$old_uid :$new_uid / # change the group IDs
- Log out
- Log in as
$username
Disable the root account:
sudo passwd -dl root