Running headless on a RasPi2, it seems that items (e.g., environment variables) set up in .profile on the terminal do not take effect in the desktop, at least when accessed by VNC. Of course it is possible to source the .profile manually from the desktop. What is the right way to set up dotfiles so that the terminal and the desktop have the same environment?

  • What does "headless" mean in this context?
    – Bex
    Commented Jun 2, 2015 at 7:17
  • @Bex: In this case "headless" means without keyboard or display, thus accessed with ssh and/or a remote GUI. Commented Jun 3, 2015 at 5:04

1 Answer 1


.profile is only sourced by "login shells". What makes a login shell a login shell is basically the options used to start it; e.g. with bash --login, or (from man bash):


A login shell is one whose first character of argument zero is a -, or one started with the --login option.

"Argument zero" here refers to the name of the executable itself, i.e., -bash would refer to a login shell (but it is still /bin/bash1). This is typically done by the login command if you log in locally at a console; sshd will also do it if you log in that way.

However, if you log in graphically, e.g., using a display manager, (DM) this depends on the attitude of the people who wrote the display manager, because it never starts a shell. You may never start a shell. If you do, it is probably inside a GUI terminal, and those do not use a login shell because normally you only have one for every login session, not everytime you open a terminal. Hence, some DM's will source .profile to compensate for this. Some others, on the idea that it is not their place to do this, do not, including the default lightDM used on Raspbian.

Evidently this applies to your VNC login as well.

What is the right way to set up dotfiles so that the terminal and the desktop have the same environment?

There is such thing as .xprofile, which is supposedly sourced by DM's and startx and xinit. So you could make it a softlink to .xprofile. In this case, you should make /etc/xprofile a link to /etc/profile, since this is used too.

sudo ln -s /etc/profile /etc/xprofile
ln -s ~/.profile ~/.xprofile

The problem with this is that if you then log in on a console and run startx, you'll have sourced .profile twice, which is usually undesirable.

Another idea is to use ~/.xinit and do this:

if [[ -z $I_AM_LOGGED_IN ]]; then
    source /etc/profile
    source $HOME/.profile

Then in ~/.profile make sure you have:

export I_AM_LOGGED_IN=yes

This should make all logins identical and prevent repeated sourcing of .profile.

1. Presumably it's accomplished by tweaking "argument zero" in the exec() call at the end of login; I mention this because you can see login shells with ps -o cmd -C bash; they're the -bash ones.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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