cygwin sets file permission to 000
Asked Answered
S

4

65

I have a folder /cygwin/d/myfolder/ And everytime I save files there, from cygwin if i do an ls -la I see that the files are given permission 000. That actually causes me quite a bit of problem as I rsync this folder to my server and none of the files are accessible. How can I get the files to automatically get a reasonable permission?

Sierra answered 29/4, 2011 at 4:50 Comment(1)
These errors may be fixed by setting correct security attributes on Windows. Right-click folder -> select Properties -> select security tab. Now fix any incorrect settings. Also check the "Advanced" option. Try "Enable inheritence" and replacing child object permissions with the current folder settings.Kettledrum
C
135

Have a read through the answers at this link: http://cygwin.1069669.n5.nabble.com/vim-and-file-permissions-on-Windows-7-td61390.html

The solution there worked for me also:

Edit /etc/fstab and add this line at the end of the file:

none /cygdrive cygdrive binary,noacl,posix=0,user 0 0

Then close all Cygwin processes, open a new terminal and ls -l on your files again.

Explanation: By default, Cygwin uses the filesystem's access control lists (ACLs) to implement real POSIX permissions. Some Windows-native program or process may create or modify the ACLs such that Cygwin computes the POSIX permissions as 000. With the noacl mount option, Cygwin ignores filesystem ACLs and only fakes a subset of permission bits based on the DOS readonly attribute.

Copeland answered 16/8, 2011 at 17:43 Comment(6)
I want to +10 this. I've been working around this problem for years. Thanks!Corking
When I try this, all my files are -rw-r--r-- no matter what chmod() I do. I can't mark the files as executable; it just reverts to 0644. (umask==0022)Ochone
I'd like to second that this is only workaround that also helps when patch command ran from outside CYGWIN shell and resets permissions of patched files (very nasty!). more info here: cygwin.com/ml/cygwin/2011-10/msg00324.htmlAmbrosial
I am now deleting the script I wrote to fix this 2 years ago. Wish I'd found this then. :)Mohandas
This worked. Another thing I tried, which also worked, was to relax the permissions in Windows (7). I basically made everything chmod u+rw . and chown -r me . (in Unix parlance) from Windows Explorer. I'm not recommending my solution, since it is a security disaster. I'm only making this note in the interest of providing more data.Moonlight
FTR: I needed this solution for a Jenkins job that does a git clone in a cygwin bash script. Windows complained about "The permissions on <node> are incorrectly ordered, which may cause some entries to be ineffective" because of a “NULL SID” in the permission list. See also boltblog postIntracardiac
S
7

Check to make sure that your umask is set correctly with the umask command. If your umask is say 0777 that subtracts from the permissions of new files and will end up with 000 permissions. There's probably several other possibilities to consider beyond that.

If your id is not set up correctly in /etc/passwd and /etc/group that can also cause ls to show unexpected results. Check the permissions of the folder. Also check the Windows permissions with the getfacl command. Maybe also check the mount command.

Sherbrooke answered 10/8, 2011 at 5:27 Comment(1)
getfacl . is what I was looking for.Contrapositive
W
4

In above answer, solution was proposed:

Edit /etc/fstab and add this line at the end of the file:

none /cygdrive cygdrive binary,noacl,posix=0,user 0 0

And in that answer there was this comment:

When I try this, all my files are -rw-r--r-- no matter what chmod() I do. I can't mark the files as executable; it just reverts to 0644. (umask==0022)

I had this same problem, but it manifested in inability to execute DOS batch files (*.bat) when running Cygwin ksh or mksh. I stumbled across this website: http://pipeline.lbl.gov/code/3rd_party/licenses.win/cygwin-doc-1.4/html/faq/ which contains this helpful advice:

Note that you can use mount -x to force Cygwin to treat all files under the mount point as executable. This can be used for individual files as well as directories. Then Cygwin will not bother to read files to determine whether they are executable.

So then cross-referencing with this page - https://cygwin.com/cygwin-ug-net/using.html#mount-table - with its advice:

cygexec - Treat all files below mount point as cygwin executables.

I added cygexec to fourth field of my fstab. This did it. My .bat is now executable inside ksh/mksh, which is necessary since I'm running a Jenkins job that calls a Korn shell stack 3 files deep, that I have no modifiable control over. I just needed the .bat to run!

Update: the solution above wasn't quite what I needed, on further testing. It resulted in some executables such as javac and cl to behave oddly (the utilities would print their usage and exit). I think what I needed instead of 'cygexec' was just 'exec'. As the same page notes:

exec - Treat all files below mount point as executable.

Wistful answered 23/1, 2018 at 19:46 Comment(0)
M
3

On my Win7 PC files were usually ----------+ 1 David None 69120 Jun 17 13:17 mydoc.txt

I tried all of above no luck Turned out I still had some old historical mount entries in my .zshrc I deleted these and Bob's your Uncle problem gone away!

Militia answered 17/6, 2014 at 15:2 Comment(1)
That is so useful. Knowing where to look for old historical mount entries saved me.Stevenson

© 2022 - 2024 — McMap. All rights reserved.