can you change the user account name, if so HOW?

Asked by scott pritchard on 2011-08-17

i want to get rid of this computer and want to change my user account name. no idea how to do much with ubuntu, just installed it today, but want to sell this pc

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu adduser Edit question
Assignee:
No assignee Edit question
Solved by:
Eliah Kagan
Solved:
2011-08-19
Last query:
2011-08-19
Last reply:
2011-08-17

If you are getting rid of the system then this can be done much easier. make a new user and add it to the admin group:

sudo adduser foo
sudo usermod -a -G admin foo

Then log off and log on as foo then run:

gksudo nautilus /home

Delete the original first users folder. This will destroy ALL settings and data so be sure you have backed up what you need. Close nautilus and the system is now ready to give away :)

Obviously change 'foo' for a username of your choosing and write down the password you set to give the next owner.

There are some serious disadvantages to the approach that actionparsnip has presented.

(1) The new user is not made a member of the default groups for desktop users, which is necessary for performing functions like reading CD's and sharing folders over a network. To make this happen, the new user should be created with this alternative adduser command:

sudo adduser --add_extra_groups foo

(foo is still replaced by the login name for the new user. And you still need to run the usermod command after that, to add the new user to the admin group, making them an administrator.)

If you already created the new user with the adduser command listed above, then you can manually add the user to the necessary groups--they are probably whatever groups your own user account is in (besides admin, which you want the new user to be in anyway). If you are logged in as the original user, you can run "groups" to find out what groups you are in. If you are logged into the new user and your old user account is/was called scott, then you can find out by running "groups scott". Then you can add these groups with usermod, like you added admin. Separate them with commas, and not spaces. On most Ubuntu systems the command would be:

sudo usermod -a -G adm,dialout,cdrom,plugdev,lpadmin,sambashare foo

(Where, again, foo is replaced by the name of the new user account. Assuming the new user account is in admin, that command can be run in either user account.)

You can also manage users graphically, including adding them, changing their group memberships, and removing them. You can do this in System Settings, or with System > Administration > Users and Groups. (An alternative way to get to the latter is to press Alt+F2 and run users-admin.)

(2) After you delete the old user's home directory, the old user's settings and data will be deleted (though probably recoverable, at least in part--see point 3 below), with occasional exceptions like the user's local mail spool (if you are running a mail server). But the old user account itself is still there. In particular, the old user's password is still stored in /etc/shadow. It is stored as an encrypted hash, but that password hash can be dumped and cracked and its presence may be, in effect, something of an attractive nuisance. If you are giving/selling the computer to someone who you do not know and trust (or who you might one day not know and trust, or where some other person you do not know and trust will have full access to it), you might want to go the full measure of scrambling all the data on it (see point 3). But even if you do not, it is advisable to at least remove the password entry for your user account.

Just as the adduser utility is provided to make it easy to perform the various actions associated with setting up a user account, so too is deluser provided for removing user accounts, and if you want to remove a user account from the command-line, deluser is typically the way to go. If your user account's name is scott, then while logged in as foo (the new user, whatever it is actually called), run:

sudo deluser --remove-all-files scott

If you have already removed the files, then it is sufficient to run it without --remove-all-files. If you really only want to remove the user's files that are stored in /home, then you can run this instead:

sudo deluser --remove-home scott

You might also want to remove the user's primary group:

sudo delgroup --only-if-empty scott

Or you can use the graphical utilities described in point 1 to remove users. Or you can manually edit /etc/passwd, /etc/group, and /etc/shadow (though I cannot think of a good reason to use that approach, and if you make a mistake you can create serious problems).

While manually editing those files is usually inadvisable, manually viewing the contents of /etc/passwd and /etc/group (as well as the contents of /home) can be useful in verifying that a user and group has been removed. "gedit /etc/passwd" and "gedit /etc/group" will let you view these files without allowing you to modify them (because there is no leading "gksudo", "gksu", or "sudo"). You can also view them in the Terminal with "cat /etc/passwd" and "cat /etc/group", or "less /etc/passwd" and "less /etc/group".

(3) Deleted files can often be recovered, and earlier versions of modified files can sometimes be recovered too (though it would probably be hard, and thus require substantial motivation, to recover your password from an earlier version of /etc/shadow after you run deluser or remove the account with one of the graphical administration tools). See https://help.ubuntu.com/community/DataRecovery for some details. Besides your user account password on Ubuntu, you may have had stored passwords, sensitive documents, or other data you don't want recovered. If you want to render your data truly inaccessible, and you have a *magnetic* hard drive (not, for example, and SSD or magneto-optical drive), then using the "scrub" utility while booted from the Ubuntu live CD to write random patterns to the *entire* disk should be sufficient for this (anything less might not be sufficient). See http://manpages.ubuntu.com/manpages/natty/en/man1/scrub.1.html for details. Of course, you would lose everything on the disk if you did this, so you'd then have to perform a fresh installation of Ubuntu for the new user.

wow...all of that just to change a user name...forget it...ill just reinstall the operating system, it'll be easier and just as fast as trying to figure out all of this stuff.

The steps we have described typically take less than one minute...