There are several reasons why permissions/ownership of a directory or file gets messed up,
- Probably a reinstall of Windows OS has been performed. After re-install previous user IDs don’t match with current users of new OS.
- It is possible that some software has modified the file system.
- Probably you performed some experiments with tools that changes permission/ownership.
- Virus/spyware has taken ownership of, modified certain files/directory to take control of the system.
When directory is set read-only, option for creating files such as “New Text Document” inside the directory disappears as displayed in the screenshot.
Figure 1: Read-only scenario, click here to enlarge image.
However you can always set back default permission/ownership. Here is the procedure provided with screenshots.
Right click and select properties of the directory you are having problem with access.
Figure 2: Step 1, file properties, click here to enlarge image.
Untick “Read-only” attribute and click Advanced button.
This will open another dialog box.
Figure 3: Step 2, security settings, click here to enlarge image.
Please click Advanced button again.
Advanced security settings dialog box will appear.
Figure 4: Step 3, advanced security settings, click here to enlarge image.
First thing you should do here is that you change the owner to correct username. To do that, click the Change link on the right side of Owner. This will bring up a new dialog to set owner to a user. Enter correct username of your computer.
Figure 5: Step 4, editing owner, click here to enlarge image.
Click “Check Names” to be certain whether provided user name is correct.
Now check permission entries list. If list does not contain “Allow” for principal “Authenticated Users” you will not be able to create files in the directory. The image below illustrates this scenario.
Figure 6: Step 5, advanced security settings, “Authenticated users” missing, click here to enlarge image.
To fix this problem, we have to add “Authenticated Users” to this list. We have to click “Add” button under the list. This will open up the dialog box titled “Permission Entry for default permission”. Now click “select a principal”. Type “Authenticated Users” there.
Figure 7: Step 6, adding principal “Authenticated users” to permission allow list, click here to enlarge image.
Click “Check Names” to be certain that the principal has been accepted. Now click OK in all remaining dialog boxes to apply change.
You can take ownership of a file or directory applying following command on an elevated (with admin privilege) command prompt:
$ takeown /f "F:\Sourcecodes" /r
Using chown command you can change owner of a file,
$ chown username:username file_path
Using chown command you can change owner of directory recursively,
$ chown -R username:username dir_path
To view permission and owners of files and directories
$ ls -lsh dir