0

Every single command I run gives me permission denied as root, this happened shortly after I changed /etc/fstab and remounted ext4.

The only commands I appear to be able to run is echo and cd, not that it is much help, all others I have tried show the following:

bash: /bin/ls: Permission denied
bash: /bin/bash: Permission denied
bash: /bin/mount: Permission denied
bash: /bin/chmod: Permission denied

All running programs are continuing to run, I also cannot SSH in as that also gives me permission denied so only my existing connection is working. I believe it may be caused by noexec but I am unable to run mount to fix it and it was on the root file system. Also I would rather not restart if at all possible and since it was changed in fstab it would likely happen again.

I have exhausted all my ideas and searching neither mount or chmod have helped as they are permission denied as almost every other command I have thought of.

  • So…why not fix your fstab then reboot your computer? – 炸鱼薯条德里克 Jul 6 '19 at 5:16
  • Because all applications currently running are fine, I'd rather not have to reboot if there is an option and because the fstab is also broken it will only happen again but without the ability to use or start anything (assuming it boots). I am not sure how to fix fstab, vi, vim, nano, cat do not work so I am unsure how other than booting from a recovery usb or mounting the drive on another machine - any suggestions? – Jack Jul 6 '19 at 5:30
  • 1
    What changes did you make in /etc/fstab? noexec, anything else? – Stephen Kitt Jul 6 '19 at 6:00
  • 1
    echo, cd are shell builtin commands, which is why they still "run". To fix fstab, run the command while read x; do echo "$x"; done < /etc/fstab, which displays the contents of /etc/fstab, then run while read x; do echo "$x"; done > /etc/fstab, which will clobber /etc/fstab but allow you to replace it with what you type in at the terminal. Then proceed to type in (or if you're lucky, copy&paste) the original contents of /etc/fstab, modified so that you can execute stuff on the root fs again. Terminate input with Ctrl-D (or whatever your tty eof char is) then reset computer. – Murray Jensen Jul 6 '19 at 6:05
  • @MurrayJensen has the answer right here. – Bruce Becker Jul 6 '19 at 7:32
1

echo and cd are shell builtin commands, which is why they still "run".

To fix fstab, run the command

while read x; do echo "$x"; done < /etc/fstab

which will display the contents of /etc/fstab, then run

while read x; do echo "$x"; done > /etc/fstab

which will clobber /etc/fstab (a very bad thing) but will allow you to replace it with what you type in at the terminal.

Then proceed to type in (or if you're lucky, copy&paste) the original contents of /etc/fstab, modified so that you can execute stuff on the root filesystem again.

Terminate input with Control-D (or whatever your tty eof character is) then reboot (or reset / power-cycle) the computer.

Rebooting cleanly could prove difficult because it will want to run stuff to do that, so you might be forced to reset / power-cycle - but that may be risky if the buffer cache has not been flushed to disk ... best you can do is give it a bit of time before doing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.