[GH-ISSUE #1732] Bash scripts unable to be run as logged in user #1078

Closed
opened 2026-03-02 02:21:00 +03:00 by kerem · 2 comments
Owner

Originally created by @ghost on GitHub (Jan 9, 2024).
Original GitHub issue: https://github.com/amidaware/tacticalrmm/issues/1732

I'm finding some problems with running macOS bash scripts through TRMM.

Updating brew is impossible because it doesn't find the users $PATH

Basically anything that required the user prompt fails unless I'm doing something wrong?

Is there a workaround for this?

Originally created by @ghost on GitHub (Jan 9, 2024). Original GitHub issue: https://github.com/amidaware/tacticalrmm/issues/1732 I'm finding some problems with running macOS bash scripts through TRMM. Updating brew is impossible because it doesn't find the users $PATH Basically anything that required the user prompt fails unless I'm doing something wrong? Is there a workaround for this?
kerem closed this issue 2026-03-02 02:21:00 +03:00
Author
Owner

@dinger1986 commented on GitHub (Jan 9, 2024):

  1. Follow the template, it's there for a reason
  2. Use remote background and see what you need to do to run the commands.

brew for example is a third party app so could have all sorts of oddities, essentially you need to figure out how to run brew as root. I chatgpt'd it, see below -

When you run the brew command as root, it can't find the $PATH variable due to the change in the environment variables when switching to the root user. Typically, running Homebrew as root is not recommended because it is designed to work without elevated privileges and running as root can cause various issues, including security risks and permission problems.

If you're encountering issues with brew not finding the $PATH, here's what you can do:

  1. Avoid using root: Run Homebrew with your regular user account. Homebrew is designed to work without needing root access.

  2. Check your $PATH: Make sure that the $PATH variable includes the directory where Homebrew is installed, typically /usr/local/bin for macOS. You can check your $PATH by running echo $PATH in the terminal.

  3. Correct permissions: If there are permission issues, you can fix them by running sudo chown -R $(whoami) /usr/local/* to take ownership of the Homebrew directories. This is safer than running Homebrew as root.

  4. Use sudo -E: If you absolutely must run a command as root and need to preserve the environment variables, you can use sudo -E. However, this is generally not recommended for Homebrew.

Remember, running Homebrew as root can lead to security risks and is against its recommended usage. It's best to troubleshoot the issue without resorting to root privileges.

<!-- gh-comment-id:1882585555 --> @dinger1986 commented on GitHub (Jan 9, 2024): 1. Follow the template, it's there for a reason 2. Use remote background and see what you need to do to run the commands. brew for example is a third party app so could have all sorts of oddities, essentially you need to figure out how to run brew as root. I chatgpt'd it, see below - When you run the `brew` command as root, it can't find the `$PATH` variable due to the change in the environment variables when switching to the root user. Typically, running Homebrew as root is not recommended because it is designed to work without elevated privileges and running as root can cause various issues, including security risks and permission problems. If you're encountering issues with `brew` not finding the `$PATH`, here's what you can do: 1. **Avoid using root:** Run Homebrew with your regular user account. Homebrew is designed to work without needing root access. 2. **Check your `$PATH`:** Make sure that the `$PATH` variable includes the directory where Homebrew is installed, typically `/usr/local/bin` for macOS. You can check your `$PATH` by running `echo $PATH` in the terminal. 3. **Correct permissions:** If there are permission issues, you can fix them by running `sudo chown -R $(whoami) /usr/local/*` to take ownership of the Homebrew directories. This is safer than running Homebrew as root. 4. **Use `sudo -E`:** If you absolutely must run a command as root and need to preserve the environment variables, you can use `sudo -E`. However, this is generally not recommended for Homebrew. Remember, running Homebrew as root can lead to security risks and is against its recommended usage. It's best to troubleshoot the issue without resorting to root privileges.
Author
Owner

@silversword411 commented on GitHub (Jan 9, 2024):

Also
To run a Bash script as a specific user while you are logged in as root on a Mac, you can use the su command followed by the -c option and the username of the user. Here's the general format:

su - [username] -c "/path/to/script.sh"

Replace [username] with the actual username and /path/to/script.sh with the full path to your script. This command switches to the specified user and executes the script in their context.

I'm sure we could do some more to try and determine the currently logged in user etc.

A good discussion for the Discord #script channel

<!-- gh-comment-id:1882683364 --> @silversword411 commented on GitHub (Jan 9, 2024): Also To run a Bash script as a specific user while you are logged in as root on a Mac, you can use the `su` command followed by the `-c` option and the username of the user. Here's the general format: ```bash su - [username] -c "/path/to/script.sh" ``` Replace `[username]` with the actual username and `/path/to/script.sh` with the full path to your script. This command switches to the specified user and executes the script in their context. I'm sure we could do some more to try and determine the currently logged in user etc. A good discussion for the Discord #script channel
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tacticalrmm#1078
No description provided.