Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Problem with sudo in a script

    Hi, i have a slight problem with a script. the below script was just to make using jailkit easier. the problem is when i use the parameter --start.

    the specific line is

    sudo chrootuid "$jail" "$jailuser" "$jailedbinary" &

    chrootui just lowers the user privileges after the process is running in the jail, the & is so i can close the ssh session after it is launched.

    The problem is, when i execute this line of code, i get some terminal spam.

    $ [sudo] password for axe: Sorry, try again.
    [sudo] password for axe: Sorry, try again.
    [sudo] password for axe: Sorry, try again.
    sudo: 3 incorrect password attempts
    it doesn't even prompt me for a password. The only workaround is if i use sudo before hand to get superuser privs, then run it.

    any ideas what is going wrong?


    here is the whole script.
    binarybasename=$(basename "$jailedbinary")
    if [ "$1" == "--help" ]; then
    	echo -e "location:\t/bin"
    	echo -e "usage:\t\tjail OPTION... PARAMETER..."
    	echo -e "\n\t--update"
    	echo -e "\t--copy\t\t- must specify a target binary"
    	echo -e "\t--ps\t\t- lists running jailed processes"
    	echo -e "\t--start\t\t- user and target binary are specified in the script"
    	echo -e "\t--killall\t- kills the process specified in the script ( $binarybasename )"	
    	echo ""
    elif [ "$1" == "--update" ]; then
    	sudo jk_update -vj "$jail"
    elif [ "$1" == "--copy" ] || [ "$1" == "--cp" ];then
    	if [ "$2" == "" ]; then
    		echo ":: you need to specify a target binary"
    		sudo jk_cp -fov -j "$jail" "$2"
    elif [ "$1" == "--ps" ]; then
    	sudo jk_list
    elif [ "$1" == "--start" ]; then
    	sudo chrootuid "$jail" "$jailuser" "$jailedbinary" &
    elif [ "$1" == "--killall" ]; then
    	sudo killall "$binarybasename"
    	echo ":: unknown command"	

  2. #2
    turns out that backgrounding that line with & interferes with sudo, since the entire command is backgrounded before sudo prompts. a fix is to use the -b with sudo. ie, sudo -b <command>.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts