3

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.

  • It should work. You might also want to chown -R new_username:new_groupname /home/new_username to transfer ownership of the files in the new home directory to the new user. But please do check the files in /home/new_username first: It is very well possible that the UID has stayed the same, so then the files are already owned by the "new user". – NZD Aug 22 '16 at 5:56
  • UID and GID both are same as that of the olduser and file ownership is also owned by the newuser. – Chetan Aug 22 '16 at 6:04
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".

  • find /home/new_username -type f -exec egrep -H '/home/old_username' {} \; It is showing me the path which is under /home/new_user but I have doubt that will it automatically make changes for every installed applications specially for above mentioned apps..?? – Chetan Aug 22 '16 at 6:18
  • That is correct, it won't fix the files. It will only find them for you. you could use sed for that. 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. – NZD Aug 22 '16 at 6:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.