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
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:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With