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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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 Debug systemd boot process in CentOS/RHEL 7 and 8
  2. How to Tune Btrfs Filesystem for Better Performance
  3. Firewalld Command line Reference (Cheat Sheet)
  4. CentOS / RHEL 7 : How to change runlevels (targets) with systemd
  5. BTRFS: too many missing devices, writeable mount is not allowed
  6. Installing Security Vulnerabilities with yum on CentOS/RHEL 5,6,7 (Cheat Sheet)
  7. How To Retain Current And Older Linux Packages While Doing Update With ‘yum’ Command
  8. How to Configure Network Teaming in CentOS/RHEL 7
  9. Understanding the nfsiostat command output (Examples Included)
  10. How to Use Iperf to Test Network Performance in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright