How do I fix an invalid /etc/sudoers file if root access is disabled?











up vote
0
down vote

favorite
1












This pertains to my Raspberry Pi, on which I have Raspbmc installed. I do realize that there is a Raspberry Pi StackExchange site, but I figured I might get more eyes on this problem here.



The issue is that I modified /etc/sudoers in an attempt to grant NOPASSWD permissions to one of the users, but I guess somewhere along the way I borked up the file and now I'm getting the following error whenever I login/attempt to use sudo:



sudo: parse error in /etc/sudoers near line 19
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin


I've found similar posts on Ubuntu as well as StackOverflow, but the problem is all the answers require a root password, and the root account is disabled by default on Raspbmc, and I obviously had not enabled it before attempting to change /etc/sudoers.



So my question is: how do I fix the file if I don't have root access enabled? Is it even possible?










share|improve this question




















  • 2




    Don't forget to use visudo next time for editing.
    – slhck
    Dec 24 '13 at 12:50















up vote
0
down vote

favorite
1












This pertains to my Raspberry Pi, on which I have Raspbmc installed. I do realize that there is a Raspberry Pi StackExchange site, but I figured I might get more eyes on this problem here.



The issue is that I modified /etc/sudoers in an attempt to grant NOPASSWD permissions to one of the users, but I guess somewhere along the way I borked up the file and now I'm getting the following error whenever I login/attempt to use sudo:



sudo: parse error in /etc/sudoers near line 19
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin


I've found similar posts on Ubuntu as well as StackOverflow, but the problem is all the answers require a root password, and the root account is disabled by default on Raspbmc, and I obviously had not enabled it before attempting to change /etc/sudoers.



So my question is: how do I fix the file if I don't have root access enabled? Is it even possible?










share|improve this question




















  • 2




    Don't forget to use visudo next time for editing.
    – slhck
    Dec 24 '13 at 12:50













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





This pertains to my Raspberry Pi, on which I have Raspbmc installed. I do realize that there is a Raspberry Pi StackExchange site, but I figured I might get more eyes on this problem here.



The issue is that I modified /etc/sudoers in an attempt to grant NOPASSWD permissions to one of the users, but I guess somewhere along the way I borked up the file and now I'm getting the following error whenever I login/attempt to use sudo:



sudo: parse error in /etc/sudoers near line 19
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin


I've found similar posts on Ubuntu as well as StackOverflow, but the problem is all the answers require a root password, and the root account is disabled by default on Raspbmc, and I obviously had not enabled it before attempting to change /etc/sudoers.



So my question is: how do I fix the file if I don't have root access enabled? Is it even possible?










share|improve this question















This pertains to my Raspberry Pi, on which I have Raspbmc installed. I do realize that there is a Raspberry Pi StackExchange site, but I figured I might get more eyes on this problem here.



The issue is that I modified /etc/sudoers in an attempt to grant NOPASSWD permissions to one of the users, but I guess somewhere along the way I borked up the file and now I'm getting the following error whenever I login/attempt to use sudo:



sudo: parse error in /etc/sudoers near line 19
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin


I've found similar posts on Ubuntu as well as StackOverflow, but the problem is all the answers require a root password, and the root account is disabled by default on Raspbmc, and I obviously had not enabled it before attempting to change /etc/sudoers.



So my question is: how do I fix the file if I don't have root access enabled? Is it even possible?







sudo root raspberry-pi sudoers raspbmc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 23 '17 at 12:41









Community

1




1










asked Dec 24 '13 at 1:27









3cheesewheel

4281825




4281825








  • 2




    Don't forget to use visudo next time for editing.
    – slhck
    Dec 24 '13 at 12:50














  • 2




    Don't forget to use visudo next time for editing.
    – slhck
    Dec 24 '13 at 12:50








2




2




Don't forget to use visudo next time for editing.
– slhck
Dec 24 '13 at 12:50




Don't forget to use visudo next time for editing.
– slhck
Dec 24 '13 at 12:50










3 Answers
3






active

oldest

votes

















up vote
6
down vote













You should still be able to boot up the Pi in Single User mode to get access to root.



Using another computer, modify cmdline.txt and add single to the end of the line

Then when you boot up the Pi from the SD card, it should automatically dump you to a root prompt which well allow you to update /etc/sudoers






share|improve this answer





















  • Unfortunately I need root access to be able to modify /boot/cmdline.txt :(
    – 3cheesewheel
    Dec 24 '13 at 1:57






  • 2




    Hence using another computer
    – Lawrence
    Dec 24 '13 at 2:06






  • 1




    Raspberry Pi's hard drive is just SD card, so it is possible to plug it in via card reader to another computer and make all changes there without booting Pi in single mode.
    – VL-80
    Dec 24 '13 at 2:19










  • @Nikolay Assuming the OP has another computer with Linux installed or has a Live Distro handy of course.
    – Lawrence
    Dec 24 '13 at 2:21












  • (Or Windows/OSX with VirtualBox; the "USB sharing" feature works well.) Though, single also asks for root password, so while it does allow logins to a locked or expired root account, it may still refuse access on occassion, so editing /etc/sudoers directly from the live system would be a bit easier and quicker.
    – grawity
    Dec 24 '13 at 2:56




















up vote
0
down vote













The easiest solution is to boot up another OS on a LiveDVD or LiveUSB (ideally a LiveUSB, and ideally a Linux OS) then mount the disc and manually change the file. I've done similar things before and fixed it in this manner. All of your files will be visible and editable from the Live system. Unless you've encrypted the drive; that makes things a bit more complicated.



Let me know if you have questions and I'll edit this answer - I'm not sure how comfortable you might be with setting up a live USB, but it's not very hard.






share|improve this answer




























    up vote
    0
    down vote













    After two days of research and browsing the web I have finally found a solution and been able to save my own Raspberry Pi system (not having to reformat the SD card and start from scratch)!



    NOTE: This answer is pretty long. If you want to get to the actual solution quickly, I've added a header that you can scroll down to. I do recommend you read the whole answer though, as it may bring some insight into the differences between the Raspbian distribution and other Linux distributions as well as clarity to why a lot of the suggested solutions you find across the internet may not work on your Pi.



    So normally, in a Linux environment, the quickest way to repair the broken sudo without even having to reboot is by using PolicyKit or the pkexec -command like this:



    pkexec visudo


    But on the Pi it most likely won't work, it will ask for the root password, but no password is accepted. (I mean, do you even remember setting a root password? Wait, you do? Then skip to the asterisk*.)



    Some Linux distributions, for example Ubuntu, come with a recovery mode that can be accessed by holding down the shift-key during bootup and offers a user-friendly interface and allows one to be dropped into a root shell prompt where one could get access to fix the broken files. The Pi's Raspbian Linux distribution does not come with that kind of a recovery mode so that solution is not a solution for us. Yet the Pi does prompt you at bootup to hold down the shift-key to enter some kind of recovery mode and by entering the Pi's recovery mode or the NOOBS dialog we are surely on the right path towards repairing the broken sudo on our Pi.



    Another common way of repairing sudo is by booting into single-user mode which gets you to a root shell prompt. The way you do this is by adding the word single to the end of the cmdline.txt -file on the system's boot partition. The next time your system boots up it will boot into single-user mode.



    We can easily try this solution on our Pi because, conviniently, the Pi's recovery mode or the NOOBS dialog allows us to edit the cmdline.txt -file. In the recovery mode or the NOOBS dialog, by pressing the "Edit config" -icon you open up an editor that lets you edit two files, one of which is cmdline.txt. By pressing "OK" in the editor your changes are saved.



    Unfortunately, when you boot into single-user mode or "rescue mode" on the Pi, you'll most likely get the following message:



    Cannot open access to console, the root account is locked.
    See sulogin(8) man page for more details.

    Press Enter to continue.


    This – as well as why the previously mentioned root password prompt didn't accept any passwords – is because Raspbian, by default, has no password set for the root account. This is not to be confused with a password that is nothing or that no password would be required. Raspbian, just like a handful of other Linux distributions (for example Debian which Raspbian is a derivate of), expects the user to operate as root through sudo and not through the account itself. Hence the root account is in the "lockdown" state that we are experiencing.



    *If you set the root password yourself, for example through the command sudo passwd root, then you should be able to use the pkexec -command and boot into single-user mode. Note that when you do this, you need to use sudo, so this is obviously not a solution once sudo is broken, but I point this out because this is probably why some people found success in fixing their Pi's when applying the solutions suggesting the pkexec -command or single-user mode. These people had at some point gone and manually set a root password, unlocking their system's root account.



    The Solution



    This blog post explains how to do what we need to do. The steps are almost identical to the steps we took when trying to repair sudo through single-user mode. You don’t have to do all the cumbersome stuff the blog post mentions in order to edit the cmdline.txt -file, instead just do it in the NOOBS dialog. The key is to add init=/bin/sh to the end of the cmdline.txt -file. With that snippet added, the next time you boot up your Pi, you will be dropped into a root shell prompt.



    Initially, the file system will be loaded in read-only mode, so before being able to edit anything, you’ll have to remount the root partition in read and write mode by executing the following command:



    mount -o remount,rw /dev/mmcblk0p2 /


    Now you should be in a root shell prompt, where you can freely edit any file, including the broken sudo files.






    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "3"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f692443%2fhow-do-i-fix-an-invalid-etc-sudoers-file-if-root-access-is-disabled%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      6
      down vote













      You should still be able to boot up the Pi in Single User mode to get access to root.



      Using another computer, modify cmdline.txt and add single to the end of the line

      Then when you boot up the Pi from the SD card, it should automatically dump you to a root prompt which well allow you to update /etc/sudoers






      share|improve this answer





















      • Unfortunately I need root access to be able to modify /boot/cmdline.txt :(
        – 3cheesewheel
        Dec 24 '13 at 1:57






      • 2




        Hence using another computer
        – Lawrence
        Dec 24 '13 at 2:06






      • 1




        Raspberry Pi's hard drive is just SD card, so it is possible to plug it in via card reader to another computer and make all changes there without booting Pi in single mode.
        – VL-80
        Dec 24 '13 at 2:19










      • @Nikolay Assuming the OP has another computer with Linux installed or has a Live Distro handy of course.
        – Lawrence
        Dec 24 '13 at 2:21












      • (Or Windows/OSX with VirtualBox; the "USB sharing" feature works well.) Though, single also asks for root password, so while it does allow logins to a locked or expired root account, it may still refuse access on occassion, so editing /etc/sudoers directly from the live system would be a bit easier and quicker.
        – grawity
        Dec 24 '13 at 2:56

















      up vote
      6
      down vote













      You should still be able to boot up the Pi in Single User mode to get access to root.



      Using another computer, modify cmdline.txt and add single to the end of the line

      Then when you boot up the Pi from the SD card, it should automatically dump you to a root prompt which well allow you to update /etc/sudoers






      share|improve this answer





















      • Unfortunately I need root access to be able to modify /boot/cmdline.txt :(
        – 3cheesewheel
        Dec 24 '13 at 1:57






      • 2




        Hence using another computer
        – Lawrence
        Dec 24 '13 at 2:06






      • 1




        Raspberry Pi's hard drive is just SD card, so it is possible to plug it in via card reader to another computer and make all changes there without booting Pi in single mode.
        – VL-80
        Dec 24 '13 at 2:19










      • @Nikolay Assuming the OP has another computer with Linux installed or has a Live Distro handy of course.
        – Lawrence
        Dec 24 '13 at 2:21












      • (Or Windows/OSX with VirtualBox; the "USB sharing" feature works well.) Though, single also asks for root password, so while it does allow logins to a locked or expired root account, it may still refuse access on occassion, so editing /etc/sudoers directly from the live system would be a bit easier and quicker.
        – grawity
        Dec 24 '13 at 2:56















      up vote
      6
      down vote










      up vote
      6
      down vote









      You should still be able to boot up the Pi in Single User mode to get access to root.



      Using another computer, modify cmdline.txt and add single to the end of the line

      Then when you boot up the Pi from the SD card, it should automatically dump you to a root prompt which well allow you to update /etc/sudoers






      share|improve this answer












      You should still be able to boot up the Pi in Single User mode to get access to root.



      Using another computer, modify cmdline.txt and add single to the end of the line

      Then when you boot up the Pi from the SD card, it should automatically dump you to a root prompt which well allow you to update /etc/sudoers







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Dec 24 '13 at 1:47









      Lawrence

      3,047813




      3,047813












      • Unfortunately I need root access to be able to modify /boot/cmdline.txt :(
        – 3cheesewheel
        Dec 24 '13 at 1:57






      • 2




        Hence using another computer
        – Lawrence
        Dec 24 '13 at 2:06






      • 1




        Raspberry Pi's hard drive is just SD card, so it is possible to plug it in via card reader to another computer and make all changes there without booting Pi in single mode.
        – VL-80
        Dec 24 '13 at 2:19










      • @Nikolay Assuming the OP has another computer with Linux installed or has a Live Distro handy of course.
        – Lawrence
        Dec 24 '13 at 2:21












      • (Or Windows/OSX with VirtualBox; the "USB sharing" feature works well.) Though, single also asks for root password, so while it does allow logins to a locked or expired root account, it may still refuse access on occassion, so editing /etc/sudoers directly from the live system would be a bit easier and quicker.
        – grawity
        Dec 24 '13 at 2:56




















      • Unfortunately I need root access to be able to modify /boot/cmdline.txt :(
        – 3cheesewheel
        Dec 24 '13 at 1:57






      • 2




        Hence using another computer
        – Lawrence
        Dec 24 '13 at 2:06






      • 1




        Raspberry Pi's hard drive is just SD card, so it is possible to plug it in via card reader to another computer and make all changes there without booting Pi in single mode.
        – VL-80
        Dec 24 '13 at 2:19










      • @Nikolay Assuming the OP has another computer with Linux installed or has a Live Distro handy of course.
        – Lawrence
        Dec 24 '13 at 2:21












      • (Or Windows/OSX with VirtualBox; the "USB sharing" feature works well.) Though, single also asks for root password, so while it does allow logins to a locked or expired root account, it may still refuse access on occassion, so editing /etc/sudoers directly from the live system would be a bit easier and quicker.
        – grawity
        Dec 24 '13 at 2:56


















      Unfortunately I need root access to be able to modify /boot/cmdline.txt :(
      – 3cheesewheel
      Dec 24 '13 at 1:57




      Unfortunately I need root access to be able to modify /boot/cmdline.txt :(
      – 3cheesewheel
      Dec 24 '13 at 1:57




      2




      2




      Hence using another computer
      – Lawrence
      Dec 24 '13 at 2:06




      Hence using another computer
      – Lawrence
      Dec 24 '13 at 2:06




      1




      1




      Raspberry Pi's hard drive is just SD card, so it is possible to plug it in via card reader to another computer and make all changes there without booting Pi in single mode.
      – VL-80
      Dec 24 '13 at 2:19




      Raspberry Pi's hard drive is just SD card, so it is possible to plug it in via card reader to another computer and make all changes there without booting Pi in single mode.
      – VL-80
      Dec 24 '13 at 2:19












      @Nikolay Assuming the OP has another computer with Linux installed or has a Live Distro handy of course.
      – Lawrence
      Dec 24 '13 at 2:21






      @Nikolay Assuming the OP has another computer with Linux installed or has a Live Distro handy of course.
      – Lawrence
      Dec 24 '13 at 2:21














      (Or Windows/OSX with VirtualBox; the "USB sharing" feature works well.) Though, single also asks for root password, so while it does allow logins to a locked or expired root account, it may still refuse access on occassion, so editing /etc/sudoers directly from the live system would be a bit easier and quicker.
      – grawity
      Dec 24 '13 at 2:56






      (Or Windows/OSX with VirtualBox; the "USB sharing" feature works well.) Though, single also asks for root password, so while it does allow logins to a locked or expired root account, it may still refuse access on occassion, so editing /etc/sudoers directly from the live system would be a bit easier and quicker.
      – grawity
      Dec 24 '13 at 2:56














      up vote
      0
      down vote













      The easiest solution is to boot up another OS on a LiveDVD or LiveUSB (ideally a LiveUSB, and ideally a Linux OS) then mount the disc and manually change the file. I've done similar things before and fixed it in this manner. All of your files will be visible and editable from the Live system. Unless you've encrypted the drive; that makes things a bit more complicated.



      Let me know if you have questions and I'll edit this answer - I'm not sure how comfortable you might be with setting up a live USB, but it's not very hard.






      share|improve this answer

























        up vote
        0
        down vote













        The easiest solution is to boot up another OS on a LiveDVD or LiveUSB (ideally a LiveUSB, and ideally a Linux OS) then mount the disc and manually change the file. I've done similar things before and fixed it in this manner. All of your files will be visible and editable from the Live system. Unless you've encrypted the drive; that makes things a bit more complicated.



        Let me know if you have questions and I'll edit this answer - I'm not sure how comfortable you might be with setting up a live USB, but it's not very hard.






        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          The easiest solution is to boot up another OS on a LiveDVD or LiveUSB (ideally a LiveUSB, and ideally a Linux OS) then mount the disc and manually change the file. I've done similar things before and fixed it in this manner. All of your files will be visible and editable from the Live system. Unless you've encrypted the drive; that makes things a bit more complicated.



          Let me know if you have questions and I'll edit this answer - I'm not sure how comfortable you might be with setting up a live USB, but it's not very hard.






          share|improve this answer












          The easiest solution is to boot up another OS on a LiveDVD or LiveUSB (ideally a LiveUSB, and ideally a Linux OS) then mount the disc and manually change the file. I've done similar things before and fixed it in this manner. All of your files will be visible and editable from the Live system. Unless you've encrypted the drive; that makes things a bit more complicated.



          Let me know if you have questions and I'll edit this answer - I'm not sure how comfortable you might be with setting up a live USB, but it's not very hard.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 24 '13 at 1:31









          Dylan

          7881614




          7881614






















              up vote
              0
              down vote













              After two days of research and browsing the web I have finally found a solution and been able to save my own Raspberry Pi system (not having to reformat the SD card and start from scratch)!



              NOTE: This answer is pretty long. If you want to get to the actual solution quickly, I've added a header that you can scroll down to. I do recommend you read the whole answer though, as it may bring some insight into the differences between the Raspbian distribution and other Linux distributions as well as clarity to why a lot of the suggested solutions you find across the internet may not work on your Pi.



              So normally, in a Linux environment, the quickest way to repair the broken sudo without even having to reboot is by using PolicyKit or the pkexec -command like this:



              pkexec visudo


              But on the Pi it most likely won't work, it will ask for the root password, but no password is accepted. (I mean, do you even remember setting a root password? Wait, you do? Then skip to the asterisk*.)



              Some Linux distributions, for example Ubuntu, come with a recovery mode that can be accessed by holding down the shift-key during bootup and offers a user-friendly interface and allows one to be dropped into a root shell prompt where one could get access to fix the broken files. The Pi's Raspbian Linux distribution does not come with that kind of a recovery mode so that solution is not a solution for us. Yet the Pi does prompt you at bootup to hold down the shift-key to enter some kind of recovery mode and by entering the Pi's recovery mode or the NOOBS dialog we are surely on the right path towards repairing the broken sudo on our Pi.



              Another common way of repairing sudo is by booting into single-user mode which gets you to a root shell prompt. The way you do this is by adding the word single to the end of the cmdline.txt -file on the system's boot partition. The next time your system boots up it will boot into single-user mode.



              We can easily try this solution on our Pi because, conviniently, the Pi's recovery mode or the NOOBS dialog allows us to edit the cmdline.txt -file. In the recovery mode or the NOOBS dialog, by pressing the "Edit config" -icon you open up an editor that lets you edit two files, one of which is cmdline.txt. By pressing "OK" in the editor your changes are saved.



              Unfortunately, when you boot into single-user mode or "rescue mode" on the Pi, you'll most likely get the following message:



              Cannot open access to console, the root account is locked.
              See sulogin(8) man page for more details.

              Press Enter to continue.


              This – as well as why the previously mentioned root password prompt didn't accept any passwords – is because Raspbian, by default, has no password set for the root account. This is not to be confused with a password that is nothing or that no password would be required. Raspbian, just like a handful of other Linux distributions (for example Debian which Raspbian is a derivate of), expects the user to operate as root through sudo and not through the account itself. Hence the root account is in the "lockdown" state that we are experiencing.



              *If you set the root password yourself, for example through the command sudo passwd root, then you should be able to use the pkexec -command and boot into single-user mode. Note that when you do this, you need to use sudo, so this is obviously not a solution once sudo is broken, but I point this out because this is probably why some people found success in fixing their Pi's when applying the solutions suggesting the pkexec -command or single-user mode. These people had at some point gone and manually set a root password, unlocking their system's root account.



              The Solution



              This blog post explains how to do what we need to do. The steps are almost identical to the steps we took when trying to repair sudo through single-user mode. You don’t have to do all the cumbersome stuff the blog post mentions in order to edit the cmdline.txt -file, instead just do it in the NOOBS dialog. The key is to add init=/bin/sh to the end of the cmdline.txt -file. With that snippet added, the next time you boot up your Pi, you will be dropped into a root shell prompt.



              Initially, the file system will be loaded in read-only mode, so before being able to edit anything, you’ll have to remount the root partition in read and write mode by executing the following command:



              mount -o remount,rw /dev/mmcblk0p2 /


              Now you should be in a root shell prompt, where you can freely edit any file, including the broken sudo files.






              share|improve this answer

























                up vote
                0
                down vote













                After two days of research and browsing the web I have finally found a solution and been able to save my own Raspberry Pi system (not having to reformat the SD card and start from scratch)!



                NOTE: This answer is pretty long. If you want to get to the actual solution quickly, I've added a header that you can scroll down to. I do recommend you read the whole answer though, as it may bring some insight into the differences between the Raspbian distribution and other Linux distributions as well as clarity to why a lot of the suggested solutions you find across the internet may not work on your Pi.



                So normally, in a Linux environment, the quickest way to repair the broken sudo without even having to reboot is by using PolicyKit or the pkexec -command like this:



                pkexec visudo


                But on the Pi it most likely won't work, it will ask for the root password, but no password is accepted. (I mean, do you even remember setting a root password? Wait, you do? Then skip to the asterisk*.)



                Some Linux distributions, for example Ubuntu, come with a recovery mode that can be accessed by holding down the shift-key during bootup and offers a user-friendly interface and allows one to be dropped into a root shell prompt where one could get access to fix the broken files. The Pi's Raspbian Linux distribution does not come with that kind of a recovery mode so that solution is not a solution for us. Yet the Pi does prompt you at bootup to hold down the shift-key to enter some kind of recovery mode and by entering the Pi's recovery mode or the NOOBS dialog we are surely on the right path towards repairing the broken sudo on our Pi.



                Another common way of repairing sudo is by booting into single-user mode which gets you to a root shell prompt. The way you do this is by adding the word single to the end of the cmdline.txt -file on the system's boot partition. The next time your system boots up it will boot into single-user mode.



                We can easily try this solution on our Pi because, conviniently, the Pi's recovery mode or the NOOBS dialog allows us to edit the cmdline.txt -file. In the recovery mode or the NOOBS dialog, by pressing the "Edit config" -icon you open up an editor that lets you edit two files, one of which is cmdline.txt. By pressing "OK" in the editor your changes are saved.



                Unfortunately, when you boot into single-user mode or "rescue mode" on the Pi, you'll most likely get the following message:



                Cannot open access to console, the root account is locked.
                See sulogin(8) man page for more details.

                Press Enter to continue.


                This – as well as why the previously mentioned root password prompt didn't accept any passwords – is because Raspbian, by default, has no password set for the root account. This is not to be confused with a password that is nothing or that no password would be required. Raspbian, just like a handful of other Linux distributions (for example Debian which Raspbian is a derivate of), expects the user to operate as root through sudo and not through the account itself. Hence the root account is in the "lockdown" state that we are experiencing.



                *If you set the root password yourself, for example through the command sudo passwd root, then you should be able to use the pkexec -command and boot into single-user mode. Note that when you do this, you need to use sudo, so this is obviously not a solution once sudo is broken, but I point this out because this is probably why some people found success in fixing their Pi's when applying the solutions suggesting the pkexec -command or single-user mode. These people had at some point gone and manually set a root password, unlocking their system's root account.



                The Solution



                This blog post explains how to do what we need to do. The steps are almost identical to the steps we took when trying to repair sudo through single-user mode. You don’t have to do all the cumbersome stuff the blog post mentions in order to edit the cmdline.txt -file, instead just do it in the NOOBS dialog. The key is to add init=/bin/sh to the end of the cmdline.txt -file. With that snippet added, the next time you boot up your Pi, you will be dropped into a root shell prompt.



                Initially, the file system will be loaded in read-only mode, so before being able to edit anything, you’ll have to remount the root partition in read and write mode by executing the following command:



                mount -o remount,rw /dev/mmcblk0p2 /


                Now you should be in a root shell prompt, where you can freely edit any file, including the broken sudo files.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  After two days of research and browsing the web I have finally found a solution and been able to save my own Raspberry Pi system (not having to reformat the SD card and start from scratch)!



                  NOTE: This answer is pretty long. If you want to get to the actual solution quickly, I've added a header that you can scroll down to. I do recommend you read the whole answer though, as it may bring some insight into the differences between the Raspbian distribution and other Linux distributions as well as clarity to why a lot of the suggested solutions you find across the internet may not work on your Pi.



                  So normally, in a Linux environment, the quickest way to repair the broken sudo without even having to reboot is by using PolicyKit or the pkexec -command like this:



                  pkexec visudo


                  But on the Pi it most likely won't work, it will ask for the root password, but no password is accepted. (I mean, do you even remember setting a root password? Wait, you do? Then skip to the asterisk*.)



                  Some Linux distributions, for example Ubuntu, come with a recovery mode that can be accessed by holding down the shift-key during bootup and offers a user-friendly interface and allows one to be dropped into a root shell prompt where one could get access to fix the broken files. The Pi's Raspbian Linux distribution does not come with that kind of a recovery mode so that solution is not a solution for us. Yet the Pi does prompt you at bootup to hold down the shift-key to enter some kind of recovery mode and by entering the Pi's recovery mode or the NOOBS dialog we are surely on the right path towards repairing the broken sudo on our Pi.



                  Another common way of repairing sudo is by booting into single-user mode which gets you to a root shell prompt. The way you do this is by adding the word single to the end of the cmdline.txt -file on the system's boot partition. The next time your system boots up it will boot into single-user mode.



                  We can easily try this solution on our Pi because, conviniently, the Pi's recovery mode or the NOOBS dialog allows us to edit the cmdline.txt -file. In the recovery mode or the NOOBS dialog, by pressing the "Edit config" -icon you open up an editor that lets you edit two files, one of which is cmdline.txt. By pressing "OK" in the editor your changes are saved.



                  Unfortunately, when you boot into single-user mode or "rescue mode" on the Pi, you'll most likely get the following message:



                  Cannot open access to console, the root account is locked.
                  See sulogin(8) man page for more details.

                  Press Enter to continue.


                  This – as well as why the previously mentioned root password prompt didn't accept any passwords – is because Raspbian, by default, has no password set for the root account. This is not to be confused with a password that is nothing or that no password would be required. Raspbian, just like a handful of other Linux distributions (for example Debian which Raspbian is a derivate of), expects the user to operate as root through sudo and not through the account itself. Hence the root account is in the "lockdown" state that we are experiencing.



                  *If you set the root password yourself, for example through the command sudo passwd root, then you should be able to use the pkexec -command and boot into single-user mode. Note that when you do this, you need to use sudo, so this is obviously not a solution once sudo is broken, but I point this out because this is probably why some people found success in fixing their Pi's when applying the solutions suggesting the pkexec -command or single-user mode. These people had at some point gone and manually set a root password, unlocking their system's root account.



                  The Solution



                  This blog post explains how to do what we need to do. The steps are almost identical to the steps we took when trying to repair sudo through single-user mode. You don’t have to do all the cumbersome stuff the blog post mentions in order to edit the cmdline.txt -file, instead just do it in the NOOBS dialog. The key is to add init=/bin/sh to the end of the cmdline.txt -file. With that snippet added, the next time you boot up your Pi, you will be dropped into a root shell prompt.



                  Initially, the file system will be loaded in read-only mode, so before being able to edit anything, you’ll have to remount the root partition in read and write mode by executing the following command:



                  mount -o remount,rw /dev/mmcblk0p2 /


                  Now you should be in a root shell prompt, where you can freely edit any file, including the broken sudo files.






                  share|improve this answer












                  After two days of research and browsing the web I have finally found a solution and been able to save my own Raspberry Pi system (not having to reformat the SD card and start from scratch)!



                  NOTE: This answer is pretty long. If you want to get to the actual solution quickly, I've added a header that you can scroll down to. I do recommend you read the whole answer though, as it may bring some insight into the differences between the Raspbian distribution and other Linux distributions as well as clarity to why a lot of the suggested solutions you find across the internet may not work on your Pi.



                  So normally, in a Linux environment, the quickest way to repair the broken sudo without even having to reboot is by using PolicyKit or the pkexec -command like this:



                  pkexec visudo


                  But on the Pi it most likely won't work, it will ask for the root password, but no password is accepted. (I mean, do you even remember setting a root password? Wait, you do? Then skip to the asterisk*.)



                  Some Linux distributions, for example Ubuntu, come with a recovery mode that can be accessed by holding down the shift-key during bootup and offers a user-friendly interface and allows one to be dropped into a root shell prompt where one could get access to fix the broken files. The Pi's Raspbian Linux distribution does not come with that kind of a recovery mode so that solution is not a solution for us. Yet the Pi does prompt you at bootup to hold down the shift-key to enter some kind of recovery mode and by entering the Pi's recovery mode or the NOOBS dialog we are surely on the right path towards repairing the broken sudo on our Pi.



                  Another common way of repairing sudo is by booting into single-user mode which gets you to a root shell prompt. The way you do this is by adding the word single to the end of the cmdline.txt -file on the system's boot partition. The next time your system boots up it will boot into single-user mode.



                  We can easily try this solution on our Pi because, conviniently, the Pi's recovery mode or the NOOBS dialog allows us to edit the cmdline.txt -file. In the recovery mode or the NOOBS dialog, by pressing the "Edit config" -icon you open up an editor that lets you edit two files, one of which is cmdline.txt. By pressing "OK" in the editor your changes are saved.



                  Unfortunately, when you boot into single-user mode or "rescue mode" on the Pi, you'll most likely get the following message:



                  Cannot open access to console, the root account is locked.
                  See sulogin(8) man page for more details.

                  Press Enter to continue.


                  This – as well as why the previously mentioned root password prompt didn't accept any passwords – is because Raspbian, by default, has no password set for the root account. This is not to be confused with a password that is nothing or that no password would be required. Raspbian, just like a handful of other Linux distributions (for example Debian which Raspbian is a derivate of), expects the user to operate as root through sudo and not through the account itself. Hence the root account is in the "lockdown" state that we are experiencing.



                  *If you set the root password yourself, for example through the command sudo passwd root, then you should be able to use the pkexec -command and boot into single-user mode. Note that when you do this, you need to use sudo, so this is obviously not a solution once sudo is broken, but I point this out because this is probably why some people found success in fixing their Pi's when applying the solutions suggesting the pkexec -command or single-user mode. These people had at some point gone and manually set a root password, unlocking their system's root account.



                  The Solution



                  This blog post explains how to do what we need to do. The steps are almost identical to the steps we took when trying to repair sudo through single-user mode. You don’t have to do all the cumbersome stuff the blog post mentions in order to edit the cmdline.txt -file, instead just do it in the NOOBS dialog. The key is to add init=/bin/sh to the end of the cmdline.txt -file. With that snippet added, the next time you boot up your Pi, you will be dropped into a root shell prompt.



                  Initially, the file system will be loaded in read-only mode, so before being able to edit anything, you’ll have to remount the root partition in read and write mode by executing the following command:



                  mount -o remount,rw /dev/mmcblk0p2 /


                  Now you should be in a root shell prompt, where you can freely edit any file, including the broken sudo files.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 25 at 18:25









                  Daniel Giljam

                  1




                  1






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Super User!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f692443%2fhow-do-i-fix-an-invalid-etc-sudoers-file-if-root-access-is-disabled%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Probability when a professor distributes a quiz and homework assignment to a class of n students.

                      Aardman Animations

                      Are they similar matrix