You are not logged in.

#1 2010-05-29 02:04:42

andonuts_388
Member
Registered: 2010-05-23
Posts: 15

What is a login shell

I was following the Archwiki guide on colouring the bash prompt and found that if I open gnome-terminal and use 'su root' I get a colourised prompt but if I used 'su - root' which I found out to be the same as 'su -l root' then I didn't.

Some further research told me that -l makes the shell a login shell but I still don't really understand what that is or how it is any different. Can anyone enlighten me? Thankyou.

Offline

#2 2010-05-29 02:36:22

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: What is a login shell

A shell will produce a different environment when started as a login shell than when not. You should read your shell's manpage for a description of the process. Assuming you are using bash as your shell, you would want to read the section titled INVOCATION.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#3 2010-05-29 03:29:09

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,791

Re: What is a login shell

I may be mistaken, but I believe the major difference is that when you su using a login shell, all of the login scripts for that shell run when it is instantiated.  On my system, that includes changing to the new user's $HOME. 

Without the -l, the system changes to the new user, but things like the CWD and PATH remain unchanged

For the purposes of system administration where you are switching to root, I don't think it matters which you use -- unless you do or don't what to change the environment.

[edit: added a missing verb.  Note to self: Don't post when you are tired]

Last edited by ewaller (2010-05-29 14:41:48)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#4 2010-05-29 10:31:56

andonuts_388
Member
Registered: 2010-05-23
Posts: 15

Re: What is a login shell

So in normal use, there's no issue using su -l or just su?

Offline

#5 2010-05-29 14:46:40

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,791

Re: What is a login shell

andonuts_388 wrote:

So in normal use, there's no issue using su -l or just su?

I would say that is true.  In practice, I almost always use sudo.  The only time I actually change to root is if I'm trying to write to a pipe to a second program which also needs root privilege.  I am too lazy to figure out the correct incarnation for that.  I don't believe I have ever used su -l

edit: fixed typo

Last edited by ewaller (2010-05-29 16:08:12)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#6 2010-05-29 14:58:07

cesura
Package Maintainer (PM)
From: Tallinn, Estonia
Registered: 2010-01-23
Posts: 1,867

Re: What is a login shell

In a nice way to put it, without -l, it will just change users. With it, it will take that user to their home directory and use their config files.

Hope I was right on that one wink

Offline

#7 2010-05-29 14:58:10

hbekel
Member
Registered: 2008-10-04
Posts: 311

Re: What is a login shell

The common solution is to source ~/.bashrc from ~/.profile, e.g. add

. $HOME/.bashrc

to ~/.profile

So that your bashrc gets sourced regardless of whether it's a login shell or not.

Offline

#8 2010-05-29 14:58:50

andonuts_388
Member
Registered: 2010-05-23
Posts: 15

Re: What is a login shell

Thankyou all

Offline

Board footer

Powered by FluxBB