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:

  1. Open the terminal and login as the root user or use the sudo command to obtain administrator privileges.
  2. Use the following command to create a new user (such as username newuser):
  3. Create a new user with superuser privileges.
  4. The system will prompt you to enter a new user’s password and other relevant information, follow the prompts to complete the setup.
  5. Create a new group (for example, named “newgroup”) using the following command.
  6. Create a new group called “newgroup” using the sudo command.
  7. Use the following command to add a new user to a new group:
  8. Add the user “newuser” to the group “newgroup” using the sudo command.
  9. 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.
  10. 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!

Leave a Reply 0

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


广告
Closing in 10 seconds
bannerAds