How to switch user from “pi” to original user on Raspberry Pi 4? 

Raspberry Pi
Reading Time: 2 minutes



Raspberry Pi OS has default user as

User name: pi
Password: raspberry

 

If you use Raspberry Pi 4 only in home Wi-Fi, it is OK.
But if you want to allow access from internet, this default user is security risk because everyone knows this username/password.

This article shows how to change user.

 Adding new user

First let’s add user.
We can add user by using command “adduser”, which needs interactive inputs.
Below is example of user “yasu”.

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



Next let’s grant the same rights as pi.

# Granting the same rights as pi
$ sudo usermod -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,spi,i2c,gpio yasu
# Verifying
$ groups yasu
yasu : yasu adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio




Now “yasu” can do the same thing as “pi”.

Deleting user “pi” 

“pi” can be deleted.

$ sudo userdel -r pi
userdel: user pi is currently used by process 7185



Oh? process 7185 is doing something?
– Actual process ID differs.
– It may ends with no errors. 



Let’s confirm which process is 7185. 

$ ps aux | grep 7185
pi 7185 0.0 0.3 14596 6704 ? Ss 13:37 0:00 /lib/systemd/systemd --user
yasu 7659 0.0 0.0 7348 540 pts/0 S+ 13:49 0:00 grep --color=auto 7185



It looks systemd.
The easiest way to solve is just reboot.
– sudo reboot
To disconnect power supply from Raspberry Pi 4 is little bit danger because unflushed data may be in kernel memory.



After rebooting let’s retry.

$ sudo userdel -r pi
[sudo] password for yasu: (Input password)
userdel: pi mail spool (/var/mail/pi) not found

# Verifying
$ id -a pi
id: ‘pi’: no such user
$ ls -l /home/
total 4
drwxr-xr-x 4 yasu yasu 4096 Nov 11 13:40 yasu



Good!
From now you cannot login as “pi”.

Conclusion 

 How was it?

This takes a few minutes, so let’s do it soon!



In below article I introduce each step how to establish nextcloud on Raspberry Pi 4!
You should be interested in it too!

Comments

タイトルとURLをコピーしました