Change default users on Raspberry Pi

The default user on a fresh Raspbian is pi with the password raspberry. To feel a little bit more save I would like to delete the user pi and change the default root user password.

Connecting to the Raspberry Pi

To bypass the hassle of connecting the Raspberry Pi with a screen and a keyboard I mostly just connect the Raspberry Pi to my router. Normally the pi should register itself as raspberrypi at the router. So we can connect via ssh. If you have connected your Raspberry Pi with a screen and a keyboard you can skip this step and just login as pi.

ssh pi@raspberrypi

Create new user

The pi user has super-user rights so we can switch to the root user.

sudo -i

Let's create a new user. In my case I just name the user gordon.

adduser gordon
Adding user `gordon' ...
Adding new group `gordon' (1001) ...
Adding new user `gordon' (1001) with group `gordon' ...
Creating home directory `/home/gordon' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for gordon
Enter the new value, or press ENTER for the default
	Full Name []: Gordon Lesti
	Room Number []:
	Work Phone []:
	Home Phone []:
	Other []:
Is the information correct? [Y/n]

Add the new user to the sudo group

Raspbian has sudo preinstalled as we have already used it above. So we just need to add the new user to the sudo group.

adduser gordon sudo
Adding user `gordon' to group `sudo' ...
Adding user gordon to group sudo
Done.

Adding own ssh key as authorized key

Let's add our own public ssh key to the file /home/gordon/.ssh/authorized_keys so that we can connect via ssh without a password in future. We need to create the directory /home/gordon/.ssh and change the user to the new one. Again, if you have screen and a keyboard connected to the Raspberry Pi, you can skip this step.

mkdir /home/gordon/.ssh
chown gordon:gordon /home/gordon/.ssh/

After that we will exit from the Raspberry Pi.

exit
exit
exit
logout
Connection to raspberrypi closed.

Now we will create the file /home/gordon/.ssh/authorized_keys on the Raspberry Pi via scp. Hopefully you have public ssh key on your current computer at ~/.ssh/id_rsa.pub.

scp ~/.ssh/id_rsa.pub gordon@raspberrypi:/home/gordon/.ssh/authorized_keys
gordon@raspberrypi's password:
id_rsa.pub                                   100%  401     0.4KB/s   00:00

Delete pi

After that we should now connect again with our new user via ssh without a password. Or if screen and keyboard are connected to the Raspberry Pi, you just login as the new user.

ssh gordon@raspberrypi

Let's remove the user pi and check our super-user permissions.

sudo deluser pi
[sudo] password for gordon:
Removing user `pi' ...
Warning: group `pi' has no more members.
Done.

Create new root password

Let's change the root user password and we are fine for now.

sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Next Previous