I have centos 7.3 machine on AWS. The default ssh user is 'centos' However when i run any command with sudo for this user it doesn't ask for password. So how do i make it to prompt for password while doing sudo for default ssh user.I even tried adding Defaults rootpw in /etc/sudoers file

Note: When i create a new user and give sudo access to it, it always asks password while running sudo command for this new user. Its just doesnot work for default user.


You won’t be prompted for a password when either the configuration file /etc/sudoers or any of the the drop in configuration snippets in etc/sudoers.d/ contain lines similar to


Which allows only your user account to execute commands without a password prompt or a line similar to


Which allows all members of the group named sudo that privilege and your user centos is a member of that group.

Either remove the centos user from that group or edit the configuration and remove the NOPASSWD: directive.

  • Isn't removing the NOPASSWD: directive the only method that answers the question? – Esa Jokinen Apr 8 '18 at 6:41
  • /etc/sudoers.d/90-cloud-init-users is 'readonly'. Is it ok if i change the permission? It has an entry centos ALL=(ALL) NOPASSWD:ALL – MMA Apr 8 '18 at 7:44
  • It's read-only on purpose. You're supposed to use visudo to edit it. visudo validates the edit before commiting it, avoiding syntax errors that could lock you out of root access. – A.B Apr 8 '18 at 9:05
  • @EsaJokinen if the permissions are assigned to group and you remove all members of said then removing the :NOPASSWD is not needed – HBruijn Apr 8 '18 at 18:59
  • @HBruijn: I interpret "and give sudo access to it" as adding the user to the sudo group. Maybe that's why I understood this a bit differently. :) – Esa Jokinen Apr 8 '18 at 19:43

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.