Use sudo without password INSIDE a script

前端 未结 8 1947
礼貌的吻别
礼貌的吻别 2020-11-29 03:29

For some reason I need, as user, to run without sudo a script script.sh which needs root privileges to work.
I saw as the only solution to put sudo INSIDE script.sh. Let

8条回答
  •  隐瞒了意图╮
    2020-11-29 03:48

    If your password isn't something you want to be very secure about, (maybe some testing server in the company etc.) you can elevate to sudo in the script via echo like:

    echo YourPasswordHere | sudo -S Command
    

    The prompt still prints the "enter password" text to output though. So don't expect it to be neat.

    See this Askubuntu post

提交回复
热议问题