Change username and home directory name

by Chetan   Last Updated July 13, 2019 00:02 AM

I have changed the username of a user.

Commands:

killall -u username
usermod -l new_username old_username
groupmod -n new_groupname old_groupname
usermod -d /home/new_username -m new_username
usermod -c "New Name" new_username

chown new_username:new_groupname .Xauthority

I want to know if changing the home directory from for example /home/test/ to /home/ubuntu/ will affect any applications.

I have already installed RVM, Ruby, Rails, Oracle and a few more.



Answers 2


It should work.

Some applications will store absolute pathnames in their configuration files or in other files they keep. You will have to change those manually or set up the user-specific parts of the application again.

You can search for these files as follows (at least the ones that store the pathnames as text):

find /home/new_username -type f -exec egrep -H '/home/old_username' {} \;

That command won't fix the files. It will only find them for you. You could use sed to change the files. Something along the lines of:

find /home/new_username -type f -exec egrep -l '/home/old_username' {} \;|xargs sed -i 's%/home/old_username%/home/new_username/‌​;g'

Please test first.

Note that some files might seem to be text files, but actually are binary files. Doing a search-and-replace on these files can break them.

Note: You don't need to use chown -R new_username:new_groupname /home/new_username to transfer ownership of the files in the new home directory to the new user, because the UID for the "new user" is the same as for the "old user", so then the files are already owned by the "new user".

NZD
NZD
August 22, 2016 06:01 AM

the only thing that work for me was:

sudo gedit /etc/passwd

sudo gedit /etc/group

and made the changes that I wanted manually!

Alexandre Viana
Alexandre Viana
July 12, 2019 23:55 PM

Related Questions



Renaming user name

Updated October 06, 2015 19:01 PM

Sudo command locked

Updated February 23, 2016 09:01 AM

Removing user photo (18.04)

Updated July 15, 2018 07:02 AM

Keep a laptop running with closed lid

Updated July 26, 2018 14:02 PM