Brain Dump

A place to store my random thoughts and anything else I might find useful.

How-To: Rename/Change User in Linux

Posted by mzanfardino on October 4, 2012


1. Overview
2. Solution
3. Notes
4. Attribution

NOTE: This entry is just a basic overview and should not be considered complete. Changing an existing user can be complicated by application configuration dependencies that may not be changed when the user is changed. Be sure you have a backup of your data before you proceed!


Recently I have found that I have a need to change my user account on a virtual machine (VM) running liunx to a more generic account in order that others may use the virtual machine without having to use my user credentials. I find VM’s extremely handy for portable development and stability, as I don’t always want to expose my development environment to the kinds of changes that often accompany upgrades in my desktop distribution.

To that end, I have found that with a few fairly simple commands I can not only rename my user account, but ensure that group associations are maintained and the home path is updated appropriately. However, as I state at the beginning of this article, none of the following commands will guarantee that installed applications will work without a little ‘tweaking’. In my case, my Netbeans project files needed to be updated with the new home path as I did not define them with relative paths but rather with direct path references. You have been warned (again)


Before beginning, but sure you have logged out of your user account. Do not attempt to run these commands from a shell while logged in as your user! In my case, I booted my machine using the “recovery mode” and dropped to the root-user shell to issue the following commands.

# killall -u old
# id old
# usermod -l new old
# groupmod -n new old
# usermod -d /home/new -m new
# usermod -c “New Real Name” new
# id new

The following is a brief summary of what these commands do. For more information, RTFM (remember, man is your friend)

‘killall -u old’ will kill all processes owned by the user ‘old’ where ‘old’ should be the name of the user to be changed.

‘id old’ will print out the real and effective user and group ID’s for user ‘old’.

‘usermod -l new old’ will change the user name ‘old’ to ‘new’ (where ‘new’ is the new user name to be used). Note that this only changes the users name, not his home directory, groups or any else.

‘groupmod -n new old’ will change the group name ‘old’ to ‘new’. Similar to the previous usermod command, this command will only update the group and nothing else.

‘usermod -d /home/new -m new’ will change the new user’s home folder to /home/new.

‘usermod -c “New Real Name” new’ will change the user’s password file comment field only.

‘id new’ will print out the real and effective user and group ID’s for user ‘new’. This is done so that you can verify that the expected changes have occurred.


These commands should result in changing the user ‘old’ to a new user ‘new’ as well as creating and assigning a new home folder and ensuring that all groups that ‘old’ belonged to are transferred to ‘new’. After logging into the new account, I promptly changed the user password (with passwd) and will encourage the user of this VM to change it to something unique to them and changed my keyring password (using seahorse).

Lastly, I install a few utilities that rely on a local MTA (postfix in my case) and found I had to modify the postfix configuration in order to ensure continued mail receipt. I also run apt-listchanges which is configured to mail to my account the changelogs and news of any packages that are to be changed/updated (I highly recommend installing this feature if you run a debian machine and use apt). I had to reconfigure apt-listchanges in order to update the mail account name to use when sending these notifications. Finally, I had to dig deep into my Netbeans project folder to locate and private.xml in order to update the path assignments for project paths and server paths such as for my instance of apache tomcat.

I can’t be sure that this covers all my specific issues however, and in time may discover other configuration files that will need to be changed. However, from the looks of it, these steps will cover about 90%+ of the changes required.


Thanks to the post I found at and the comment from a user who identifies himself as simply ‘ubuntu’ for the expanded set of commands.


One Response to “How-To: Rename/Change User in Linux”

  1. Ramesh Oruganti said

    thank you, it was really nice article and it helped me alot -Ramesh o

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: