Lui*_*lli 6 permissions command-line
我正在使用postgres用户执行一些特殊命令。为此,我正在尝试以下操作:
$ sudo su - postgres
postgres$ ls -l /tmp
drwxrwxrwt 13 root root 4096 jun 8 12:20 tmp
Run Code Online (Sandbox Code Playgroud)
PGPASSWORD=mypasswordhere time pg_dump --username=postgres --no-password -f /tmp/myfilehere.sql mydatabasehere
pg_dump: [archiver] could not open output file "/tmp/myfilehere.sql": Permiso denegado
Command exited with non-zero status 1
0.25user 0.06system 0:02.04elapsed 15%CPU (0avgtext+0avgdata 58064maxresident)k
0inputs+0outputs (0major+5110minor)pagefaults 0swaps
Run Code Online (Sandbox Code Playgroud)
问题:为什么我不能/tmp用 user写入postgres?注意粘性标志设置在 上/tmp。
粘滞位将阻止除文件所有者(以及目录和根的所有者)之外的任何用户删除/重命名包含粘滞位的目录中的任何文件。如果任何用户没有写入权限,那么他将无法在/tmp设置了粘滞位的目录或任何其他目录中创建任何文件,读取和执行操作也是如此。
在您的情况下,如果postgres有足够的权限来读/写/执行文件,/tmp那么他可以这样做,否则您需要手动设置适当的权限。
例子 :
drwxrwxrwt 7 root root 4096 Jun 9 00:41 tmp
$ sudo chmod o-rwx /tmp
drwxrwx--T 7 root root 4096 Jun 9 00:41 tmp
$ touch /tmp/foo.txt
touch: cannot touch ‘/tmp/foo.txt’: Permission denied
$ sudo chmod o+rwx /tmp
$ touch /tmp/foo.txt
$ ls -l /tmp/
-rw-rw-r-- 1 user user 0 Jun 9 00:50 foo.txt
Run Code Online (Sandbox Code Playgroud)