How to Create a New Raspberry Pi User

How do you create or add a new Raspberry Pi user? Here’s the short answer:

You can create a new Raspberry Pi user with the adduser command. You can enter information interactively or pass flags in from the command line or through a script.

Step 1. Get to the command line

Remote login over ssh or open up a terminal window via the desktop.

Step 2. Create or add a new user interactively

To add a new user interactively, run this command (and give sudo your password when prompted):

$ sudo adduser luke

First you will be shown some steps that happen automatically. Then you will be prompted to enter additional user info.

Automatic Steps

When the command above is run, you will see the following first:

Adding user `luke' ...
Adding new group `luke' (1004) ...
Adding new user `luke' (1003) with group `luke' ...
Creating home directory `/home/luke' ...
Copying files from `/etc/skel' ...
  • The user (in this case luke) is added
  • A new group based on the username will be created
  • The username will be added to the new group of the same name
  • A new home directory will be created under the /home folder based on the username
  • Files for the user will be copied to their home folder from /etc/skel

What’s up with /etc/skel? I’ll explain that later in this article.

Interactive Steps

After the new user and their home folder is created, you will be prompted to enter additional info.

You must enter and confirm a new password. For the remaining items you can either enter new information or just accept the default (empty) values.

New password: 
Retype new password: 
passwd: password updated successfully
Changing the user information for luke
Enter the new value, or press ENTER for the default
	Full Name []: Luke Skywalker
	Room Number []: 94 
	Work Phone []: 555-555-1234
	Home Phone []: 555-555-5678
	Other []: 
Is the information correct? [Y/n] Y

Step 3. Confirm the users home directory

Once the new user has been created, confirm that their home folder was setup using this command:

$ ls /home

The command should return a list that includes the new users home folder:

darth  luke  mitch  pi

Step 4. Confirm the users information using lslogins

With this command you can confirm that the user information is correct:

$ lslogins -u

You should see a new entry for the user like this:

 UID USER  PROC PWD-LOCK PWD-DENY  LAST-LOGIN GECOS
   0 root    99                               root
1000 pi       5                         21:24 ,,,
1001 mitch    0                   Aug29/17:22 Mitch Allen
1002 darth    0                               Darth V.
1003 luke     0                               Luke Skywalker,94,555-555-1234,555

Step 5. Confirm using getent

You can also confirm the new users information using getent against the passwd file using this command:

getent passwd luke

The command should return something like this entry in /etc/passwd:

luke:x:1003:1004:Luke Skywalker,94,555-555-1234,555-555-5678:/home/luke:/bin/bash

What is /etc/skel for?

Think of /etc/skel as standing for skeleton. A skeleton of default files to be copied over to create a new users home folder.

List the contents of /etc/skel using this command:

$ ls -la /etc/skel

You should see something like this:

total 20
drwxr-xr-x  2 root root 4096 Aug 20 11:31 .
drwxr-xr-x 79 root root 4096 Sep  6 21:25 ..
-rw-r--r--  1 root root  220 Apr 18  2019 .bash_logout
-rw-r--r--  1 root root 3523 Aug 20 11:31 .bashrc
-rw-r--r--  1 root root  807 Apr 18  2019 .profile

List the contents of new users home folder and you will see the same thing (though the default dates will match when you created the user):

$ ls -la /home/luke

Advanced users could edit those files. The new versions would then be copied over when a new user is created.

Step 6. Create a user using flags

Instead of interactive mode, you can create a user using flags passed to the adduser command.

For a list of those flags the -h or --help flag.

sudo adduser -h

This will dump a set of the options to the screen.

Step 7. Add user to groups

After creating a user, look at what groups they belong to using the groups command followed by the username:

$ groups luke

In this examaple the response would just be a group that matches the username:

luke : luke

Now see what groups the user pi belongs to:

$ groups pi

You should see a response like this:

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

As an example, add the new user to the gpio group:

$ sudo adduser luke gpio

Confirm the user is now part of the group:

$ groups luke

You should see a response like this:

luke : luke gpio

Step 8. Look at the /etc/adduser.conf file

To see what parameters the adduser command sets by default, dump the contents of this configuration file:

$ cat /etc/adduser.conf

Advanced users could edit this file to change the defaults used by the adduser command.

Conclusion

In this article you learned how to:

  • Create a new user
  • See where the default files to create a new users home folder are copied from
  • List help information for the adduser command
  • Add a new user to a group
  • See where adduser parameters are configured by default

References

  • Linux users [1]



About the Author

Mitch Allen works for a robotics company in New England.