2

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?

kzh
  • 866
  • 2
  • 10
  • 23
  • _preset in any virtual terminal_ and _not present in TTY1_ are contradictory. TTY1 is a virtual terminal. – JdeBP Jun 15 '15 at 12:04

2 Answers2

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.

Gunnar Hjalmarsson
  • 32,938
  • 3
  • 63
  • 94
0

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
dgpro
  • 554
  • 4
  • 6
  • 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 '16 at 19:34