Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Aug 2021 15:31:29 +1000
From:      Aristedes Maniatis via freebsd-stable <freebsd-stable@freebsd.org>
To:        freebsd-stable <freebsd-stable@freebsd.org>
Subject:   Run script as root without sudo
Message-ID:  <a7d48318-6b21-231e-1042-2d2daad72c50@ish.com.au>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------3I5dazuS4QtlY0107pPjQxYY
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

I've got some scripts which are intended to run on a new EC2 instance 
right after it is created. Since the script needs to install packages it 
need to run as root. But because I don't have sudo installed at this 
point (it is a brand new instance), I've only got 'su' to get root.

The script itself is launched over SSH with the ec2-user account and 
there is no root password at this point in the startup.

My first attempt was to put this inside the script itself:

if ["$($whoami)" !="root" ];thenexec su -c"$0" exit1 fi


But su complains that I'm not allowed to execute a command using the -c 
option as root.

How else can I get this script running as root remotely in a completely 
unattended way?



Cheers

Ari Maniatis
--------------3I5dazuS4QtlY0107pPjQxYY--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a7d48318-6b21-231e-1042-2d2daad72c50>