Applications Systems

Run a script as root to monitor Linux profile elements in SCM

The SCM plugin that executes manager profiles runs as an unprivileged user called swiagent. Linux script elements can be run as root by invoking scripts on the target server using sudo. To do so, you must configure /etc/sudoers properly on the Linux box being profiled, and the script you run must exist on each target. This article explains the process to follow.

First published date

11/5/2019 7:45 AM

Last published date

11/5/2019 7:45 AM

Overview

The Server Configuration Monitor (SCM) plugin that executes manager profiles runs as an unprivileged user called swiagent. Linux script elements can be run as root by invoking scripts on the target server using sudo. To do this, you must configure /etc/sudoers properly on the Linux box being profiled, and the script you run must exist on each target. This article explains the process to follow.

Product section

Server Configuration Monitor

Resolution

Option 1:
On each Linux machines, create a restricted directory where you can store scripts that run as part of the Linux script element.

Note: Restrict access to either root or swiagent.

  1. See the following example:
    /opt/SolarWinds/scm
  2. On each targeted Linux server, add the following lines to /etc/sudoers: 
    Cmnd_Alias SCMCMDS = /opt/SolarWinds/scm/
    Swiagent  All=(root) NOPASSWD:  SCMCMDS
    This configures sudo to allow the user and only the user swiagent to execute any script in /opt/SolarWinds/scm as root.


Option 2:
Alternatively, a profile may consist of a simple command, such as a command to monitor the /etc/sudoers file itself, using cat to add the command to the command alias list.

Note: All commands should be full pathnames, For example:

Cmnd_Alias SCMCMDS = /opt/SolarWinds/scm/, /usr/bin/cat /etc/sudoers

Invoke sudo in each command line field, followed by the command or script.

For example, to monitor /etc/sudoers itself, the command field should read as follows: 

sudo  /opt/SolarWinds/scm/scriptname 

See the man sudoers page for information on how to configure /etc/sudoers.