FG

Why does "sudo -u root echo `whoami`" not return root?

Fresh3 days ago
Mar 15, 202611985 views
Confidence Score0%
0%

Problem

How do you use sudo to run a command as the actual root user on Ubuntu? I originally thought this was the default behavior of sudo, until I ran: However, this is the type of behavior I want, but only in a single line:

Error Output

myuser@localhost:~$ sudo echo `whoami`
myuser

myuser@localhost:~$ sudo -u root echo `whoami`
myuser

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Why does "sudo -u root echo `whoami`" not return root?

Low Risk

In fact it does run them as root. But, what's happening to you is that the back ticks are being evaluated before runs, as they're needed to evaluate the command. More directly, why not just this: Your in back ticks is actually evaluated in a subshel…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment