How to Create New Users on Raspberry Pi OS
This article will demonstrate how to create new users on Raspberry Pi OS.
Create a New User on Raspberry Pi OS
User management on Linux-based systems is generally a significant topic that involves many subtle details.
Still, this article will cover several command-line tools and methods to create/remove new users. Notice that most of the user management commands on Raspberry Pi OS will be the same as Debian/Ubuntu-based systems.
Let’s get into a practical example and create a new user bob
on Raspberry Pi:
sudo adduser bob
Sample Output:
[sudo] password for pi:
Adding user `bob' ...
Adding new group `bob' (1001) ...
Adding new user `bob' (1001) with group `bob' ...
Creating home directory `/home/bob' ...
Copying files from `/etc/skel' ...
New password:
The previous command needs to be executed using sudo
privileges. adduser
is, in fact, a Debian-based system wrapper for low-level useradd
utility, and it’s recommended way on Raspberry Pi OS well.
This command creates a corresponding home directory for the user bob on path /home/bob
and assigns the first available UID. UID stands for user ID, and it’s usually a unique 32-bit integer stored in the system.
The available range for normal users is specified in the /etc/adduser.conf
file, and it happens to be 1000-59999 on the current Raspberry Pi OS release. You can inspect all existing users by opening the /etc/passwd
file.
The adduser
command with only username (bob
) argument will prompt a new password to activate password login to the given username. Generally, a new user can be created without setting a password, which will result in a disabled account similar to a disabled root
user on Raspberry Pi OS.
The latter can be achieved using the --disabled-login
argument to adduser
command:
sudo adduser --disabled-login bob
The latter command will create a bob
user without a password, which can later be set using the passwd
command, and the username will be activated automatically.
Delete Users on Raspberry Pi OS
To delete specific users from the Raspberry Pi OS, we need to utilize the deluser
command. This command is a wrapper for the userdel
Linux utility, and it’s usually provided on Debian/Ubuntu-based systems.
The basic command structure for deleting bob
user is as follows:
sudo deluser bob
This command deletes the user without removing its home directory and other files owned by bob
.
However, you can specify the --remove-home
argument to delete the home directory with the user or the --remove-all-files
argument to delete the home directory and all user-owned files/directories on the system.
Notice that the latter argument is the superset of the former, so you don’t need to specify both:
sudo deluser --remove-home bob
sudo deluser --remove-all-files bob
Sometimes, it’s likely that user bob
has some running programs, and when you try to delete the user, the command will yield an error with the corresponding message.
It’s best to run the killall
command and terminate all existing processes associated with the user bob
before executing the deluser
command. The following command can be utilized to complete all processes:
sudo killall -TERM -u bob
Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.
LinkedIn Facebook