Raspberry Pi

Step-by-Step Guide to Manage Users on Raspberry Pi

The Raspberry Pi system supports multiple users to access the system and perform tasks. Managing all the users is an essential administrative task for the Raspberry Pi system. There are different parts of managing users in Raspberry Pi like creating a user, switching users, changing passwords, adding users to a group and other such tasks.

In this article we will cover everything from creating a user to deleting a user, in short this article will guide you on how to manage users on Raspberry Pi.

Step-by-Step Guide to Manage User on Raspberry Pi

The list of topics that we will cover here are:

The commands and description of each are discussed below.

1: Creating a New User

The first command in our list is to create a new user on Raspberry Pi. Multiple users can be created on Raspberry Pi. To create a new system user on Raspberry Pi, you can use the below-mentioned command:

Syntax

$ sudo adduser --system <username>

Example

$ sudo adduser --system rpiuser1

Or use simple adduser command can also be used to create a new user in Raspberry Pi:

$ sudo adduser rpiuser2

After running this command, you will be asked for a password for a new user and some information too which you can add if you want or else skip it by pressing Enter:

For further details about creating a new user follow the article.

2: Listing All Users

To list all the user that are part of your Raspberry Pi system, use the below-mentioned command:

$ cut --delimiter=: --fields=1 /etc/passwd

If you are interested in getting the list of normal users on Raspberry Pi system, follow the below-given command:

$ awk -F ":" '/home/ {print $1}' /etc/passwd | sort

3: Switching to User

After creating a user, if you now want to switch to a new user, you can use the below-mentioned command:

Syntax

$ su - rpiuser2

Example

$ su - rpiuser2

4: Changing a User Password

To change the password of any user, switch to that user using the su command.

$ su - rpiuser2

Then use the passwd command to set a new password for the user.

$ passwd

5: Creating a Group

If you want to create a new group in your Raspberry Pi, use the below-mentioned command:

Syntax

$ sudo addgroup <group name>

Example

$ sudo addgroup linuxhintgroup1

6: Listing All Groups

To display the list of all the system users’ groups in Raspberry Pi, just copy the below-mentioned command into terminal:

$ cut --delimiter=: --fields=1 /etc/group

The output will show all the groups in the system as shown in the image below:

7: Adding User to a Group

In Raspberry Pi, some privileges are only for users that are present in a group, so to get the privileges of a certain group, you have to add a user to that group through the following command:

Syntax

$ sudo usermod -aG <group name> <username>

Example

$ sudo usermod -aG linuxhintgroup1 rpiuser2

8: Showing Group of User

To find out the group of any user, switch to that user by using su command.

$ su - rpiuser2

Then simply run the groups command and it will display the groups of that user

$ groups

9: Listing All Users in a Group

To list the all the users present in any group, you can use the below-written command:

Syntax

$ cat /etc/group | cut --delimiter=: --fields=1,4 | grep <group name>

Example

$ cat /etc/group | cut --delimiter=: --fields=1,4 | grep linuxhintgroup1

The output will display the users present in the mentioned group:

10: Deleting a User from Group

If you feel that you no longer need a specific user inside a group, you can delete the user from any group using the below-mentioned command:

Syntax

$ sudo deluser <user name> <group name>

Example

$ sudo deluser rpiuser1 linuxhintgroup1

11: Deleting a Group

And to delete a group, you can use delgroup command with the group name as shown below:

Syntax

$ sudo delgroup <group name>

Example

$ sudo delgroup linuxhintgroup1

12: Deleting a User

To delete any user entirely from the system, use the the below-mentioned command:

Syntax

$ sudo deluser <user name>

Example

$ sudo deluser rpiuser1

Conclusion

Managing users is an essential part of the Raspberry Pi system. Different commands to manage users in Raspberry Pi are discussed in the above guidelines, which include the creation of a user or group, changing passwords for users, switching users, listing users or groups and other such related commands. The users can get help from these commands for easily managing the users on the Raspberry Pi system.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.