- How to Create Normal User in Linux
- Tutorial Details
- Basic information you must know
- Creating a Normal User
- Set Password to New User
- Assign New User to Group
- Creating a Normal User with a Different Home Directory
- Creating a New User with a Specific User ID
- Creating a New User with a Specific Group ID
- Creating a New User without a Home Directory
- Creating a New User with an Account Expiration Date
- Creating a New User with a Password Expiry Date
- Creating a New User with Custom Comments
- Creating New User with a Different Login Shell
- Removing a New User Account
- System Users and Human Users in Linux Explained with Examples
- System Users and Human Users in Linux Explained with Examples
- Human Users
- System Users
- How to Find UID and GID of a user
- Create System User
- Create System group
- Good To Know
- What’s the difference between a normal user and a system user?
- 3 Answers 3
How to Create Normal User in Linux
In Linux, we have a root user created by the system administrator and normal users, which are also created by the system administrator.
However, root user have more privileges than normal user accounts, which is why we suggest letting other people have normal user accounts instead of directly having a root account.
It will restrict them from doing a lot of miscellaneous and unintentional damage to the system, and you can also create users with an expiry date, limited permissions, and many more.
Also remember that only the root user or a user with sudo privileges has access to create a new normal user account in Linux.
Tutorial Details
Description | Creating Normal Users |
Difficulty Level | Moderate |
Root or Sudo Privileges | Yes |
Host System and Architecture | Ubuntu 22.10 (x64) |
OS Compatibility | Ubuntu, Manjaro, Fedora, etc. |
Prerequisites | useradd, passwd |
Internet Required | No |
Discussed Tools in this Article |
Basic information you must know
The useradd and adduser commands are used to create users in a Linux system.
The useradd command is a compiled binary and available in all Linux distributions; however, adduser is a Perl script that utilizes the useradd command to provide more rich features.
Creating a new account will populate the /etc/passwd , /etc/shadow , /etc/group , and /etc/gshadow files.
Creating a Normal User
Specify the username in the following command to create a normal user account.
$ sudo useradd [USERNAME]
Set Password to New User
A newly created user has an empty password that can be set using the passwd command.
$ sudo passwd [USERNAME] New password: Retype new password:
Assign New User to Group
After creating a user, if you want to assign that user to a group like sudo, specify the name of that group and username as shown.
$ sudo usermod -aG sudo [USERNAME]
Creating a Normal User with a Different Home Directory
Create a new directory at the “/home/” location and specify it to the following command to use it as the default home directory for your new user.
$ sudo useradd -d /home/[DIRECTORY-NAME] [USERNAME]
Creating a New User with a Specific User ID
You can specify a user ID for your newly created user in the range of 100 to 999, as shown.
$ sudo useradd -u 666 [USERNAME]
Creating a New User with a Specific Group ID
If you want to add your current user ID as group to the new user account than find out its ID by reading the “/etc/passwd” file and specify it to the following command.
$ sudo useradd -g [CURRENT-USER] [USERNAME]
Creating a New User without a Home Directory
Assign the -M flag to create a new user without a home directory, but in the next login, the root home directory or previous user’s home directory will be used as the default home directory for that user.
$ sudo useradd -M [USERNAME]
Creating a New User with an Account Expiration Date
To remove the new user account at a specified date, specify that date to the following command with username and the -e flag.
$ sudo useradd -e 2023-12-26 [USERNAME]
Creating a New User with a Password Expiry Date
The same password for the long run can be easily breached, so set the password expiry days after which users will be forced to change their password on that specific day.
$ sudo useradd -f [NUMBER-OF-DAYS] [USERNAME]
If you specify “5” to [NUMBER-OF-DAYS], you will be forced to change your password after 5 days.
Creating a New User with Custom Comments
Comments are helpful to let you know the purpose of that user account or a few details related to that account, which can be easily set using the -c flag.
$ sudo useradd -c "This is my comment" [USERNAME]
Creating New User with a Different Login Shell
By default, the bash shell is used by most Linux distributions, which will be the default shell for a new user, although you can easily install another shell like ZSH or Fish and specify this shell as the default for the new user account.
$ sudo useradd -s /bin/zsh [USERNAME]
Execute the echo $0 command to find the path of the current shell.
Removing a New User Account
In case you accidentally created a new user without any intention to use it further, you can remove it using the following command:
$ sudo userdel [USERNAME]
That’s all the possible ways to create a new user in Linux; if you have more, feel free to share them in the comment section.
System Users and Human Users in Linux Explained with Examples
In this article, we will look into two types of user in Linux — System Users and Human Users. As you probably know, every Linux System has an entity called User which performs a range of system management tasks. Each user will have a unique ID called UID(User ID) and GID(Group ID). Similarly, there is another entity available called groups which is nothing but collection of users has its own role to play. User Management and Groups is an integral part of Linux System Administration which needs to be understood in detail. Here we will look into different types of users in detail with examples.
System Users and Human Users in Linux Explained with Examples
There are basically two types of users in Linux:-
Human Users
Each user has unique UID(User ID) and GID(Group ID) . Whenever a user is created, it owns a home directory where all personal files and folders can be stored.
Switch to home directory. Then create a new user. We will notice that whenever a new user is created, its home directory also gets created.
[root@cyberithub home]# pwd /home [root@cyberithub home]# useradd cyberithub [root@cyberithub home]# ls cyberithub
Human users are further of two types:-
- Root user -> also known as superuser which has all the privileges and has all the control to do anything on the system.
- Common user -> also known as unprivileged users has limited rights to perform operation on their owned files and directory. Normal users can be given different level of privileges or complete root privilege totally based on the need and requirement.
System Users
System Users mostly run system services and processes in the background also known as non-interactive processes. System Users doesn’t own home directory. We can find all the created users details in /etc/passwd file and all active groups details in /etc/group file.
Root user has the privileges to add, delete, update any users and groups. Below are the useful command to perform any operations on users and groups.
a) useradd -> to create a new user
[root@cyberithub home]# useradd cyberithub [root@cyberithub home]# grep cyberithub /etc/passwd cyberithub:x:1003:1003::/home/ cyberithub:/bin/bash
b) userdel -> to delete an existing user
[root@cyberithub home]# userdel cyberithub
c) groupadd -> to create a new group
[root@cyberithub home]# groupadd cyberithub [root@cyberithub home]# grep cyberithub /etc/group cyberithub:x:1003:
d) groupdel -> to delete an existing group
[root@cyberithub home]# groupdel cyberithub
e) usermod -> make changes to existing users. There are many operations that can be performed once the user is created like adding the comment, changing the password, changing the home dir etc. One such example is given below. We are changing the home directory of user cyberithub from /home/cyberithub to /home/gpuser . More about usermod command.
[root@cyberithub home]# grep cyberithub /etc/passwd cyberithub:x:1003:1003::/home/ cyberithub:/bin/bash [root@cyberithub home]# usermod -d /home/gpuser cyberithub [root@cyberithub home]# grep cyberithub /etc/passwd cyberithub:x:1003:1003::/home/gpuser:/bin/bash
f) passwd -> create or change password for any user
[root@cyberithub home]# passwd cyberithub Changing password for user cyberithub. New password: Retype new password: passwd: all authentication tokens updated successfully.
How to Find UID and GID of a user
To find the UID or GID of any user simply execute below command.
a) id -> to view the UID and GID of current user
[root@cyberithub home]# id uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
b) id user_name -> to view UID and GID of a particular user
[root@cyberithub home]# id cyberithub uid=1003(cyberithub) gid=1003(cyberithub) groups=1003(cyberithub)
Create System User
System users can also be created using useradd command but with some extra flags in the command. Below we are creating a system user called ‘cyberuser’ where
r -> create a system user with a real ID in the correct numerical range for system users
s -> specifies the login shell
/bin/false -> dummy command that prevents the user from logging into the system.
[root@cyberithub home]# useradd -rs /bin/false cyberuser [root@cyberithub home]# grep cyberuser /etc/passwd cyberuser:x:997:993::/home/cyberuser:/bin/false
Create System group
System user can be created using the same command but with -r flag.
[root@cyberithub home]# groupadd -r cyberuser [root@cyberithub home]# grep cyberuser /etc/group cyberuser:x:993:
Good To Know
Human users differ from Group users in terms of UID and GID range that are assigned to them. This setting can be found in /etc/login.defs file. Notice the below section of the file where UID and GID range is different for system and human users.
[root@cyberithub home]# view /etc/login.defs # Min/max values for automatic uid selection in useradd # UID_MIN 1000 UID_MAX 60000 # System accounts SYS_UID_MIN 201 SYS_UID_MAX 999 # # Min/max values for automatic gid selection in groupadd # GID_MIN 1000 GID_MAX 60000 # System accounts SYS_GID_MIN 201 SYS_GID_MAX 999 #
What’s the difference between a normal user and a system user?
Some documentation I’m going through has a boolean switch on whether or not a user is a ‘system’ user or a ‘normal’ user (defaulting to ‘normal’). What is the difference between these two modes of user-ship? I don’t need to learn what a user is or why you need them (even ‘fake’ ones), but this particular distinction isn’t intuitive to me.
3 Answers 3
That is not a technical difference but an organizational decision. E.g. it makes sense to show normal users in a login dialog (so that you can click them instead of having to type the user name) but it wouldn’t to show system accounts (the UIDs under which daemons and other automatic processes run) there.
Thus a border is defined or rather two ranges for the UIDs for the two groups. In openSUSE the file /etc/login.defs contains these lines:
# Min/max values for automatic uid selection in useradd # # SYS_UID_MIN to SYS_UID_MAX inclusive is the range for # UIDs for dynamically allocated administrative and system accounts. # UID_MIN to UID_MAX inclusive is the range of UIDs of dynamically # allocated user accounts. # UID_MIN 1000 UID_MAX 60000 # System accounts SYS_UID_MIN 100 SYS_UID_MAX 499
# Min/max values for automatic gid selection in groupadd # # SYS_GID_MIN to SYS_GID_MAX inclusive is the range for # GIDs for dynamically allocated administrative and system groups. # GID_MIN to GID_MAX inclusive is the range of GIDs of dynamically # allocated groups. # GID_MIN 1000 GID_MAX 60000 # System accounts SYS_GID_MIN 100 SYS_GID_MAX 499