Changing Initial Username in UBUNTU

Change Initial Username in UBUNTU for a newer established account

Code:
sudo usermod –login NEWNAME –home /home/NEWNAME -m OLDNAME
sudo groupmod –new-name NEWGROUP OLDGROUP

OLDNAME is the current login name
NEWNAME is the desired login name

On a default ubuntu install,
OLDGROUP is the same as OLDNAME,
NEWGROUP is the same as NEWNAME

The “usermod” command will change the login name and move the home directory from /home/OLDNAME to /home/NEWNAME
And “groupmod” command will rename the old group name to the new group name, for permissions etc

Change Initial Username in UBUNTU for an older established account

If your OLDNAME is quite unique, one could follow up the “usermod” and “groupmod” commands with find command

Code:
find /home/NEWNAME/ -type f -name ‘*’ -exec sed -i ‘s/OLDNAME/NEWNAME/g’ {} \;

The “find” command will loop through every single file in /home/NEWNAME and change every occurrence of OLDNAME *within* the contents of the file to NEWNAME. This is an attempt to correct any mention of OLDNAME in your hidden configuration files, the .filename ones

The reason why this command is dangerous is because if your OLDNAME is something short like “igh” which is a substring of other words. If you try to change username “igh” to “may”, do not use the above command because any document that contains the word “right” would be changed to “rmayt”.
Be careful as terrible damage can be done with this find command

Trying the above commands is suggested only when you back-up first.

The other problem that sometimes occurs is that the .wine directory contains symlinks whose path contains the name OLDNAME.
(Things like this /home/NENWAME/.wine/drive_c/windows/profiles/OLDNAME/Desktop become broken symlinks).

Mostly these can be done manually, as they aren’t so many symlinks – I am assuming 😉

Thanks to unutbu’s comments at Ubuntu Forums

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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