Technology Encyclopedia Home >How to create and manage users on Linux?

How to create and manage users on Linux?

To create and manage users on Linux, you can use the useradd, passwd, usermod, and userdel commands in the terminal.

Creating a User:
To create a new user, you use the useradd command followed by the username. For example:

sudo useradd -m username

The -m option creates a home directory for the new user.

Setting a Password:
After creating a user, you need to set a password for them using the passwd command:

sudo passwd username

You'll be prompted to enter a new password and confirm it.

Modifying User Information:
To modify existing user information, such as changing the home directory or adding the user to a group, use the usermod command. For example, to change the home directory:

sudo usermod -d /new/home/directory username

Deleting a User:
To delete a user, use the userdel command. Be cautious with this command as it can delete the user's home directory and mail spool if not used carefully:

sudo userdel username

To also remove the home directory and mail spool, use the -r option:

sudo userdel -r username

For managing users in a more scalable and secure manner, especially in cloud environments, consider using identity and access management services. For instance, Tencent Cloud offers the CAM (Cloud Access Management) service, which allows you to manage users, groups, permissions, and policies for accessing cloud resources securely.