2

I have the following line in /etc/environment:

AAABBB=cccddd

When I login using the text console, the variable is set, I don't even need to reboot. But if I do su -, the variable is cleared. Why is that?

I have this on ArchLinux and on CentOS 6 and 7.

here grawity says:

Logging out and back in would apply the changes

But issuing the su command with dash is that very thing!

I'm really unhappy that su - clears the variable. Is there a way to make su behave better? One workaround is to duplicate the record in /etc/profile.d. It's not enough to have the record in profile and not /etc/environment, because there are cases when profile scripts aren't sourced, e.g. scp.

Upd

[root@reallin ~]# cat /etc/pam.d/su
#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth           required        pam_wheel.so use_uid
auth            required        pam_unix.so
account         required        pam_unix.so
session         required        pam_unix.so
[root@reallin ~]# cat /etc/pam.d/su-l
#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth           required        pam_wheel.so use_uid
auth            required        pam_unix.so
account         required        pam_unix.so
session         required        pam_unix.so
8
  • 1
    Have you tried su - with -m or -p flags?
    – coffeMug
    Jun 29, 2016 at 9:35
  • @coffeMug I don't want to preserve my env. I want it to reinitialize honoring /etc/environment
    – basin
    Jun 29, 2016 at 9:39
  • What is the shell of the root user (which is whom you're logging in as with su -)? Is the variable set when root ordinarily logs in?
    – Kusalananda
    Jun 29, 2016 at 9:54
  • @Kusalananda 1) /bin/bash ; 2) yes
    – basin
    Jun 29, 2016 at 9:56
  • @basin Do you have /etc/security/pam_env.conf file in your system? If yes, try to set the variable in that file and see if it works. Format is like Name DEFAULT=value
    – coffeMug
    Jun 29, 2016 at 9:59

1 Answer 1

3

Although su -l <user> works fine on my system, I noticed that sudo su -l <user> – although it picks up ".profile" just fine – seemed to cause the same problem you describe of clearing variables supposedly set universally in "/etc/environment".

I was able to get what appeared to be a full login (execution of the ".profile" of <user> plus the variables from "/etc/environment") by doing:

sudo -i -u <user>
1
  • Are there any nuances to the difference of sudo and su here that one should be aware of?
    – Reaver
    Oct 6, 2021 at 8:30

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.