0

I was trying to transfer some files from home directory to /var/www/html folder. This was not possible due to permission settings as the system was saying I was not the owner of the folder. So after searching online for a solution I tried following commands,

sudo chmod 766 -R /var/www/html
sudo chmod 766 -R /var/www/
sudo chmod 766 -R /var
sudo chmod 766 -R /var/
sudo chown pi /var/www/html

Output of ls -l /var/www/html and file /var/www/html is permission denied.

Then later I see that all folders in /var/ were converted to binary files. I restarted the system. Then I was able to recover them but only till /var/www. The /var/www/html folder was still a binary file. How do I convert it back to a folder? I use ubuntu 16.04

  • 2
    Use your backup to restore the whole directory structure. – Ipor Sircer Sep 25 '18 at 11:50
  • @IporSircer Then? – user103292 Sep 25 '18 at 11:50
  • 1
    Neither chmod nor chown will convert a "folder" (directory) to a binary file. Whatever happened must be something else. And how to turn it back depends on what happened. Can you edit your question with the output of ls -l /var/www/html and file /var/www/html? – dirkt Sep 25 '18 at 12:28
  • @dirkt done. I get permission denied. Wasn't able to post a pic cus I don't have enough reputation points. The output is "ls: cannot access '/var/www/html': Permission denied" and "/var/www/html: cannot open `/var/www/html' (Permission denied)" respectively. – user103292 Sep 25 '18 at 13:19
  • If you get "permission denied", how did you figure out it was a binary file? Retry (1) as root, and (2) for every parent directory (that is, shorten the path) until you get a result. Also try ls -ld /var/www/html etc. instead to get the permissions in case it is a directory. – dirkt Sep 25 '18 at 13:25
1

As you got for ls -ld /var/www/html the output

drwxrw-rw- 2 root root 4096 Sep 25 11:49 /var/www/html

that means you have a directory (d) which is readable and writeable by everybody (rw), but only searchable (x) by root. So it's not a binary file. I don't know which program you were using that shows folder icons and properties, but whatever it is, it is wrong.

This came about because you set the permissions of this directory and all its parent-directories to 766 (which is octal for rwxrw-rw-). At least in case of /var, this is totally wrong, because it will deny search rights to all non-root parts of the system, and this may break things.

The lesson you should learn from this is don't blindly follow some recipes you found on the internet without understanding what you are doing.

So your first task is to read man chmod (all of it) and understand file permissions, and how they differ for files and directories. If this is not enough, google for explanations until you understood it.

Your next task is to fix the permissions of /var, /var/www, and /var/www/html to something that makes sense (depending on your needs). For this you need to answer the question "who should be able to read/write/search those directories". In case of /var, you should arrive at something like 755. If you don't, think again.

And finally, you should execute again chown pi /var/www/html to change the owner of this directory from user root to user pi, because it didn't work. You can use ls -d to verify if it worked. And while you are at it, think about which group it should belong to (which groups does the user pi belong to?). Read man chown and man chgrp.

  • Thanks dirkt it worked. I'll try following ur advice next time. But any idea why the folder was shown as a binary file. – user103292 Sep 26 '18 at 6:43
  • Sorry, no idea. – dirkt Sep 26 '18 at 7:31

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.