I want to turn off ASLR on my own PC. But each time I type "sudo echo 0 > /proc/sys/kernel/randomize_va_space", the system shows that "Permission denied". How can I make it work? By the way, my OS kernel is 2.6.30.

Hope anyone can give me a hand.


  • 2
    This is a valid question on shell programming. – liori Apr 3 '10 at 13:33
  • Why do you want to turn off ASLR?! – Jeremy Visser May 25 '14 at 12:18

This is a common problem with sudo and shell redirection. The "sudoness" doesn't propagate past the redirection. One way to get around it is

sudo bash -c "echo 0 > /path/to/file"

In your command, the I/O redirection > is handled by the current shell. The command is seen by the interpreter as 3 parts:

  1. sudo echo 0
  2. >
  3. /proc/sys/kernel/randomize_va_space

The echo is executed using the superuser privilege while the current shell (with normal user privilege) tries to write to /proc/sys/kernel/randomize_va_space, and thus triggers a Permission denied error.

There are several ways to overcome this. The first way is to run a shell with superuser privilege and pass the command to the shell using the -c switch:

sudo sh -c "echo 0 > /proc/sys/kernel/randomize_va_space"

(You may use sh for POSIX shell and bash for Bash)

Another way is to use the tee command. The tee command copies the contents from standard input to the standard output (usually means the "screen") as well as the listed files. Therefore, the following command prints the character A to the standard output as well as the files output1.txt and output2.txt.

echo A | tee output1.txt output2.txt

In your problem, writing to /proc/sys/kernel/randomize_va_space needs the superuser privilege while echo-ing 0 does not. So, the solution is:

echo 0 | sudo tee /proc/sys/kernel/randomize_va_space >/dev/null

The final redirection to /dev/null prevents the 0 from printing to the screen.


The sudo only works for your echo command (not after the pipe).

You can try:

echo 0 | sudo tee /proc/sys/kernel/randomize_va_space

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.