scp 文件未设置正确的所有者
SCP 在设置文件权限时是否有问题或者我的服务器配置错误?
用例:
服务器上有一个我想要编辑的文件,名为“importantFile.txt”。 该文件的所有者和组为“主”:
ls -l importantFile.txt:
-rw-rw-r-- 1 master master 7 Mar 18 08:11 importantFile.txt
我被称为“从”,但幸运的是,我在“主”组中,因此我可以根据需要编辑该文件。 但是,我是一个懒惰的奴隶,懒得在服务器上编辑文件,我更愿意在本地计算机上编辑文件并将其 SCP 到服务器:
echo "bored slave info" > importantFile.txt
scp importantFile.txt slave@theServerAddress:/pathToFile/importantFile.txt
如果我这样做,服务器上的文件上传正常,文件的时间戳已更新,但文件的权限没有改变,该文件仍然属于“master”。 这是一个问题,因为如果“奴隶”上传了不良内容,没有人会知道是“奴隶”造成了问题,“主人”会显得很内疚。
也许我必须设置一个umask? 如果是的话在哪里? 我尝试了 .bash_profile 但没有成功,并且在 Google 上没有在 /etc/ssh/sshd_config
中找到任何有关 umask 的内容。
Does SCP have a problem setting file permissions or have I misconfiguration my server?
Use case:
There is a file on a server that I want to edit called "importantFile.txt". The file has owner and group of "master":
ls -l importantFile.txt:
-rw-rw-r-- 1 master master 7 Mar 18 08:11 importantFile.txt
I am called "slave" but luckily, I am in group "master" so I can edit the file as I see fit. However, I'm a lazy slave and can't be bothered to edit the file on the server, I'd prefer to edit the file on my local machine and SCP it to the server:
echo "bored slave info" > importantFile.txt
scp importantFile.txt slave@theServerAddress:/pathToFile/importantFile.txt
If I do this, the contents of the file on the server are uploaded fine and the timestamp of the file is updated but the permissions of the file don't change, the file is still owned by "master". This is a problem because if "slave" uploaded bad content, no one would know it was "slave" who caused the problem, "master" would look guilty.
Perhaps I have to set a umask? if so where? I tried .bash_profile without success and haven't found anything on Google about umask in /etc/ssh/sshd_config
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
scp 没什么特别的 - 尝试以从服务器身份登录到服务器,并使用您最喜欢的文本编辑器编辑文件...您会发现发生相同的行为...写入文件并不会使您成为该文件的所有者文件。
示例:
作为 root
用户(在 vboxusers 组中)
That's nothing special about scp - try logging on to the server as slave, and editing the file using your favourite text editor... You'll find the same behaviour occurs... Writing to a file does not make you the owner of the file.
Example:
as root
as user (in vboxusers group)
您必须删除该文件才能覆盖它。 您是否能够执行此操作取决于目录的权限和所有权。 劫持现有文件的所有权是不可能的。 您拥有的写入权限仅适用于文件的内容。
You have to delete the file to overwrite it. Wether you are able to do that depends on the directory's permissions and ownership. Hijacking ownership of an already existing file is not possible. The write permission you have is only applied on the contents of the file.
看来您可以通过
backup-by-copying-when-mismatch
变量配置 Emacs 如何处理此问题(请参阅 Emacs 手册或输入Chv backup-by-copying-when-mismatch< /code> 在 Emacs 中)。
我实际上提交了一份关于此的错误报告,因为我认为这是一个流浪汉中的错误。
It seems you can configure how Emacs deals with this through the
backup-by-copying-when-mismatch
variable (see the Emacs Manual or typeC-h-v backup-by-copying-when-mismatch
in Emacs).I actually filed a bug report about this, because I thought it was a bug in Tramp.
我误解了文件的工作方式,修改文件内容不会更改所有权或组。
为什么会出现混乱? EMACS - 每当我编辑文件时,我都会使用 Emacs,而 Emacs 确实会将所有者和组更改为当前用户。 它这样做是因为它通过将“文件名”移动到“文件名〜”并创建一个名为“文件名”的新文件来在保存时创建备份文件 - 因为它是一个新文件,所以它具有当前用户的文件权限。 我猜这是 1up to VI 粉丝?
I had misunderstood the way files work, modifying file contents do not change ownership or group.
Why the confusion? EMACS - Whenever I was editing a file I was using Emacs and Emacs does change the owner and group to the current user. It does this because it makes a backup file at save time by moving the "filename" to "filename~" and creating a new file called "filename" - because it's a new file, it has the current users file permissions. I guess this is 1up to VI fans?