From nobody Thu Aug 19 05:31:29 2021 X-Original-To: freebsd-stable@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 76FD6177051F for ; Thu, 19 Aug 2021 05:31:37 +0000 (UTC) (envelope-from ari@ish.com.au) Received: from mail.ish.com.au (mail.ish.com.au [203.29.62.212]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Gqtfv4cVlz3FjR for ; Thu, 19 Aug 2021 05:31:35 +0000 (UTC) (envelope-from ari@ish.com.au) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ish.com.au; s=mail; h=Subject:From:To:MIME-Version:Date:Message-ID:Content-Type:Sender: Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Y/eyL9NkeDe2dJ97Le1OhYBpepJssZ2rMdB9CdqvwVI=; b=tvKMgEu/mNjPW5Q9tPGL71yd8V o8s/8cBPNZKvTXjrPmF8OUNCakzSAZMpYrx3/OBDwu9m0lx6o/aQQFqwyb/k5HbDJk7oniVlXEzj2 /4sgG4VD8nfO9gkQlA+vQVcKebVGzIWISpzyyHwZ0wkoa2FPRPYLHnCZTWpDA6BK7iYLP05Y9mZ4V cxA6RtGPOZZui9PDUHyktWGxINBHmzR7/z0UrhI6+3WOCzFsMJP4cz0PFFMthoO0kq0Sfjtx2hF15 HlAW5DSrzrPEMlwIBTWg9Cme0SkRA2Fyl7khj0l8B5xlynXhWZuJHBs6TFvepFMkqhRHVnhrOCz0G AJcUxCMA==; Received: from [10.242.2.3] by mail.ish.com.au with esmtpsa (TLS1.3) tls TLS_AES_128_GCM_SHA256 (Exim 4.94.2 (FreeBSD)) (envelope-from ) id 1mGaeH-000GNl-UB for freebsd-stable@freebsd.org; Thu, 19 Aug 2021 15:31:29 +1000 Content-Type: multipart/alternative; boundary="------------3I5dazuS4QtlY0107pPjQxYY" Message-ID: Date: Thu, 19 Aug 2021 15:31:29 +1000 List-Id: Production branch of FreeBSD source code List-Archive: https://lists.freebsd.org/archives/freebsd-stable List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-stable@freebsd.org X-BeenThere: freebsd-stable@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:92.0) Gecko/20100101 Thunderbird/92.0 To: freebsd-stable Content-Language: en-AU Subject: Run script as root without sudo X-Rspamd-Queue-Id: 4Gqtfv4cVlz3FjR X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=ish.com.au header.s=mail header.b="tvKMgEu/"; dmarc=pass (policy=quarantine) header.from=ish.com.au; spf=pass (mx1.freebsd.org: domain of ari@ish.com.au designates 203.29.62.212 as permitted sender) smtp.mailfrom=ari@ish.com.au X-Spamd-Result: default: False [-4.00 / 15.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[ish.com.au:s=mail]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:203.29.62.0/24]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCPT_COUNT_ONE(0.00)[1]; TO_DN_ALL(0.00)[]; DKIM_TRACE(0.00)[ish.com.au:+]; DMARC_POLICY_ALLOW(-0.50)[ish.com.au,quarantine]; NEURAL_HAM_SHORT(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; ASN(0.00)[asn:7545, ipnet:203.29.62.0/24, country:AU]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] Reply-To: ari@ish.com.au From: Aristedes Maniatis via freebsd-stable X-Original-From: Aristedes Maniatis X-ThisMailContainsUnwantedMimeParts: Y 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--