How to change my Username in Linux

How to change or rename the username and home folder in Linux, here I will explain how to rename the username, home folder name and login user name.




To make this change, we use the usermod command that is used by an administrator to change a user's system account settings. Here you can choose his different's options.


My username is linux and me to want to change to love.


1. Calling the Virtual Console

Ctrl + Alt + F1




2. Log in using your username and password

new login


3. To know what groups are currently in use on linux user (my username), and not to repeat it, we write the consoles groups command. The groups command shows the groups as currently applied to your user, and the list starting with the current primary group followed by the supplementary groups from the time of login.

When writing on the Terminal

linux@linuxusers:~$ groups

The output is

linux cdrom floppy sudo audio dip video plugdev netdev bluetooth




4. We give root a password, in Linux Mint and Ubuntu the root user is not active, in Debian, we enable it when we install it, so for Linux Mint and Ubuntu users, we give root a password. Write it down on a piece of paper, so you don't forget it...

linux@linuxusers:~$ sudo passwd root


First, we ask for the password of our user, mine linux.

Second, he asks us for the password we want to give to root, and he asks us to repeat it.


password for root







5. Restart the computer and log in as root

Restart the computer

linux@linuxusers:~$ reboot


When you are at the beginning of the session,

inicio de sesión

Calling the Virtual Console

Ctrl + Alt + F1

We write the root user and give him the password which we provided in the previous step

inicio de sesión




6. To avoid mistakes because the linux user is using some process, we kill that process with the pkill -9 commands, the number -9 means the first nine features of the process.

The syntax

ps aux | grep linux

Written in a terminal

linux@linuxusers:~$ ps aux | grep linux


The syntax

pkill -u linux

and

pkill -9 -u linux

Written in a terminal

linux@linuxusers:~$ sudo pkill -u linux

linux@linuxusers:~$ sudo pkill -9 -u linux




7. Change the username and home folder with usermod and write the new name you want, I write love.

The syntax to do this

usermod -l <new_name> -d /home/<new_name> -m <old_name>

Written in a terminal

linux@linuxusers:~$ sudo usermod -l love -d /home/love -m linux




8. Change the name of the group and give it a new one that you want, I give love

The syntax

groupmod -n <nuevo_usuario> <viejo_usuario>

Written in a terminal

root@linuxusers:~# groupmod -n love linux


Restart the computer

linux@linuxusers:~$ reboot

When you are at the beginning of the session, call the Virtual Console with,

Ctrl + Alt + F1

We write the root user and give him the password which we provided in the previous step

inicio de sesión




9. This step is optional - Change the UID of your user, my name is love.

As Wikipedia says, the users have assigned a UID within the system range, 1–1000, or in the field 65530–65535.


For instance, the user id is 1000.

Test your self, write in your root account, you username, I write my user name, love

root@linuxusers:~# id -u love

The output is

1000

1- Execute the following command to remount the filesystem as read-write

The syntax

mount -o remount, rw /

Written in a Terminal

root@linuxusers:~# mount -o remount, rw /

2- Update the user ID and group ID , we assign the new value to 2000

The syntax

usermod -u [new UID] user

groupmod -g [new UID] user

Written in a Terminal

root@linuxusers:~# usermod -u 2000 love

root@linuxusers:~# groupmod -g 2000 love

3- Update the file ownerships

The syntax

chown -Rhc --from=[old UID] [new UID] /

chown -Rhc --from=:[old UID] :[new UID] /

Written in a Terminal

chown -Rhc --from=1000 2000 /

chown -Rhc --from=:1000 :2000 /




10. Disable the root account. It is advisable to use only the root user for exceptional cases, as here to say. Change the login username. I write to love.

The syntax

passwd -dl root

Written in a Terminal

root@linuxusers:~# passwd -dl root

and leave the root account with the exit command

exit

salida de sesión

and type your new username and password, mine is love

salida de sesión

Change the login name, as I have already changed the username and home folder name to love, now we change the login username, Now I have linux, and change it to love, for this purpose we use the chfn command.

The syntax

sudo chfn -f [options] [LOGIN]


Written in a Terminal

love@linuxusers:~$ sudo chfn -f love

or

love@linuxusers:~$ sudo chfn -f "love" love


Restart the computer

love@linuxusers:~$ reboot




11. Log in with your new user. Mine is love

inicio de sesión con tu nuevo usuario

The new user in Terminal

inicio de sesión con tu nuevo usuario











You comment is welcome: