Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I try to put value "1" into some virtual file of /proc, and I get "permission denied" despite using sudo:

name@comp-name:/etc/dhcp$ sudo echo 1 > /proc/sys/net/ipv4/ip_forward 
bash: /proc/sys/net/ipv4/ip_forward: Permission denied

I guess that echo command runs with root permissions, but redirection (>) maybe runs without? Can I run both of them with root permissions?

share|improve this question
have you tried using sysctl to write the values in these /proc files? – l1zard Nov 3 '12 at 14:18
up vote 4 down vote accepted

In this case, sudo will only apply to echo, as you said.

Instead, you could run an elevated shell like this:

sudo sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'

Or even shorter:

sudo -s 'echo 1 > /proc/sys/net/ipv4/ip_forward'
share|improve this answer

the recommended way to do that is piping to the program tee

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

share|improve this answer

The problem is that the redirection is done by your shell, not sudo. Ordinarily the program you run gets exec()ed after the redirection. Since you don't have permissions to write to the file, the redirection fails. As mentioned above, the recommended way is to use tee, as in

echo stuff | sudo tee /some/file/path
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .