Replies

This profile is from a federated server and may be incomplete. Browse more on the original instance.

nirogu, to linux
@nirogu@vivaldi.net avatar

Run command as not-root

Hi everyone

At work, I have to run a command in an AWS instance. In that particular instance only exists the root user. The command should not be executed with root privileges (it executes mpirun, which is not recommended to run as sudo or the machine might break), so I was wondering if there is a way to block or disable the sudo privileges while the command is running. As mentioned, the only user existing there is root, so I suppose "sudo -u" is not an option.

Does anyone know how to do it? Thanks in advance!

@linux

Oisteink,

There’s no way to run a command as another user if that user is not created.

linux.die.net/man/1/runuser

Edit:sudo is also an option but I like runuser for your use-case

Oisteink,

Linux privilege only understands user id’s and group id’s. These are mapped through /etc/passwd and /etc/groups. You will see in passwd that the root user has UID 0. Any account you create with UID 0 will have root privileges. So running the command specifying any user with UID!=0 will run without those privileges.

It’s also possible to set user on execution with setuid - but that won’t work on scripts only binary executables.

en.wikipedia.org/wiki/Setuid

en.wikipedia.org/wiki/User_identifier

en.wikipedia.org/wiki/Group_identifier

Oisteink,

Read your other post and it seems to me that a rebuild of the system to accommodate non-root users would be my preferred solution. Trying to “work around“ issues like this are prone to break as the system is updated/changed. And you’re back to trying to figure out what’s changed and makes your script break.

Oisteink,

Laziness sparks innovation, and there could possibly be some other way to drop privileges. There’s loads of stuff I learn about Linux still - and my first install was summer 94

Keep at it!

  • All
  • Subscribed
  • Moderated
  • Favorites
  • localhost
  • All magazines
  • Loading…
    Loading the web debug toolbar…
    Attempt #