How to use sudo?

Not familiar with sudo, need to allow a user "patuser" to edit /etc/my.cf and allow to restat mysql, i.e
sudo vi /etc/my.cf
sudo /etc/init.d/mysql
What entry do I need to make to /etc/sudoers and can I edit the entry with vi or is there a seperate tool to edit /etc/sudoers
Please assist.

you edit sudo with the visudo utility. This is in case you accidentally bungle a setting, it will complain and undo the changes instead of potentially blocking you from the ability to 'sudo visudo'.

The sudoers file has lots of examples in it.

username ALL=vi /etc/my.cf, /etc/init.d/mysql

I think that will require 'vi /etc/my.cf' and not let him sudo vi anything else, but will let him run /etc/init.d/mysql restart or /etc/init.d/mysql stop etc. As with any changes you make to sudo, test it thoroughly.

1 Like