I accidentally deleted the sudoers file on Mac OS X; is there any way to recover it?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite
1












I accidentally deleted the sudoers file on Mac OS X; is there any way to recover it?

And once you've recovered it, how do you set it to mode 0440?



I presume not but I am desperate to get it back!










share|improve this question



























    up vote
    5
    down vote

    favorite
    1












    I accidentally deleted the sudoers file on Mac OS X; is there any way to recover it?

    And once you've recovered it, how do you set it to mode 0440?



    I presume not but I am desperate to get it back!










    share|improve this question

























      up vote
      5
      down vote

      favorite
      1









      up vote
      5
      down vote

      favorite
      1






      1





      I accidentally deleted the sudoers file on Mac OS X; is there any way to recover it?

      And once you've recovered it, how do you set it to mode 0440?



      I presume not but I am desperate to get it back!










      share|improve this question















      I accidentally deleted the sudoers file on Mac OS X; is there any way to recover it?

      And once you've recovered it, how do you set it to mode 0440?



      I presume not but I am desperate to get it back!







      osx sudo






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 23 '17 at 23:02









      G-Man

      12k92860




      12k92860










      asked May 2 '12 at 17:10









      rake

      711310




      711310




















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          5
          down vote













          If I understand your problem correctly, then currently you don't have sudoers and you are trying to do sudo and it's not working. In this case, to get sudo working you can do the following :



          1. Create sudoers file in your home folder. You can find default content here sudoers

          2. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”).

          3. Now copy sudoers file from home folder's to /etc folder via Finder.

          4. Prompt will come asking for password.

          5. Enter correct password and you are done.

          To check sudo is running fine cd /etc and sudo vim sudoers. You should able to view sudoers file via vim editor. Any read/write operation in /etc would require the sudo command.



          I know this is a bit surprising that even after not having sudoers, via UI we can do operations in /etc. But it worked for me :)






          share|improve this answer


















          • 1




            It is indeed odd that the GUI equivalent of what is impossible from the command line works. I guess Apple test for GUI workflows more thoroughly than command line. Thank goodness, this post rescued me.
            – user7000
            Mar 12 '16 at 19:20










          • Good to know that it helped you.
            – Tanmay
            Mar 13 '16 at 7:01

















          up vote
          4
          down vote













          I'm assuming you are trying to run a sudo command and it's giving you an error that /etc/sudoers does not have the correct permissions?



          If you have previously granted your account Admin status, you should be able to fix the permissions through the GUI. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”), then open the sudoers file properties. Click the lock. Grant the admin group read/write, the system user read-only, the wheel group read-only, and the everyone group no access. The permissions should now be correct.



          If you did not put yourself in the admin group, you will need to reboot OSX into single user mode and perform the command chmod 0440 /etc/sudoers.






          share|improve this answer





























            up vote
            4
            down vote













            Enable the root user using system preferences, and then create /etc/sudoers while logged in as the root user using



            touch /etc/sudoers; chmod 440 /etc/sudoers


            Note: Since the command is run as root in this case, and the group id of /etc is 0, it should by default be owned by the correct user and group after re-creation, but if for some reason it isn't, run



            chown root:wheel /etc/sudoers


            After you have created /etc/sudoers use visudo to insert this code into it:



            # sudoers file.

            #
            # This file MUST be edited with the 'visudo' command as root.
            # Failure to use 'visudo' may result in syntax or file permission errors
            # that prevent sudo from running.
            #
            # See the sudoers man page for the details on how to write a sudoers file.
            #

            # Host alias specification

            # User alias specification

            # Cmnd alias specification

            # Defaults specification
            Defaults env_reset
            Defaults env_keep += "BLOCKSIZE"
            Defaults env_keep += "COLORFGBG COLORTERM"
            Defaults env_keep += "__CF_USER_TEXT_ENCODING"
            Defaults env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"
            Defaults env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"
            Defaults env_keep += "LINES COLUMNS"
            Defaults env_keep += "LSCOLORS"
            Defaults env_keep += "SSH_AUTH_SOCK"
            Defaults env_keep += "TZ"
            Defaults env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
            Defaults env_keep += "EDITOR VISUAL"

            # Runas alias specification

            # User privilege specification
            root ALL=(ALL) ALL
            %admin ALL=(ALL) ALL

            # Uncomment to allow people in group wheel to run all commands
            # %wheel ALL=(ALL) ALL

            # Same thing without a password
            # %wheel ALL=(ALL) NOPASSWD: ALL

            # Samples
            # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
            # %users localhost=/sbin/shutdown -h now
            ALL ALL=(ALL) NOPASSWD:/opt/dplat/bin/Revision/CMUpdatePackage/Installer.app/Contents/MacOS/I nstaller
            ALL ALL=(ALL) NOPASSWD:/opt/dplat/bin/UpdatePackageInstaller.app/Contents/MacOS/UpdatePackage Installer


            If you aren't an admin, you can boot the system into single-user-mode instead (if you don't know how to do this, just google it) and run:



            mount -uw /


            and you will be in the terminal with root privileges, and you will be able to run the above commands to set up /etc/sudoers






            share|improve this answer





























              up vote
              -1
              down vote













              The answers above cover the default contents of the file, how to move it into place with Finder and change it's permissions. However, sudo will complain unless the owner of the sudoers file is root. The only way to change the owner without sudo is via this command:



              osascript -e 'do shell script "chown root:wheel /etc/sudoers" with administrator privileges'






              share|improve this answer


















              • 1




                This appears to at most answer the "how do you set it to mode 0440" part, which has already been addressed, but not address the recovery aspect. Since the OP is missing an /etc/sudoers file to begin with, how does this help them?
                – Jeff Schaller
                Oct 15 '17 at 1:23










              • You can create the file with any editor and move it into place with Finder. The hard part is changing the owner to root, which is not possible via any other method.
                – tmm1
                Oct 15 '17 at 5:05











              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              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: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f37764%2fi-accidentally-deleted-the-sudoers-file-on-mac-os-x-is-there-any-way-to-recover%23new-answer', 'question_page');

              );

              Post as a guest






























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              5
              down vote













              If I understand your problem correctly, then currently you don't have sudoers and you are trying to do sudo and it's not working. In this case, to get sudo working you can do the following :



              1. Create sudoers file in your home folder. You can find default content here sudoers

              2. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”).

              3. Now copy sudoers file from home folder's to /etc folder via Finder.

              4. Prompt will come asking for password.

              5. Enter correct password and you are done.

              To check sudo is running fine cd /etc and sudo vim sudoers. You should able to view sudoers file via vim editor. Any read/write operation in /etc would require the sudo command.



              I know this is a bit surprising that even after not having sudoers, via UI we can do operations in /etc. But it worked for me :)






              share|improve this answer


















              • 1




                It is indeed odd that the GUI equivalent of what is impossible from the command line works. I guess Apple test for GUI workflows more thoroughly than command line. Thank goodness, this post rescued me.
                – user7000
                Mar 12 '16 at 19:20










              • Good to know that it helped you.
                – Tanmay
                Mar 13 '16 at 7:01














              up vote
              5
              down vote













              If I understand your problem correctly, then currently you don't have sudoers and you are trying to do sudo and it's not working. In this case, to get sudo working you can do the following :



              1. Create sudoers file in your home folder. You can find default content here sudoers

              2. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”).

              3. Now copy sudoers file from home folder's to /etc folder via Finder.

              4. Prompt will come asking for password.

              5. Enter correct password and you are done.

              To check sudo is running fine cd /etc and sudo vim sudoers. You should able to view sudoers file via vim editor. Any read/write operation in /etc would require the sudo command.



              I know this is a bit surprising that even after not having sudoers, via UI we can do operations in /etc. But it worked for me :)






              share|improve this answer


















              • 1




                It is indeed odd that the GUI equivalent of what is impossible from the command line works. I guess Apple test for GUI workflows more thoroughly than command line. Thank goodness, this post rescued me.
                – user7000
                Mar 12 '16 at 19:20










              • Good to know that it helped you.
                – Tanmay
                Mar 13 '16 at 7:01












              up vote
              5
              down vote










              up vote
              5
              down vote









              If I understand your problem correctly, then currently you don't have sudoers and you are trying to do sudo and it's not working. In this case, to get sudo working you can do the following :



              1. Create sudoers file in your home folder. You can find default content here sudoers

              2. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”).

              3. Now copy sudoers file from home folder's to /etc folder via Finder.

              4. Prompt will come asking for password.

              5. Enter correct password and you are done.

              To check sudo is running fine cd /etc and sudo vim sudoers. You should able to view sudoers file via vim editor. Any read/write operation in /etc would require the sudo command.



              I know this is a bit surprising that even after not having sudoers, via UI we can do operations in /etc. But it worked for me :)






              share|improve this answer














              If I understand your problem correctly, then currently you don't have sudoers and you are trying to do sudo and it's not working. In this case, to get sudo working you can do the following :



              1. Create sudoers file in your home folder. You can find default content here sudoers

              2. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”).

              3. Now copy sudoers file from home folder's to /etc folder via Finder.

              4. Prompt will come asking for password.

              5. Enter correct password and you are done.

              To check sudo is running fine cd /etc and sudo vim sudoers. You should able to view sudoers file via vim editor. Any read/write operation in /etc would require the sudo command.



              I know this is a bit surprising that even after not having sudoers, via UI we can do operations in /etc. But it worked for me :)







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 9 mins ago









              Community♦

              1




              1










              answered Apr 30 '13 at 5:41









              Tanmay

              15111




              15111







              • 1




                It is indeed odd that the GUI equivalent of what is impossible from the command line works. I guess Apple test for GUI workflows more thoroughly than command line. Thank goodness, this post rescued me.
                – user7000
                Mar 12 '16 at 19:20










              • Good to know that it helped you.
                – Tanmay
                Mar 13 '16 at 7:01












              • 1




                It is indeed odd that the GUI equivalent of what is impossible from the command line works. I guess Apple test for GUI workflows more thoroughly than command line. Thank goodness, this post rescued me.
                – user7000
                Mar 12 '16 at 19:20










              • Good to know that it helped you.
                – Tanmay
                Mar 13 '16 at 7:01







              1




              1




              It is indeed odd that the GUI equivalent of what is impossible from the command line works. I guess Apple test for GUI workflows more thoroughly than command line. Thank goodness, this post rescued me.
              – user7000
              Mar 12 '16 at 19:20




              It is indeed odd that the GUI equivalent of what is impossible from the command line works. I guess Apple test for GUI workflows more thoroughly than command line. Thank goodness, this post rescued me.
              – user7000
              Mar 12 '16 at 19:20












              Good to know that it helped you.
              – Tanmay
              Mar 13 '16 at 7:01




              Good to know that it helped you.
              – Tanmay
              Mar 13 '16 at 7:01












              up vote
              4
              down vote













              I'm assuming you are trying to run a sudo command and it's giving you an error that /etc/sudoers does not have the correct permissions?



              If you have previously granted your account Admin status, you should be able to fix the permissions through the GUI. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”), then open the sudoers file properties. Click the lock. Grant the admin group read/write, the system user read-only, the wheel group read-only, and the everyone group no access. The permissions should now be correct.



              If you did not put yourself in the admin group, you will need to reboot OSX into single user mode and perform the command chmod 0440 /etc/sudoers.






              share|improve this answer


























                up vote
                4
                down vote













                I'm assuming you are trying to run a sudo command and it's giving you an error that /etc/sudoers does not have the correct permissions?



                If you have previously granted your account Admin status, you should be able to fix the permissions through the GUI. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”), then open the sudoers file properties. Click the lock. Grant the admin group read/write, the system user read-only, the wheel group read-only, and the everyone group no access. The permissions should now be correct.



                If you did not put yourself in the admin group, you will need to reboot OSX into single user mode and perform the command chmod 0440 /etc/sudoers.






                share|improve this answer
























                  up vote
                  4
                  down vote










                  up vote
                  4
                  down vote









                  I'm assuming you are trying to run a sudo command and it's giving you an error that /etc/sudoers does not have the correct permissions?



                  If you have previously granted your account Admin status, you should be able to fix the permissions through the GUI. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”), then open the sudoers file properties. Click the lock. Grant the admin group read/write, the system user read-only, the wheel group read-only, and the everyone group no access. The permissions should now be correct.



                  If you did not put yourself in the admin group, you will need to reboot OSX into single user mode and perform the command chmod 0440 /etc/sudoers.






                  share|improve this answer














                  I'm assuming you are trying to run a sudo command and it's giving you an error that /etc/sudoers does not have the correct permissions?



                  If you have previously granted your account Admin status, you should be able to fix the permissions through the GUI. Open the “/etc” folder in Finder (“Go” -> “Go to Folder…”), then open the sudoers file properties. Click the lock. Grant the admin group read/write, the system user read-only, the wheel group read-only, and the everyone group no access. The permissions should now be correct.



                  If you did not put yourself in the admin group, you will need to reboot OSX into single user mode and perform the command chmod 0440 /etc/sudoers.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 2 '12 at 19:19

























                  answered May 2 '12 at 19:06









                  George M

                  8,89623247




                  8,89623247




















                      up vote
                      4
                      down vote













                      Enable the root user using system preferences, and then create /etc/sudoers while logged in as the root user using



                      touch /etc/sudoers; chmod 440 /etc/sudoers


                      Note: Since the command is run as root in this case, and the group id of /etc is 0, it should by default be owned by the correct user and group after re-creation, but if for some reason it isn't, run



                      chown root:wheel /etc/sudoers


                      After you have created /etc/sudoers use visudo to insert this code into it:



                      # sudoers file.

                      #
                      # This file MUST be edited with the 'visudo' command as root.
                      # Failure to use 'visudo' may result in syntax or file permission errors
                      # that prevent sudo from running.
                      #
                      # See the sudoers man page for the details on how to write a sudoers file.
                      #

                      # Host alias specification

                      # User alias specification

                      # Cmnd alias specification

                      # Defaults specification
                      Defaults env_reset
                      Defaults env_keep += "BLOCKSIZE"
                      Defaults env_keep += "COLORFGBG COLORTERM"
                      Defaults env_keep += "__CF_USER_TEXT_ENCODING"
                      Defaults env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"
                      Defaults env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"
                      Defaults env_keep += "LINES COLUMNS"
                      Defaults env_keep += "LSCOLORS"
                      Defaults env_keep += "SSH_AUTH_SOCK"
                      Defaults env_keep += "TZ"
                      Defaults env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
                      Defaults env_keep += "EDITOR VISUAL"

                      # Runas alias specification

                      # User privilege specification
                      root ALL=(ALL) ALL
                      %admin ALL=(ALL) ALL

                      # Uncomment to allow people in group wheel to run all commands
                      # %wheel ALL=(ALL) ALL

                      # Same thing without a password
                      # %wheel ALL=(ALL) NOPASSWD: ALL

                      # Samples
                      # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
                      # %users localhost=/sbin/shutdown -h now
                      ALL ALL=(ALL) NOPASSWD:/opt/dplat/bin/Revision/CMUpdatePackage/Installer.app/Contents/MacOS/I nstaller
                      ALL ALL=(ALL) NOPASSWD:/opt/dplat/bin/UpdatePackageInstaller.app/Contents/MacOS/UpdatePackage Installer


                      If you aren't an admin, you can boot the system into single-user-mode instead (if you don't know how to do this, just google it) and run:



                      mount -uw /


                      and you will be in the terminal with root privileges, and you will be able to run the above commands to set up /etc/sudoers






                      share|improve this answer


























                        up vote
                        4
                        down vote













                        Enable the root user using system preferences, and then create /etc/sudoers while logged in as the root user using



                        touch /etc/sudoers; chmod 440 /etc/sudoers


                        Note: Since the command is run as root in this case, and the group id of /etc is 0, it should by default be owned by the correct user and group after re-creation, but if for some reason it isn't, run



                        chown root:wheel /etc/sudoers


                        After you have created /etc/sudoers use visudo to insert this code into it:



                        # sudoers file.

                        #
                        # This file MUST be edited with the 'visudo' command as root.
                        # Failure to use 'visudo' may result in syntax or file permission errors
                        # that prevent sudo from running.
                        #
                        # See the sudoers man page for the details on how to write a sudoers file.
                        #

                        # Host alias specification

                        # User alias specification

                        # Cmnd alias specification

                        # Defaults specification
                        Defaults env_reset
                        Defaults env_keep += "BLOCKSIZE"
                        Defaults env_keep += "COLORFGBG COLORTERM"
                        Defaults env_keep += "__CF_USER_TEXT_ENCODING"
                        Defaults env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"
                        Defaults env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"
                        Defaults env_keep += "LINES COLUMNS"
                        Defaults env_keep += "LSCOLORS"
                        Defaults env_keep += "SSH_AUTH_SOCK"
                        Defaults env_keep += "TZ"
                        Defaults env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
                        Defaults env_keep += "EDITOR VISUAL"

                        # Runas alias specification

                        # User privilege specification
                        root ALL=(ALL) ALL
                        %admin ALL=(ALL) ALL

                        # Uncomment to allow people in group wheel to run all commands
                        # %wheel ALL=(ALL) ALL

                        # Same thing without a password
                        # %wheel ALL=(ALL) NOPASSWD: ALL

                        # Samples
                        # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
                        # %users localhost=/sbin/shutdown -h now
                        ALL ALL=(ALL) NOPASSWD:/opt/dplat/bin/Revision/CMUpdatePackage/Installer.app/Contents/MacOS/I nstaller
                        ALL ALL=(ALL) NOPASSWD:/opt/dplat/bin/UpdatePackageInstaller.app/Contents/MacOS/UpdatePackage Installer


                        If you aren't an admin, you can boot the system into single-user-mode instead (if you don't know how to do this, just google it) and run:



                        mount -uw /


                        and you will be in the terminal with root privileges, and you will be able to run the above commands to set up /etc/sudoers






                        share|improve this answer
























                          up vote
                          4
                          down vote










                          up vote
                          4
                          down vote









                          Enable the root user using system preferences, and then create /etc/sudoers while logged in as the root user using



                          touch /etc/sudoers; chmod 440 /etc/sudoers


                          Note: Since the command is run as root in this case, and the group id of /etc is 0, it should by default be owned by the correct user and group after re-creation, but if for some reason it isn't, run



                          chown root:wheel /etc/sudoers


                          After you have created /etc/sudoers use visudo to insert this code into it:



                          # sudoers file.

                          #
                          # This file MUST be edited with the 'visudo' command as root.
                          # Failure to use 'visudo' may result in syntax or file permission errors
                          # that prevent sudo from running.
                          #
                          # See the sudoers man page for the details on how to write a sudoers file.
                          #

                          # Host alias specification

                          # User alias specification

                          # Cmnd alias specification

                          # Defaults specification
                          Defaults env_reset
                          Defaults env_keep += "BLOCKSIZE"
                          Defaults env_keep += "COLORFGBG COLORTERM"
                          Defaults env_keep += "__CF_USER_TEXT_ENCODING"
                          Defaults env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"
                          Defaults env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"
                          Defaults env_keep += "LINES COLUMNS"
                          Defaults env_keep += "LSCOLORS"
                          Defaults env_keep += "SSH_AUTH_SOCK"
                          Defaults env_keep += "TZ"
                          Defaults env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
                          Defaults env_keep += "EDITOR VISUAL"

                          # Runas alias specification

                          # User privilege specification
                          root ALL=(ALL) ALL
                          %admin ALL=(ALL) ALL

                          # Uncomment to allow people in group wheel to run all commands
                          # %wheel ALL=(ALL) ALL

                          # Same thing without a password
                          # %wheel ALL=(ALL) NOPASSWD: ALL

                          # Samples
                          # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
                          # %users localhost=/sbin/shutdown -h now
                          ALL ALL=(ALL) NOPASSWD:/opt/dplat/bin/Revision/CMUpdatePackage/Installer.app/Contents/MacOS/I nstaller
                          ALL ALL=(ALL) NOPASSWD:/opt/dplat/bin/UpdatePackageInstaller.app/Contents/MacOS/UpdatePackage Installer


                          If you aren't an admin, you can boot the system into single-user-mode instead (if you don't know how to do this, just google it) and run:



                          mount -uw /


                          and you will be in the terminal with root privileges, and you will be able to run the above commands to set up /etc/sudoers






                          share|improve this answer














                          Enable the root user using system preferences, and then create /etc/sudoers while logged in as the root user using



                          touch /etc/sudoers; chmod 440 /etc/sudoers


                          Note: Since the command is run as root in this case, and the group id of /etc is 0, it should by default be owned by the correct user and group after re-creation, but if for some reason it isn't, run



                          chown root:wheel /etc/sudoers


                          After you have created /etc/sudoers use visudo to insert this code into it:



                          # sudoers file.

                          #
                          # This file MUST be edited with the 'visudo' command as root.
                          # Failure to use 'visudo' may result in syntax or file permission errors
                          # that prevent sudo from running.
                          #
                          # See the sudoers man page for the details on how to write a sudoers file.
                          #

                          # Host alias specification

                          # User alias specification

                          # Cmnd alias specification

                          # Defaults specification
                          Defaults env_reset
                          Defaults env_keep += "BLOCKSIZE"
                          Defaults env_keep += "COLORFGBG COLORTERM"
                          Defaults env_keep += "__CF_USER_TEXT_ENCODING"
                          Defaults env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"
                          Defaults env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"
                          Defaults env_keep += "LINES COLUMNS"
                          Defaults env_keep += "LSCOLORS"
                          Defaults env_keep += "SSH_AUTH_SOCK"
                          Defaults env_keep += "TZ"
                          Defaults env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
                          Defaults env_keep += "EDITOR VISUAL"

                          # Runas alias specification

                          # User privilege specification
                          root ALL=(ALL) ALL
                          %admin ALL=(ALL) ALL

                          # Uncomment to allow people in group wheel to run all commands
                          # %wheel ALL=(ALL) ALL

                          # Same thing without a password
                          # %wheel ALL=(ALL) NOPASSWD: ALL

                          # Samples
                          # %users ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
                          # %users localhost=/sbin/shutdown -h now
                          ALL ALL=(ALL) NOPASSWD:/opt/dplat/bin/Revision/CMUpdatePackage/Installer.app/Contents/MacOS/I nstaller
                          ALL ALL=(ALL) NOPASSWD:/opt/dplat/bin/UpdatePackageInstaller.app/Contents/MacOS/UpdatePackage Installer


                          If you aren't an admin, you can boot the system into single-user-mode instead (if you don't know how to do this, just google it) and run:



                          mount -uw /


                          and you will be in the terminal with root privileges, and you will be able to run the above commands to set up /etc/sudoers







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 4 '17 at 18:24

























                          answered Mar 27 '16 at 22:09









                          John Militer

                          6542928




                          6542928




















                              up vote
                              -1
                              down vote













                              The answers above cover the default contents of the file, how to move it into place with Finder and change it's permissions. However, sudo will complain unless the owner of the sudoers file is root. The only way to change the owner without sudo is via this command:



                              osascript -e 'do shell script "chown root:wheel /etc/sudoers" with administrator privileges'






                              share|improve this answer


















                              • 1




                                This appears to at most answer the "how do you set it to mode 0440" part, which has already been addressed, but not address the recovery aspect. Since the OP is missing an /etc/sudoers file to begin with, how does this help them?
                                – Jeff Schaller
                                Oct 15 '17 at 1:23










                              • You can create the file with any editor and move it into place with Finder. The hard part is changing the owner to root, which is not possible via any other method.
                                – tmm1
                                Oct 15 '17 at 5:05















                              up vote
                              -1
                              down vote













                              The answers above cover the default contents of the file, how to move it into place with Finder and change it's permissions. However, sudo will complain unless the owner of the sudoers file is root. The only way to change the owner without sudo is via this command:



                              osascript -e 'do shell script "chown root:wheel /etc/sudoers" with administrator privileges'






                              share|improve this answer


















                              • 1




                                This appears to at most answer the "how do you set it to mode 0440" part, which has already been addressed, but not address the recovery aspect. Since the OP is missing an /etc/sudoers file to begin with, how does this help them?
                                – Jeff Schaller
                                Oct 15 '17 at 1:23










                              • You can create the file with any editor and move it into place with Finder. The hard part is changing the owner to root, which is not possible via any other method.
                                – tmm1
                                Oct 15 '17 at 5:05













                              up vote
                              -1
                              down vote










                              up vote
                              -1
                              down vote









                              The answers above cover the default contents of the file, how to move it into place with Finder and change it's permissions. However, sudo will complain unless the owner of the sudoers file is root. The only way to change the owner without sudo is via this command:



                              osascript -e 'do shell script "chown root:wheel /etc/sudoers" with administrator privileges'






                              share|improve this answer














                              The answers above cover the default contents of the file, how to move it into place with Finder and change it's permissions. However, sudo will complain unless the owner of the sudoers file is root. The only way to change the owner without sudo is via this command:



                              osascript -e 'do shell script "chown root:wheel /etc/sudoers" with administrator privileges'







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Oct 15 '17 at 19:19

























                              answered Oct 15 '17 at 0:16









                              tmm1

                              993




                              993







                              • 1




                                This appears to at most answer the "how do you set it to mode 0440" part, which has already been addressed, but not address the recovery aspect. Since the OP is missing an /etc/sudoers file to begin with, how does this help them?
                                – Jeff Schaller
                                Oct 15 '17 at 1:23










                              • You can create the file with any editor and move it into place with Finder. The hard part is changing the owner to root, which is not possible via any other method.
                                – tmm1
                                Oct 15 '17 at 5:05













                              • 1




                                This appears to at most answer the "how do you set it to mode 0440" part, which has already been addressed, but not address the recovery aspect. Since the OP is missing an /etc/sudoers file to begin with, how does this help them?
                                – Jeff Schaller
                                Oct 15 '17 at 1:23










                              • You can create the file with any editor and move it into place with Finder. The hard part is changing the owner to root, which is not possible via any other method.
                                – tmm1
                                Oct 15 '17 at 5:05








                              1




                              1




                              This appears to at most answer the "how do you set it to mode 0440" part, which has already been addressed, but not address the recovery aspect. Since the OP is missing an /etc/sudoers file to begin with, how does this help them?
                              – Jeff Schaller
                              Oct 15 '17 at 1:23




                              This appears to at most answer the "how do you set it to mode 0440" part, which has already been addressed, but not address the recovery aspect. Since the OP is missing an /etc/sudoers file to begin with, how does this help them?
                              – Jeff Schaller
                              Oct 15 '17 at 1:23












                              You can create the file with any editor and move it into place with Finder. The hard part is changing the owner to root, which is not possible via any other method.
                              – tmm1
                              Oct 15 '17 at 5:05





                              You can create the file with any editor and move it into place with Finder. The hard part is changing the owner to root, which is not possible via any other method.
                              – tmm1
                              Oct 15 '17 at 5:05


















                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f37764%2fi-accidentally-deleted-the-sudoers-file-on-mac-os-x-is-there-any-way-to-recover%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?