Managing User Accounts on Your Raspberry Pi

By Sean McManus, Mike Cook

If you want to share the Raspberry Pi with different family members, you could create a user account for each one so that they all have their own home directory. The robust permissions in Linux help to ensure that people can’t accidentally delete each other’s files, too.

You might already know that users can be members of groups. On the Raspberry Pi, groups control access to resources like the audio and video hardware, so before you can create a new user account, you need to understand which groups that user should belong to. To find out, use the groups command to see which groups the default pi user is a member of:

pi@raspberrypi ~ $ groups pi

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

When you create a new user, you want to make him a member of most of these groups, except for the group pi (which is the group for the user pi).

If you give users membership of the sudo group, they will be able to install software, change passwords, and do pretty much anything on the machine (if they know how). In a home or family setting, that should be fine, however. The permissions system still protects users from accidentally deleting data they shouldn’t, as long as they steer clear of the sudo command.

To add a user, you use the useradd command with the -m option to create a home directory for him and use the -G option to list the groups the user should be a member of, like this:

sudo useradd –m –G [list of groups] [username]

For example:

sudo useradd –m –G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,netdev,input,spi,gpio karen

Make sure the list of groups is separated with a comma and there are no spaces in there.

You can do a quick check to confirm that a new home directory has been created with the user’s name in directory /home, alongside the home directory for the pi user:

ls /home

You also need to set a password for the account, like this:

sudo passwd [username]

For example,

sudo passwd karen

Usernames are case sensitive, so if you use any capital letters, you must do so consistently. You’re prompted to enter the password twice, to make sure you don’t mistype it, and you can use this command to change the password for any user. There is no output on the screen as you type the password, which can be a bit off-putting, but keep typing and it should work fine.

You can test whether it’s worked and log in as the new user without restarting your Pi by logging out from your current user account. Close the shell window and select Shutdown from the Applications menu. Choose Logout from the options, and you’ll be presented with the login screen, where you can test that the new username is working. The default password for the pi account is raspberry.

If you use the passwd command to set a password for the username root, you will be able to log on as the superuser, who has the power to do anything on the machine. As a last resort, this might enable you to get some types of software working, but you might want to reconsider using. It’s safer to take on the mantle of the superuser only when you need it, by using sudo.

If you want to share the Raspberry Pi with different family members, you could just give each user his own SD card to insert when he’s using the machine, and let him log on with the pi username and password.