Skip to content

Instantly share code, notes, and snippets.

@OhMeadhbh
Last active August 29, 2015 14:12
Show Gist options
  • Save OhMeadhbh/f7785032e0abd01a66ea to your computer and use it in GitHub Desktop.
Save OhMeadhbh/f7785032e0abd01a66ea to your computer and use it in GitHub Desktop.
Unhorking Raspbian
# raspiuser
#
# Having a fixed username / password combination is generally considered
# insecure. This script renames the default 'pi' user to one of your own
# choosing (please choose a name other than 'pi'.) Run it as root, passing
# the new username as the first parameter:
#
# sudo ./raspihork testuser
#
if [ $# -lt "1" ]
then
echo "Usage: $0 <new username>"
exit 1
fi
NEWU=$1
addgroup --system nopasswd
adduser pi nopasswd
echo '%nopasswd ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/nopasswd
chown root /etc/sudoers.d/nopasswd
chmod 440 /etc/sudoers.d/nopasswd
sed /etc/sudoers -i -e 's/^pi/#&/'
for file in /etc/group /etc/gshadow; do
echo $file
sed $file -i -e "s/:pi/:$NEWU/"
done
for file in /etc/passwd /etc/shadow; do
echo $file
sed $file -i -e "s/^pi/$NEWU/"
done
sed /etc/passwd -i -e "s/\/home\/pi/\/home\/$NEWU/"
mv /home/pi /home/$NEWU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment