Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
1  
@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
4  
@boburob "you also answered your own question as soon as you asked it. Seemed a waste of time" please see: blog.stackoverflow.com/2011/07/… –  Jeznet Oct 11 '12 at 15:14
4  
@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
1  
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
1  
Specifically, copied from here: askubuntu.com/questions/131180/changing-short-name-of-user –  boburob Oct 11 '12 at 15:34

2 Answers 2

up vote 8 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.

Syntax:

usermod -l new-user-name old-user-name

Only the user's (login) name will be changed, and nothing else. You may also want to change the user's home directory name, as below:

usermod -l new-user-name -m -d /new/home/dir old-user-name

share|improve this answer
2  
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). –  Jeznet Oct 11 '12 at 15:23

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

Your Answer

 
discard

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.