I want one of my users to be able to 'sudo init 5' without being asked for a passwd. How to do it?

I want one of my users to be able to 'sudo init 5' without being asked for a passwd. How to do it?

I want one of my users (let's call him: pn) to be able to start X by sudo init 5.
I don't want to give him access to any other commands.


I read man sudoers, but I don't understand too much of it.

Can anyone provide a quick line to add to /etc/sudoers file that would do the trick?
I would be grateful eternally.

答案1

Run sudo visudo and add the following line to the end of /etc/sudoers:

pn [hostname] = (root) NOPASSWD: /sbin/init 5

Replace [hostname] with the output of hostname.

After this change, the user pn will be able to execute sudo init 5 without a password.

相关内容