0

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.

Zanna
  • 70,465
Jeff
  • 11
  • 4

2 Answers2

5

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.

Rinzwind
  • 299,756
  • I already tried that command: chmod 440 /etc/sudoers but it says: chmod: changing permissions of 'etc/sudoers': Operation not permitted – Jeff Jul 31 '23 at 08:33
  • 3
    "from grub rescue or a live session" will never give a permissions error. – Rinzwind Jul 31 '23 at 08:55
  • What is grub rescue or live session? And how can I access that? – Jeff Jul 31 '23 at 08:57
  • 1
    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. – Rinzwind Jul 31 '23 at 10:07
  • Is it the grub rescue? https://itgala.xyz/how-to-enter-single-user-mode-in-ubuntu/ – Jeff Aug 01 '23 at 01:24
  • Can I have an easy and detailed steps how to access that? – Jeff Aug 01 '23 at 01:30
0

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.

mehdiMj
  • 53
  • Hi, is it a grub rescue? – Jeff Aug 01 '23 at 01:33
  • Yes, from that point you have all control over your system. – mehdiMj Aug 01 '23 at 07:56
  • I can't see the linux /boot/vmlinuz, only linux /vmlinuz was there: https://snipboard.io/XMywkF.jpg – Jeff Aug 02 '23 at 03:13
  • 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 Aug 02 '23 at 03:22
  • Also, after the chmod 440 /etc/sudoers, should I reboot again and change the rw init=/bin/bash back to its original? – Jeff Aug 02 '23 at 03:36