plz explain why use visudo to edit /etc/sudoers file and not vi /etc/sudoers and how does the file get corrupt. How can we restore the corrupt file?
If you use
visudo, a validation of the file is done before you are returned to shell, allowing many bad typos or errors to be caught (in the validation check), returning you to editor to have another chance to fix them.
This prevents the user from finding out about errors later, and being unable to use
sudo vi to correct those errors in later commands because of easily-missed typos detected too late.
I commonly use
sudo vi myself, but am sure to have an escape route in place to allow correction (eg. another connection logged into root active in case I make errors whilst I validate it myself etc).
Do you have root enabled? If so login using it & edit the file (correcting your typos) using root.
If you have more than one user with
sudo privileges, you may find an earlier
sudo privileged user (as defined in the file) can still use their
sudo (thus allowing editing). This has worked for me in the past, so I assume the part of the file after the error isn't read (but this may have changed - it was years ago I found it saved me)