I had installed Cygwin, then later deleted my Windows 7 account and recreated the account with the same name. Now I am having trouble editing files in my Cygwin folder or creating new folders/files. Is there a command I can run to get my permissions back?
I had to use takeown in cygwin to first take ownership of all the files. I ran cygwin in admin mode (right click). Taking ownership of the cygwin directory is tricky, because cygdrive will link to all your harddrives, so I'd suggest to not do it recursively on the cygwin folder. The syntax is:
takeown /F folder /R
where /R is recursive. So do that for all the files and folders in cygwin (or try it on the cygwin folder but I don't recommend).
After that I needed to set up my permissions through Windows explorer. Right-click on the "cygwin" folder, go to the "security" tab, make sure that your username is in the top window. I also removed the "unknown" user which I assume was my previous account. If you aren't in there: Click edit->Add-> Type your name in and click "Check Names". It should find who you think you are and then click "OK". Click the check-box for allow "Full Control" and it should check all the boxes. Click "OK".
Then you should still be in the security tab, click "Advanced"->"Change Permissions"->Highlight your username->"edit"->make sure all boxes are checked under "allow" and the Apply to is "This folder, subfolders and files" (the check box should not be checked). Press "OK" once, make sure that "Replace all child object permissions..." is checked, click "OK", "OK", "OK".
And you should be good to go.
Human names are irrelevant. Computers work with numbers.
In this particular case, the numbers are security identifiers, SIDs.
When you created the new account, it was given a new SID. The old SID of the old account wasn't re-used. (That would be a security mess.) All of your files and directories are marked with the old SID as their creator-owner. They also very probably grant access rights, in their ACLs, to either their creator-owners or directly to the old SID. Thus the old SID is what continues to have the access rights.
So, for example, if your old account had the SID
Taking ownership, with a tool such as
If the ACLs grant access directly to the old SID rather than indirectly via the creator-owner, then taking ownership is not the answer to this, although one might want to do that later for other reasons. Substituting the new SID for the old SID in the ACEs is. You do that with the
So I was able to use takeown as was administrator under cygwin. I agree that ONLY the directory cygwin/, rather than cygdrive, should be changed recursively. The only thing I can add is, that once I took ownership, I was able to issue unix commands, as administrator, to change permissions
chmod 744 *
Changes permissions so that the owner has rwx and everyone else has read-only. So, no tinkering around with the Windows side.