DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Execute sudo without password


Tom (username: tom) want to execute sudo command without input password. For example: sudo cat /etc/sudoers.

Append tom ALL=(ALL:ALL) NOPASSWD:ALL to /etc/sudoers.

Logout (the desktop if you are in the desktop environment) and login to make the rule works.

If the tmux server is created before the modification of the sudoers files, quit the tmux server (which means quit all it's sessions) and the new rule will works in the new session.

Note

Q: Why not add this line right after root ALL=(ALL:ALL) ALL?

A: Because in this way the rule tom ... will be overwritten by the rule below ():

%sudo   ALL=(ALL:ALL) ALL

This rule make all users in sudo group run sudo command with password. When tom is a member of group 'sudo', he will have to input password when sudo a command. You can remove tom from 'sudo' group to make things work. But this is not as elegant as put tom All... at the bottom of the file.

Q: Why does rule of tom overwritten by rule of sudo group?

A: Because /etc/sudoers is a script, a posterior command overwrites preceding commands.



Published

Sep 4, 2016

Last Updated

Sep 4, 2016

Category

Tech

Tags

  • linux 158
  • password 2
  • sudo 1

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor