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.
chmod -R +X
command as well or just the finds? – tfmertz Apr 05 '15 at 02:01