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 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.


share|improve this question

migrated from Apr 4 '10 at 4:44

This question came from our site for professional and enthusiast programmers.

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
up vote 11 down vote accepted

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"
share|improve this answer

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.

share|improve this answer

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
share|improve this answer

You must log in to answer this question.

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