How to create a user and add them to a group in Linux?
To create a user and add them to a group in a Linux system, you can follow these steps:
- Open the terminal and login as the root user or use the sudo command to obtain administrator privileges.
- Use the following command to create a new user (such as username newuser):
- Create a new user with superuser privileges.
- The system will prompt you to enter a new user’s password and other relevant information, follow the prompts to complete the setup.
- Create a new group (for example, named “newgroup”) using the following command.
- Create a new group called “newgroup” using the sudo command.
- Use the following command to add a new user to a new group:
- Add the user “newuser” to the group “newgroup” using the sudo command.
- Note: In this command, the -a option is used to add a user to a group, while the -G option specifies the group name, and “newuser” is the username to be added to the group.
- After completing the above steps, the new user “newuser” has been successfully created and added to the new group “newgroup”.
You can use the following commands to verify the creation status of new users and groups:
id newuser
groups newuser
These commands will display information about new users, including a list of the groups they belong to.
I hope the above information is helpful to you!