www-data user can't write to /tmp folder

5,874

Probably the file already exists. In this case, if it has been created by another process already, the system will not allow you to either modify or delete it since you're not the owner. In this case, right after the file is created, you might want to

chmod 666 /tmp/test.txt

I had the same exact problem, and this was the solution.

Share:
5,874

Related videos on Youtube

Matt
Author by

Matt

Updated on September 18, 2022

Comments

  • Matt
    Matt over 1 year

    Linux 4.4.0-75-generic #96-Ubuntu SMP Thu Apr 20 09:56:33 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

    Permissions seem wide open

    >>> ll /
    ...
    drwxrwxrwt   8 root   root         4096 May  1 02:44 tmp/
    

    Denied access:

    sudo -u www-data echo "hello" > /tmp/test.txt
    -bash: /tmp/test.txt: Permission denied
    

    Disk space seems OK:

    >>> df -h
    Filesystem      Size  Used Avail Use% Mounted on
    udev            980M     0  980M   0% /dev
    tmpfs           200M  8.2M  192M   5% /run
    /dev/xvda1      7.8G  6.3G  1.1G  86% /
    tmpfs          1000M     0 1000M   0% /dev/shm
    tmpfs           5.0M     0  5.0M   0% /run/lock
    tmpfs          1000M     0 1000M   0% /sys/fs/cgroup
    cgmfs           100K     0  100K   0% /run/cgmanager/fs
    tmpfs           200M     0  200M   0% /run/user/1000
    
    • Admin
      Admin about 7 years
      Check your selinux logs.
    • Admin
      Admin about 7 years
      @EEAA Is selinux used in Ubuntu 16?
    • Admin
      Admin about 7 years
      Just use /dev/shm instead of tmp. Your apps will run even faster that way...
    • Admin
      Admin about 7 years
      Is there a /tmp/test.txt file already? What is the output of ls -alh /tmp/test.txt.
  • Stephane
    Stephane over 2 years
    In my case, the file does not yet exist serverfault.com/q/1074904/249412