Can a Non-Root Modify Environment Variables?

Can a Non-Root Modify Environment Variables?

Can a non-root (without sudo permissions) run the following command:

export PATH=/tml:$PATH

If so, how does it work?

I thought environment variables are read-only for non-root users, while shell variables can be modified freely.

7

1 Answer

The output of the following commands should convince you that you can modify your environment variables.

$ grep PATH ~/.profile 
# set PATH so it includes user's private bin if it exists
    PATH=~/bin:"${PATH}"
PATH="$PATH:/usr/games"

$ ls -l ~/.profile
-rw-r--r-- 1 sudodus sudodus 632 dec 10  2010 /home/sudodus/.profile

In other words, you can not only modify these variables temporarily, but also make it persist by modifying your configuration file ~/.profile. You, as a regular user can do it.


The following command line shows system files, where the PATH is set or modified

sudo grep -r 'PATH=' /etc/*

You may want to get more details. See for example the following link,

Unix & Linux: Complete view of where the PATH variable is set in bash - particularly the answer by Gilles.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.