Server Fault is a question and answer site for system and network administrators. 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

I put some script on my ubuntu linux in /etc/profile.d/ but it's just work on my user.

But it's work only user logged in not when I use sudo.

export MYVAL="HELLO"

echo $MYVAL // HELLO

sudo echo $MYVAL // ?!
share|improve this question
up vote 1 down vote accepted

Could you please explain better what are you trying to achieve? .profile is executed with a user privileges, when the user logs on.
So in order to use sudo in .profile you have to put user/group, user belongs to in /etc/sudoers

ok, sudo strips environment variables for various security reasons. In order to do what you want, you have to put in /etc/sudoers

Defaults        env_reset  
Defaults        env_keep += "MYVARIABLE YETANOTHER"
share|improve this answer
i need to define a variable that can i use in each user with and without sudo. it's so simple. – sweb Nov 5 '12 at 9:04

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.