Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to create a new user and remove the `pi` user on a Raspberry Pi

How to create a new user and remove the pi user on a Raspberry Pi

Note: This has been tested in Rasbian Buster released on 2019-06-20

Important: replace jeremy below with whatever username you'd like as your new user.

  1. sudo adduser jeremy
    • You will be asked to enter a password
    • When filling out basic information about the user, you may leave it blank
    Adding user `jeremy' ...
    Adding new group `jeremy' (1001) ...
    Adding new user `jeremy' (1001) with group `jeremy' ...
    jeremy ALL=(ALL) NOPASSWD: ALL
    Creating home directory `/home/jeremy' ...
    Copying files from `/etc/skel' ...
    New password:
    Retype new password:
    passwd: password updated successfully
    Changing the user information for jeremy
    Enter the new value, or press ENTER for the default
      Full Name []: Jeremy Iglehart
      Room Number []:
      Work Phone []:
      Home Phone []:
      Other []:
    Is the information correct? [Y/n] Y
  2. sudo adduser jeremy sudo
    Adding user `jeremy' to group `sudo' ...
    Adding user jeremy to group sudo
    Done.
  3. sudo cp /etc/sudoers.d/010_pi-nopasswd /etc/sudoers.d/010_jeremy-nopasswd
    • If you don't like typing in the sudo password all the time, copy this file.
  4. sudo chmod u+w /etc/sudoers.d/010_jeremy-nopasswd
    • Add write permissions (so that you can change it)
  5. sudo vi /etc/sudoers.d/010_jeremy-nopasswd
    • Change "pi" to "jeremy"
  6. sudo chmod u-w /etc/sudoers.d/010_jeremy-nopasswd
    • remove write permissions (should be 0440 or -r--r-----)
  7. sudo reboot
    • To allow all settings to go into effect. You may get away with something else here - but rebooting does the trick. Also it ensures that the pi user is fully logged out and has nothing left running.
  8. Login as your new user
  9. sudo deluser -remove-home pi
    Looking for files to backup/remove ...
    Removing user `pi' ...
    Warning: group `pi' has no more members.
    Done.
    If you try to do this before rebooting you will see something like this:
    Looking for files to backup/remove ...
    Removing files ...
    sh: 0: getcwd() failed: No such file or directory
    Removing user `pi' ...
    Warning: group `pi' has no more members.
    userdel: user pi is currently used by process 702
    /usr/sbin/deluser: `/usr/sbin/userdel pi' returned error code 8. Exiting.
    
  10. sudo rm -vf /etc/sudoers.d/010_pi-nopasswd
    removed '/etc/sudoers.d/010_pi-nopasswd'
    

Done.

also note, on a fresh system where you haven't set any locale you will see this a lot:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LC_CTYPE = "en_US.UTF-8",
	LANG = "en_GB.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_GB.UTF-8").

Credit: https://raspi.tv/2012/how-to-create-a-new-user-on-raspberry-pi So, I first tried a few things outlined in this article above and found out quickly that the way Raspberry Pi is setting up the pi user is different than in this article, hence writing this new gist. After some trial and error I ended up settling on the method I describe here in this gist. I'd like to give credit to what got me started on this path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.