Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

It is said that settings for non login shell to go into .bashrc file and login shell settings to go into .profile file.

What is really meant by login and non-login shells?

Please explain without using technical jargon as far as possible.

share|improve this question
add comment

1 Answer

up vote 27 down vote accepted

Simply put:

  • If you open a shell or terminal (or switch to one), and it asks you to log in (Username? Password?) before it gives you a prompt, it's a login shell.
  • If it doesn't (like gnome-terminal), and lets you use it straight away, it's a non-login shell.

If you are a normal user of Ubuntu Desktop, the only login shell is...your desktop (you type a password to get in, right ;)? Well, technically it's a login shell that starts a GUI, but that's getting in to jargon. And yes, it will read the settings in .profile

The only time you (a normal user) will probably see a login shell that looks like a login shell is if you are having some problem with your desktop and you switch to a virtual terminal with the Ctrl+Alt+F1 shortcut.


The other general cases for having a login shell include:

  • accessing your computer remotely via ssh (or connecting locally with ssh localhost)
  • simulating an initial login shell with bash -l (or sh -l)
  • simulating an initial root login shell with sudo -i
    • or sudo -u username -i for another non-root user
  • authenticating as another non-root user with su - username (and their password)
  • using the sudo login command to switch user
share|improve this answer
    
If I start my Eclipse IDE from terminal, it opens as expected, but if I try to open it by clicking the Eclipse icon, it is unable to recognize Java location (unless otherwise PATH for Java is set in .profile file). That means clicking Eclipse icon needs a login shell, why? –  DUKE Jun 26 '12 at 12:45
2  
@DUKE, No, it means that environment variables need to be set differently when you are using a desktop/GUI versus a true command-line-only console system. Put your PATH, etc. in ~/.pam_environment (variables only, no bash commands in there!), logout, login, and watch everything magically appear in the desktop as well as in gnome-terminal! –  izx Jun 26 '12 at 12:49
    
the clearest explanation i've found. thanks –  chanHXC Sep 8 '13 at 4:15
add comment

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.