Last active
May 1, 2025 07:07
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually, it is the other way: