Sunday, December 1, 2013

Using RegEx in SUDO Access

We can use 'Regular expression' in Sudoers file !

Let's say we have a Command Alias in '/etc/sudoers' as follows:

Cmnd_Alias      DBTASKS=/sbin/service mysqld start, /sbin/service mysqld stop, /sbin/service mysqld restart, /sbin/service mysqld status, /etc/init.d/mysqld start, /etc/init.d/mysqld stop, /etc/init.d/mysqld status, /etc/init.d/mysqld restart

This can be shrunken using RegEx as follows:
Cmnd_Alias      DBTASKS =/sbin/service mysqld [a-z]*,  /etc/init.d/mysqld [a-z]*
Cmnd_Alias      DBTASKS =/sbin/service mysqld ?*,  /etc/init.d/mysqld ?* 

No comments:

Post a Comment