Skip to content

Instantly share code, notes, and snippets.

@jriguera
Created February 8, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jriguera/f97925ca7534a75eedfa to your computer and use it in GitHub Desktop.
Save jriguera/f97925ca7534a75eedfa to your computer and use it in GitHub Desktop.
Raspberry PI password recovery for arch linux
#!/bin/bash -e
#
# Raspberry PI password recovery for arch
# The SD should be mounted on $DEV (usually sdb2)
USER=root
PASSWORD=hola
DEV=sdb2
# Creating SHA512 password for arch
PASS=$(echo "$USER:$PASSWORD" | chpasswd -c SHA512 -S | cut -d: -f2)
# Looking for the mountpoint
BASE=$(mount | awk "/\/dev\/$DEV/ { print \$3 }")
# Creating backup
sudo cp -a $BASE/etc/shadow $BASE/etc/shadow.old
# Updating file with the new password
sudo sed -i "s|^\(${USER}\):\([^:]*\):\(.*\)\$|\1:${PASS}:\3|g" $BASE/etc/shadow
sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment