Add Users and Groups Manually

This section provides a tutorial example on how to add users and groups manually on Linux computers.

Sometimes, you may want to add a user and its group manually without using the "useradd" and "groupadd" commands. This can be done by editing 4 system files and adding 2 user directories:

1. /etc/passwd - Contains information about users. You can add a new line in /etc/passwd to define the new user:

herong$ sudo vi /etc/passwd

jennifer:x:1066:1066:Jennifer Lopez:/home/jennifer:/bin/bash
|        | |    |    |              |              |- Shell command path
|        | |    |    |              |- Home directory path
|        | |    |    |- Full name
|        | |    |Group ID, unique and > GID_MIN
|        | |User ID, unique and > UID_MIN
|        |- x indicates that encrypted password is in /etc/shadow
|- User name

2. /etc/shadow - Contains information about user passwords. You can add a new line in /etc/shadow to define password for the new user:

herong$ sudo vi /etc/shadow

jennifer:$6$wjcfpF...$QMEmJy...:18878:0:99999:7:::
|        |                      |     | |     |||- Expiration time
|        |                      |     | |     ||- Grace period
|        |                      |     | |     |- Warning period
|        |                      |     | |- Maximum days before change
|        |                      |     |- Minimum days before change
|        |                      |- Last time is was changed
|        |- Password, encrypted with a salt
|- User name

The difficult part of the above line is the encrypted password. You can copy it from an existing user in the /etc/shadow file.

3. /etc/group - Contains information about groups. You can add a new line in /etc/group to define the new group for the new user:

herong$ sudo vi /etc/group

jennifer:x:1066:
|        | |Group ID, matches the group ID in /etc/password
|        |- x indicates that encrypted password is in /etc/shadow
|- Group name

4. /etc/gshadow - Contains information about group passwords. You can add a new line in /etc/gshadow to define password for the new group:

herong$ sudo vi /etc/gshadow

jennifer:!::
|        |||- Group members, 'jennifer' is defaulted
|        ||- Group administrators, 'jennifer' is defaulted
|        |- ! indicates that non-members can not access it with password
|- Group name

5. /home/{username} - User's home directory. You can create it manually with "mkdir" command and change its ownership:

herong$ sudo mkdir /home/jennifer
herong$ sudo chown jennifer /home/jennifer
herong$ sudo chgrp jennifer /home/jennifer

herong$ sudo ls -la /home/jennifer
drwxr-xr-x. 10 jennifer  jennifer   29 Apr 1 2022 .
drwxr-xr-x.  9 root      root      133 Apr 1 2022 ..

Or you can copy user's home directory from another system and adjust its ownership.

6. /var/spool/mail/{username} - User's email file. You can create an empty file and change its ownership:

herong$ sudo touch /var/spool/mail/jennifer
herong$ sudo chown jennifer /var/spool/mail/jennifer
herong$ sudo chgrp mail /var/spool/mail/jennifer

herong$ sudo ls -l jennifer /home/jennifer
-rw-rw----.  1 jennifer   mail    0 Apr 1 2022 jennifer

Or you can copy user's email file from another system and adjust its ownership.

Table of Contents

 About This Book

 Introduction to Linux Systems

 Cockpit - Web Portal for Administrator

 Process Management

 Files and Directories

Users and Groups

 Manage User Groups

 Group Access Permissions on Files

 "sudo" Command and Privilege

 "adduser/usermod/userdel" - Commands to Manage Users

 System Users and Groups

Add Users and Groups Manually

 File Systems

 Block Devices and Partitions

 LVM (Logical Volume Manager)

 Installing CentOS

 SELinux - Security-Enhanced Linux

 Network Connection on CentOS

 Internet Networking Tools

 SSH Protocol and ssh/scp Commands

 Software Package Manager on CentOS - DNF and YUM

 vsftpd - Very Secure FTP Daemon

 Postfix - Mail Transport Agent (MTA)

 Dovecot - IMAP and POP3 Server

 Email Client Tools - Mail User Agents (MUA)

 LDAP (Lightweight Directory Access Protocol)

 Administrative Tasks

 References

 Full Version in PDF/EPUB