sudo
Version
sudo --version
Usage
sudo -l
Shows what commands you can run
User myuser may run the following commands on myserver: (ALL) NOPASSWD: ALL (ALL) NOPASSWD: /bin/vi /etc/my.cnf, /bin/mkdir *, /bin/systemctl enable *, /bin/systemctl disable *, /bin/systemctl status *, /bin/systemctl stop *, /bin/systemctl start *, /bin/journalctl -xe, /usr/bin/mysql * *, /bin/cat *, /bin/zcat *, /usr/bin/mysql_secure_installation, /usr/bin/less *, /usr/bin/more *, /bin/du * *, /bin/yum install *, /bin/yum erase *, /bin/grep * *, /bin/vi /etc/yum.repos.d/paragon.repo, /bin/yum clean all, /bin/dnf module list, /bin/dnf module list, /bin/su - mysql, /usr/sbin/usermod mysql -s /bin/*, /bin/chown mysql* /*, /bin/chown -R mysql* /*, /bin/hostnamectl status
Configuration & Logging
Configuration is held in:
/etc/sudoers
You should edit this file with:
visudo
To check
cat /var/log/secure | grep patcher
Running commands as non-login users
For example, when you install MySQL/Percona Server using yum, by default you get a 'mysql' user with a login shell of /bin/false. It seems like good security to keep things like this. But, what can you do if you need to run something as 'mysql', like cron scheduling a backup? ...
sudo -u mysql -s crontab -l
Examples
Add a user to the sudo group to allow them to run any command...
usermod -a -G sudo myuser
Assumes this default line is present in /etc/sudoers...%sudo ALL=(ALL:ALL) ALLAdd this line to the /etc/sudoers file (using visudo) to allow user 'oracle' to run /u01/dba/patcher/perms.sh as 'root' on the host 'delphi' without needing a password...
oracle delphi = (root) NOPASSWD: /u01/dba/patcher/perms.sh