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 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.

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
  • 594