Creating and Renaming a User
In this step, you will create a new user and learn how to rename them. This is a common task when users change roles or when you need to standardize usernames across your system.
First, open your terminal. You should already be in the ~/project directory. Let's start by creating a new user called temporaryuser:
sudo useradd temporaryuser
This command creates a new user account in the system. By default, useradd doesn't create a home directory or set a password.
Now, let's check if the user was created successfully:
grep temporaryuser /etc/passwd
You should see an entry for temporaryuser in the output, confirming that the user has been created.
Next, we'll rename this user from temporaryuser to permanentuser using the usermod command:
sudo usermod -l permanentuser temporaryuser
The -l option specifies that we want to change the login name. After executing this command, the user previously known as temporaryuser will now be known as permanentuser.
Let's verify that the username has been changed:
grep permanentuser /etc/passwd
You should see the user entry with the new name permanentuser.
Now, let's create and assign a home directory for this user:
sudo usermod -d /home/permanentuser -m permanentuser
In this command:
-d specifies the new home directory path
-m creates the new home directory if it doesn't exist, or moves the content from the old home directory to the new one if both exist
Let's verify that the home directory has been created:
ls -ld /home/permanentuser
You should see the newly created home directory for permanentuser.