Skip to main content
Quiet comment
Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324

You can't easily do what you ask (i.e. make sudo startup.sh run as a named non-root user). What you can do, though, is one or both of the following

  1. Tell users to use sudo -u tomcat /path/to/startup.sh instead of sudo /path/to/startup.sh, and disallow the latter anyway

    Add this line to your sudoers (remember visudo) such that tomcat here is the target user account. Change the first ALL to a list of users if there are only certain people allowed to run the script as the target user

     ALL ALL=(tomcat) /path/to/startup.sh 
  2. Make the script perform the sudo, and disallow sudo -u root for the script. You'll need #1 (above). Ensure that tomcat here matches the tomcat in sudoers.

      
     #!/bin/bash # targetUser=tomcat if [[ $UID -ne "$(id -u "$targetUser")" ]] then exec sudo -u "$targetUser" "$0" "$@" exit 1 fi # ...script continues but as the $targetUser... 

    This allows people to run /path/to/startup.sh (or even just startup.sh if it's in the $PATH) and not worry about the sudo part.

You can't easily do what you ask (i.e. make sudo startup.sh run as a named non-root user). What you can do, though, is one or both of the following

  1. Tell users to use sudo -u tomcat /path/to/startup.sh instead of sudo /path/to/startup.sh, and disallow the latter anyway

    Add this line to your sudoers (remember visudo) such that tomcat here is the target user account. Change the first ALL to a list of users if there are only certain people allowed to run the script as the target user

     ALL ALL=(tomcat) /path/to/startup.sh 
  2. Make the script perform the sudo, and disallow sudo -u root for the script. You'll need #1 (above). Ensure that tomcat here matches the tomcat in sudoers.

     
     #!/bin/bash # targetUser=tomcat if [[ $UID -ne "$(id -u "$targetUser")" ]] then exec sudo -u "$targetUser" "$0" "$@" exit 1 fi # ...script continues but as the $targetUser... 

    This allows people to run /path/to/startup.sh (or even just startup.sh if it's in the $PATH) and not worry about the sudo part.

You can't easily do what you ask (i.e. make sudo startup.sh run as a named non-root user). What you can do, though, is one or both of the following

  1. Tell users to use sudo -u tomcat /path/to/startup.sh instead of sudo /path/to/startup.sh, and disallow the latter anyway

    Add this line to your sudoers (remember visudo) such that tomcat here is the target user account. Change the first ALL to a list of users if there are only certain people allowed to run the script as the target user

     ALL ALL=(tomcat) /path/to/startup.sh 
  2. Make the script perform the sudo, and disallow sudo -u root for the script. You'll need #1 (above). Ensure that tomcat here matches the tomcat in sudoers.

     
     #!/bin/bash # targetUser=tomcat if [[ $UID -ne "$(id -u "$targetUser")" ]] then exec sudo -u "$targetUser" "$0" "$@" exit 1 fi # ...script continues but as the $targetUser... 

    This allows people to run /path/to/startup.sh (or even just startup.sh if it's in the $PATH) and not worry about the sudo part.

added 9 characters in body
Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324

You can't easily do what you ask (i.e. make sudo startup.sh run as a named non-root user). What you can do, though, is one or both of the following

  1. Tell users to use sudo -u tomcat /path/to/startup.sh instead of sudo /path/to/startup.sh, and disallow the latter anyway

    Add this line to your sudoers (remember visudo) such that tomcat here is the target user account. Change the first ALL to a list of users if there are only certain people allowed to run the script as the target user

     ALL ALL=(tomcat) /path/to/startup.sh 
  2. Make the script perform the sudo, and disallow sudo -u root for the script. You'll need #1 (above). Ensure that tomcat here matches the tomcat in sudoers (above). You'll need #1 (above), too

     #!/bin/bash # targetUser=tomcat if [[ $UID -ne "$(id -u "$targetUser")" ]] then exec sudo -u "$targetUser" "$0" "$@" exit 1 fi # ...script continues but as the $targetUser... 

    This allows people to run /path/to/startup.sh (or even just startup.sh if it's in the $PATH) and not worry about the sudo part.

You can't do what you ask (i.e. make sudo startup.sh run as a named non-root user). What you can do is one or both of the following

  1. Tell users to use sudo -u tomcat /path/to/startup.sh instead of sudo /path/to/startup.sh, and disallow the latter anyway

    Add this line to your sudoers (remember visudo) such that tomcat here is the target user account. Change the first ALL to a list of users if there are only certain people allowed to run the script as the target user

     ALL ALL=(tomcat) /path/to/startup.sh 
  2. Make the script perform the sudo, and disallow sudo -u root for the script. Ensure that tomcat here matches the tomcat in sudoers (above). You'll need #1 (above), too

     #!/bin/bash # targetUser=tomcat if [[ $UID -ne "$(id -u "$targetUser")" ]] then exec sudo -u "$targetUser" "$0" "$@" exit 1 fi # ...script continues but as the $targetUser... 

    This allows people to run /path/to/startup.sh (or even just startup.sh if it's in the $PATH) and not worry about the sudo part.

You can't easily do what you ask (i.e. make sudo startup.sh run as a named non-root user). What you can do, though, is one or both of the following

  1. Tell users to use sudo -u tomcat /path/to/startup.sh instead of sudo /path/to/startup.sh, and disallow the latter anyway

    Add this line to your sudoers (remember visudo) such that tomcat here is the target user account. Change the first ALL to a list of users if there are only certain people allowed to run the script as the target user

     ALL ALL=(tomcat) /path/to/startup.sh 
  2. Make the script perform the sudo, and disallow sudo -u root for the script. You'll need #1 (above). Ensure that tomcat here matches the tomcat in sudoers.

     #!/bin/bash # targetUser=tomcat if [[ $UID -ne "$(id -u "$targetUser")" ]] then exec sudo -u "$targetUser" "$0" "$@" exit 1 fi # ...script continues but as the $targetUser... 

    This allows people to run /path/to/startup.sh (or even just startup.sh if it's in the $PATH) and not worry about the sudo part.

added 25 characters in body
Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324

You can't do what you ask (i.e. make sudo startup.sh run as a named non-root user). What you can do is one or both of the following

  1. Tell users to use sudo -u tomcat /path/to/startup.sh instead of sudo /path/to/startup.sh, and disallow the latter anyway

    Add this line to your sudoers (remember visudo) such that tomcat here is the target user account. Change the first ALL to a list of users if there are only certain people allowed to run the script as the target user

     ALL ALL=(tomcat) /path/to/startup.sh 
  2. Make the script perform the sudo, and disallow sudo -u root for the script. Ensure that tomcat here matches the tomcat in sudoers (above). You'll need #1 (above), too

     #!/bin/bash # targetUser=tomcat   targetUID=$if [[ $UID -ne "$(id -u "$targetUser")  " [[]]  $UIDthen  -ne "$targetUID" ]] && exec sudo -u "$targetUser" "$0" "$@" exit 1 fi # ...script continues but as the $targetUser... 

    This allows people to run /path/to/startup.sh (or even just startup.sh if it's in the $PATH) and not worry about the sudo part.

You can't do what you ask (i.e. make sudo startup.sh run as a named non-root user). What you can do is one or both of the following

  1. Tell users to use sudo -u tomcat /path/to/startup.sh instead of sudo /path/to/startup.sh, and disallow the latter anyway

    Add this line to your sudoers (remember visudo) such that tomcat here is the target user account. Change the first ALL to a list of users if there are only certain people allowed to run the script as the target user

     ALL ALL=(tomcat) /path/to/startup.sh 
  2. Make the script perform the sudo, and disallow sudo -u root for the script. Ensure that tomcat here matches the tomcat in sudoers (above). You'll need #1 (above), too

     #!/bin/bash # targetUser=tomcat targetUID=$(id -u "$targetUser")   [[ $UID -ne "$targetUID" ]] && exec sudo -u "$targetUser" "$0" "$@" # ...script continues but as the $targetUser... 

    This allows people to run /path/to/startup.sh (or even just startup.sh if it's in the $PATH) and not worry about the sudo part.

You can't do what you ask (i.e. make sudo startup.sh run as a named non-root user). What you can do is one or both of the following

  1. Tell users to use sudo -u tomcat /path/to/startup.sh instead of sudo /path/to/startup.sh, and disallow the latter anyway

    Add this line to your sudoers (remember visudo) such that tomcat here is the target user account. Change the first ALL to a list of users if there are only certain people allowed to run the script as the target user

     ALL ALL=(tomcat) /path/to/startup.sh 
  2. Make the script perform the sudo, and disallow sudo -u root for the script. Ensure that tomcat here matches the tomcat in sudoers (above). You'll need #1 (above), too

     #!/bin/bash # targetUser=tomcat   if [[ $UID -ne "$(id -u "$targetUser")" ]]  then  exec sudo -u "$targetUser" "$0" "$@" exit 1 fi # ...script continues but as the $targetUser... 

    This allows people to run /path/to/startup.sh (or even just startup.sh if it's in the $PATH) and not worry about the sudo part.

One or both, not one or the other
Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324
Loading
Source Link
Chris Davies
  • 128.3k
  • 16
  • 179
  • 324
Loading