Hi,

I've done this silly thing. How can I bring old setting/permissions back.

Thanks advance

ubuntu@ubuntu:~$ sudo chmod 444 /var/www
[sudo] password for ubuntu: 
ubuntu@ubuntu:~$ ls -l /var/www
ls: cannot access /var/www/index.html: Permission denied
ls: cannot access /var/www/http: Permission denied
total 0
d????????? ? ? ? ?                ? http
-????????? ? ? ? ?                ? index.html
ubuntu@ubuntu:~$ sudo chmod 751 /var/www
ubuntu@ubuntu:~$ ls -l /var/www
ls: cannot open directory /var/www: Permission denied
ubuntu@ubuntu:~$ su root
Password: 
su: Authentication failure
ubuntu@ubuntu:~$ sudo chown root /var/www
ubuntu@ubuntu:~$ ls -l /var/www
ls: cannot open directory /var/www: Permission denied

Dani AI

Generated

Short diagnosis and context: changing the mode on the web root removed the permissions a non‑owner needs to traverse and list the directory, which is why files inside looked inaccessible. On Ubuntu the root account is usually locked, so su root will fail unless the root password was explicitly set — administrative tasks should be done with sudo. was on the right track restoring normal directory access, and ’s accidental mode change is a common pitfall.

Quick, low‑risk inspection steps (run before broad fixes):

stat -c "%A %a %U %G" /var/www
namei -l /var/www/index.html
getfacl /var/www
lsattr -d /var/www

These show the current mode/owner, permissions along the path, any ACLs, and file attributes (immutable), so the exact cause can be identified (missing execute on a path component, restrictive ACL, immutable bit, etc.).

Safe repair approach and cautions: obtain a root shell (sudo -i) and restore sensible directory/file modes without making every file executable — the X token does that. For example, run a single recursive chmod that gives owner full access and gives group/others read+traverse where appropriate:

chmod -R u=rwX,g=rX,o=rX /var/www

If the webserver must write, add the webserver user (commonly www-data on Debian/Ubuntu) to the owning group or change ownership for only the writable subtree. Avoid blanket recursive chown on system trees (it can break packages). If permissions still behave oddly, check ACLs, immutable attributes, mount options, or restore from backup.

Recommended Answers

All 2 Replies

Hello

Try
sudo chmod 755 /var/www

Your problem is the third permission which is for every one else. First is the owner, second is the groups permissions and third is everyone else in the world. 755 will set it to rwxr-xr-x (r=4 w=2 and x=1 ) you add them to set each group of permissions.

ls -la /var/www/
total 32
drwxr-xr-x.  8 root      root 4096 2010-04-10 10:22 .
drwxr-xr-x. 27 root      root 4096 2010-08-12 00:28 ..
drwxr-xr-x.  2 root      root 4096 2010-04-10 10:22 cgi-bin
drwxr-xr-x.  3 root      root 4096 2010-07-12 07:15 error
drwxr-xr-x.  7 root      root 4096 2010-08-16 13:50 html
drwxr-xr-x.  3 root      root 4096 2010-07-12 07:15 icons
drwxr-xr-x. 14 root      root 4096 2010-07-12 07:25 manual
drwxr-xr-x.  2 webalizer root 4096 2010-08-08 03:11 usage

It is the next directory down (html) that should be set for apache to read:

ls -la /var/www/html
total 28
drwxr-xr-x.  7 root   root   4096 2010-08-16 13:50 .
drwxr-xr-x.  8 root   root   4096 2010-04-10 10:22 ..
drwxr-xr-x   2 apache apache 4096 2010-07-28 23:27 default.com
drwxr-xr-x  13 rod    apache 4096 2010-08-11 16:20 SmokeDepot
drwxr-xr-x   8 rod    apache 4096 2010-08-21 02:41 smokeshop

I cannot believe this. I meant to do 755 instead of 751. Anyway, you solved it. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.