Domanda

I have been trying to set up some stuff for JS, but I need to use sudo. Every time I use sudo, I get this message.

>>> /etc/sudoers: syntax error near line 80 <<<
>>> /etc/sudoers: syntax error near line 82 <<<
>>> /etc/sudoers: syntax error near line 84 <<<
sudo: parse error in /etc/sudoers near line 80
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

I checked the /etc/sudoers file and found out that it is completely empty. How would I fix this?

È stato utile?

Soluzione

I know that Todd said that it wasn't smart to do this, but I went to the opensource sudoers file from apple and copied that into my sudoers file, now sudo is working just fine!

Altri suggerimenti

  1. Boot to recovery mode
  2. Open Terminal (menubar > Utilities > Terminal)
  3. cd to your system data volume:

    cd /Volumes/Macintosh\ HD\ -\ Data/private/etc/
    

    (In system 10.14 and lower this is /Volumes/Macintosh\ HD/private/etc/)

  4. Download a default macOS sudoers file (e.g. from an online repository)

    curl -LJO https://gist.githubusercontent.com/keith/9061156/raw/1f056fa364640900eb42fcc9023d60a759c668c8/sudoers
    
  5. Check permissions:

    ls -l /Volumes/Macintosh\ HD/private/etc/sudoers
    -r--r-----  1 root  wheel  1283 May 13  2020 /private/etc/sudoers
    
  6. Boot to your main system volume
  7. Edit the sudoers file with sudo visudo and replace it with the content of the default Catalina sudoers file:

    #
    # Sample /etc/sudoers file.
    #
    # This file MUST be edited with the 'visudo' command as root.
    #
    # See the sudoers man page for the details on how to write a sudoers file.
    
    ##
    # Override built-in defaults
    ##
    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"
    Defaults    env_keep += "HOME MAIL"
    
    Defaults    lecture_file = "/etc/sudo_lecture"
    
    ##
    # User alias specification
    ##
    # User_Alias    FULLTIMERS = millert, mikef, dowdy
    
    ##
    # Runas alias specification
    ##
    # Runas_Alias   OP = root, operator
    
    ##
    # Host alias specification
    ##
    # Host_Alias    CUNETS = 128.138.0.0/255.255.0.0
    # Host_Alias    CSNETS = 128.138.243.0, 128.138.204.0/24, 128.138.242.0
    # Host_Alias    SERVERS = master, mail, www, ns
    # Host_Alias    CDROM = orion, perseus, hercules
    
    ##
    # Cmnd alias specification
    ##
    # Cmnd_Alias    PAGERS = /usr/bin/more, /usr/bin/pg, /usr/bin/less
    
    ##
    # User specification
    ##
    
    # root and users in group wheel can run anything on any machine as any user
    root        ALL = (ALL) ALL
    %admin      ALL = (ALL) ALL
    
    ## Read drop-in files from /private/etc/sudoers.d
    ## (the '#' here does not indicate a comment)
    #includedir /private/etc/sudoers.d
    

Hint:

You can access this question & answer in Recovery Mode with Safari and copy the curl command.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a apple.stackexchange
scroll top