7

My Cygwin installation is behaving strangely: chmod does not work.

[09:45 Administrator@DellIns14 ~] > ls -ls /usr/bin/chmod
64K -rwxr-xr-x 1 Administrator None 38K Feb  6  2012 /usr/bin/chmod

[09:47 Administrator@DellIns14 ~] > rm /tmp/example.sh
rm: remove regular empty file `/tmp/example.sh'? y
[09:48 Administrator@DellIns14 ~] > touch /tmp/example.sh
[09:48 Administrator@DellIns14 ~] > ls -ls /tmp/example.sh
0 -rw-r--r-- 1 Administrator None 0 Jul  8 09:48 /tmp/example.sh
[09:48 Administrator@DellIns14 ~] > chmod -v +x /tmp/example.sh
mode of `/tmp/example.sh' changed from 0644 (rw-r--r--) to 0755 (rwxr-xr-x)
[09:48 Administrator@DellIns14 ~] > ls -ls /tmp/example.sh
0 -rw-r--r-- 1 Administrator None 0 Jul  8 09:48 /tmp/example.sh
[09:48 Administrator@DellIns14 ~] >

Note that the directory is writable, as the file is created.

When I look at this directory from a windows perspective, it is reported as read-only (even after I change it to read-write, it reverts to read-only).
Screen-captures are at cygwin's /tmp is read-only in windows, and cannot be changed to read-write

Can you suggest how to debug/solve?


Environment:
Windows 7, Cygwin 1.7.29(0.272/5/3) i686

4
  • Same problem for ~/.ssh/config on win7+cygwin64, (ssh won't run unless I can chmod 0600 config) and NONE of the answers below help (/etc/fstab, setfacl, subinacl /file config /display).
    – mosh
    Aug 3, 2016 at 17:15
  • @boardrider : The link to your screen capture gives error 404. Do you mean that you can't change the file to writable even on the Windows command line, or using Windows Explorer? Sep 3, 2021 at 7:00
  • @boardrider: What happens if you set the permissions with setfacl? See man setfacl. Perhaps this article is also useful. Sep 8, 2021 at 9:02
  • 1
    Sorry, @user1934428, this is a thread from more than seven years ago: I don't remember.
    – boardrider
    Sep 8, 2021 at 18:20

5 Answers 5

9

Kudos to this answer https://stackoverflow.com/questions/25730041/updating-file-permissions-with-git-bash-on-windows-7 contents pasted below


You are probably using NTFS or FAT32 on Windows, and those filesystems do not support the executable permission. Instead, cygwin looks at the file name and contents to determine whether it's executable:

Files are considered to be executable if the filename ends with .bat, .com or .exe, or if its content starts with #!.

So you should make sure that the bash file starts with a shebang. Then, you should be able to just execute the file, disregarding the permission output of ls.

0
2

I was unable to chmod until I found that /etc/fstab contained:

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

but needed to be:

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

After closing all open Cygwin processes and restarting, all worked.

1
  • Thanks @rshdev, but on my machine, the noacl is already absent, viz: $ tail -1 /etc/fstab none /cygdrive cygdrive binary,posix=0,user 0 0
    – boardrider
    Apr 30, 2016 at 21:32
1

I found This Answer helpful.

Besides normal POSIX permissions that contoll owner, group, other access, the file permission in Cygwin may also be affected by Windows ACL.

In your case, please try

ls -l /tmp/example.sh
getfacl /tmp/example.sh
setfacl -b /tmp/example.sh
ls -l /tmp/example.sh
chmod -v +x /tmp/example.sh
ls -l /tmp/example.sh
2
  • If you found additional permission by getfacl, you make need to check/reset /tmp too.
    – Danny Zeng
    Feb 16, 2015 at 4:03
  • Thanks @Danny Zeng: I'll keep the [gs]etfacl commands in mind. As for the original problem - seems that in the meantime, it vanished, and now chmod works as expected on my cygwin. Quite a few things were changed on my system in the interim, so I cannot hazard a guess what was the change that solved the problem.
    – boardrider
    Feb 17, 2015 at 22:03
1

Just add #!/bin/bash in the first line of the script,

but it is important to do it with nano or vi .

After saving - the file will showed as green, with executable permission.

see image for example :

enter image description here

2
  • How does it answer the question on the top?
    – peterh
    Mar 12, 2020 at 14:54
  • I edited it now, and give a detailed explain how adding this line. Mar 12, 2020 at 17:57
0

Chmod does not work (silently) on my computer if the paths are in Windows format. With "cygdrive" paths it works. Here is the example:

D:\>mkdir D:\test

D:\>touch D:\test\qwe

D:\>ls -l D:\test\qwe
-rw-r--r-- 1 cat None 0 Sep 16 10:40 'D:\test\qwe'

D:\>cacls D:\test\qwe
D:\test\qwe Все:(ID)F

D:\>chmod 600 D:\test\qwe

D:\>ls -l D:\test\qwe
-rw-r--r-- 1 cat None 0 Sep 16 10:40 'D:\test\qwe'

D:\>cacls D:\test\qwe
D:\test\qwe Все:(ID)F

D:\>chmod 600 /cygdrive/D/test/qwe

D:\>ls -l D:\test\qwe
-rw-r--r-- 1 cat None 0 Sep 16 10:40 'D:\test\qwe'

D:\>cacls D:\test\qwe
D:\test\qwe CAT\cat:(специальный доступ:)
                STANDARD_RIGHTS_ALL
                DELETE
                READ_CONTROL
                WRITE_DAC
                WRITE_OWNER
                SYNCHRONIZE
                STANDARD_RIGHTS_REQUIRED
                FILE_GENERIC_READ
                FILE_GENERIC_WRITE
                FILE_READ_DATA
                FILE_WRITE_DATA
                FILE_APPEND_DATA
                FILE_READ_EA
                FILE_WRITE_EA
                FILE_READ_ATTRIBUTES
                FILE_WRITE_ATTRIBUTES

        CAT\None:(специальный доступ:)
                 READ_CONTROL
                 SYNCHRONIZE
                 FILE_READ_ATTRIBUTES

        Все:(специальный доступ:)
            READ_CONTROL
            SYNCHRONIZE
            FILE_READ_ATTRIBUTES

Also there is an oddity in ls -l behaviour. Native Windows cacls confirms that second chmod 600 was successful, but ls -l says -rw-r--r-- even after that.

So I've used cmd "function" for convert windows-paths to cygdrive-paths:

call :chmod "D:\test\qwe"
rem ...
goto :eof

:chmod
set "STMP=%~dp1"
set "STMP=%STMP:\=/%"
set "STMP=%STMP::=%"
set "STMP=/cygdrive/%STMP%%~nx1"
chmod 600 "%STMP%"
set "STMP="
goto :eof

My configuration: Windows 7, cygwin x64 updated at September 2020, NTFS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.