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_
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.
You must specify the group name on the Windows system which your user belongs to.
So I just did this:
chown -R ONEX:Users ~/*
You can find your user name and group here:
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'.
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 previous answers, not recognized groups cause such issues. It mostly happens in Windows Domains.
The easiest way to fix it is regenerate your /etc/passwd
and /etc/group
files (parameter -d
is needed for domain users):
mkpasswd -l -d > /etc/passwd
mkgroup -l -d > /etc/group
Close and launch Cygwin again.
I had this issue when working remotely from the Domain and using cygserver.
Running ls -l
showed a numeric group id instead of a group name.
I stopped cygserver, net stop "CYGWIN cygserver
, and other Cygwin processes, then ran the ls -l
again, and group names were then displayed correctly.
I guess cygserver was holding incomplete domain group information.
After restarting cygserver the system continued to work correctly.