1

Trying to figure out the correct Cmnd_Alias for the sudoers file

The command i which to run without any password is the following:

sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1

The lines i have added to sudoers file is:

## Cmnd alias specification
Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1
Cmnd_Alias AXTOOLTTYSTOP = /etc/init.d/axtty stop
Cmnd_Alias AXTOOLTTYSTATUS = /etc/init.d/axtty status
Cmnd_Alias AXTOOLINTCTLSTART = /sbin/initctl start ttyp?
Cmnd_Alias AXTOOLINTCTLSTOP = /sbin/initctl stop ttyp?

## This will disable password request for the axtools commands
%sudoaxtools ALL=(root) NOPASSWD: AXTOOLTTYSTART, AXTOOLTTYSTOP, AXTOOLTTYSTATUS, AXTOOLINTCTLSTART, AXTOOLINTCTLSTOP
Defaults!AXTOOLTTYSTART !requiretty
Defaults!AXTOOLTTYSTOP !requiretty

The command in mention is ran inside a script (axopen), executed either by member of group sudoaxtools or root's crontab

/usr/local/bin/axopen

#!/bin/sh

SUDO=''
if (( $EUID != 0 )); then
    SUDO='sudo'
fi

echo -n "Checking for open connections"
while netstat -d | grep -q axel
do
  ((c++)) && ((c==900)) && break
  echo -n "."
  sleep 4
done
echo "done"

echo "Starting axtty service.."
$SUDO /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1
sleep 4
$SUDO /etc/init.d/axtty status

When axopen is executed på member of sudoaxtools, then it still prompts for password. I expect its because of the >/dev/null 2>&1 pieces.

Secondary

The reason i'm using nohup is because the service for some reason will not start, when executed simply using

sudo /etc/init.d/axtty start

So if someone have ideas to fix that, it will be great as well.

3

You don't want the redirections as part of the sudo rule. /etc/sudoers contains the program that is executed, and the redirections happen separately (at the containing shell level) from the sudo command:

(shell) sudo /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1

This calls sudo and redirects the output; sudo sees:

(sudo) /usr/bin/nohup /etc/init.d/axtty start

Change this sudoers line:

Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1

to:

Cmnd_Alias AXTOOLTTYSTART = /usr/bin/nohup /etc/init.d/axtty start
  • The redirect is meant to handle the nohup output, thats why i have it. If i Sudo the script itself, will i the. Have to sudo the lines inside the script? – Phliplip Jul 13 '18 at 6:48
  • 1
    Leave the redirection in the script but take it out of sudoers. – Jeff Schaller Jul 13 '18 at 10:01
0

I ended up putting the nohup script in a seperate bash script.

/usr/local/bin/axttystart

#!/bin/sh

## Intermediate bashscript in order to sudo nohup properly
/usr/bin/nohup /etc/init.d/axtty start >/dev/null 2>&1

Then changed sudo'ers line containing the Cmnd_alias for AXTOOLTTYSTART to

Cmnd_Alias AXTOOLTTYSTART = /usr/local/bin/axttystart

The updated axopen script will instead for the sudoing the nohup line directly, sudo the axttystart script

#!/bin/sh

[...]

echo "Starting axtty service.."
$SUDO /usr/local/bin/axttystart
sleep 4
$SUDO /etc/init.d/axtty status
  • Woops... You're correct, copy-paste mistake :-) – Phliplip Jul 15 '18 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.