scp 文件未设置正确的所有者

发布于 2024-07-15 22:45:54 字数 728 浏览 8 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

阳光下的泡沫是彩色的 2024-07-22 22:45:54

scp 没什么特别的 - 尝试以从服务器身份登录到服务器,并使用您最喜欢的文本编辑器编辑文件...您会发现发生相同的行为...写入文件并不会使您成为该文件的所有者文件。


示例:

作为 root

#cd /tmp
#mkdir fubar
#chgrp vboxusers fubar
#cd fubar/
#touch testfile
#chgrp vboxusers testfile 
#chmod g+w . testfile
#ls -al
total 16
drwxrwxr-x  2 root vboxusers  4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root      12288 2009-03-19 10:29 ..
-rw-rw-r--  1 root vboxusers     0 2009-03-19 10:30 testfile
#echo foo > testfile 
#ls -al
total 20
drwxrwxr-x  2 root vboxusers  4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root      12288 2009-03-19 10:29 ..
-rw-rw-r--  1 root vboxusers     4 2009-03-19 10:30 testfile

用户(在 vboxusers 组中)

>cd /tmp/fubar
>ls -al
total 20
drwxrwxr-x  2 root vboxusers  4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root      12288 2009-03-19 10:29 ..
-rw-rw-r--  1 root vboxusers     4 2009-03-19 10:30 testfile
>echo bar >> testfile 
>ls -al
total 20
drwxrwxr-x  2 root vboxusers  4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root      12288 2009-03-19 10:29 ..
-rw-rw-r--  1 root vboxusers     8 2009-03-19 10:31 testfile
>vim testfile
>ls -al
total 20
drwxrwxr-x  2 root vboxusers  4096 2009-03-19 10:31 .
drwxrwxrwt 15 root root      12288 2009-03-19 10:31 ..
-rw-rw-r--  1 root vboxusers    12 2009-03-19 10:31 testfile
>cat testfile 
foo
bar
baz

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

#cd /tmp
#mkdir fubar
#chgrp vboxusers fubar
#cd fubar/
#touch testfile
#chgrp vboxusers testfile 
#chmod g+w . testfile
#ls -al
total 16
drwxrwxr-x  2 root vboxusers  4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root      12288 2009-03-19 10:29 ..
-rw-rw-r--  1 root vboxusers     0 2009-03-19 10:30 testfile
#echo foo > testfile 
#ls -al
total 20
drwxrwxr-x  2 root vboxusers  4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root      12288 2009-03-19 10:29 ..
-rw-rw-r--  1 root vboxusers     4 2009-03-19 10:30 testfile

as user (in vboxusers group)

>cd /tmp/fubar
>ls -al
total 20
drwxrwxr-x  2 root vboxusers  4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root      12288 2009-03-19 10:29 ..
-rw-rw-r--  1 root vboxusers     4 2009-03-19 10:30 testfile
>echo bar >> testfile 
>ls -al
total 20
drwxrwxr-x  2 root vboxusers  4096 2009-03-19 10:30 .
drwxrwxrwt 15 root root      12288 2009-03-19 10:29 ..
-rw-rw-r--  1 root vboxusers     8 2009-03-19 10:31 testfile
>vim testfile
>ls -al
total 20
drwxrwxr-x  2 root vboxusers  4096 2009-03-19 10:31 .
drwxrwxrwt 15 root root      12288 2009-03-19 10:31 ..
-rw-rw-r--  1 root vboxusers    12 2009-03-19 10:31 testfile
>cat testfile 
foo
bar
baz
ゝ杯具 2024-07-22 22:45:54

您必须删除该文件才能覆盖它。 您是否能够执行此操作取决于目录的权限和所有权。 劫持现有文件的所有权是不可能的。 您拥有的写入权限仅适用于文件的内容。

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.

稳稳的幸福 2024-07-22 22:45:54

看来您可以通过 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 type C-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.

拥有 2024-07-22 22:45:54

我误解了文件的工作方式,修改文件内容不会更改所有权或组。

为什么会出现混乱? 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文