Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Initial Setup of Raspberry Pi
A brand new raspberry pi
You want to change the default username pi to mypie
You want to adapt also the main group from pi to mypie
You want other things to work out like sudo
Initial Setup for Raspian Hardware and Software
These instructions assume that your Pi will not
have WAN access. There are security options that
should never be facing outside your LAN
Use Rasberry Tool to get the latest release:
Or (Looks like a great option)
Install image onto SD card.
Create a file named SSH on the boot partition
Login using pi - raspberry
Check for updates
sudo apt update
Do upgrade
sudo apt upgrade
Run raspi-config
sudo raspi-config
System Options:
change pi password
change hostname
(Optional) Setup wireless config
Interface Options:
Enable SSH again. (Sets SSHD as a service rather than the hack above)
Performance Options:
Set GPU memory to 16 (No need for the GPU) # Researching this later
Localisation options:
Set Locale to en_US.UTF-8 UTF-8
Set to correct timezone
Proceed to:
Step 1: stop user pi from running before the change.
Boot it, go to RPI configurations and
allow SSH,
disallow auto-login
hit ok
Press ALT+F1 to go to the first tty
Escalate to root with sudo su -
Edit $vim /etc/systemd/system/autologin@.service
Find and comment (#) the line
#ExecStart=-/sbin/agetty --autologin pi --noclear %I $TERM
you can uncomment it later if you want console autologin, but then don't forget to change the user pi to your new username mypi
Create a new root password with passwd. (DON'T FORGET IT)
Type reboot
Step 2: make the user change
If you see the graphical login prompt, you are good. Do not login. Instead, press ALT+F1 (* if you want to do it via ssh, see the apendix)
After ALT+F1, you should see a login question (and not an autologin).
Login as root with your root password. Now you are alone in the system, and changes to pi will not be met with usermod: user pi is currently used by process 2104. Check with ps -u pi to see an empty list.
Very carefully, key by key, type usermod -l mypie pi . This will change your username, from /etc/passwd file, but things are not ready yet. Anyway, check with tail /etc/passwd and see the last line mypie:1000:... The 1000 is the UID and it is now yours.
Try su mypie just to be sure. Do nothing. Just exit again to root. It should work. Now you need to adjust the group and a $HOME folder.
Step 3: make the group change
Type, again carefully, groupmod -n mypie pi . This will change the pi group name. Check it with tail /etc/group and you will see the last line the new name associated with GID 1000.
Just to clarify, type ls -la /home/pi and you will see that the pi HOME now belongs to you, mypie.
Step 4: lets adopt the new home.
I see in the answers above the creation of a new folder, copying everything. No need. Lets just use the same.
First move to cd /home to make it easier. Type ls -la and see pi, onwer mypie group mypie
Type carefully: mv pi mypie . You now need to associate this change with your new user.
Type carefully: usermod -d /home/mypie mypie . This will change your home directory. Check it with tail /etc/passwd and look at the sixth field (separated by :).
Step 5: some adjusts after the fact.
Reboot with reboot
Login as your new user mypie in the graphical interface.
Open a terminal.
Change your password
Type passwd to change the password of mypie to something else than raspberry
Type sudo su - and you will be asked your password.
auto-login again if you will (I don't recommend, but well)
If you want to autologin your new account, edit the file:
$vim etc/lightdm/lightdm.conf
find the line with #autologin-user=, change it to autologin-user=mypie (no comment #)
If you want back the ALT+F1 autologin, find and edit the file:
$vim /etc/systemd/system/autologin@.service and change the line
#ExecStart=-/sbin/agetty --autologin mypie --noclear %I $TERM
Make your sudo passwordless again (I don't recommend as well)
Move yourself (root) to cd /etc/sudoers.d
Rename the file 010_pi-nopasswd to 010_mypie_nopasswd
Open it vim 010_mypie_nopasswd and change the line pi ALL=(ALL) NOPASSWD: ALL to, obviously mypie ALL=(ALL) NOPASSWD: ALL. It is read-only, so save it forcing with :x!
While you are into it, change your hostname
Edit $vim /etc/hosts and change raspberry to something more appropriate like myoven.
Edit $vim /etc/hostname and let a single line with myoven.
Step 6: reboot
Type, carefully, reboot
Appendix - ssh
You may want to do this via ssh. For this to work, first you need to allow root login.
Find the file /etc/ssh/sshd_config
Comment the line #PermitRootLogin without-password
Add the line PermitRootLogin yes
Save, exit, restart ssh with /etc/init.d/ssh restart
After you have done it, undo this changes as they are too dangerous to let that way.
Same file, delete PermitRootLogin yes line and remove the comment from PermitRootLogin without-password
Note 1: This is a guide, and the content deals with very dangerous commands. Backup first, or be aware that maybe you will need to burn again your image. As I am assuming a brand new raspberry pi, there is not much to backup anyway. But if you adapt it to another situation, be advised.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment