Older versions of Raspberry Pi OS used to have standard user credentials by default. Although the newer version asks you to create a custom username and password during installation, you may need to create more users down the road to meet additional requirements.

You can do this easily using Linux commands, and since Raspberry Pi OS is a flavor of Linux, the same commands apply to other distros as well.

Create a New User in Raspberry Pi OS

You can use both useradd and adduser to create a new user on Linux; the commands are slightly different though. useradd is a low-level command and works with all Linux distributions, whereas adduser is 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 would create system users that do not need a home directory. Also, you have to set the password for the new user using:

        sudo passwd vishnu
    
Creation of new user using useradd command in linux

In contrast, the adduser command asks you to set the password at the time of creating the user.

        sudo adduser vishnu
    

Also, it creates a home directory with the name of the user. You can check it with:

        ls /home
    
Creation of new user using adduser command in linux

Create a New User With a Specific ID

New users get the next available UID by default. Sometimes it is desirable to create a new user with a custom UID. You can do this by using:

        sudo useradd -u 2200 vishnu
    

-u specifies UID, 2200 in this case. Once the new user is created, you can check with the id command, which shows UID as well as the groups a user belongs to.

        id vishnu
    
Creation of new user with specific uid in linux

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 the home directory must be created and -d specifies the location of the directory.

Creation of new user and custom home directory using useradd command in linux

Give a New User the Right Privileges

You created a new user, but it's a standard user and does not belong to the groups that the default user of the Raspberry Pi does. Without being a member of those groups, the new user cannot administer the system and manage situations where elevated privileges are required. For example:

  • Upgrading the system would require sudo privileges
  • Connecting to new Wi-Fi networks using the network manager would require the user to be in the netdev group

To add the new user to the sudo group, run:

        sudo usermod -a -G sudo vishnu
    

...where -a specifies add and -G specifies group.

To add the new user to all the groups as the default user, first list the groups of the default user with:

        id vishnu
    

Then, add the new user to those groups with:

        sudo usermod -a -G comma,separated,group,names vishnu
    
Giving the new user similar privilages as the default user

Delete Unwanted Users on Raspberry Pi OS

On Raspberry Pi OS, you need to delete the default user pi if it's not essential. This is for security reasons. If you've enabled SSH on the Raspberry Pi with the default username pi, it is vulnerable to brute force hacking unless it is protected by a rate limiter application like Fail2Ban.

On Raspbian, which is an older version of the OS, it is almost mandatory to delete the user pi when SSH is enabled because the default username and password are preset.

To delete the default user, you must log in as a different user. To do that, you need to disable Auto login first.

How to turn off auto login on a raspberry pi

Now login as another user who has sudo privileges and delete the required user using:

        sudo userdel tom
    

If you want to remove the user's home directory as well, use:

        sudo userdel -r jill
    

...where -r is for removing the home directory.

You can also use the deluser command to do the same; the arguments are different though.

        sudo deluser --remove-home jack
    
Deleting users using userdel and deluser commands in linux

Creating New Users Using Commands Is Easier Than You Think

Commands are what make Linux special; they give you far more flexibility to specify the exact instructions.

Often, GUI cannot accommodate all the elaborate functions that commands can do. Learning commands is like talking to the computer in its native language, and it is easy.