Ubuntu – Change username and home directory name

14.04oraclervmuser-management

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.

Best Answer

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".

Related Question