How to create a new user in Raspberry Pi OS
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
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
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
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.
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:
- System upgrades will require sudo privileges
- 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
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.
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
You should read it
- How to create custom shortcut keys for Raspberry Pi
- How to add an ADC to Raspberry Pi: What you need to know
- Create NAS network storage with Raspberry Pi and Samba
- How to create a Plex Server on Raspberry Pi 4
- Raspberry Pi Zero vs Model A and B, how are they different?
- How to turn Raspberry Pi into travel router with VPN
- How to run VM on Raspberry Pi using Proxmox
- Create your own wireless printer with Raspberry Pi
- What is the Raspberry Pi and how is the Raspberry Pi used?
- 7 great ideas using Raspberry Pi as a server
- How to start Raspberry Pi 3 from USB
- Why should people try Raspberry Pi 4?
Maybe you are interested
This is the culprit that prevents users from updating Windows 11 24H2
How to switch users on the Linux command line
4 reasons why users are looking forward to the Samsung Galaxy S25 Ultra
5 things Pro users may have to give up to switch to iPhone 17 Air
Mozilla quietly adds user tracking feature in new Firefox update
8 Windows 11 features that make users decide to give up Windows 10