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

2 Answers 2

up vote 35 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
    
Login via ssh does not invoke a login shell. It doesn't load /etc/profile, /etc/profile.d or ~/.profile. –  xuhdev Jul 19 '14 at 0:17
    
See this question. –  xuhdev Jul 19 '14 at 0:29

I do not think that correct answer can be given without “technical jargon”. Since this question is the first one popping up in Google for the query “what is a login shell” I am providing a more correct answer below:

Login shell is simply a shell that was told to be a login shell. It does not mean shell that pops up after you login, though usually application that logs you in is telling shell it launches to be a login shell. There exists the following ways to tell shell it should be a login one:

  1. Running shell with -l or --login argument assuming it knows it (I do not know any shells which do not know -l, but --login is only supported by a few shells).
  2. Running shell with argv[0] set to -{some_string} (i.e. with HYPHEN-MINUS prepended to usual argv[0] or to some other string). This is what ssh and su do: su just runs executable with -su as argv[0] (hello to everybody thinking argv[0] has something to do with currently running executable name), ssh runs zsh with -zsh when user has set /bin/zsh as his shell.

Loginess of the shell has absolutely nothing to do with anybody asking you a password or performing some other authenication procedure. Some programs like ssh or login (or some terminal emulators like urxvt) run shells as a login ones using argv[0] that starts with a HYPHEN-MINUS. Some like su or sudo (or zsh: see - precommand modifier described in section PRECOMMAND MODIFIERS in man zshmisc) do not do this by default, but can be told so. Some have the only option of telling shell to be the login one using its argument (i.e. bash -l): ssh with a command argument (that explicitly tells ssh what to run on the remote end).

Generally it is better to first consult the documentation of the program used to invoke the shell to determine whether shell will be the login one and second perform some tests to determine whether app will launch a login shell (e.g. by adding echo to .profile).

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.