I have a Unix script which creates a temporary log file, say tempfl.log. When this file is created it has permission rw-r--r--.

There is a line

chmod 0440 /etc/sudoers tempfl.log 2>&1

But when the script is done the permission changes to r--r--r-- but it should be rw-r--r--. If I change the line to

chmod 0644 /etc/sudoers tempfl.log

The permissions are right for tempfl.log but it throws errors saying:

sudo: /usr/local/etc/sudoers is mode 0644, should be 0440

I do not understand what sudoers is doing and what is wrong.

  • thanks for the responses. what i understand is that, the command chmod 0440 /etc/sudoers tempfl.log 2>&1 is changing the file permisssion for both sudoers and templ.log to 440 but what i want is that the file templ.log should have the permission 644. is my understanding right ? so the solution to my problem is chmod 0440 /etc/sudoers tempfl.log 2>&1 chmod 644 tempfl.log Please let me know if these 2 commands are going to create any error. – randeepsp Sep 1 '10 at 4:36
  • 2
    I would just remove the /etc/sudoers from the command, you shouldn't ever have to change the permission of that file. If for some reason you needed to modify it, then you would just have two chmod commands. – Drew Frezell Sep 1 '10 at 4:56

Your script is changing the permission of 2 files, /etc/sudoers and tempfl.log. Split the command in two lines and you should be fine.

| improve this answer | |
  • please have a look at the comment i added. – randeepsp Sep 1 '10 at 4:37

Your script is doing exactly what you're telling it to do:

chmod 0440 /etc/sudoers tempfl.log

will apply r--r----- to both of those files.

You really shouldn't be fiddling around with the sudoers file unless you're writing admin scripts and, even then, the permissions should be left alone since that helps secure your system. The sudo program itself checks the permissions of its configuration file and warns you (as you've seen). Listen to it. It obviously knows better than you :-)

Are you sure you aren't just trying to run certain parts of your script under sudo, as in:

sudo chmod 0440 tempfl.log 2>&1

If not, and you really want to modify both files (but with different permissions, use two separate commands:

chmod 0440 /etc/sudoers 2>&1
chmod 0644 tempfl.log 2>&1
| improve this answer | |
  • ya, im sure of it. – randeepsp Sep 1 '10 at 5:53

When you write chmod 0440 /etc/sudoers tempfl.log it changes the permissions of /etc/sudoers and tempfl.log to both be 0440, which is wrong.

When you write chmod 0644 /etc/sudoers tempfl.log it changes the permissions of /etc/sudoers and tempfl.log to both be 0644, which is wrong.

Do you need to change permissions on /etc/sudoers at all? Did you actually want to write chmod 0644 tempfl.log?

| improve this answer | |
  • Agree, there is not a practical need I can think of to change the permissions of /etc/sudoers. – wuputah Sep 1 '10 at 4:29
  • 3
    Nothing should touch /etc/sudoers at all besides visudo. – hobbs Sep 1 '10 at 4:36

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.