Take ownership or remove read-only attributes of a directory or file

On Windows

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.

read-only scenario fix 1

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.

Step 1:

Right click and select properties of the directory you are having problem with access.

file props

Figure 2: Step 1, file properties, click here to enlarge image.

Untick “Read-only” attribute and click Advanced button.

Step 2:
This will open another dialog box.

security settings

Figure 3: Step 2, security settings, click here to enlarge image.

Please click Advanced button again.

Step 3:
Advanced security settings dialog box will appear.

Advanced security settings

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.

editing owner

Figure 5: Step 4, editing owner, click here to enlarge image.

Click “Check Names” to be certain whether provided user name is correct.

Step 4:
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.

authenticated users missing

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.

Adding to authenticated users

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

On Linux

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

References

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s