如何从脚本提供sudo密码? [英] How to supply sudo with password from script?

查看:72
本文介绍了如何从脚本提供sudo密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请注意::这是在本地计算机上运行的来宾VM(VBox),我并不担心安全性.

Please note: this is a guest VM (VBox) running on my local machine, and I'm not worried about security.

我正在编写一个脚本,该脚本将以 myuser 用户的身份在Linux(Ubuntu)VM上执行.该脚本将在/etc/myapp 下创建一个非常大的目录树.目前,我必须手动完成所有操作,首先要在/etc 下授予 myuser 递归 rwx 权限,如下所示:

I am writing a script that will be executed on a Linux (Ubuntu) VM as the myuser user. This script will create a very large directory tree under /etc/myapp. Currently I have to do all this manually, and it starts with me giving myuser recrusive rwx permissions under /etc like so:

sudo chmod -R 777 /etc
[sudo] password for myuser:  <now I enter the password and hit ENTER>

我的问题:我该如何编写一个bash脚本,为 sudo 命令提供密码,以便我可以执行 bash myscript.sh ,它将使我需要进行必要的权限更改吗?

My question: how do I write a bash script that supplies the sudo command with my password so that I can just execute bash myscript.sh and it will make the necessary permission changes for me?

推荐答案

如您所说,如果完全不在乎安全性...

If, as you say, you completely don't care about security...

运行 visudo 来编辑/etc/sudoers 并进行验证.添加以下行:

Run visudo to edit /etc/sudoers with validation in place. Add the following line:

ALL ALL=(ALL) NOPASSWD: ALL

这将防止 sudo 向任何用户,任何命令询问密码.

This will prevent sudo from ever asking for a password, for any user, for any command.

这篇关于如何从脚本提供sudo密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆