Technology Encyclopedia Home >How to create and manage user accounts on CentOS?

How to create and manage user accounts on CentOS?

Creating and managing user accounts on CentOS involves several commands and configurations. Here’s a step-by-step guide:

Creating a User Account

To create a new user account, you can use the useradd command. For example, to create a user named john, you would run:

sudo useradd john

This command creates a home directory for the user in /home/john by default and sets up the necessary files.

Setting a Password

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

sudo passwd john

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

Managing User Accounts

Adding a User to a Group

You can add a user to a group using the usermod command. For example, to add john to the developers group:

sudo usermod -aG developers john

The -aG option appends the user to the specified group without removing them from other groups.

Deleting a User Account

To delete a user account and their home directory, use the userdel command:

sudo userdel -r john

The -r option removes the user's home directory and mail spool.

Locking and Unlocking Accounts

To lock a user account, preventing them from logging in, use:

sudo passwd -l john

To unlock the account:

sudo passwd -u john

Example Scenario

Suppose you are setting up a CentOS server for a development team. You might create individual user accounts for each developer and add them to a developers group. This allows you to manage permissions and access control more effectively.

Cloud-Related Recommendation

For managing user accounts and permissions in a cloud environment, consider using Tencent Cloud’s Identity and Access Management (IAM) service. IAM allows you to create and manage users, groups, and roles with fine-grained access controls, ensuring security and compliance in your cloud infrastructure.

By following these steps and utilizing tools like Tencent Cloud IAM, you can efficiently manage user accounts on CentOS and in cloud environments.