Wednesday, October 22, 2008

How to Prevent "sudo" from Asking a Password

Some commands like "echo 3 > /proc/sys/vm/drop_caches"* require superuser priviliges so (if you are just a user and you are a sudoer) you need to sudo.

"sudo" asks for a password. However, if you're "sudo"ing in a script then it's a problem: you wouldn't want to reveal your password as a text.

You can work around so that "sudo" doesn't require a password:
Edit "/etc/sudoers": ALL=(ALL) NOPASSWD: ALL

* NOTE:
  1. echo 1 > drop_caches : just to free "pagecache" (memory which is used to cache the user data pages)
  2. echo 2 > drop_caches: just to free dcache (which stores recently generated dentries which are created when a pathname is resolved) and inodes (which contain metadata for files).
  3. echo 3 > drop_caches: remove all caches