Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

WHere is the $HOME environment variable set in Centos 6.3?

I've looked in:

  • /etc/profile
  • /etc/profile.d/*
  • /etc/bashrc
  • ~/.bash_profile
  • ~/.bashrc

Also, the second to last column in /etc/passwd has the correct home directory.

SELinux is disabled, fwiw.

share|improve this question
    
login program set it. see comptechdoc.org/os/linux/howlinuxworks/linux_hllogin.html –  Laurentiu Roescu Apr 3 '13 at 18:35
    
Looking to set HOME for a non-tty login. That link doesn't point to a script that's run, from what I saw. –  trimbletodd Apr 3 '13 at 18:54

1 Answer 1

up vote 3 down vote accepted

The login programs set these variables. You can of course override HOME if you must, or even unset it -- but unless you went to effort to modify the source of each program you can not ever get rid of it.

Note even if you alter HOME to be something else the authoritative source of your home directory will always be present in passwd or the nsswitch derivative.

If you login via a real TTY, login will set it.

From util-linux in login-utils/login.c

setenv("HOME", pwd->pw_dir, 0); /* legal to override */
setenv("USER", pwd->pw_name, 1);
setenv("SHELL", pwd->pw_shell, 1);
setenv("TERM", termenv, 1);

If you login via SSH sshd will set it:

From session.c in sshd

child_set_env(&env, &envsize, "USER", pw->pw_name);
child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
child_set_env(&env, &envsize, "HOME", pw->pw_dir);

If you login via GDM it will set it in there.

From gdm in daemon/gdm-session-worker.c

gdm_session_worker_set_environment_variable (worker, "LOGNAME", worker->priv->username);
gdm_session_worker_set_environment_variable (worker, "USER", worker->priv->username);
gdm_session_worker_set_environment_variable (worker, "USERNAME", worker->priv->username);
gdm_session_worker_set_environment_variable (worker, "HOME", home);
gdm_session_worker_set_environment_variable (worker, "SHELL", shell);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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