0

I am trying to rename default user 'pi' to something else, and I am failing miserably.

Raspbian is based on Debian, so I assumed that it behaves as Debian, am I wrong?

What I tried?

I did normal route, as logging as root and using usermod - it does not work. I keep getting errors that user pi still runs processes of various PIDs. I tried to kill all processes related to the user by using killall -u pi and it also did not work. I used then pkill -9 -u pi without a success. After each of these commands, when I run usermod -l newname pi, the system still reports running processes related to the 'pi' user. Why? What am I doing wrong? Yes, 'pi' is logged out, and I am logged in as a root. I know that I need to change few other things too, but I cannot go even through login change due to ongoing processes I cannot kill.

Edit: After some comments, I realized that my question looks like I ask how to change a username. I rather ask why my attempts to kill processes related to user pi failed. I will do my best to be more precise next time. Thank you all for hints!

8
  • What does id pi say after you have changed the name?
    – goldilocks
    Commented Jan 20, 2021 at 15:04
  • I did not managed to change the name, there is the thing. Even after executing commands to kill all processes related to the user, the system communicates about running processes and refuses to change the name...
    – rd.break
    Commented Jan 20, 2021 at 15:12
  • Ah, ok -- this is why things like "it does not work" are ambiguous. You could have meant 1) the command literally fails, 2) the command succeeds, but I still have a user pi. Thankfully #1 is less complicated. You should try logging in outside of the GUI by switching to a console -- try ctrl-alt-f[1-6] in order until you see a plain login console. Do this after booting the system and having never logged in on the GUI. If you have autologin for the pi user enabled, obviously that is something you should change.
    – goldilocks
    Commented Jan 20, 2021 at 15:15
  • If that still fails, paste in the output from ps -u pi.
    – goldilocks
    Commented Jan 20, 2021 at 15:17
  • 2
    Just create a new user and then stop using the pi user. Delete the pi user (if you want) after the new user is known to work.
    – joan
    Commented Jan 20, 2021 at 16:15

2 Answers 2

1

First - yes, RPi OS (née Raspbian) is based on Debian, but it is not Debian. One difference is that there is a default user assigned in RPi OS - user pi. I'll leave it to you to contemplate why they did that.

Other than the ability to read, I have no applicable expertise here, but you may be aware that Linux uses a UID (a number) in addition to the username. Quoting from a Wikipedia article:

The UID, along with the group identifier (GID) and other access control criteria, is used to determine which system resources a user can access. The password file maps textual user names to UIDs. UIDs are stored in the inodes of the Unix file system, running processes, tar archives...

man usermod informs us that for the option you used, -l, --login:

The name of the user will be changed from LOGIN to NEW_LOGIN. Nothing else is changed.

CAVEATS
You must make certain that the named user is not executing any processes when this command is being executed if the user's numerical user ID, the user's name, or the user's home directory is being changed. usermod checks this on Linux. On other platforms it only uses utmp to check if the user is logged in.

(emphasis mine)

And so - this explains why you are "failing miserably". There is much more to be done beyond usermod -l newname pi.

If this is more than just an exercise in mental gymnastics, we'll try to help. I suspect this is a fair amount of work, so if you could perhaps share your motivation by disclosing what you're trying to accomplish?

3
  • Hey! I appreciate the time you spent on writing this post. I am not sure if you read mine because I specified that I was trying to use usermod -l new pi, but this failed due to running processes related to user pi. I could not kill them. I mentioned that I know that other things need to be changed along with the name. My question was mainly why I could not kill processes related to user pi using mentioned commands. I will do my best to be more precise next time. Anyways, as goldilocks above advised, I logged in into console, and I further managed to do change everything. Thank you :)
    – rd.break
    Commented Jan 21, 2021 at 4:29
  • @graphiccard: My apologies for the oversight wrt usermod -l newname pi. I have edited the answer. And FWIW, I felt what your question lacked was any sort of rationale or purpose for making this change. This suggested your Q was one of idle curiosity. If you're interested in "why", there are some explanations in this U&L Q&A & many other sources if you care to search.
    – Seamus
    Commented Jan 23, 2021 at 5:40
  • thank you for a link. This is pretty nice thread, and it gives me a good starting point. Some questions are difficult to ask precisely because I do not know enough yet to formulate them precisely enough, and vague request I sent to google gave me back tones of "not the info I wanted". I am still learning (also English, haha). I cannot vote, so I thank you here, and I hope this will be forgiven that I use comment to do that.
    – rd.break
    Commented Jan 25, 2021 at 0:43
0

Maybe try editing the /etc/passwd and /etc/shadow files and changing the "pi" username to whatever else you want it to be. Then reboot.

Unless the Raspbian folks did something stupid like hard-code the "pi" user into some special places, you should just be able to login as whatever you changed pi to be. It will have retained it's native UID and GID.

You can also check in /etc/group to see if "pi" was added to any secondary groups.

1
  • Hey! Thank you for a hint. From what I know, using this method is very discouraged to use not only in Raspbian, but in all distros. I managed to change username and all related stuff logging directly to the console at the system start (before GUI started). I also edited my question because I did not ask how to change the username, but mainly why I cannot kill processes related to user pi while logged as a root. Thank you!
    – rd.break
    Commented Jan 25, 2021 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.