How can I execute a series of commands in a bash subshell as another user using sudo?

后端 未结 6 889
别跟我提以往
别跟我提以往 2021-01-30 10:33

I\'m writing a bash script that needs to sudo multiple commands. I can do this:

( whoami ; whoami )

but I can\'t do this:

sudo          


        
6条回答
  •  余生分开走
    2021-01-30 11:13

    sudo only asks for your passwd the first time.The passwd answered is valid for about 5 minutes by default.You can change this value as this told.So just worry about the passwd prompt at the beginning of your script,then you can use sudo through out. changing Defaults:user_name timestamp_timeout's value to -1 may be a security hole on your system.

提交回复
热议问题