Flo*_*yer 53 upload scp permissions
我正在使用 scp 将文件上传到我的 shell 帐户。由于我在服务器上需要与在计算机上不同的权限,因此我希望有一种方法可以在上传时轻松更改权限,而无需通过 ssh 连接到帐户并手动更改它们。
zig*_*don 39
如果您是从 Windows 机器上复制,则可以使用WinSCP进行复制,并且可以选择在上传后设置对复制文件的权限。
如果没有,我认为您唯一的选择是在上传后在服务器上执行 chmod,您可以使用 ssh 命令远程执行此操作:
scp /path/to/file server:/server/path/to/file
ssh server chmod 644 /server/path/to/file
Run Code Online (Sandbox Code Playgroud)
小智 34
我首选的工作解决方案是使用rsync:
代替:
scp /path/to/file server:/server/path/to/file
Run Code Online (Sandbox Code Playgroud)
和:
rsync --perms --chmod=u+rwx,g+rwx,o+rwx /path/to/file server:/path/to/file
Run Code Online (Sandbox Code Playgroud)
这可以防止您进行两次身份验证。rsync还有很多其他选项,它们可能会增加价值,例如能够保留所有者、组等。
你可以像这样使用 tar、ssh 和 umask 来做到这一点:
在主机 1 上:
[saml@host1 testdir]$ pwd
/tmp/testdir
[saml@host1 testdir]$ ls -l
total 12
-rw-r--r-- 1 saml saml 21 May 19 00:21 file1
-rw-r--r-- 1 saml saml 48 May 19 00:21 file2
-rw-r--r-- 1 saml saml 28 May 19 00:21 file3
[saml@host1 testdir]$ tar cvf - . | (ssh host2 "umask 0277; cd /tmp/testdir;tar xvf -")
./
./file1
./file2
./file3
./
./file1
./file2
./file3
Run Code Online (Sandbox Code Playgroud)
在主机 2 上:
[samr@host2 testdir]$ pwd
/tmp/testdir
[samr@host2 testdir]$ ls -l
total 12
-r-------- 1 samr web 21 May 19 00:21 file1
-r-------- 1 samr web 48 May 19 00:21 file2
-r-------- 1 samr web 28 May 19 00:21 file3
Run Code Online (Sandbox Code Playgroud)
您可以将 -v 开关放到 tar 中,我在此处包含了它,这样您就可以看到在 host1 上压缩并通过 STDOUT(又名 -)发送的文件,然后在 host2 上解压缩。
注意:为什么会这样?Tar 的默认行为是使用远程用户的 umask 解压缩文件。在上面的示例中,我包含了命令umask以将其显式设置为不同的内容,这表明远程 tar 正在更改远程端的权限。
我用 scp 做了一些实验。对于上传到目标服务器的新文件,文件具有与源服务器相同的权限。如果目标服务器上的现有文件被覆盖,则这些文件的权限不会更改。
我在 CentOS 4.6 上做了这些实验。
| 归档时间: |
|
| 查看次数: |
91789 次 |
| 最近记录: |