Page 1 of 1

[HowTo!]Change default username pi

Posted: Sat Jan 19, 2019 9:19 pm
by ztealmax
Ok so here it is simple but works, tested on: Raspbian Stretch Lite :)

It changes default username pi to what you want it to be, you must be logged in as root to make this work

to set root password and enable login as root: sudo passwd root
then logout and login as: root

Make sure no processes is run as user pi before running this script with this command: sudo top -U pi

if no processes is run by user pi then run the script

when script is complete to lock root account again type: sudo passwd -l root then reboot

* added so it locks root after script is run and logsout

Code: Select all

# **********************************************************************
# * Project: - Change defualt username pi to your name *
# * Created: 01/19/2019 22:00                                          *
# * Author: Martin Svensson aka ztealmax -          *
# * Info: run when logged in as root                                   *
# **********************************************************************
# -[01]-START-----------------------------------------------------------
echo What loginname do you wish to have?
read loginname
echo Setting up new account login name as: $loginname
usermod -l $loginname -d /home/$loginname -m pi
groupmod --new-name $loginname pi
echo What\'s your realname?
read realname
usermod -c "$realname" $loginname
echo Now to set new password for $realname aka $loginname 
passwd $loginname
echo all done please reboot and login as $loginname
echo locking root account
passwd -l root
echo now logging out in:
echo 3 sec && sleep 1 && echo 2 sec && sleep 1 && echo 1 sec && sleep 1
# -------------------------------------------------------------[01]-END-