Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chmod cannot change group permission on Cygwin

Tags:

cygwin

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_rsa 

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

But this does not work. I can change permission for user and others. Seems that the permission level for group somehow keeps the same as that of user?

like image 470
sma Avatar asked Jun 13 '13 16:06

sma


People also ask

How do I fix Permission denied in Cygwin?

The fix was to set the shortcut to "Run as Administrator". If you are using this method to access your Cygwin environment, go to the properties of the shortcut, select the Advanced button to get the options to "Run as Administrator", check the box, click Ok. And off you go!!

How do I enable chmod 777?

If you are going for a console command it would be: chmod -R 777 /www/store . The -R (or --recursive ) options make it recursive.

What is the use of chmod 777?

Changing File Permissions Using chmod 777 It means to make the file readable, writable and executable by everyone with access. As such, it's a powerful and a potential system-breaker – so extra care should be taken with it.

What does chmod 555 mean?

What Does Chmod 555 Mean? Setting a file's permissions to 555 makes it so that the file cannot be modified at all by anyone except the system's superuser (learn more about the Linux superuser).


3 Answers

I was having a similar problem to you, and I was using the NTFS filesystem, so Keith Thompson's answer didn't solve it for me.

I changed the file's group owner to the Users group:

chown :Users filename

After doing that I was able to change the group permissions to my will using chmod. In my case, since it was an RSA key for OpenSSH, I did:

chmod 700 filename

And it worked. In Cygwin you get two groups by default, the Root group and the Users group. I wanted to add another group, but I wasn't able to do it with the tools I'm used to use on Linux. For that reason I just used the Users group.

like image 189
volotec Avatar answered Sep 28 '22 06:09

volotec


Cygwin doesn't like files to be owned by groups that it doesn't know. Unfortunately, that happens quite often in Cygwin, especially if your PC is in a Windows domain where things keep changing. I also synchronise my files between two PCs, via an external drive, and the uids/gids are different between the different PCs, so this is a source of problems.

If you do ls -l and see a numeric group id instead of a group name, it means Cygwin doesn't know the gid - i.e. it's not in /etc/group, and Cygwin can't query it from Windows either. You can confirm this by running getent group <gid>, where <gid> is the numeric group id.

To fix it, you can either use chgrp to change the group for all affected files/directories, as described in the accepted answer above, or create an entry for the unknown gid in /etc/group, with any unused group name (e.g. Users2).

After doing this, it may be necessary to close all of your Cygwin windows and then re-open them.

like image 33
Laurence Renshaw Avatar answered Sep 28 '22 07:09

Laurence Renshaw


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'.

like image 41
Keith Thompson Avatar answered Sep 28 '22 07:09

Keith Thompson