Sunday, November 24, 2013

"Rename" a user in Linux system

I tried this in Ubuntu 12.04 LTS. Run these commands as Root in a terminal.

To change a user name.

usermod -l<new_user_id> <old_user_id>

To change the home directory

usermod -m -d /home/<new_user_id> <new_user_id>

The above 2 can be combined into a command.

usermod -l <new_user_id> -m -d /home/<new_user_id> <old_user_id>

* I didn't tried this though. :P

Next, change the content of the following files. Edit the content by replacing <old_user_id> to <new_user_id>.


What is next? Yes, the user name. This can be change via  User Accounts. Click on the upper right people icon and open the User Accounts GUI. The name can be changed via that interface.

After logout, you'll see the new_user_id account is ready to be used. :)

Note, if you are seeing error prompting unable to change the user_id, you'll need to login to the system as Root, not to use sudo su as Root.

Reference : 

This is useful when you are using clone VM from your peer. :P

Ah.. nearly forgot the last step. After you relogin, you'll see the group name is remained as <old_user_id>. Run this command to change the group name. :)

groupmod -n <new_user_id> <old_user_id>


No comments:

Post a Comment