Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
@Jeznet I downvoted because not only is this an incredibly simple task that could be solved by typing your title into google, you also answered your own question as soon as you asked it. Seemed a waste of time. – boburob Oct 11 '12 at 15:13
@boburob "you also answered your own question as soon as you asked it. Seemed a waste of time" please see:… – Szymon Jeż Oct 11 '12 at 15:14
@boburob Did you see that tick box that says Answer your own question – share your knowledge, Q&A-style when you ask a question? It's there for a reason, and wouldn't be there if they didn't want it used. (Ideally on better questions, but regardless, downvoting someone for answering their own question is bad form.) – HopelessN00b Oct 11 '12 at 15:19
Yes, I have also answered my own question before but to me, asking a question and pasting the google result in the same minute is a bit of a waste of time – boburob Oct 11 '12 at 15:32
Specifically, copied from here: – boburob Oct 11 '12 at 15:34
up vote 22 down vote accepted

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:

usermod -l new_username old_username

To change the username and home directory name:

usermod -l new_username -m -d /new/home/dir old_username

You may also want to change the name of the group associated with the user:

groupmod -n new_username old_username
share|improve this answer
You can use usermod to do the whole thing usermod -l new-user-name -m -d /new/home/dir old-user-name – Iain Oct 11 '12 at 15:20
@Iain Thanks. I will extend my answer to reflect that. BTW That's why I asked this "trivial" question - to get an answer that is better than mine (and also because I could not find it already at SF). – Szymon Jeż Oct 11 '12 at 15:23
Also note, that the group is not changed either. If you need to rename the old-user-name group as well, use # groupmod -n new-user-name old-user-name. – alxs Oct 22 '14 at 18:41

Generally you can rename a user by changing their username in the /etc/passwd (and /etc/shadow, if applicable) files. On most unix systems the vipw 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), and vipw(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 (or smitty in a terminal).
These commands will often handle the cleanup items like renaming home directories, if you ask them to.

share|improve this answer

The straight out way of doing this is:

  1. Create a new temp account with sudo rights:
sudo adduser temp
sudo adduser temp sudo
  1. Log out from your current account and back in with the temp account.

  2. Rename your username and directory:

sudo usermod -l new-username -m -d /home/new-username old-username

  1. Rename your username default's group:
sudo groupmod -n new-username old-username
  1. Log out from temp account and log back into your account with new-username.

  2. Remove temp account:

sudo userdel -r temp

Please, don't try this if your directory is encrypted!

If that is your case you might want to check:

Or even just creating a user and rsync 'ing the old user home folder to the new and then chown 'ing it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.