• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

RHEL 7 – RHCSA Notes : Create, delete, and modify local user accounts

by admin

RHEL 7 – RHCSA Notes (Cheat Sheets)

Adding a user account

Use the useradd command to add new user :

# useradd [options] [username]

The default settings for new user can viewed and modified using the -D option :

# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

For example, to change the default user shell for new user to /bin/ksh :

# useradd -D -s /bin/ksh

Examples

To simple add a user with all default options :

# useradd user01

To add user with uid 1099, comment “new user” and default shell as /bin/ksh :

# useradd -u 1099 -c "new user" -s /bin/ksh user01

Check new user’s entry in /etc/passwd file :

grep user01 /etc/passwd
user01:x:1099:1099:new user:/home/user01:/bin/ksh

To modify existing user (e.g. changing the comment) :

# usermod -c "modified user" user01

To assign the password to new user:

# passwd user01
Changing password for user user01.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

View the /etc/shadow file :

# grep user01 /etc/shadow
user01:$6$dox84xyJ$89DdMcxSlI9OHxUCyY1ryaFsmG6MSEwbmSbZXJoFY.tHgdEEeQQgQjDV0dD8jEiHusrUjj3p8gtMTKR4sXXN5.:17058:0:45:7:::

To delete the user :

# userdel user01

nologin shell

You can create a user with nologin shell for running services such as SMTP, FTP etc. A user without a login shell can not login to a system and therefore cannot run any command on the system interactively on the system. Processes can run as that users however.

To add new user “test” with shell nologin :

# useradd -s /sbin/nologin test

Make sure the nologin shell is present in the /etc/shells file :

# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin

Filed Under: CentOS/RHEL 7, RHCSA notes

Some more articles you might also be interested in …

  1. How to change the path of the auditd log file /var/log/audit/audit.log
  2. BTRFS: too many missing devices, writeable mount is not allowed
  3. How to Re-generate initramfs and vmlinuz for Rescue Kernel with Current Kernel in CentOS/RHEL 7
  4. How to set children-max for udev Service in CentOS/RHEL 7
  5. How to Convert Ext File Systems to Btrfs
  6. Time goes out of sync on a node running CentOS/RHEL 7
  7. How to Extend the Last Existing Filesystem Partition with Parted
  8. CentOS / RHEL 7 : How to rename the volume group for root and swap
  9. What are different Samba Server Types
  10. PAM password complexity and pam_cracklib credit system in CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • glab Command Examples
  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright