Frequently Asked Question

How to add users to a system?
Last Updated 3 years ago

1. Introduction

In this guide, we will describe how to handle the user creation on one of your VM's . You can check the manual of your distribution in the terminal with man useradd

This article goes hand in hand with the Group creation Article.

2. How to Add a New User in Linux

The basic syntax of the command is:

ubuntu@eodc:~$ sudo useradd [options] username

To create a user you need to have adequate permissions on the system. You can either get them while logging in as the root user or with the sudo (superuser do) command. By default, a group with the same name will also be created for the new user.

3. Create a User

As a privileged user run

ubuntu@eodc:~$ sudo useradd -m -G sudo,developers,webadmin -s /bin/bash your_user

Depending on the distribution you might already be asked for an password while the creation. If not and in the case that your user doesn't have shell access but needs RDP or other services which are depending on the native authentication create a password with the passwd Command

ubuntu@eodc:~$ sudo passwd your_user

3.1. -m

The -m will create a home directory for af new user under /home. This option is needed when your user should be authenticated with an SSH key.

3.2. -G

-G (Group) flag will add your_user to previously created groups. How to create groups

ubuntu@eodc:~$ sudo useradd -G sudo,developers,webadmin your_user

3.3 -s

Sometimes, you want to add a user which has nothing to do with the login shell. You can assign a different login shell with the -s (shell) flag.

ubuntu@eodc:~$ sudo useradd -s /sbin/nologin your_user

4. Other options

4.1. Add an User with an expiry Date

You can use the -e (expiry) flag for this.

ubuntu@eodc:~$ sudo useradd -e 2038-01-19 your_user

The format is YYYY-MM-DD. This is helpful for creating temporary accounts for a specific period of time.

4.2 Do not create a Home diretory

You're supposed to run the command with all the flags at the same time. Check the man page for all available options

ubuntu@eodc:~$ sudo useradd -M -G samba -e 2038-01-19  your_user

5. Add an SSH key

It is a good choice to add an SSH key while creating an user. Refer to articles below for a comprihensive guide.

How to create SSH keys?
How to add an SSH key to a user?

This website relies on temporary cookies to function, but no personal data is ever stored in the cookies. For further information see our

privacy policy.


Loading ...