linux 与 windows 中的文件权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/299826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
File permission in linux vs. in windows
提问by jbu
In linux, if I have a file I'm sharing with a group, and I put the file on a USB memory stick, for example, and copy it to a computer that doesn't have the same group or users, does the file have no permissions for anyone on that new computer? What if I bring a linux file that only lets user X to read it to a windows machine? Who gets to read it on the windows machine? since user X (and group) doesn't exist on that machine.
在 linux 中,如果我有一个文件要与一个组共享,并且我将文件放在 U 盘上,例如,将它复制到没有相同组或用户的计算机上,该文件是否对那台新计算机上的任何人都没有权限吗?如果我带一个只允许用户 X 读取它到 Windows 机器的 linux 文件怎么办?谁可以在 Windows 机器上阅读它?因为该机器上不存在用户 X(和组)。
What kind of security do I get copying a linux file to another linux machine? how about to a windows machine?
将 linux 文件复制到另一台 linux 机器有什么样的安全性?Windows机器怎么样?
What kind of security do I get copying a windows file to another windows machine? how about to a linux machine?
将 Windows 文件复制到另一台 Windows 机器可以获得什么样的安全性?linux机器怎么样?
Please let me know.
请告诉我。
jbu
吉布
回答by technophile
Regarding the USB key: generally, USB keys use one of the FAT family of filesystems; FAT doesn't support security at all, so as soon as you copy the file to it the security information is lost. So for your first question, anyone who has the USB key can read it on any computer from any user account. It is possible to format USB keys using another filesystem (for example, NTFS, which does support security); in that case, if the accounts (in Windows, at least, it must be a domain account or similar, just naming two accounts the same will not do it) do not exist on the target computer, only a user who can ignore filesystem permissions (such as root on *nix or Administrator on Windows) will be able to access the file.
关于 USB 密钥:通常,USB 密钥使用 FAT 文件系统家族之一;FAT 根本不支持安全性,因此只要您将文件复制到其中,安全性信息就会丢失。因此,对于您的第一个问题,任何拥有 USB 密钥的人都可以在任何计算机上从任何用户帐户读取它。可以使用其他文件系统(例如,支持安全性的 NTFS)格式化 USB 密钥;在这种情况下,如果目标计算机上不存在帐户(至少在 Windows 中,它必须是域帐户或类似帐户,仅命名两个帐户相同不会这样做),则只有可以忽略文件系统权限的用户(例如 *nix 上的 root 或 Windows 上的管理员)将能够访问该文件。
For the second, I'm not 100% sure but I believe it depends on how you copy it; things like FTP and rcp generally don't copy permissions over, so I would assume that the file gets some kind of default permissions for the target directory, or a default built into the copy program, depending on what the copy program does.
第二,我不是 100% 肯定,但我相信这取决于你如何复制它;像 FTP 和 rcp 这样的东西通常不会复制权限,所以我假设文件获得了目标目录的某种默认权限,或者复制程序中内置的默认权限,这取决于复制程序的作用。
For windows, to the best of my knowledge the security descriptor is initially inherited from the target folder; permissions are, again, not persisted across machines. It can be modified after the copy.
对于 Windows,据我所知,安全描述符最初是从目标文件夹继承的;同样,权限不会跨机器保持。复制后可以修改。
In general, except in specific environments that are designed to transfer permissions, I would assume that transferring any file from one computer to another resets the security permissions to a default (generally whatever a newfile in that location would receive).
一般来说,除了在旨在传输权限的特定环境中,我会假设将任何文件从一台计算机传输到另一台计算机会将安全权限重置为默认值(通常是该位置中的新文件将收到的任何内容)。
回答by Javier
as technophile said, removable drives usually use FAT filesystems, so no permission info is copied at all.
正如技术爱好者所说,可移动驱动器通常使用 FAT 文件系统,因此根本不会复制任何权限信息。
on more 'direct' copies between *nix machines, if the writing process is run under root, usually there are flags to preserve permission bits and owner/group. also, most of them preserve user/group identities by the numbers. if there's no 'global' user identity database (LDAP, NIS, or even AD), be sure to look for a 'by name' identity.
在 *nix 机器之间的更多“直接”副本上,如果写入过程在 root 下运行,通常会有一些标志来保留权限位和所有者/组。此外,它们中的大多数通过数字保留用户/组身份。如果没有“全局”用户身份数据库(LDAP、NIS 甚至 AD),请务必查找“按名称”身份。
some examples:
一些例子:
- NFS: assumes 'identity by number', unless you use some 'squash' option to make every file the same owner/group.
- cp: the '-p' flag preserves mode, ownership (by number) and timestamp.
- scp: the '-p' flag preserves modes, but (usually) not ownership
- rsync: only root can preserve ownership (-o,-g, or -p), tries to match usernames, but falls back to userids if not possible.
- NFS:假定“按编号标识”,除非您使用某些“挤压”选项使每个文件都具有相同的所有者/组。
- cp:'-p' 标志保留模式、所有权(按数字)和时间戳。
- scp:'-p' 标志保留模式,但(通常)不保留所有权
- rsync:只有 root 可以保留所有权(-o、-g 或 -p),尝试匹配用户名,但如果不可能,则回退到用户 ID。
回答by crazysquirrel
Why bother with permissions?
为什么要考虑权限?
They get in the way most of the time unless you are running some sort of server.
除非您正在运行某种服务器,否则它们大部分时间都会妨碍您。
Perhaps copy from linux FS to a FAT32, exfat, or NTFS FS so you don't have to deal with permissions?
也许从 linux FS 复制到 FAT32、exfat 或 NTFS FS 以便您不必处理权限?
That is what I do. I usually choose NTFS for file 'sharing' between desktop and laptop where laptop has linux and desktop has windows 7. Cannot easily do *nix laptop to *nix desktop without doing chmod multiple times (and even THAT doesn't guarantee R/W permissions)
这就是我所做的。我通常选择 NTFS 用于台式机和笔记本电脑之间的文件“共享”,其中笔记本电脑有 linux,台式机有 Windows 7。如果不多次执行 chmod,就无法轻松地将 *nix 笔记本电脑转换为 *nix 台式机(甚至这也不能保证 R/W 权限)
When I tried to share between *nix's, everything was quite bad. I need FULL read/write access by everyone on any box from any external drive.
当我试图在 *nix 之间共享时,一切都很糟糕。我需要任何人在任何外部驱动器上的任何盒子上进行完全读/写访问。
Only problem with ntfs is if your *nix doesn't write to it or shut it down correctly. Then I have to use windows to fix it (pain too). Hence one of the reasons I keep windows around.
ntfs 的唯一问题是您的 *nix 没有写入或正确关闭它。然后我必须使用窗户来修复它(也很痛苦)。因此,我保留窗户的原因之一。
Every flash and external drive I have are all NTFS except 2 of them which are fat 32 to 100% GUARANTEE no foul ups with linux demanding permissions (which many times I cannot change for some reason even with chmod).
我拥有的每个闪存和外部驱动器都是 NTFS,除了其中 2 个是 32% 到 100% 的胖 保证 linux 要求的权限没有任何问题(很多时候即使使用 chmod 也由于某种原因我无法更改)。
Of course my data is plain old movies music pictures, similar domestic items.
当然我的数据是普通的老电影音乐图片,类似的国产货。
But the same theory holds that if you don't or can't write permissions with the file, anyone should be able to use the file from any operating system.
但同样的理论认为,如果您没有或不能对文件进行写入权限,则任何人都应该能够从任何操作系统使用该文件。
I have gone so far as to copy a stubborn file onto a fat 32 flash drive just to strip permissions then copy it back. HATE typing command line stuff.
我什至将一个顽固的文件复制到一个胖 32 的闪存驱动器上,只是为了去除权限,然后再将其复制回来。讨厌输入命令行的东西。
For me I need 100% read, write access to ANY data I have on external drives for all computers.
对我来说,我需要对所有计算机的外部驱动器上的任何数据进行 100% 读、写访问。
About using root - most linux 'suppliers' strongly discourage the use of root for doing many things.
关于使用 root - 大多数 linux '供应商' 强烈反对使用 root 做很多事情。
Again, easy way around permissions is if you can copy it you can strip itby sending it to fat32. Or ntfs. And there goes the security.
同样,绕过权限的简单方法是,如果您可以复制它,则可以通过将其发送到 fat32来剥离它。或者ntfs。然后就是安全性。
If something is so sensitive that you NEED file security when file sharing then why share it in the first place?
如果某些东西非常敏感,以至于您在共享文件时需要文件安全性,那么为什么首先要共享它?
If you want to prevent tampering with a file then burn it to a cd/dvd. That is read only. Even if they copy it and tamper with it the original is still untouched.
如果您想防止篡改文件,请将其刻录到 cd/dvd。那是只读的。即使他们复制并篡改它,原始文件仍然没有受到影响。