For security reasons, it is often advisable to remove the default “pi” user on your Raspberry Pi. In this very short article I will describe step by step how to create a new user with the same characteristics and privileges as the default user.
Of course, to start you need to log in to the machine as the pi user. You can do this either through the Raspberry Pi’s graphical interface or via the terminal from a remote workstation. So if you are on the Raspberry Pi’s desktop, open the terminal; if you are on a remote workstation, connect via SSH.
The first command to run is:
groups pi
this gives you a list of all the groups the pi user belongs to; the result will be similar to the following:
pi : pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio lpadmin
make a note of all these groups, because in the next command we will create the new user and assign it all of them (note that the groups must be separated by commas):
sudo useradd -m -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio,lpadmin yourNewUserName
once that’s done, set a password for the new user with the command:
passwd yourNewUserName
after pressing ENTER you will be asked to enter the password twice.
As a final step, you need to edit the /etc/sudoers.d/010_pi-nopasswd file, so type:
sudo nano /etc/sudoers.d/010_pi-nopasswd
and add a line at the end of the file containing:
yourNewUserName ALL=(ALL) NOPASSWD: ALL
Now, to apply these settings, restart the Raspberry Pi and check that everything works perfectly using the new user.
Finally, if you wish, you can remove the pi user (logging in with the new user, of course) by typing the following command:
sudo deluser pi
Enjoy!
Enjoy!
