I have a user named hedgehog
and I want him to be named squirrel
, but I don't want to change his numeric user ID.
How can I accomplish this?
I have a user named hedgehog
and I want him to be named squirrel
, but I don't want to change his numeric user ID.
How can I accomplish this?
Under Linux, the
usermod
command changes user names. It modifies the system account files to reflect the changes that are specified on the command line.To change just the username:
To change the username and home directory name:
You may also want to change the name of the group associated with the user:
NOTE: don't try this if your directory is encrypted! If this is your case you might want to check first: https://askubuntu.com/questions/107410/can-you-unencrypt-remove-encryption-from-a-user-home-folder
The straight out way of doing this is:
Create a new temp account with sudo rights:
Log out from your current account and back in with the temp account.
Rename your username and directory:
Rename your username default's group:
Log out from temp account and log back into your account with new-username.
Remove temp account:
Otherwise, you just (1) create a new user and (2)
rsync
the old user home folder to the new and then (3)chown
it.Generally you can rename a user by changing their username in the
/etc/passwd
(and/etc/shadow
, if applicable) files. On most unix systems thevipw
command is used to edit these files (and on many systems includes some safeguards to ensure that you don't mess things up too badly).See the man pages for
passwd(5)
,shadow(5)
, andvipw(8)
for more information.Note that the method above does not rename other things which may bear the original username (home directories being the prime example, per-user personal groups (on systems which use them) being another). You may wish to clean these up as well for consistency, by changing the appropriate fields in the passwd file and renaming the directories.
Several operating systems provide a system-specific way of renaming users. For example many Linux systems include the
usermod(8)
command, and on AIX you can change account names using SMIT (orsmitty
in a terminal).These commands will often handle the cleanup items like renaming home directories, if you ask them to.