jlazkano
Posts: 14
Joined: Wed Nov 13, 2013 8:19 pm

Delete pi user in Raspbian

Mon Jan 15, 2018 8:05 pm

Hello,

Is it possible to delete the default "pi" user in Raspbian?

I want to use same users with they uid and gid.

Regards.

User avatar
HawaiianPi
Posts: 5996
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Delete pi user in Raspbian

Mon Jan 15, 2018 10:12 pm

I did that once by creating a new temporary user, logging in as the temp user, deleting the "pi" user, and then creating my user. There's supposed to be a way to change the name of the pi user as well, but it all seems like more fuss than it's worth, and removing the pi user can have consequences since it is much too integrated into Raspbian OS (more problematic with Desktop than Lite version).

Normally I just create my user and lock the pi account (sudo passwd --lock pi).
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

User avatar
DougieLawson
Posts: 40194
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Delete pi user in Raspbian

Mon Jan 15, 2018 11:13 pm

Crude and ugly way is sudo nano /etc/passwd; sudo nano /etc/group; sudo nano /etc/shadow;
Change pi to your new ID in those three files then reboot.

If you use the GUI you'll need to muck about with the lightdm autologin stuff.
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

n67
Posts: 938
Joined: Mon Oct 30, 2017 4:55 pm

Re: Delete pi user in Raspbian

Tue Jan 16, 2018 1:23 am

You really have to ask yourself why you want to do this.

The short answer is: Yes, you can, but not without a lot of pain.
"L'enfer, c'est les autres"

G fytc hsqr rum umpbq rm qyw rm rfc kmbq md rfgq dmpsk:

Epmu Sn!

J lnacjrw njbruh-carppnanm vxm rb mnuncrwp vh yxbcb!

jlazkano
Posts: 14
Joined: Wed Nov 13, 2013 8:19 pm

Re: Delete pi user in Raspbian

Tue Jan 16, 2018 8:19 pm

Hello,

I did it enabling root access, then:

Code: Select all

userdel -r -f pi
adduser user1
adduser user2
Regards.

Iznogood1
Posts: 23
Joined: Wed Dec 07, 2016 6:51 pm

Re: Delete pi user in Raspbian

Wed Feb 13, 2019 3:37 pm

It can be done without pain...

1/ Create a new user (named userx here)

Code: Select all

sudo add user userx

2/ Add userx to sudoers (not mandatory, but could be usefull)

Code: Select all

sudo visuo

Append a line under # User previlege specification

Code: Select all

# User privilege specification
root  ALL=(ALL:ALL) ALL
userx ALL=(ALL:ALL) ALL

3/ List groups wich pi is belonging

Code: Select all

sudo cat/etc/group | grep pi
you get something like

Code: Select all

adm:x:4:pi
dialout:x:20:pi
cdrom:x:24:pi
sudo:x:27:pi
audio:x:29:pi
video:x:44:pi
plugdev:x:46:pi
games:x:60:pi
users:x:100:pi
input:x:101:pi
netdev:x:108:pi
4/ Add userx to these groups

Code: Select all

sudo usermod -G adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev userx
5/ delete pi user

Code: Select all

deluser -r pi

tesdda
Posts: 5
Joined: Thu Apr 18, 2019 5:51 pm

Re: Delete pi user in Raspbian

Thu Apr 18, 2019 6:01 pm

Hi,

"the without pain solution" works fine. But you are not able to add/remove software by desktop gui any more. Just as root ... Is there any way to assign rights to the newuser to appear in that dropdwon menue as pi before was, again?

fbe
Posts: 649
Joined: Thu Aug 17, 2017 9:08 pm

Re: Delete pi user in Raspbian

Fri Apr 19, 2019 9:40 am

Edit /etc/polkit-1/localauthority.conf.d/60-desktop-policy.conf

Hasn't got as much pi in it as pi egg sausage and pi, has it?

Replace "unix-user:pi" by "unix-group:sudo"

Code: Select all

AdminIdentities=unix-group:sudo;unix-user:0

tesdda
Posts: 5
Joined: Thu Apr 18, 2019 5:51 pm

Re: Delete pi user in Raspbian

Fri Apr 19, 2019 11:57 am

OMG... Thanks... searched for hours before ... great support 8-)

CompleteTeresa
Posts: 1
Joined: Wed Jul 03, 2019 1:57 pm

Re: Delete pi user in Raspbian

Sun Jul 07, 2019 5:08 pm

I tried a number of suggestions to get rid of pi but the one that worked the best was to change pi to the newuser in the following files:

sudo nano /etc/ightdm/lightdm.cong

sudo nano /etc/passwd

sudo nano /etc/group

sudo nano /etc/shadow

There were a couple of files where changing pi to newuser created duplicate entries so I just deleted the pi one. After completing the changes I tried:

sudo deluser pi and got the no such user response so I assume I did everything correctly.

Smrtka
Posts: 9
Joined: Mon Jan 14, 2019 11:09 am

Re: Delete pi user in Raspbian

Fri Jun 12, 2020 9:12 pm

Just out of curiosity, I am following this guide :
https://www.raspberrypi.org/documentati ... ecurity.md
It says you can remove the PI user by following the steps, I did all the prep work, log in to my other (new) user and tried the

Code: Select all

sudo pkill -u pi
and then the

Code: Select all

sudo deluser pi
But there was always some program running, preventing me to do this, And I tried to kill the tasks manually but it was keep on reopening the programs again and again.
Is that article on securing PI not good ? I mean I want to remove PI and make sure I only have one user but it seems the PI user is heavily baked in.
I want to use the PI for my banking so I want it as tight and locked as possible, but maybe just using the PI user with a good long password would be good ?

User avatar
HawaiianPi
Posts: 5996
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Delete pi user in Raspbian

Fri Jun 12, 2020 11:56 pm

Smrtka wrote:
Fri Jun 12, 2020 9:12 pm
But there was always some program running, preventing me to do this, And I tried to kill the tasks manually but it was keep on reopening the programs again and again.
What running programs are associated with the pi user?
What version of Raspbian?
Is auto-login still enabled?

Removing the pi user shouldn't be a problem any longer. It used to be a big problem, but those issues should have been resolved by now. I usually just create my own user and lock the pi account, but I thought I'd give deleting pi a try. I had recently made a full backup of my test system, so I went ahead and removed the pi user with the following command.

Code: Select all

sudo deluser --remove-home pi
Then rebooted, and that seemed to work okay. I enabled "Login as user pi" in the Raspberry Pi Configuration utility to see what would happen, and was pleasantly surprised when it auto-logged in as my user after a reboot. So it seems removing pi isn't a problem, as far as I could tell. If you are having a specific issue with removing the pi user, we need a detailed description of the problem, and how to re-create it.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

bjtheone
Posts: 955
Joined: Mon May 20, 2019 11:28 pm
Location: The Frozen North (AKA Canada)

Re: Delete pi user in Raspbian

Sat Jun 13, 2020 1:57 am

Easiest is just renaming user pi to whatever you want, via "usermod" command. The trick is to be running at the console. Assuming nothing else is running with your username other then the shell on the console - no X session, no ssh login, etc, the following works:

Code: Select all

exec sudo -s
cd /
usermod -l newname -d /home/newname -m oldname 
If you desperately want to do it with the full GUI up you need to give root a password, and then log in as root to make the changes. You can remove the root password if you want the default (and crazy in my opinion) sudo behaviour afterwards.

Smrtka
Posts: 9
Joined: Mon Jan 14, 2019 11:09 am

Re: Delete pi user in Raspbian

Sun Jun 14, 2020 1:48 pm

HawaiianPi wrote:
Fri Jun 12, 2020 11:56 pm
Smrtka wrote:
Fri Jun 12, 2020 9:12 pm
But there was always some program running, preventing me to do this, And I tried to kill the tasks manually but it was keep on reopening the programs again and again.
What running programs are associated with the pi user?
What version of Raspbian?
Is auto-login still enabled?

Removing the pi user shouldn't be a problem any longer. It used to be a big problem, but those issues should have been resolved by now. I usually just create my own user and lock the pi account, but I thought I'd give deleting pi a try. I had recently made a full backup of my test system, so I went ahead and removed the pi user with the following command.

Code: Select all

sudo deluser --remove-home pi
Then rebooted, and that seemed to work okay. I enabled "Login as user pi" in the Raspberry Pi Configuration utility to see what would happen, and was pleasantly surprised when it auto-logged in as my user after a reboot. So it seems removing pi isn't a problem, as far as I could tell. If you are having a specific issue with removing the pi user, we need a detailed description of the problem, and how to re-create it.
I managed to remove the PI user after disabling the auto login and rebooting and doing the Pkill command

Code: Select all

sudo pkill -u pi
and then

Code: Select all

sudo deluser pi
To remove the home folder I tried this commend

Code: Select all

sudo deluser -remove-home pi
but was erroring out :
/usr/sbin/deluser The user 'pi' does not exist
I can see you are using -- instead of - but I ended up removing the home/pi/ directory using rm -dr /home/pi and that worked.

Now I am facing new issue likely related, I am trying to install keepass from the
MENU>Preferences>Add remove programs
I find my software and its asking me put in ROOT password, there is a small arrow button on the root like to let you select other user to install as but its not showing any other users
And my sudo password for my new user I created does not work for there. Do I need to add my new user to ROOT group or something ?

Please be gentle on my I this is first week of me playing with linux.
The os Is RASPBERRY OS 10 fresh from here https://www.raspberrypi.org/downloads/raspberry-pi-os/
(re)installed today after I totally screwed up my previous attempts with removing the pi user.

bjtheone seems to be touching up on this root password not sure if it related. Again please be gentle on my I am not a power user.

User avatar
HawaiianPi
Posts: 5996
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

Re: Delete pi user in Raspbian

Sun Jun 14, 2020 4:16 pm

For future reference, the option --remove-home is supposed to be added to the deluser command when removing a user (not a separate step).

For your troubles with Add / Remove software, you probably need to edit /etc/polkit-1/localauthority.conf.d/60-desktop-policy.conf. Either change unix-user:pi to your new user, or replace it with unix-group:sudo (AdminIdentities=unix-group:sudo;unix-user:0).
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

Smrtka
Posts: 9
Joined: Mon Jan 14, 2019 11:09 am

Re: Delete pi user in Raspbian

Sun Jun 14, 2020 8:54 pm

HawaiianPi wrote:
Sun Jun 14, 2020 4:16 pm
For future reference, the option --remove-home is supposed to be added to the deluser command when removing a user (not a separate step).

For your troubles with Add / Remove software, you probably need to edit /etc/polkit-1/localauthority.conf.d/60-desktop-policy.conf. Either change unix-user:pi to your new user, or replace it with unix-group:sudo (AdminIdentities=unix-group:sudo;unix-user:0).
HawaiianPI the first suggestion worked flawlessly, all is now well, the PI user is gone and I can work on my last tweaks. Thank you very much for your help. I will need to put all of this into some sort of TXT document in case I need to rebuild the PI :D

automaciej
Posts: 1
Joined: Mon Jun 22, 2020 6:29 pm

Re: Delete pi user in Raspbian

Mon Jun 22, 2020 6:33 pm

The pkill trick doesn't seem to work anymore:

Code: Select all

myuser@raspberrypi:~ $ sudo pkill -u pi
myuser@raspberrypi:~ $ sudo deluser --remove-home pi
Looking for files to backup/remove ...
Removing user `pi' ...
Warning: group `pi' has no more members.
userdel: user pi is currently used by process 1915
/usr/sbin/deluser: `/usr/sbin/userdel pi' returned error code 8. Exiting.
Looks like systemd is spawning a new process immediately after I kill the previous ones.

Code: Select all

myuser@raspberrypi:~ $ pgrep -a -u pi
1915 /lib/systemd/systemd --user
1918 (sd-pam)
1931 -bash
I found which piece of configuration was responsible for it. There was a line that ensured that the first console (CTRL+ALT+F1) was always logged in. I guess it was to make the first experience of beginners a little less frustrating.

I edited this file:

Code: Select all

sudo nano /etc/systemd/system/getty@tty1.service.d/autologin.conf
I commented out the two ExecStart lines. Then I needed to tell systemd to reload the configuration, and restart the CTRL+ALT+F1 service.

Code: Select all

sudo systemctl daemon-reload
sudo systemctl restart getty@tty1.service
Then I could remove the user with

Code: Select all

sudo deluser --remove-home pi
.

andrewTheMainiac
Posts: 1
Joined: Wed Jul 15, 2020 5:54 pm

Re: Delete pi user in Raspbian

Wed Jul 15, 2020 6:17 pm

It seems this is an ongoing problem. I've also removed my "pi" user and updated the /etc/polkit_1/localauthority.conf.d/60-desktop_policy.conf file so instead of directly referencing the "pi" user it references the "unix-group:sudo". However, upon doing a apt update/apt upgrade, this file reverted to the original setting. There should not be such a direct dependency on the "pi' user. This totally breaks the software install GUI tool, as it then requires a root password.

I am running Raspberry Pi OS on a Pi 4; uname -a = 4.19.118-v7L+ #1311

Return to “Beginners”