this post was submitted on 02 Nov 2023
27 points (88.6% liked)

Linux

47538 readers
589 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

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

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 11 months ago (1 children)

@Rustmilian yeah, already tried it. The problem is that all of the apps in the instance are only installed for the root user (e.g. python and all it's libraries. So, when I use su -c all I get is a lot of command not found messages that would take a lot to solve. Besides I expect a lot more problems when the command needs access to some files and some processes (like a sql database) that would require me to do a lot of stuff to grant permissions to the new user. That would eventually work but given the work it requires I thought that some kind of "anti sudo" command or something like that could exist so I can still be the root user but pretend I am not a superadmin

[–] Rustmilian 1 points 11 months ago* (last edited 11 months ago) (1 children)

There's a source that says something about using the AWS Systems Manager Session Manager by ""Configuring the necessary IAM permissions for your user or role to access the instance using Session Manager 1
Open the AWS Systems Manager console, navigate to the "Session Manager" page, and select the instance you want to access
Click on the "Start session" button to initiate the session with the instance.
Once the session is established, you can run commands as the root user without the need for sudo""
I'm unsure if this achieves exactly what you need though.

[–] [email protected] 1 points 11 months ago

@Rustmilian Just did that and that is exactly what I needed, but in this case it didn't work. In this page https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-prerequisites.html they explain that what the manager does is creating another root account in the instance, and that new account is the one that can disable its own permissions. So, I ended up with the same problem of having to configure everything for the new user. However I'm done with the laziness and I'm gonna do it lol, everyone else pointed out that not having a regular user is a security issue and they are right. If I had configured the instance from the beginning with the SSM, I could have skipped all that work, but the reality is that I have to do it
After I'm done configuring everything, I think I'll set up the rest of the instances to work with the SSM so that I don't have to go through all that again
Thanks for the help!