How to manage users?

Managing users in a Linux environment involves several key tasks, including creating, modifying, and deleting user accounts. Here are some common commands and their purposes:

1. Creating a User

To create a new user, you can use the useradd command:

sudo useradd username

Replace username with the desired username. You can also specify additional options, such as home directory and shell.

2. Setting a Password

After creating a user, set a password using:

sudo passwd username

3. Modifying a User

To modify an existing user, use the usermod command. For example, to change a user's home directory:

sudo usermod -d /new/home/directory username

4. Deleting a User

To remove a user, use the userdel command:

sudo userdel username

To remove the user while preserving their home directory, add the -r option:

sudo userdel -r username

5. Listing Users

To view all users on the system, you can check the /etc/passwd file:

cat /etc/passwd

6. Checking Current User

To see the currently logged-in user, use:

whoami

Additional Considerations:

  • Always perform user management tasks with root privileges.
  • Be cautious when deleting users to avoid losing important data.

For more hands-on practice, consider exploring user management labs on LabEx. If you have specific scenarios or questions, feel free to ask!

0 Comments

no data
Be the first to share your comment!