Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I installed Ubuntu on a computer that is now used by somebody else. I renamed the account with her name, but it only changes the fullname, not the user name, which is still displayed in the top right (in the fast-user-switch-applet). Is there a command to rename an Unix user account?

I've thought of creating a new user account with the new name, and then copying everything in the "old" home to the home of the new account. Would it be enough? But then I think the files would have the old account's permissions' owner? So should I do chown -R newuser ~?

Is there a simpler/recommended way to do this?

share|improve this question
add comment

4 Answers

up vote 34 down vote accepted

Try

usermod --move-home --login <new-login-name> --home <new-home-dir> <old-login-name>

The --move-home option moves the old home directory's contents to the new one given by the --home option which is created if it doesn't already exist.

If you want the primary user group to match the new-login-name, add --gid <new-login-name> to the command above, but the group must be pre-existing.

See the man page for more info:

man usermod
share|improve this answer
    
Thanks! I didn't know about this command. :) However, that's the only account on this computer and the man says this: « You must make certain that the named user is not executing any processes when this command is being executed if the users numerical user ID, the users name, or the users home directory is being changed. usermod checks this on Linux, but only check if the user is logged in according to utmp on other architectures. » Would you suggest using a live cd to do this or creating a temp account that I will delete once it's done? –  Yann Dìnendal Aug 18 '10 at 10:30
2  
Since you're using Ubuntu and can't login as root, I would create another account called, say, admin that you use for just this type of task. A temporary account will work just as well but you might as well keep it since you could be doing similar things in the future. –  gvkv Aug 18 '10 at 15:23
    
I will do that, thanks. :) –  Yann Dìnendal Aug 18 '10 at 17:41
add comment

While it's possible to rename a user, and usermod will do some of the job, this is quite likely to cause trouble. Here's a list of places where the user name may appear; I do not claim that this list is exhaustive.

  • The user entry in /etc/passwd and related files (e.g. /etc/shadow, /etc/master.passwd).
  • Group entries in /etc/group (and /etc/gshadow).
  • Possibly entries in /etc/sudoers.
  • The system mailbox, typically /var/mail/$USER or /var/spool/mail/$USER.
  • The crontab, typically /var/spool/cron/crontabs/$USER
  • In at jobs (/var/spool/cron/atjobs/*)

The home directory is likely to appear in even more places. Many applications write absolute paths in various dot files. If you decide to rename the home directory as well (while there's no requirement that user alice's home directory be /home/alice, having it be /home/bob would be confusing), you'll need to take care of those. A global replacement will work for most applications, but I make no promises. If possible, keep the old home directory name as a symbolic link to the renamed directory.

share|improve this answer
add comment

Here's a summary of the commands I used on a Debian system:

groupadd NEW
usermod -l NEW -m -d /home/NEW -g NEW OLD
chfn -f "New Fullname" NEW
cd /home
ln -s NEW OLD

The last two commands create a symbolic link from the name of the old home directory (/home/OLD) to the name of the new one (/home/NEW).

share|improve this answer
    
What is the groupadd for? –  Yann Dìnendal yesterday
add comment

all above are elegant methods, but why don't just create a new user, copy all it's home content from the first one, and that's it? of course, if it's about a service (application) account, perhaps it's not the best practice

share|improve this answer
1  
It seems that this might be better placed as a comment rather than a full answer post which adds almost nothing except mentioning a solution that was already mentioned in the OP. You should consider adding some information as to why you think this solution is better, or even acceptable. –  HalosGhost Jul 9 at 8:01
add comment

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.