Score:0

/etc/sudoers is world writable in linux ssh

ke flag

I tried everything but nothing works.

sudo is not working because it says:

/etc/sudoers is world writable

Can't login as the root user even if I typed the command sudo -i

chmod: changing permissions of 'etc/sudoers': Operation not permitted

su: Authentication failure

Before this error happened, I tried to change the permission of the /etc folder to allow me to create a new folder inside the /etc folder, then after I open the ssh the next day, this error came up.

The following commands are the only ones that I remembered to allow me to create a folder:

sudo chmod -R 777 /etc chmod a+w test mkdir /etc/backup

I'm new to Linux commands so I just search them and tried it on my ssh then this error happens.

errors in terminal

Can anyone help me? Thanks in advance.

muru avatar
us flag
Does this answer your question? [Set myself as owner of /etc with chown command now getting all kinds of errors](https://askubuntu.com/questions/300641/set-myself-as-owner-of-etc-with-chown-command-now-getting-all-kinds-of-errors)
cn flag
please provide the exact command used; it is more likely your problem is larger than this: if you chmod'ed the whole of /etc/ you got more problems.
Organic Marble avatar
us flag
Unfortunately, if that is the command, you have destroyed your system.
Jeff avatar
ke flag
I think I chmod the whole /etc folder. These are the commands that I remembered: sudo chmod -R 777 /etc, chmod a+w test, mkdir /etc/backup
Score:4
cn flag

Before this error happens, I tried to change the permission of the /etc folder to allow me to create a new folder inside the /etc folder

There is NO valid reason to alter /etc/. This is a system directory maintained by packages/he package manager. If you need a personal directory put it either in /home/$USER or if multi-user server in /opt/etc (but even those are icky IMO ;)).

You fix this by rebooting into grub rescue or from a live session and then do

chmod 440 /etc/sudoers

so it matches

r--r----- 1 root root 1800 feb 20 18:38 /etc/sudoers

Mind that this might be a futile attempt: if you did something to the whole of /etc/ you might have changed more then just sudoers file. Then a reinstall without formatting would be the answer.

Jeff avatar
ke flag
I already tried that command: chmod 440 /etc/sudoers but it says: chmod: changing permissions of 'etc/sudoers': Operation not permitted
cn flag
"from grub rescue or a live session" will never give a permissions error.
Jeff avatar
ke flag
What is grub rescue or live session? And how can I access that?
cn flag
Live session: use the usbstick or dvd or cd you used to create Ubuntu, pick "try" , mount the partitions and then open the terminal. Yoy will have a # prompt and root. Same for grub rescue: you pick command prompt at the grub screen during boot.This one is more hands-on: you need to know how your system is set up.
Jeff avatar
ke flag
Is it the grub rescue? https://itgala.xyz/how-to-enter-single-user-mode-in-ubuntu/
Jeff avatar
ke flag
Can I have an easy and detailed steps how to access that?
Score:0
lk flag

You should reboot your system and start as single user mode, drop into root shell, change ownership of /etc/sudoers:

After reboot press shfit until GRUB menu appears, then press e to edit, afther that go to the line that starts with linux /boot/vmlinuz and replace the end of the line ro \ console=ttyS0 console=tty0 with rw init=/bin/bash.

Instructions from itgala with images.

Now chmod 440 /etc/sudoers at then end the sudoers file should look like this

-r--r-----

I recommend you to edit sudoers file with visudo and for adding more config to /etc/sudoers.d/my-sudoers.

Jeff avatar
ke flag
Hi, is it a grub rescue?
lk flag
Yes, from that point you have all control over your system.
Jeff avatar
ke flag
I can't see the linux /boot/vmlinuz, only linux /vmlinuz was there: https://snipboard.io/XMywkF.jpg
Jeff avatar
ke flag
I'm already in a root and entered the chmod 440 /etc/sudoers, then what's next? I tried sudo but still it says /etc/sudoers is world writable. https://snipboard.io/VbUudi.jpg
Jeff avatar
ke flag
Also, after the chmod 440 /etc/sudoers, should I reboot again and change the rw init=/bin/bash back to its original?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.