sudo & redirect output

Posted by Khaled on Ask Ubuntu See other posts from Ask Ubuntu or by Khaled
Published on 2011-01-08T09:20:33Z Indexed on 2011/01/08 9:59 UTC
Read the original article Hit count: 313

Filed under:
|
|

I have a small question regarding using sudo with output redirect >. To enable IP forwrding, someone can use the command:

$ echo 1 > /proc/sys/net/ipv4/ip_forward

Executing this command will give permission denied as it requires root privileges. However, executing the same command with sudo gives also permission denied error! It seems that output redirect > does not inherit the permissions of the preceding command echo. Is this right?

As a workaround I do:

$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

Is this the best way to do it? Am I missing something?

Please, note that this is an example and it applies to all commands that use output redirect.

© Ask Ubuntu or respective owner

Related posts about sudo

Related posts about output