Adding and Removing Users with useradd, usermod, and userdel in Red Hat

Adding and Removing Users with useradd, usermod, and userdel in Red Hat

The useradd command in Red Hat-based Linux distributions is used to create new user accounts on the system. It allows you to specify various parameters while creating a user account. Here’s a table with information and examples related to the useradd command:

ParameterDescriptionExample
-c, --comment <comment>Provide a comment or description for the useruseradd -c "John Doe" john
-d, --home <directory>Set the home directory for the useruseradd -d /home/john john
-g, --gid <group>Set the primary group for the useruseradd -g users john
-G, --groups <groups>Specify additional groups for the user (comma-separated list)useradd -G developers,admins john
-m, --create-homeCreate the user’s home directory if it doesn’t existuseradd -m john
-s, --shell <shell>Set the login shell for the useruseradd -s /bin/bash john
-u, --uid <UID>Set the user ID (UID) for the useruseradd -u 1001 john
-p, --password <password>Set the encrypted password for the useruseradd -p 'encrypted_password' john
usernameThe username of the new useruseradd newuser

Examples:

  1. Create a user named “john” with a comment:
Bash
   useradd -c "John Doe" john
  1. Create a user named “john” with a specific home directory:
Bash
   useradd -d /home/john john
  1. Create a user named “john” and assign them to the “users” primary group:
Bash
   useradd -g users john
  1. Create a user named “john” and add them to the “developers” and “admins” groups:
Bash
   useradd -G developers,admins john
  1. Create a user named “john” with a home directory and a default login shell:
Bash
   useradd -m -s /bin/bash john
  1. Create a user named “john” with a specific UID (user ID):
Bash
   useradd -u 1001 john
  1. Create a user named “john” with a pre-encrypted password:
Bash
   useradd -p 'encrypted_password' john
  1. Create a user named “newuser”:
Bash
   useradd newuser

Please note that managing user accounts might require administrative privileges (sudo). Additionally, it’s a good practice to use the passwd command after creating a user to set their password interactively, as storing passwords in plain text or with reversible encryption is not recommended for security reasons.

CommandDescriptionExample
useraddCreate a new user account with specified parametersuseradd -c "John Doe" -m -s /bin/bash john
usermodModify existing user account attributesusermod -aG developers john
userdelDelete a user account and related filesuserdel -r john

Examples:

  1. useradd: Create a user named “john” with a comment, home directory, and default shell:
Bash
   useradd -c "John Doe" -m -s /bin/bash john
  1. usermod: Add user “john” to the “developers” group:
Bash
   usermod -aG developers john
  1. userdel: Delete the user “john” and remove their home directory and files:
Bash
   userdel -r john
Total
2
Shares

Leave a Reply

Previous Post
Managing User Environments in Red Hat

Managing User Environments in Red Hat

Next Post
how to Install Docker on Ubuntu 18.04

How to Install Docker on Ubuntu 18.04: Complete Step-by-Step Installation and Configuration Guide

Related Posts