Sunday, February 8, 2015

Adding yourself back into the sudo group on Raspberry Pi

Greetings, weary tech[no] traveler!

Have you ever lock yourself out of the sudo group, on your Raspberry Pi, by accident...and your user was the only one that had sudo permissions?  It happened to me once.  I was worried that I would need to reformat my SD card, reinstall Raspbian, and reconfigure my Raspberry Pi all over again.  However, that is completely unnecessary.  Here's what you need to do:



  1. Power down your Raspberry Pi.
  2. Remove the SD card and insert it into your PC.
  3. Change directory to your mounted SD card.  Since I am using OSX:

    cd /Volumes/boot/

  4. Open the file named "cmdline.txt" with your favorite text editor.
  5. Add the following text to the end of the existing text.  It will drop you into a root shell upon reboot:

    init=/bin/sh

    Make sure it is all one line!

  6. Save "cmdline.txt" and eject the SD card from the PC.
  7. Put the SD card back into the Raspberry Pi.
  8. Connect a USB keyboard and monitor to the Raspberry Pi.
  9. Power on the Raspberry Pi.
  10. Once you see a flashing cursor, remount the filesystem as read-write, add your user back into the sudo group, and shutdown the Raspberry Pi.  To do that, enter the following commands at the prompt:

    mount -o remount,rw /
    usermod -a -G sudo <username>
    shutdown -P now

  11. Remove the SD card, reinsert it into your PC, and open the "cmdline.txt" file again with a text editor.
  12. Delete the “init=/bin/sh” text you added in step 5.
  13. Save "cmdline.txt" and eject the SD card from the PC.  One last time.
  14. Put the SD card back into your Raspberry Pi, reboot, and rejoice in your reclaimed sudoer privileges!

No comments: