Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to restrict the user from changing some set of environment variables?

I have have a script that sets PATH to point at a specific build of some software, and puts the user in a new bash session. I'm wondering if it's possible to make PATH (and a handful of other variables) unchangeable for that session of bash, forcing them to exit if they'd like to start changing the parts of their environment that would affect how the software runs.

share|improve this question
up vote 3 down vote accepted

This will do what you want:

readonly PATH
share|improve this answer
I'm not sure that that would help. The users could always reexececute bash again. Or run another shell. Or ... Maybe a chroot environment would be better. – maxelost Jan 21 '11 at 16:28
Agreed, if the PATH isn't set appropriately to start with, then the user can get around the restriction - how important this is depends on the exact use case. As you say, chroot is worth investigating, as is setting the shell to rbash ("bash -r") to restrict what the user can do. – Alex Howell Jan 21 '11 at 16:47
In this case, it's just an extra check to avoid mistakes. Depending on what the user specifies, their PATH points to a handful of bin/ dirs (and LD_LIBRARY_PATH to a handful of lib/ dirs, etc.). I'm trying to reduce that chances that after they run my script to "use environment X" they change something important taking them out of the selected "software quarantine." – Andrew Wood Jan 21 '11 at 16:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.