On CentOS 8 I have a Bash script which uses a non-standard file descriptor (/dev/fd/5) and needs to be executed by a standard user (not root).

When the user executes the script it receives

tee: /dev/fd/5: Permission denied

The code snippet which is raising this error is this:

# Print message both to stdout and FD5
msg() {
    echo "$msg" | tee /dev/fd/5

What kind of permission I should give to user to let it create and use a new File Descriptor?


There's no permission you can give for a program to write to a read only section of the /proc filesystem.

Take a look at the path you used /dev/fd/5. Notice that /dev/fd is actually a symlink to /proc/self/fd. This means that these descriptors reference each program's own open files.

When you ask tee to write to /dev/fd/5 it can't do so because /proc/self/fd/5 doesn't exist. It doesn't exist because tee didn't open it. And the kernel won't allow it to be created as a regular file.

If the file descriptor was opened by the script, then you should just send output there directly.

echo "$msg" >&5

If the file descriptor was not opened by the script, you need to rethink your approach to whatever you are doing.

| improve this answer | |
  • Ok, so why this is working with root user? – Mat Nov 19 at 18:06
  • @Mat Who knows? Maybe it's put random files named 5 somewhere. Since your example is contrived, it's very difficult to guess. – Michael Hampton Nov 19 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.