I have environment variables set in ~/.pam_environment and they exist as expected in any graphical terminal emulator I open. If I open a virtual terminal, e.g. TTY1, and login, my PAM environment variables are not present.

How can I ensure ~/.pam_environment variables are always loaded?

  • preset in any virtual terminal and not present in TTY1 are contradictory. TTY1 is a virtual terminal.
    – JdeBP
    Jun 15, 2015 at 12:04

2 Answers 2


One way is to edit /etc/pam.d/login like this:

--- a/login 2015-06-15 03:35:17.422387358 +0200
+++ b/login 2015-06-15 03:36:41.535536201 +0200
@@ -50,7 +50,7 @@
 session       required   pam_env.so readenv=1
 # locale variables are also kept into /etc/default/locale in etch
 # reading this file *in addition to /etc/environment* does not hurt
-session       required   pam_env.so readenv=1 envfile=/etc/default/locale
+session       required   pam_env.so readenv=1 user_readenv=1 envfile=/etc/default/locale

 # Standard Un*x authentication.
 @include common-auth

Can't tell if it's 'the proper way', though.


As per official documentation, ~/.pam_environment is for session-wide environment variables which will affect just a particular user. It means that when you edit that file as yourself or as root you edit two different files. If you do this as your user:

user@here:~$ sudo nano ~/.pam_environment

it will open /home/user/.pam_environment.

But if you if open it as root

user@here:~$ sudo su
root@here:~$ nano ~/.pam_environment

it will open /root/.pam_environment. So you have to be carefull not to edit this file as root.

To check that your environment variables do exist, edit ~/.pam_environment save it and logout or exit ssh session. When you login again run export which prints out all variables

user@here:~$ export
  • The issue is not that the wrong file is being edited. The issue is that if I open a virtual TTY under X, pam_environment is loaded, but if I open TTY1 (ctrl+alt+F1) the pam_environment is not loaded.
    – kzh
    Mar 31, 2016 at 19:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .