
Linux change username and home directory
To change a username:
usermod -l login-name old-name
To change a UID
usermod -u UID username
do backup all user data before doing this. For a complete change including home directory name, mail spool name etc. read man pages for usermod and groupmod. An example below shows how to kill processes running under old username, display old ID’s info, change the username, change the groupname, the home folder name and Real name, display new ID’s info.
killall -u old
id old
usermod -l new old
groupmod -n new old
usermod -d /home/new -m new
usermod -c “New Real Name” new
id new
To change a user’s home folder name only, use the following usermod command.
usermod -d /path/to/new/homedir/ username