2 min read

RLG : Guide to User Management in Linux

We used AI while writing this content.

1. Adding Users

To add a new user, use the useradd command:

sudo useradd <username>

By default a primary private group with the same name is created to house the new user. That is, the newly created user Alice would be part of the Alice group.

To create a user and set their password:

sudo useradd <username>
sudo passwd <username>

2. Modifying Users

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>

To add a user to a group:

sudo usermod -aG <groupname> <username>

3. Deleting Users

To delete a user:

sudo userdel <username>

To delete a user and their home directory:

sudo userdel -r <username>

4. Viewing User Information

To view information about a user:

id <username>

To list all users:

cat /etc/passwd

5. Managing Groups

To create a new group:

sudo groupadd <groupname>

To delete a group:

sudo groupdel <groupname>

To view all groups:

group

6. Switching Users

To switch to another user:

su - <username> # - opens a log-in shell so /etc/profile and other config files are correctly loaded.

7. Locking and Unlocking Users

To lock a user account:

sudo usermod -L <username>

To unlock a user account:

sudo usermod -U <username>

8. Checking Login History

To view login history:

last

9. Managing Sudo Access

To give a user sudo privileges, add them to the sudo group:

sudo usermod -aG sudo <username>

10. Best Practices

  • Regularly review user accounts and remove unused ones.
  • Use strong passwords and enforce password policies.
  • Limit sudo access to trusted users.

By mastering these commands and practices, you can effectively manage users in a Linux environment.

Copyleft Statement

Renoncé du droit d'auteur

Much of our content is freely available under the Creative Commons BY-NC-ND 4.0 licence, which allows free distribution and republishing of our content for non-commercial purposes, as long as Ronzz.org is appropriately credited and the content is not being modified materially to express a different meaning than it is originally intended for. It must be noted that some images on Ronzz.org are the intellectual property of third parties. Our permission to use those images may not cover your reproduction. This does not affect your statutory rights.

Nous mettons la plupart de nos contenus disponibles gratuitement sous la licence Creative Commons By-NC-ND 4.0, qui permet une distribution et une republication gratuites de notre contenu à des fins non commerciales, tant que Ronzz.org est correctement crédité et que le contenu n'est pas modifié matériellement pour exprimer un sens différent que prévu à l'origine.Il faut noter que certaines images sur Ronzz.org sont des propriétés intellectuelles de tiers. Notre autorisation d'utiliser ces images peut ne pas couvrir votre reproduction. Cela n'affecte pas vos droits statutaires.