How To Properly Change Username In Linux - OSTechNix
Maybe your like
This brief guide explains how to properly change username in Linux operating system. Not just the username, this guide also describes how to change the hostname, user group, home directory and the ownership and group of that directory to the new user, along with all files.
Introduction
A few days ago, I downloaded a Fedora vagrant box and deployed it using libvirt/kvm provider. As you might already know, all vagrant boxes comes with a default user called "vagrant". And the default hostname for the vagrant box is localhost. I changed the username and hostname in the Fedora VM for better accessibility in the network.
If you're ever looking for a proper way to change the username in Linux without messing the existing configuration files, here is how.
A note of caution:
I would not recommend changing username in production system. It is always best to just create a new user rather than renaming the existing one. Because renaming username will cause so many problems if the old user's home directory is referenced by some other configuration files. You may end up changing the config files used by so many services. Also don't do it if your $HOME directory is encrypted!. So I recommend you to create a new user and move the old user's data to new one. If it is a freshly installed system or just testing system, you can then go ahead and change the user name as described below.
The right way to change username in Linux
Changing hostname in Fedora and other Linux distributions is easy!
Login as a different sudo user or root user. Because you can't change the username of the currently logged in user. I logged in as root user.
Change the current hostname using the hostnamectl command like below:
# hostnamectl set-hostname fedora33The above command changes the old hostname to "fedora33". Log out and log back in to apply the changes. You will now see that the hostname is updated in the shell prompt. You can also check it using hostname command:
# hostname fedora33Here comes the main part. Now I am going to change the user name from "vagrant" to "ostechnix". To do so, I created a new group called "ostechnix" using command:
# groupadd ostechnixFor the purpose of this guide, I used the same name for user and group. You can use different name if you want.
And finally change the username using the usermod command like below:
# usermod -d /home/ostechnix -m -g ostechnix -l ostechnix vagrantLet us break down the above command and see what each option does.
- usermod : The command to modify a user account in Unix-like systems.
- -d /home/ostechnix : Create a new $HOME directory for the user.
- -m : Move the content of the old user's $HOME directory to the new location.
- -g ostechnix : Add the new user to a group called "ostechnix".
- -l ostechnix vagrant : Change the name of the user from "vagrant" to "ostechnix". i.e. "vagrant" is the old user name and "ostechnix" is the new user.
The above command changes the user name, the user group, the $HOME directory and ownership and group of that directory to the new user, along with all the user's files and directories.
Finally, assign sudo privileges to the new user using command:
# usermod -aG wheel ostechnixIf you're on Debian-based systems like Ubuntu, you can grant sudo permissions to the user using this command:
$ sudo usermod -aG sudo ostechnixNow exit from the root user and log in as new user.
Verify if the hostname, username, and $HOME directories are changed:

Great! Everything is changed.
For more details about usermod command, refer its man page:
$ man usermodHope it helps.
LinuxLinux basicsLinux commandsLinux tipsLinux user managementUser management 2 comments 7 FacebookTwitterLinkedinRedditWhatsappTelegramEmailsk
Senthilkumar Palani (aka SK) is the Founder and Editor in chief of OSTechNix. He is a Linux/Unix enthusiast and FOSS supporter. He lives in Tamilnadu, India.
Previous postHow To Add Downloaded .box File To Vagrant In Linux
Next postTransfer Files Between Any Devices Using Piping Server
You May Also Like
How To Create A Montage From Images In...
Published: April 2, 2020How To Create GUI Dialog Boxes In Bash...
Published: October 28, 2021Steganography – Hide Files Inside Images In Linux
Published: August 15, 2019How To Check The Runlevel In Linux
Published: June 9, 2021How To Efficiently Search Linux Manual Pages
Published: September 23, 2024Good Alternatives To du Command To Check Disk...
Published: November 5, 20182 comments
I have Scientific Linux 7.9 and I’d like to move to Centos Stream 8, but SL 7.9 can’t find centos-release-stream. Is (or will there be) a fix for that? I have a RAID-10 system that Fedora didn’t want to install on, but SL 7.9 didn’t complain (that’s how I got here). I now (finally) have Python 3.9.5, TensorFlow 2.5 & Keras installed and don’t want to lose all of that downloading & configuring. See below for specifics trying to pull/install centos-release-stream… Any suggestions?
root@localhost-3c58:/etc/systemd/system$ dnf install centos-release-stream Repository ‘fermilab-debuginfo’ is missing name in configuration, using id. Repository ‘fermilab-source’ is missing name in configuration, using id. Repository ‘fermilab-testing’ is missing name in configuration, using id. Repository ‘fermilab’ is missing name in configuration, using id. Repository ‘repos’ is missing name in configuration, using id. Repository ‘repos-source’ is missing name in configuration, using id. Repository ‘sl-extras’ is missing name in configuration, using id. Repository ‘sl-extras-debuginfo’ is missing name in configuration, using id. Repository ‘sl-extras-source’ is missing name in configuration, using id. Scientific Linux $slreleasever – x86_64 0.0 B/s | 0 B 00:00 Scientific Linux $slreleasever – x86_64 – bugfix updates 0.0 B/s | 0 B 00:00 Scientific Linux $slreleasever – x86_64 – security updat 0.0 B/s | 0 B 00:00 Failed to synchronize cache for repo ‘sl’, ignoring this repo. Failed to synchronize cache for repo ‘sl-fastbugs’, ignoring this repo. Failed to synchronize cache for repo ‘sl-security’, ignoring this repo. Last metadata expiration check: 0:54:04 ago on Thu 03 Jun 2021 06:28:56 AM PDT. No match for argument: centos-release-stream
ReplyI guess you’re asking how to migrate to CentOS stream from Scientific Linux. The centos-release-stream package will only convert the CentOS systems to CentOS Stream. It won’t migrate Scientific Linux to CentOS Stream. You need to find a way (which I don’t know yet) to migrate your Scientific Linux to CentOS 8 and then convert the CentOS 8 to CentOS stream.
ReplyLeave a Comment Cancel Reply
Save my name, email, and website in this browser for the next time I comment.
* By using this form you agree with the storage and handling of your data by this website.This site uses Akismet to reduce spam. Learn how your comment data is processed.
Search
SearchKeep in touch
Facebook Twitter Linkedin Youtube Email Reddit RssAbout OSTechNix

OSTechNix (Open Source, Technology, Nix*) regularly publishes the latest news, how-to articles, tutorials and tips & tricks about free and opensource software and technology.
Facebook Twitter Linkedin Youtube Email Reddit RssArchives Select Month March 2026 (8) February 2026 (27) January 2026 (21) December 2025 (27) November 2025 (29) October 2025 (29) September 2025 (34) August 2025 (28) July 2025 (24) June 2025 (24) May 2025 (25) April 2025 (24) March 2025 (23) February 2025 (23) January 2025 (33) December 2024 (32) November 2024 (25) October 2024 (34) September 2024 (42) August 2024 (38) July 2024 (39) June 2024 (20) May 2024 (19) April 2024 (13) March 2024 (12) February 2024 (10) January 2024 (5) December 2023 (6) November 2023 (13) October 2023 (12) September 2023 (10) August 2023 (13) July 2023 (9) June 2023 (12) May 2023 (18) April 2023 (11) March 2023 (7) February 2023 (6) January 2023 (3) December 2022 (9) November 2022 (6) October 2022 (6) September 2022 (11) August 2022 (11) July 2022 (11) June 2022 (10) May 2022 (13) April 2022 (14) March 2022 (11) February 2022 (9) January 2022 (9) December 2021 (16) November 2021 (13) October 2021 (12) September 2021 (15) August 2021 (19) July 2021 (15) June 2021 (18) May 2021 (16) April 2021 (10) March 2021 (13) February 2021 (15) January 2021 (13) December 2020 (16) November 2020 (14) October 2020 (18) September 2020 (13) August 2020 (14) July 2020 (17) June 2020 (23) May 2020 (22) April 2020 (27) March 2020 (21) February 2020 (18) January 2020 (21) December 2019 (10) November 2019 (6) October 2019 (10) September 2019 (9) August 2019 (16) July 2019 (16) June 2019 (8) May 2019 (10) April 2019 (12) March 2019 (9) February 2019 (7) January 2019 (9) December 2018 (5) November 2018 (10) October 2018 (16) September 2018 (19) August 2018 (16) July 2018 (12) June 2018 (14) May 2018 (15) April 2018 (20) March 2018 (21) February 2018 (14) January 2018 (19) December 2017 (23) November 2017 (21) October 2017 (16) September 2017 (23) August 2017 (21) July 2017 (21) June 2017 (10) May 2017 (19) April 2017 (22) March 2017 (30) February 2017 (30) January 2017 (22) December 2016 (17) November 2016 (13) October 2016 (10) September 2016 (12) August 2016 (20) July 2016 (6) June 2016 (15) May 2016 (11) April 2016 (19) March 2016 (26) February 2016 (21) January 2016 (4) November 2015 (1) October 2015 (5) September 2015 (9) August 2015 (1) December 2013 (3) April 2013 (1) March 2013 (2) February 2013 (3) January 2013 (10) December 2012 (6) November 2012 (1)Popular Posts
- 1
Yt-dlp Commands: The Complete Tutorial For Beginners (2026)
Published: September 30, 2023 - 2
MidnightBSD Excludes California from Desktop Use Due to Digital Age Assurance Act
Published: February 27, 2026 - 3
How To Fix Busybox Initramfs Error On Ubuntu
Published: August 6, 2020
This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More
Tag » How To Change Username On Linux
-
Linux Change Or Rename User Name And UID - NixCraft
-
How Do I Change My Username In Linux?
-
How To Change A Username And Other Account Details On Linux
-
How Do I Change My Username? - Ask Ubuntu
-
How To Change A Username In Linux - Linuxiac
-
How To Change Username In Linux - Quora
-
How To Change Username In Linux - YouTube
-
How To Change Username In Linux Step By Step | Linux Addicts
-
How To Change The Username Of A Linux Account - Techwalla
-
How To Rename Or Change User Name In Linux - Unixmen
-
How To Change Or Rename User Name And User ID In Linux
-
3.4.4. Modifying User Settings Red Hat Enterprise Linux 6
-
How Can I Rename A Unix User? - Linux - Server Fault
-
How To Change Username And Hostname On Linux System