## https://www.techduck.ca/pi-to-newname.txt ## Changing the default admin username on the rpi4 and rpi3b. ## No other rpi versions were tested. ## If this rpi is connecting to the internet, this is not a bad idea. ## At least change the password! ## Please see the "Terms Of Service and Disclaimer" ## at https://www.techduck.ca/td-ToS-Disclaimer.html ## Note: It is bad policy to follow instructions found online. ## Read man pages: grep egrep sed groupmod usermod subgid subuid passwd ## and understand what you are about to do. ## If it did not work, so sorry - beyond the scope of this document. ## ..it can be fixed. Read those man pages. Still stuck? ## Run "history | tail -n 80" and paste output into the body of a ## non-html email and send it to info at techduck.ca - will have a look. ## So having decided to do this, be sure to substitute "newname" with ## your new admin username :^) If Auto Login is set, change that using ## main menu -> Preferences -> Raspberry Pi Configuration ## The usermod caveat that pi can not run any processes or it will fail ## so the root account needs a password to run the commands below. # sudo passwd root ## Now logout for the last time as pi. When login screen reappears, ## type Ctrl-Alt-F1 to get a terminal and log in _there_ as root. ## Now check that pi owns no running processes. # ps -U pi ## Any process still owned by pi must be stopped. # pkill -U pi ## Check the state of things before, during and after. # cat /etc/subgid # cat /etc/subuid # ls -l /home/pi # ls -l /home/newname # grep pi /etc/group # grep newname /etc/group # cat /etc/sudoers.d/010_pi-nopasswd /etc/sudoers.d/010_newname-nopasswd ## Replace the pi login name with the uid in subgid and subuid. # sed -i 's/pi/1000/' /etc/subuid # sed -i 's/pi/1000/' /etc/subgid ## Now run these commands in this order. Checking as above never hurts. # groupmod -n newname pi # usermod -l newname pi # usermod -m -d /home/newname newname ## This new user needs to have admin permission. So set this up. # mv /etc/sudoers.d/010_pi-nopasswd /etc/sudoers.d/010_newname-nopasswd # sed -i 's/pi/newname/' /etc/sudoers.d/010_newname-nopasswd ## Check state of things and if it looks good, set a password ## for the new user. # passwd newname ## Now enter Ctrl-Alt-F7 and login to the GUI as the new user. ##