sudo
sudo가 설치가 안되어 있으면 visudo 등을 사용....
sudo 설치된 상태에서 /etc/sudoers에서 설정하면 특정 그룹에 있는 user가 sudo 명령어 사용할때 passwd 안묻도록 할 수 있음
if you really want to have a script run as a user and be able to execute commands as root, there are 2 options that I know of.
Use sudo with stored password:
#!/bin/sh
whoami
sudo -S -p "" whoami <<EOF
mysuperpassword
EOFWhich will output (when run as 'user'):
user
rootUse sudo with no password.
Add a list of the commands that you wish to run into the/etc/sudoers
file by runningvisudo
as root. For example, to allowuser
to run the commandsapache2ctl
andwhoami
, add the following:User_Alias SPECIAL = user
Cmnd_Alias SPECIAL_COMMANDS = /usr/sbin/apache2ctl, /usr/bin/whoami
SPECIAL ALL = NOPASSWD: SPECIAL_COMMANDSOr if you really trust
user
, if it's you for example, you can allow the user to execute any command without a password:user ALL=(ALL) NOPASSWD: ALL
Then when the following script is run by
user
:#!/bin/sh
whoami
sudo whoamiIt will output:
user
root