Changing Username on Linux
Yes, you can just type this command and change your username
sudo usermod -l newname oldname
After running this command you may see an output like this.
Now what to do?
There are multiple solutions for this but in this article, I am going to talk about creating another new user and then changing the user name of old user.
So you can create a new user from settings or use the following command.
sudo adduser newname
After that, your OS may ask about passwords and other necessary details. You just have to provide it and create a new user.
Now give the new user sudo permission. Otherwise, you cannot do anything from the new user.
sudo usermod -aG sudo username
Now log out from the user and log in to the new user.
After switching to the new user, run this command to kill all the processes running by that particular user to whom you want to change the name.
sudo killall -u thatUsername
that will shut down all the processes running by that user.
Now run the following command, and you will be able to change the username.
sudo usermod -l newName oldName
After that reboot and enjoy your new username.
Deleting the New User
After changing the username you might not need the new user again. To delete the new user follow the following steps
less /etc/passwd
You will notice all the usernames on the file. For me, it is pritom whom I want to delete
Again use killall
to kill all the processes running by that user.
sudo killall thatUsername
After that run the following command to delete the user.
sudo userdel thatUsername
After executing this command it will not provide any output. To check if the user is deleted or not again check /etc/passwd
the file. You will see the name of that particular user is not present.
Subscribe to my newsletter
Read articles from Md Sakib Sadman Badhon directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Md Sakib Sadman Badhon
Md Sakib Sadman Badhon
Hello, I am Badhon. I tend to forget things easily which is why I opened this blog.