0

I have googling around for long time but couldn't actually find a reliable way.

This is what I want:

Use Bash script, check if user is actually root root, not the user with sudo command.

I have tried many ways , like id -u, $EUID, whoami, etc., but all of them return same value when run as root and using sudo.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
qtwrk
  • 329
  • 2
  • 7
  • 3
    Does this answer your question? [How do you find the original user through multiple sudo and su commands?](https://stackoverflow.com/questions/4598001/how-do-you-find-the-original-user-through-multiple-sudo-and-su-commands) – Joe Jan 13 '20 at 11:20
  • What is the difference between "being `root`" and running a command *as* `root`? – grooveplex Jan 13 '20 at 13:18

1 Answers1

0

You could check if there are some environment variables set by sudo:

set | grep SUDO

Output:

SUDO_COMMAND=/bin/bash
SUDO_GID=1000
SUDO_UID=1000
SUDO_USER=user1
UtLox
  • 3,744
  • 2
  • 10
  • 13