Rename a user in Linux

If you have a single user account it is not possible to rename the user login name whilst logged on. To do so use cron to run the necessary commands.

Create a script with the required commands:

nano /usr/local/bin/rename_user

# First rename the user login:
/usr/sbin/usermod --login newlogin oldlogin
# Second rename the group account:
/usr/sbin/groupmod --new-name newlogin oldlogin
# Third move the users current home directory to match:
/usr/sbin/usermod -m --home /home/newlogin newlogin

sudo crontab -e

MM HH * * * /usr/local/bin/rename_user

Set HH:MM ahead of current time and log out, wait for the time to pass before logging back in.