How to Add a User in Linux
In Linux, adding a user is a fairly simple task. There are a few steps you need to follow to accomplish this. In this article, we’ll take you through the process of adding a user in Linux.
Step 1: Open your terminal
To get started, you need to open a terminal. You can do this by pressing Ctrl+Alt+T on the keyboard, or by navigating to the terminal window through the main menu.
Step 2: Gain root access
To add a user, you need to have admin or root access. You can gain this access by typing “su” on the terminal and entering your root password when prompted.
Step 3: Add a user
To add a user in Linux, you need to use the “useradd” command. The basic syntax of the command is as follows:
`useradd [username]`
For example, if you want to add a user named “john”, you would type:
`useradd john`
Step 4: Set a password for the user
It’s important to set a password for the new user that you’ve just added for security purposes. You can do this by running the following command:
`passwd [username]`
For example, if you want to set a password for user “john” that you have just added, you would type:
`passwd john`
You will be prompted to enter and confirm the password for the user.
Step 5: Create a home directory for the user
Every user in Linux has their own home directory where their files and settings are stored. You can create a home directory for the new user by running the following command:
`mkdir /home/[username]`
For example, if you want to create a home directory for user “john”, you would type:
`mkdir /home/john`
Step 6: Set the ownership of the home directory
You need to set the ownership of the home directory to the new user. You can do this by running the following command:
`chown [username]:[username] /home/[username]`
For example, if you want to set the ownership of the home directory of user “john” to himself, you would type:
`chown john:john /home/john`
Step 7: Add the user to a group
You can add the new user to an already existing group by running the following command:
`usermod -aG [groupname] [username]`
For example, if you want to add user “john” to an existing group named “developers”, you would type:
`usermod -aG developers john`
Step 8: Exit
Once you’re done adding the user in Linux, you can exit the terminal by typing “exit” or by closing the terminal window.