chmod cannot change group permission on Cygwin

前端 未结 7 1272
孤城傲影
孤城傲影 2020-12-10 02:41

I am using Cygwin and trying to change the group access permission with chmod, e.g.

$ls -l id_rsa
-rwxrwxr-- 1 None 1679 Jun 13 10:16 id_rsa 

$ chmod g= id_         


        
7条回答
  •  盖世英雄少女心
    2020-12-10 02:45

    An experiment shows that chmod does work correctly to change group permissions under Cygwin.

    The experiment used a file on an NTFS partition. Cygwin implements a POSIX layer on top of Windows, but it still ultimately uses the features of Windows itself, and of the particular filesystem implementation.

    On modern versions of Windows, most hard drives are formatted to use NTFS, which provides enough support for chmod. But external USB drives typically use FAT32, which doesn't have the same abilities to represent permissions. The Cygwin layer fakes POSIX semantics as well as it can, but there's only so much it can do.

    Try

    $ df -T .
    

    If it indicates that you're using a FAT32 filesystem, that's probably the problem. The solution would be to store the file on an NTFS filesystem instead. A file named id_dsa is probably an SSH private key, and it needs to be stored in $HOME/.ssh anyway.

    Is your home directory on a FAT32 partition? As I recall, recent versions of Windows ("recent" meaning the last 10 or more years) are able to convert FAT32 filesystems to NTFS.


    The remainder of this answer was in response to the original version of the question, which had a typo in the chmod command.


    Cygwin uses the GNU Coreutils version of chmod. This,

    chmod g=0 fileName
    

    is not the correct syntax. I get:

    $ chmod g=0 fileName
    chmod: invalid mode: `g=0'
    Try `chmod --help' for more information.
    

    (This is on Linux, not Cygwin, but it should be the same.)

    To turn off all group permissions, this should work:

    $ chmod g= fileName
    $ ls -l fileName 
    -rw----r-- 1 kst kst 0 Jun 13 10:31 fileName
    

    To see the chmod documentation:

    $ info coreutils chmod
    

    To see the documentation on symbolic file mode:

    $ info coreutils Symbolic
    

    The format of symbolic modes is:

     [ugoa...][+-=]PERMS...[,...]
    

    where PERMS is either zero or more letters from the set 'rwxXst', or a single letter from the set 'ugo'.

提交回复
热议问题