2

Afterwards I couldn't execute any commands without receiving a 'permission denied' error.

Upon restarting the computer, when I enter my password Ubuntu will look like it's loading for a second but return to the password prompt over and over.

What I did:

  1. Entered root by typing sudo -i
  2. Entered my password
  3. I was trying to edit permissions in my /home folder but I think I changed the wrong directory. I did a chmod -R -x and now my /home has no execute permissions.
  4. Typed su tom
  5. Couldn't execute any commands or log in.

When I tried to type even the simplest command such as cd I was given a permission denied error.

I can't log into my tom user, so I'm on a guest account and don't have access to sudo. When I try to cd /home I get the error bash: cd: /home: Permission denied

tfmertz
  • 31
  • if my answer is not sufficient, you need to post exactly what it says in the terminal to indicate to you that it is broken. thanks – mchid Apr 05 '15 at 00:23
  • You will have to be more specific than saying things like "didn't work" and "broken". – psusi Apr 05 '15 at 00:41
  • Thanks for the help guys. I edited the question a bit. Right now I can't log into my tom user and it seems to have lost its password. – tfmertz Apr 05 '15 at 01:17
  • If you ran that command on / you will have to reinstall. Boot to recovery mode and try to fix permissions in home. – Panther Apr 05 '15 at 01:37
  • Thanks for the tip, I can go into all other folders but my /home – tfmertz Apr 05 '15 at 01:38
  • boot to recovery mode, remount your / or /home partition rw, and run find http://z9.io/2013/11/05/fix-file-644-directory-775-permissions-linux-easily/ – Panther Apr 05 '15 at 01:50
  • That seemed to do the trick, do I need to run the chmod -R +X command as well or just the finds? – tfmertz Apr 05 '15 at 02:01

3 Answers3

4

As bodhi.zazen says, you should boot to recovery mode and change the permissions back. Recovery mode should still work fine--this change is unlikely to render it unusable--but if for any reason you cannot use recovery mode, you can use a live CD/DVD/USB.

Hold down shift while booting so the GRUB menu is shown. Select Advanced options for Ubuntu, then select the first entry whose name ends in (recovery mode). Then on the recovery menu, select the option labeled:

root              Drop to root shell prompt

This should give you a # root shell prompt. Remount your / filesystem readwrite by running:

mount -o remount,rw /

(Note that you don't need sudo for that--nor for the chmod commands below--because you are already in a root shell, provided to you by recovery mode.)

Assuming the only changes you made were to execute permissions, you can then simply run:

chmod a+x /home
chmod -R u+X /home/tom

+X sets execute permissions specifically when a file is already executable by some user or a directory (see man chmod for details; note that capital +X is different from +x, which always sets execute permissions). On directories, execute permissions confer the ability to go into the directory. Losing that ability appears to be what has effectively locked you out of your account.

  • Since you just took away executable permissions, there's no need to walk the directory hierarchy with a more complicated find command and identify each file by type to change their permissions. Running chmod recursively with +X will make all the directories "executable" (i.e., enterable) by their owner again, which is precisely what you need here. (There's nothing really wrong with a find-based method, such as the one presented in tfmertz's answer--either way will work fine by itself. And if you happened to do both, what's fine too.)

Then boot normally, either by running reboot or by running exit (which brings you back to the recovery menu) and selecting the resume option.

Those chmod commands won't necessarily put things back to exactly what they were before--for that, it would probably be necessary to see what command you ran (but you may be able to find that by running history after logging back in). However, this will likely be sufficient to enable you to log in and use your Ubuntu system normally again.

This situation, and the solution, is similar to the more common situation where the sole administrator of a system has lost their password. Thus, while you're changing permissions rather than a password and the solution is not exactly the same, you might find it useful to take a look at How do I reset a lost administrative password? Some of the answers there contain screenshots showing how to get a root shell from recovery mode. And if you are unable to access recovery mode, the instructions there (and in this other question) about accessing your system from a live CD/DVD/USB should help.

Eliah Kagan
  • 117,780
  • I ran the find commands that @bodhi.zazen linked, hopefully those will work? Right now I am fully functional again, but I'm not sure what permissions still differ from their original settings. – tfmertz Apr 05 '15 at 02:18
  • @tfmertz Yes, that should work fine. chmoding with capital +X or using find commands to identify directories and set them executable will both work to enable you to go into your directories again (they'll both reverse the change made by chmoding everything with -x). Either way works by itself but if you happened already to have done both, that's fine too. – Eliah Kagan Apr 05 '15 at 02:21
1

The /home folder needs to have its execute permission restored

  1. Restart Ubuntu
  2. Run recovery mode in root (Recovery mode how to)
  3. Run the find commands to restore permissions

Resetting /home permissions

Run both the commands below found from z9.io

For directories only do this

find . -type d -exec chmod 775 {} \;

For files only do this.

find . -type f -exec chmod 664 {} \;

Restart Ubuntu in normal mode and try to log in.

tfmertz
  • 31
0

More than an answer is just a comment about this same issue it happened to me just a few minutes back (Jan 26 2016) where I was completing a lab and I entered a chmod 600 ~ command, so I lost access to my home, so I came to this article, and first tried the find commands and the terminal started reading everything, but it all ended in a permission denied result. I went ahead and tried the: chmod a+x /home chmod -R u+X /home/myname

and that resolved it immediately. I was able to start entering cd again.