How can I set an env variable for all the users even the nologin ones?

In particular I want to set an env variable containing a path that will be used from users script and the webserver (www-data that is a nologin shell user and then can't benefits from PAM's /etc/environment nor /etc/profile and similars)

  • Just to clarify: you want the envvar set for (interactive) login sessions started through SSH or locally, and also for scripts (CGI, PHP, whatever) started by the HTTP server? What HTTP server are you running? – ilkkachu May 16 '18 at 10:37
  • @ilkkachu, yes it is correct, I want both. I'm using apache and I already have set /etc/envinroment and /etc/apache2/envvars to achieve my goal, but what if I'll need to use also nodejs or other service? I have to set for them all. I was looking for one only config (like /etc/envinroment but that works for all users) – Luca Ricci May 16 '18 at 10:45

Assuming you use the default init system:



Sets manager environment variables passed to all executed processes. Takes a space-separated list of variable assignments. See environ(7) for details about environment variables.


DefaultEnvironment="VAR1=word1 word2" VAR2=word3 "VAR3=word 5 6"

Sets three variables "VAR1", "VAR2", "VAR3".

"all executed processes" here meaning all processes executed by systemd. Generally, all processes are either started by systemd, or children of a process that was. But please be careful with this, otherwise you might have to recover your system using init=/bin/sh etc. :-).

It is possible that some processes will clear their environment variables, or make assignments that supercede these. I think user login (PAM?) would be an important example here.

As you say, you can cover all PAM sessions using pam_env / /etc/environment.

  • thanks! setting the variable in both /etc/systemd/system.conf and /etc/environment did the trick it's more generic then my solution (/etc/apache2/envvars) but still has 2 conf that I have to update, I'll wait a little bit for other solutions, if none than I'll accept this as answer. – Luca Ricci May 16 '18 at 13:36

Your Answer

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

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