Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use asdf as root user?

Tags:

asdf-vm

I need to read some hardware data with privileges permissions, so I need to use the asdf plugin as root. How can I do that?

I tried to start the root user sudo su but I cannot access asdf

like image 249
fvarj Avatar asked Sep 03 '25 15:09

fvarj


2 Answers

tl;dr: sudo -E su

The problem is that sudo doesn't preserve (most) environment variables by default. For asdf, the environment variables ASDF_CONFIG_FILE, ASDF_DATA_DIR, and ASDF_DIR are all important, along with the usual suspects, like PATH.

Fortunately, we can instruct sudo to keep all the environment variables around. From man sudo:

-E, --preserve-env

Indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the user does not have permission to preserve the environment.


Resources:

  • An asdf issue comment from anandumdas
like image 175
Shayne Holmes Avatar answered Sep 05 '25 15:09

Shayne Holmes


The existing answer on this post pointed me in the right direction: sudo -E is required in order to carry over environment variables (including the important PATH) into the sudo shell.

However, I was still getting the unknown command: THECOMMAND. Perhaps you have to reshim?. What worked for me is getting the path to both the command you want to run and the binary you want to run it through.

In my case, I was trying to use the hostile host management tool. It failed because it couldn't find node. By specifying both the full node path and the direct path to the hostile script I was able to get around the reshim errors.

sudo -E `asdf which node` `asdf which hostile` load the_file.txt
like image 36
iloveitaly Avatar answered Sep 05 '25 16:09

iloveitaly