You are not logged in.

#1 2019-07-14 19:08:32

Sourav
Member
From: India
Registered: 2019-04-22
Posts: 84
Website

[SOLVED] Can't edit a file at /tmp/ as root user

Hello! I noticed that if you:
# As normal user
1. cd /tmp
2. touch file
# As root / any other user (let's consider root here)
3. su root
4. nano file
You get write error. So you might change the permissions to 666. That doesn't work either. No luck with omnipotent 777.

I tried mounting a mere 4 MiB partition as type tmpfs. And I saw the same behaviour too!
Yes, you can `sudo echo something > file` but then you can't edit it as the original owner.

Actually I got the problem on Arch Linux x86_64 and Arch Linux ARM while trying to write a ruby script to manage the system memory (not using low level stuff BTW!)

If you are interested, below is the that I posted first (wrongly on stackoverflow).
https://stackoverflow.com/questions/570 … 5_57023455

Here are 2 links to the screenshots:
https://imgur.com/tB4T5Jl
https://imgur.com/hzc5s27

But as the problem applicable only for Arch Linux (and not Ubuntu or Linux Mint as tested) I hope to see some interesting answers!

Last edited by Sourav (2019-07-14 19:24:27)

Offline

#2 2019-07-14 19:13:12

loqs
Member
Registered: 2014-03-06
Posts: 19,101

Re: [SOLVED] Can't edit a file at /tmp/ as root user

Offline

#3 2019-07-14 19:24:54

Sourav
Member
From: India
Registered: 2019-04-22
Posts: 84
Website

Re: [SOLVED] Can't edit a file at /tmp/ as root user

Thank you very much! Problem solved in one line wink

Offline

#4 2019-07-14 19:27:11

latalante1
Member
Registered: 2018-08-30
Posts: 112

Re: [SOLVED] Can't edit a file at /tmp/ as root user

answer here
https://git.kernel.org/pub/scm/linux/ke … s.txt#n233
and in this file
/usr/lib/sysctl.d/50-default.conf

Offline

#5 2019-07-14 19:39:32

loqs
Member
Registered: 2014-03-06
Posts: 19,101

Re: [SOLVED] Can't edit a file at /tmp/ as root user

You did solve it by creating the file as root (if you could not run the process as none root)(preferably with a unique path / name) rather than disabling the sysctl?

Offline

#6 2019-07-14 19:59:50

Sourav
Member
From: India
Registered: 2019-04-22
Posts: 84
Website

Re: [SOLVED] Can't edit a file at /tmp/ as root user

Yes I just disabled it with
```
sysctl fs.protected_regular=0
sysctl fs.protected_fifos=0
```

In my Ruby program the problem get worse if the log file is created after running it as normal user and then root user re-runs the program!
Let me add `begin <...> rescue Errno::EACCES` block in my program!

loqs wrote:

You did solve it by creating the file as root (if you could not run the process as none root)(preferably with a unique path / name) rather than disabling the sysctl?

Last edited by Sourav (2019-07-14 20:16:10)

Offline

#7 2019-07-14 20:42:29

latalante1
Member
Registered: 2018-08-30
Posts: 112

Re: [SOLVED] Can't edit a file at /tmp/ as root user

Sourav wrote:

Yes I just disabled it with
```
sysctl fs.protected_regular=0
sysctl fs.protected_fifos=0
``

Undermining the default security of the system in its own fashion is not the best idea.
Look for a more reasonable solution. Consider another folder.
/var/tmp

Offline

Board footer

Powered by FluxBB