Change Username in Ubuntu

1.(Optional) If it’s the only user account whose name you want to change , you need to enable root account in case something wrong and cause both new and old account can not login. To enable root account ,just open an terminal by pressing Ctl+Alt+t,then
issue below to commands to set a password for root

sudo -s
passwd

2.Logout the user account whose name you need to change

3.Press Ctl+Alt+F3(or F4 F5 F6) to switch to virtual console and login with root (Of course if you have another user account with admin access ,you can login gui with that account )

4.use below commands to change the username

usermod -c displayname -d /home/newname -l newname oldname

Eg: Here we assume account user01 ,whose home directory locates /home/ubuntu01 ,and the display name also is ubuntu01,below command with change all these field to ubuntu02

usermod -c ubuntu02 -d /home/ubuntu02 -l ubuntu02 ubuntu01
mv /home/ubuntu01 /home/ubuntu02

5.(Optional)Assume user01’s default unix group is also user01, we can use below command to rename group user01 to user02

groupmod -n user02 user01

6.Use command “exit” to exit current konsole and press Ctl+Alt+F2 to switch back to the GUI konsole ,now username ubuntu01 has been changed to ubuntu02

7.(Optional) You can use below command to disable root password

sudo -s
passwd -dl root

Leave a Reply

Your email address will not be published. Required fields are marked *