User avatar
ztealmax
Posts: 94
Joined: Sat Aug 19, 2017 5:19 pm
Contact: Website

[HowTo!]Change default username pi

Sat Jan 19, 2019 9:19 pm

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

#!/bin/bash
# **********************************************************************
# * Project: change-username.sh - Change defualt username pi to your name *
# * Created: 01/19/2019 22:00                                          *
# * Author: Martin Svensson aka ztealmax - pi-workstation.org          *
# * 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
exit
# -------------------------------------------------------------[01]-END-

Return to “Raspbian”