Skip to content

Instantly share code, notes, and snippets.

@luizomf
Last active May 1, 2025 07:07
Show Gist options
  • Save luizomf/559c73c70918f0d26fab13df9ea43978 to your computer and use it in GitHub Desktop.
Save luizomf/559c73c70918f0d26fab13df9ea43978 to your computer and use it in GitHub Desktop.
Rename a user on Linux - Ubuntu - Change username, user id, group id and user home directory.
# Change username from old-username to new-username
sudo usermod -l old-username new-username
# You may also want to rename the user group name
# Change old-group-name to new-group-name
sudo groupmod --new-name old-group-name new-group-name
# If you need to change the user id for some reason
# Change user id for user new-username to 1001
sudo usermod -u 1001 new-username
# You may also want to change group id (GID) for that user
# Change group id for group new-grou-name to 1001
sudo groupmod -g 1001 new-group-name
# Finally, if you want to change user home folder path
# Change home path to /home/new-home-path for user new-username
sudo usermod -d /home/new-home-path -m new-username
# Extra - Many distros will use the comment part for
# the user, with the same value as the username
# if you want to do that, use the command bellow.
# The part between quotes is the comment.
sudo usermod -c "new-username" new-username
@johann1764
Copy link

usermod -l old-username new-username

Actually, it is the other way:

sudo usermod -l new-username old-username

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment