How to create a new user in Raspberry Pi OS

Although newer versions require you to create a custom username and password during installation, you may need to create additional users later to meet additional requirements.

Older versions of Raspberry Pi OS used to have standard user credentials by default. Although newer versions require you to create a custom username and password during installation, you may need to create additional users later to meet additional requirements.

You can do this easily using Linux commands, and since Raspberry Pi OS is a version of Linux, the same commands apply to other distributions.

Create a new user in Raspberry Pi OS

You can use both useradd and adduser to create new users on Linux; The commands are slightly different though. useradd is a low-level command and works with all Linux distributions, while adduser is a high-level command and works with fewer distributions. Both commands work fine on Raspberry Pi OS.

Use this command to create a user named vishnu using useradd:

sudo useradd vishnu

However, the command does not create a home directory for the new user. This is how you create a system user without a home directory. Additionally, you must set a password for the new user using:

sudo passwd vishnu

Picture 1 of How to create a new user in Raspberry Pi OS

In contrast, the adduser command requires you to set a password at the time of user creation.

 sudo adduser vishnu

Additionally, it creates a home directory with the user's name. You can check with:

ls /home

Picture 2 of How to create a new user in Raspberry Pi OS

Create a new user with a specific ID

By default, new users will receive the next available UID. Sometimes, you should create a new user with a custom UID. You can do this using:

sudo useradd -u 2200 vishnu

-u specifies the UID, 2200 in this case. After the new user is created, you can check with the id command, which displays the UID as well as the groups to which the user belongs.

id vishnu

Picture 3 of How to create a new user in Raspberry Pi OS

How to create a new user with a custom home directory

If you want a custom name for your home directory, you can use the command:

sudo useradd -m -d /home/mychoice vishnuhome

-m specifies that a home directory must be created and -d specifies the location of the directory.

Picture 4 of How to create a new user in Raspberry Pi OS

 Provide the new user with appropriate privileges

You have created a new user, but it is a standard user and not in the group to which the Raspberry Pi's default user belongs. If not a member of those groups, new users cannot administer the system and manage situations that require admin privileges. For example:

  1. System upgrades will require sudo privileges
  2. Connecting to new WiFi networks using network manager will require the user to be in the netdev group

To add a new user to the sudo group, run:

sudo usermod -a -G sudo vishnu

.where -a specifies add and -G specifies group.

To add a new user to all groups as the default user, first list the default user's groups with:

id vishnu

Then, add new users to those groups with:

sudo usermod -a -G comma,separated,group,names vishnu

Picture 5 of How to create a new user in Raspberry Pi OS

Delete unwanted users on Raspberry Pi OS

On Raspberry Pi OS, you need to delete the pi default user if not needed. This is for security reasons. If you have SSH enabled on your Raspberry Pi with the default username pi, it is vulnerable to a Brute Force attack unless it is protected by a rate limiting application like Fail2Ban.

On Raspbian, an older version of the operating system, it is almost mandatory to delete user pi when SSH is enabled because the default username and password are already set.

To delete the default user, you must log in as a different user. To do that, you first need to turn off Auto login.

Picture 6 of How to create a new user in Raspberry Pi OS

 Now, log in as another user with sudo privileges and delete the required user using:

sudo userdel tom

If you also want to delete the user's home directory, use:

sudo userdel -r jill

.where -r is to delete the home directory.

You can also use the deluser command to do the same; although the arguments are different.

sudo deluser --remove-home jack

Picture 7 of How to create a new user in Raspberry Pi OS

Update 13 October 2023
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile