Long running commands with sudo

Configure J2SSH and ServiceNow SSH to prevent long running commands using sudo from failing when the MID Server disconnects.

ServiceNow SSH allows probes to run sudo against individual commands or an entire, long-running script. This is also supported for the pbrun and pfexec privileged commands

Sudo for individual commands

You can run sudo against individual commands within a probe, but only if all the following sudoer configurations are performed on the target:
  • The !requiretty option is required.
  • Allow individual commands to be run by the user in the provided credential with NOPASSWD configured.
  • The target specifies an individual sudo call in the command or referenced scripts. For example, set sudo as "sudo fdisk -l" or "${sudo:fdisk -l}" rather than "must_sudo" for the entire script.
Note: Running sudo against individual commands with ServiceNow SSH produces detailed and useful entries in the sudo logs on the target computer.

Running sudo on an entire script

If any of the required sudoer configuration requirements for individual commands is not in place, Discovery applies sudo to the initial and complete probes, and does not execute sudo remotely inside the command. This condition can be forced by setting must_sudo on the probe and eliminating any sudo commands within the probe.

This approach prevents long running commands from failing when the probe disconnects, but cannot specify individual commands in the sudoers configuration.

Logging

The logs from ServiceNow SSH sudo activity run against an entire script show cryptic entries, such as /tmp/.run.aef13123fe124123, which prevent administrators from controlling permissible commands and knowing the exact command that was run. Sudo run against individual commands produces more detailed log entries, such as /sbin/fdisk –l.