Show List

Managing users and groups in Linux

Managing users and groups in Linux involves creating, modifying, and deleting user accounts and groups, as well as managing their permissions and access to system resources. Here are some code examples for common user and group management tasks in Linux:

  • Creating a new user account

To create a new user account in Linux, use the adduser command followed by the username. Here's an example:

Copy code
sudo adduser johndoe

This command will prompt you to enter a password and other user information, such as full name and contact details.

  • Modifying user account properties

To modify the properties of an existing user account, use the usermod command followed by the desired options. Here are some examples:

  • Change the user's home directory:

javascript
Copy code
sudo usermod -d /new/home/directory johndoe
  • Add the user to a group:

  • Copy code
    sudo usermod -aG newgroup johndoe
    • Deleting a user account

    To delete a user account in Linux, use the userdel command followed by the username. Here's an example:

    Copy code
    sudo userdel johndoe

    This command will remove the user's home directory and any files it contains.

    • Creating a new group

    To create a new group in Linux, use the addgroup command followed by the group name. Here's an example:

    Copy code
    sudo addgroup newgroup
    • Modifying group properties

    To modify the properties of an existing group, use the groupmod command followed by the desired options. Here are some examples:

    • Rename the group:

    Copy code
    sudo groupmod -n newname oldname
  • Add a user to the group:

  • Copy code
    sudo usermod -aG newgroup johndoe
    • Deleting a group

    To delete a group in Linux, use the delgroup command followed by the group name. Here's an example:

    Copy code
    sudo delgroup oldgroup

    These are some examples of basic user and group management tasks in Linux. There are many more advanced options available, such as managing user and group permissions for specific files and directories, but these commands should be enough to get you started.


        Leave a Comment


    • captcha text