como-gestionar-usuarios-y-contrasenas-en-raspberry-pi

How to manage users and passwords on Raspberry Pi

  • 4 min

Managing users and passwords on Raspberry Pi means controlling who can log in and what they can do inside the system.

Indeed, one of the main security measures of any system is a correct configuration of users and their passwords. Raspberry Pi, of course, is no exception.

In older versions of Raspbian there was the famous default user pi with password raspberry. That should no longer appear in a modern installation, because Raspberry Pi OS asks you to create your own user during installation.

In any case, if you open Internet access with weak, repeated, or well-known credentials, you are making a very serious security mistake. And yes, Internet bots do not take long to come knocking.

Besides using a strong password, it is also worth using your own user and not relying on inherited names. Knowing the username is not “half the job”, but it does lower a barrier and makes automated attacks easier.

Fortunately, managing permissions, passwords, groups, and users, as well as configuring security, are one of the strengths of Linux-based systems.

So we are going to spend a little time looking at user and password management on Raspberry Pi, an essential security tool on any computer system.

Default Raspberry Pi User

In older versions of Raspbian, the default user was:

  • Username: pi
  • Password: raspberry

In modern Raspberry Pi OS this user is no longer created automatically by default. During installation, the normal thing is to define your own username and password with Raspberry Pi Imager or with the first-boot wizard.

Change Raspberry Pi Password

To change our user’s password, from a command console, we use the command:

passwd

Next, we type the current password and then the new one twice.

raspberry-pi-usuarios-contrase%C3%B1as-passwd

If we want to change another user’s password, we simply add the username as a parameter

sudo passwd nombreUsuario
Copied!

Where nombreUsuario is the name of the user whose password we want to change. Obviously, we can only perform this action if we are root users of the system.

Playground

Create and Delete Users

Managing users is another maintenance task for any system. Even if you are the only user, it is worth being clear on how to create, delete, and switch users, because it is a common operation on servers and Linux devices.

To create a new user, we use this command:

adduser nombreUsuario

raspberry-pi-usuarios-contrase%C3%B1as-adduser

Deleting a user is just as easy, using the command:

deluser nombreUsuario

raspberry-pi-usuarios-contrase%C3%B1as-deluser

That easy! On the other hand, sometimes you will see an alternative way to create and delete users, using the commands ‘useradd’ and ‘userdel’. The existence of two sets of commands can cause some confusion.

The explanation is that ‘useradd’ and ‘userdel’ are system binaries, while ‘adduser’ and ‘deluser’ are Perl scripts that use the aforementioned binaries.

We should get used to using exclusively the previous ‘adduser’ and ‘deluser’ from the command console. Meanwhile, ‘useradd’ and ‘userdel’ are more intended for use in scripts. However, here is the syntax for these alternative commands.

#create a new user useradd nombreUsuario

#create user, full version useradd -c “Nombre Usuario” -g grupo -d /home/usuario -s /bin/bash nombreUsuario

#delete user userdel nombreUsuario

#delete user and remove their home directory userdel -r nombreUsuario

User Session Management

Some additional useful commands for controlling user sessions. First, to end the session we use the command:

logout

If during a session we want to act briefly as another user, without logging out, we can temporarily switch with the following command

su - nombreUsuario

raspberry-pi-usuarios-contrase%C3%B1as-su

To end this “temporary session” and return to our “normal” user, we simply do:

exit

If we want to see the name of the user we are currently connected as, we use:

whoami

raspberry-pi-usuarios-contrase%C3%B1as-whoami

We can also list all users connected to the system with the command:

who
Copied!

Finally, if we want to get a record of the last login of users, we can use:

lastlog
Copied!

That covers the basics of managing users, passwords, and user sessions. Of course, there are many more related commands and options, but this covers most needs on a Raspberry Pi used as a server or work machine.