LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   /bin/login and creating a login shell~ (https://www.linuxquestions.org/questions/linux-newbie-8/bin-login-and-creating-a-login-shell%7E-4175528577/)

szejiekoh 12-17-2014 01:13 PM

/bin/login and creating a login shell~
 
Hi all,

Not sure how /bin/login works, but i cant seems to enter the correct password


Code:

[alan~racnode1 ~]$ /bin/login
login: grid
Password:
Login incorrect

login:

Yet when using su and the same login and password, i can login.

Code:

[alan~racnode1 ~]$ su - grid
Password:
[grid~racnode1 ~]$

q1) Why ?

============

Been reading about login shell

Quote:

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

The login process tells the shell to behave as a login shell with a convention: passing argument 0, which is normally the name of the shell executable, with a - character prepended. For example, for Bash shell it will be -bash.
q2) how do i simulate the creation of a login shell using the "-bash" method ?

Code:


[grid~racnode1 ~]$ /bin/login -bash
/bin/login: invalid option -- 'b'
usage: login [-fp] [username]
[grid~racnode1 ~]$ -bash
-bash: -bash: command not found

Regards,
Noob

linosaurusroot 12-17-2014 01:23 PM

perl -e 'exec {"/bin/bash"} "-bash"'

pan64 12-17-2014 01:49 PM

I would say you misunderstood something. bash --login will start you a login shell, see the man page of bash.
login -bash will not work.
also see man page of login: login may be special to the shell and may not be invoked as a sub-process.

szejiekoh 12-18-2014 12:24 AM

Quote:

Originally Posted by pan64 (Post 5286451)
I would say you misunderstood something. bash --login will start you a login shell, see the man page of bash.
login -bash will not work.
also see man page of login: login may be special to the shell and may not be invoked as a sub-process.

Hi Pan64, thanks for replying.

I tried bash --login, but it doesnt prompt me for any login or password entry and $0 doesnt return a login shell "-bash"

Code:

[alan@racnode1 ~]$ bash --login
[alan@racnode1 ~]$ echo $0
bash
[alan@racnode1 ~]$

When I do a su - user directly, it returned me a login shell.

Code:

[alan@racnode1 ~]$ su - alan
Password:
[alan@racnode1 ~]$ echo $0
-bash
[alan@racnode1 ~]$

Am I missing something ? How does the login process works (when a user 1st connnect to the terminal) ?
is "login" process really invoking "bash --login" or "bash" is invoking "--login" to let user login into a login shell ?

Regards,
Noob

pan64 12-18-2014 06:31 AM

http://comptechdoc.org/os/linux/howl...x_hllogin.html
http://www.linuxnix.com/2013/09/how-...-in-linux.html

szejiekoh 12-18-2014 01:06 PM

Thanks pan64.


All times are GMT -5. The time now is 08:09 PM.