Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

I want to run any program without asking root password. Because I'm the only person who use the system. So I googled and edited /etc/sudoers.

What I did:

# chmod 640 /etc/sudoers
# vim /etc/sudoers

Added a line like below:

# User privilege specification
root    ALL=(ALL:ALL) ALL
sgg ALL=(ALL:ALL) ALL

saved and closed the file. Rebooted system. But no change/improvement. Am I want to change any other lines? or Is there any way?

EDIT:

1.I changed permissions /etc/sudoers to 0440. ls -l /etc/sudoers result is

-r--r----- 1 root root 772 May  4 19:43 /etc/sudoers

2.I run # visudo. File content is

Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
sgg ALL=NOPASSWD:ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

But still it asking for password when I run sudo ls.

System Info: Ubuntu 14.04 x86_64 3.13.0-24-generic

share|improve this question

marked as duplicate by Gilles, slm, strugee, Braiam, jasonwryan May 5 at 1:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
do not vim /etc/sudoers, use visudo –  guido May 4 at 10:09
1  
also, I think you tinkering with sudoers file persmissions could be cause of errors, put it back to 0440 –  guido May 4 at 10:12

2 Answers 2

up vote 2 down vote accepted

First some general points:

  1. Never edit /etc/sudoers directly. You should always use sudo visudo instead which allows you to edit the file but checks it for errors before saving. The syntax of sudoers is tricky and a mistake can render your system unusable since you will not longer be able to us sudo.

  2. Never change the permissions of /etc/sudoers. In general, you shouldn't change the permissions of system files. In many cases, the programs associated with them will not work properly and it is bad practice and a security hole. That's what sudo is for in the first place, so you don't need to change the permissions.

    In addition, if you have set the permissions of /etc/sudoers to 640 and were able to write to it, that means you have also changed its owner to your user. That will effectively break it. As explained in man sudoers:

     /etc/sudoers is owned by gid N, should be 1
       The sudoers file has the wrong group ownership.  If you wish to change
       the sudoers file group ownership, please add “sudoers_gid=N” (where ‘N’
       is the group ID that owns the sudoers file) to the sudoers Plugin line
       in the sudo.conf(5) file.
    
  3. If you want regular users to be able to mount a drive, a better way is to specify that in /etc/fstab. Using your example, you would want this line there:

    /dev/sda6   /media/sgg/D    vfat    users,rw,errors=remount-ro,noauto  0   0
    

    That will allow regular users to mount it with

    mount /dev/sda6
    
  4. If despite the above, you still want to allow your user to run any command without a password, the line you want to add to /etc/sudoers (using sudo visudo) is:

    sgg ALL=NOPASSWD:ALL
    

    Save the file and exit visudo and try running sudo ls, you shouldn't be asked for a password. I just tested and can confirm it works on my LMDE.

share|improve this answer
    
visudo giving usage: visudo [-chqsV] [-f sudoers] [-x file] –  linux_inside May 4 at 13:48
    
@SGG how are you running it? Did you run sudo visudo? –  terdon May 4 at 13:49
    
i already tried with /etc/fstab. It gave me error at booting time Unable to mount /dev/sda6. press S to skip and M to manually ... some kind of message –  linux_inside May 4 at 13:50
    
sudo visudo /etc/sudoers –  linux_inside May 4 at 13:51
    
@SGG please run it the way I suggest in my answer, simply sudo visudo. The error message you're getting suggests that you are trying to mount an external or network drive that is not present at boot time. Is that so? That's the kind of detail you should mention in your question. Anyway, try the updated answer, I have changed the fstab line. –  terdon May 4 at 13:53

That just tells the system that you may run all commands (which is the default anyway) but doesn't say anything about passwords. You need:

sgg ALL = (ALL) NOPASSWD: ALL

From the man page:

FULLTIMERS      ALL = NOPASSWD: ALL

Full time sysadmins (millert, mikef, and dowdy) may run any command on any host without authenticating themselves.

share|improve this answer
    
not working. asking for password –  linux_inside May 4 at 3:57
    
@SGG Quite strange because it does work here. What exactly is the command you run? –  Hauke Laging May 4 at 4:13
    
i'm trying to run sudo mount -t vfat /media/sgg/D /dev/sda6 –  linux_inside May 4 at 4:55
    
@SGG It does not explain the password request but the mount command is wrong. It must be mount -t vfat /dev/sda6 /media/sgg/D. Please try sudo ls /root. –  Hauke Laging May 4 at 5:15
    
sorry, that's a typo. Why when run the mount command it's asking pswd. I don't want to ask it. So that normal user can also mount. –  linux_inside May 4 at 5:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.