Cygwin permissions on Windows 7 - windows-7

I suppose this question is related to a previous answer on Cygwin permissions, but I have failed to work out how the answer can be applied to my situation.
I am finding that when I edit a file (~/.screenrc in this case), I can make one change and then the permissions and ownership are reset. This is what I am doing after I make a single change to reset permissions again:
Chi Site - ~/wd
Sun Jul 30 - 03:12 PM > ls -la ~/.screenrc ; chown -R RobertMarkBram:Users ~/.screenrc ; chmod 777 ~/.screenrc ; ls -la ~/.screenrc
----rwxrwx+ 1 Administrators None 1921 Jul 30 15:12 /home/RobertMarkBram/.screenrc
-rwxrwxrwx+ 1 RobertMarkBram Users 1921 Jul 30 15:12 /home/RobertMarkBram/.screenrc
I read in the previous answer on Cygwin permissions about changing the set up of paths in /etc/fstab. This is what I have there, but it has not made a difference:
none /cygdrive cygdrive binary,posix=0,user 0 0
none / cygdrive binary,posix=0,user 0 0
These are my mount points:
Chi Site - ~/wd
Sun Jul 30 - 03:20 PM > mount
C:/cygwin/bin on /usr/bin type ntfs (binary,auto)
C:/cygwin/lib on /usr/lib type ntfs (binary,auto)
C:/cygwin on / type ntfs (binary,auto)
C: on /c type ntfs (binary,posix=0,user,noumount,auto)
D: on /d type ntfs (binary,posix=0,user,noumount,auto)

This is a case of PEBKAC.. I had done too much messing around with permissions and didn't know how to get back.
Firstly, under Windows Explorer > that folder > properties > security I noticed there was a NULL SID there that I removed.. my own user didn't have all rights anymore but the the EVERYONE group did. Then I followed advice on this social.technet.microsoft.com post: Permissions all messed up on folders within my profile on Windows 8
cd /d c:\[folders or files you would like to reset permission]
icacls * /T /Q /C /RESET
It took awhile but restored permissions.

Related

What else prevents file deletion on OS X beside permissions, ACL, flags or being in use?

As root (OS X 10.9.5), I cannot delete a file with no flags or ACL entry (at least seemingly), despite having the correct permissions:
/Library/LaunchAgents$ whoami
root
/Library/LaunchAgents$ ls -alOe
total 32
drwxr-xr-x 6 root admin - 204 Jan 12 22:56 .
drwxr-xr-x+ 66 root admin - 2244 May 9 15:26 ..
0: group:everyone deny delete
-rw-r--r-- 1 root wheel - 690 May 4 2016 com.bitdefender.antivirusformac.plist
/Library/LaunchAgents$ chmod -N com.bitdefender.antivirusformac.plist
/Library/LaunchAgents$ chflags 0 com.bitdefender.antivirusformac.plist
/Library/LaunchAgents$ rm com.bitdefender.antivirusformac.plist
rm: com.bitdefender.antivirusformac.plist: Permission denied
/Library/LaunchAgents$
The ACL entry above pertains to the /Library folder and shouldn't affect /Library/LaunchAgents. I have successfully moved other items in LaunchAgents while the bitdefender item fails. Have tried doing the above in single user mode as well with the same result.
What am I missing?
The purpose was to remove all traces of BitDefender. Having deleted its main folder where the files referenced in the plist resided, no daemons are running. I am however puzzled as to how this is possible.
There might be a kext that protects the file (the antivirus trying to "defend" itself), but sudo kextunload <name> (see the kexts with kextstat | grep -v apple) should work... Or, even better, first eliminate the daemon (vs agent) that controls it with sudo launchctl remove <name> (see the daemons with sudo launchctl list | grep -v apple).
I think it's taking advantage of OSX's System Integrity Protection model, but you don't need to worry about that.
They ship an uninstaller, it's just not very well documented. Here's how you get to it:
Open finder -> Utilities -> BitDefender Uninstaller.

What user is my Windows Bash shell running as when it interacts with Windows file system?

I have downloaded and installed Bash for Windows. When I do a simple ls -al, I get lots of permission denied errors.
I'm not clear quite how the user permissions are being resolved. Let's say that in the bash shell I set up a user called moi and has home drive /home/moi. If I then do ls -al /mnt/c, I get a bunch of permission denied errors, e.g.
ls: cannot access /mnt/c/hiberfil.sys: Permission denied
ls: cannot access /mnt/c/pagefile.sys: Permission denied
ls: cannot access /mnt/c/swapfile.sys: Permission denied total 2388
drwxrwxrwx 2 root root 0 Sep 26 18:09 .
drwxr-xr-x 2 root root 0 Jan 1 1970 ..
drwxrwxrwx 2 root root 0 Oct 22 2015 AutoDiscover
-r-xr-xr-x 1 root root 398156 Jul 26 2012 bootmgr
-r-xr-xr-x 1 root root 1 Oct 30 2015 BOOTNXT
I have checked on the "Windows side" and there is no new user called moi. So, when ls reports permission denied for /mnt/c/swapfile.sys for example, what user is being denied?
A follow on question would be: what do I need to do to get the Bash user and call it my "normal" windows user to have the same permissions?
The Windows user is the user who started bash.exe. You can verify this by creating a file from Linux in the /mnt/c directory looking at the owner of the file in Windows.
From the windows command prompt:
C:\test>echo %USERNAME%
tim
C:\test>bash.exe
wsluser#computer:/mnt/c/test$ touch foo.txt
wsluser#computer:/mnt/c/test$ exit
exit
C:\test>dir /q C:\test\foo.txt
Volume in drive C is OS
Volume Serial Number is B8BA-E032
Directory of C:\test
2017-06-26 02:06 PM 0 tim foo.txt
1 File(s) 0 bytes
0 Dir(s) 363,224,875,008 bytes free
Notice that bash.exe was started by the tim user, and the C:\test\foo.txt file which was created from WSL is also owned by tim.
You can access the Linux file system using the windows file explorer. It's located in your AppData\Local folder. It's "semi-hidden" but accessible:
C:\Users\[username]\AppData\Local\lxss\rootfs

How can I stop cygwin bash from thinking every file is executable (and other related issues)?

When I look at my files in a cygwin terminal, every file created by Windows or a Windows program has 770 permissions, which means they're executable by user & group. Files created by cygwin all have 674 permissions, which means they're executable by group but not owner (!) and also readable by other, which I don't want. In either case, if I use "ls -F", every file (except directories) is marked with an '*' to show it's executable. (Contrary to any of this, the cygwin documentation claims that files will be marked executable only under certain conditions, for example if the filename ends in ".sh" or ".exe".)
$ ls -lF
total 45
drwxrwx---+ 1 tom None 0 Nov 19 12:42 Debug/
-rwxrwx---+ 1 tom None 8347 Sep 3 14:28 lnk_delta.cmd*
drwxrwx---+ 1 tom None 0 Nov 18 14:25 notes/
-rwxrwx---+ 1 tom None 15565 Nov 19 12:44 main.c*
-rwxrwx---+ 1 tom None 5999 Nov 11 12:04 system_pre_init.c*
drwxrwx---+ 1 tom None 0 Oct 19 15:26 targetConfigs/
-rw-rwxr--+ 1 tom None 1 Nov 19 16:13 thisFileCreatedByCygwin*
Relatedly, when I create a file with cygwin, it's NTFS permissions include a group named NONE that also has read permission. If I create a directory with cygwin, it's NTFS permissions includegroups named NONE, CREATOR OWNER, and CREATOR GROUP.
This seems completely brain-damaged. Does anyone know how to fix it?
Thanks,
Tom
cygwin version: cygwin64
OS: Windows 7 Ultimate 64bit SP1
disk format: NTFS
cygwin login shell: /usr/bin/bash
cygwin terminal: mintty.exe

Scripting a file copy from Mac to Windows (IIS) machine

I'm getting permission denied attempting to copy a file at the command-line from my Mac to a remote Windows IIS server. I have access to the IIS server and have confirmed that I have write permissions to the folder. I can remote desktop to the server and navigate and work in the directories i want. I can copy the file successfully using Finder. From the Terminal command-line I'm able to mount a volume, navigate, ls and cat the file in the directory i'm trying to cp to.
$cp -f ham.html /Volumes/external-api/eggs.html
cp: /Volumes/external-api/eggs.html: Permission denied
$ ls -l ham.html
-rw-r--r-- 1 kellykx LEGAL\Domain Users 18218 Jul 29 22:58 ham.html
$ ls -ld
drwxr-xr-x 31 kellykx LEGAL\Domain Users 1054 Jul 29 23:02 .
$ ls -l /Volumes/external-api/eggs.html
-rwx------+ 1 kellykx LEGAL\Domain Users 18218 Jul 29 15:23 /Volumes/external-api/eggs.html
$ ls -ld /Volumes/external-api
drwx------+ 1 johnsob2 LEGAL\Domain Users 16384 Jul 29 17:53 /Volumes/external-api
I'm worried there's some IIS voodoo i'm missing. Or worse, something obviously trivial.
Ideas welcome.
Resolved.
The permissions of the Windows share were more restrictive than the file system permissions and took precedence, causing the permission denied message. The Windows share permission was r while the underlying directory and files were rw, as shown.
To resolve:
I used remote desktop to login to the Windows server.
Navigated file manager to the parent dir of external-api,
Right clicked and followed properties->Sharing->Advanced Sharing->Permissions
Selected my name from the list box -- already set up when the share was created
Checked Full Control, Change and Read checkboxes.
Open question:
How do you inspect permissions of mounted SMB share from the OSX command line? The equiv of ls -l.

chmod unable to change permissions

I'm facing an annoying problem. It's been pretty frustrating. I am using a computer at my school to work on the Coursera Startup class. I am trying to connect to an Amazon EC2 instance. I downloaded the key pair. I check permissions.
mac5-library:startup roh21$ ls -l
total 6
-rw-rw-rw-# 1 roh21 108 1692 Jun 22 16:45 startup-class-key.pem
So, it's not secure. So I need to change the permissions. I try:
mac5-library:startup roh21$ chmod 400 startup-class-key.pem
mac5-library:startup roh21$ ls -l
total 6
-r--r--r--# 1 roh21 108 1692 Jun 22 16:45 startup-class-key.pem
Still has read permissions to everyone. Just to demonstrate what happens I do this:
mac5-library:startup roh21$ chmod 600 startup-class-key.pem
mac5-library:startup roh21$ ls -l
total 6
-rw-rw-rw-# 1 roh21 108 1692 Jun 22 16:45 startup-class-key.pem
Is it impossible to change permissions to the user without root permission? I'd be grateful for any kind of help.
Probably not related to initial questions problem, but can be useful. (especially to Unix novices like myself)
Chmod will not work if you are not an owner of resources.
You should run chown first:
$ sudo chown -R $(whoami) .
and then
$ sudo chmod -R +rwX .
First command will change owner of everything in current folder to be logged in user, and second give them read write execute permissions.
Just for example, you, probably, should not change ownership and permissions so boldly.
I copied the file to my ~/.ssh folder and then changed the permissions with chmod. That did it.
Just to provide more information, the permissions for the ssh folder,
drwx------ 8 roh21 108 272 Jun 26 17:26 .ssh
And the permissions to the folder I used initially
drwxrwxrwx 2 roh21 108 2048 Jun 23 06:32 startup
I curious as to why I could not change the permissions to the startup folder even after multiple attempts with the chmod -R option.
Also, note that I was using Mac OS X in my school's library.
See that '#' next to the mode flags? That means that there's extended metadata associated with the file. Use ls -l# to see it. The xattr command will let you view and modify them. It's possible that there's something there that prevents you from modifying the file.
There may also be additional file flags. Use ls -lO (capital-O) to view those. Odds are that one of those flags is the "uchg" flag which means your file is immutable. You can remove that with chflags nouchg <filename> as أحمد طه suggested.
Finally, there might be an ACL attached to the file. Use ls -le to see that.
In general, if you really want to know all the metadata associated with a file on a Mac, the command is ls -leO#.
Looks like you've discovered that the Macintosh doesn't strictly agree with the UNIX permission bits.
Ultimately, there are ACL bits that MacOS sets and that the Macintosh Finder obeys.
To solve your problem quickly, in your Terminal command line, type in "open ." (or the path to your "startup" folder) and that will open up the folder in your Macintosh Finder.
Then do a "Get Info" on the file:
You can change your permissions here.
Hello And it will work
chflags nouchg /path/folder/
Please note you may get "Operation not permitted" at your Terminal when you want to run "chflags nouchg". So, first you should give your Terminal "Full Disk Access" here:
System Settings --> Privacy & Security --> Full Disk Access --> check the Terminal
then close and re-open your Terminal.
Now, run "chflags nouchg PathToYourFolder"
Finally:
chmod 400 YourFile
Done!

Resources