Create users on Raspberry Pi OS

Create users on Raspberry Pi OS

Raspberry Pi OS, formally known as Raspbian, is the official Raspberry Pi Linux. It’s based on Debian and shipped with many useful apps and configurations, one of which is the default pi user. While that eases getting started with the Raspberry Pi, it’s unsafe to continue using the pi user after you’ve done with the basic set up. In this article, we go through how to create users on Raspberry Pi OS.

The default pi user has accesses and privileges like the GPIO pin access and the ability to run sudo commands. It’s useful to keep all those privileges when creating a new user to avoid any troubles later on. Hence, we should add an identical user to the default one.

For that, you can watch this YouTube video or keep on reading 🙂

Creating a new user with proper privileges

Let’s begin by creating a user first (in this case my_user),

$ sudo adduser my_user

After that, you will have to set a password and provide some basic info for the new user.

Now we need to find out which groups the pi user belongs. For that run the following command,

$ sudo groups pi

You get an output like this,

pi : pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio lpadmin

The next step is to add the new user (my_user) to all the above groups,

$ sudo usermod -aG adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio,lpadmin my_user

We should try to see whether we can log in as the user and run a sudo command,

$ sudo login -f my_user
$ sudo ls /tmp

You should not get any error means something is not working as expected.

Once that’s done, confirm the new user can log in via GUI as well.

Deleting the pi user

The last step is to remove the pi user from the system. For that, we login as the new user and run the following command,

$ sudo userdel pi

If you get an userdel: user pi is currently used by process 2030 error message, either you have to kill the process or can force delete the user,

$ sudo userdel -f pi

You may get the exact error again, but the user should be removed already. You can confirm it by trying to log in as the pi user.

$ sudo login -f pi

It should give an Authentication failure error.

Finally, let’s remove the pi home directory (Backup all files that needed beforehand),

$ sudo rm -rf /home/pi

That’s all on how to create users on Raspberry Pi OSNow you should have a safer Raspberry Pi. Happy hacking 😀

Inline/featured images credits