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
How to create a new user in Raspberry Pi OS Picture 1
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
How to create a new user in Raspberry Pi OS Picture 2
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 in Raspberry Pi OS Picture 3
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.
How to create a new user in Raspberry Pi OS Picture 4
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
How to create a new user in Raspberry Pi OS Picture 5
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.
How to create a new user in Raspberry Pi OS Picture 6
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
How to create a new user in Raspberry Pi OS Picture 7
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?
May be interested
8 things to avoid to not damage your Raspberry Pi
Difference between Elegoo and Arduino
4 reasons to buy an old Raspberry Pi model
Why is the new Arduino Uno R4 a game changer for manufacturers?
How to use the advanced options of Raspberry Pi Imager
How to send backup copies of Raspberry Pi files to email