Use sudo without password INSIDE a script

前端 未结 8 1941
礼貌的吻别
礼貌的吻别 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条回答
  •  -上瘾入骨i
    2020-11-29 04:03

    In new /etc/sudoers.d/apt-get file, put single line:

    user ALL=(ALL:ALL) NOPASSWD:/usr/bin/apt-get update
    

    Fully qualified path to executable is required here.

    Then use following in your script:

    sudo apt-get update
    

    Here, fully specified name is not required. Sudo uses PATH environment variable for executable resolution.

    While changing and checking sudoers configuration, be sure to keep another root session open for error recovery.

提交回复
热议问题