10

when you first boot, and you're greeted with the warm glow of a black screen and flashing prompt, what program is that? What program handles evaluation of the credentials? Or rather, what component of the source code is it? I may be confusing myself, but I think the various user shells are loaded after user authentication.

... which might mean that bash is launched in single user mode, then bash checks credentials & launches a user shell? (I think this is how it works)

(Im interested in adding a feature to the credential checking process, but I'm looking at bash source code, and I'm not sure where to begin. )

3
  • 2
    I don't think a shell is involved until after authentication; getty invokes login, which probably then uses the pam_unix module for basic password authentication. If you want to add an authentication feature you will probably be looking at writing a custom PAM module. Apr 3, 2022 at 20:23
  • 2
    ... here's a possible template Externally authenticate user within PAM session/PAM session within PAM session Apr 3, 2022 at 20:33
  • 1
    now that I'm looking at it a bit more, maybe I can inspect the boot process a little more to find out exactly whats happening. I think maybe /bin/login is what I should be looking at. type -a login shows login isn't a shell built in.
    – j0h
    Apr 3, 2022 at 22:11

1 Answer 1

10

I have only a rudimentary understanding myself, however I'll post this to get you started:

First, you don't log in to a shell, you log in to a (virtual) terminal.

  • a getty program opens a tty port, prompts for a login name and invokes a login program (/bin/login by default - although Linux's agetty may be configured to use a non-standard login program)

  • the login program performs authentication and session setup, including initializing the environment and invoking the user's login shell.

In current Ubuntu systems, getty is managed as a systemd service (ex. [email protected] for the virtual terminal tty1), and login uses the Pluggable Authentication Modules (PAM) subsystem for authentication - in particular, the pam_unix module is "for traditional password authentication".

For your stated goal ("adding a feature to the credential checking process") you would probably want to look at implementing a custom PAM module, and inserting it into an appropriate place in the PAM stack; a template for that is described here:

See also:

3
  • I think this is a good start, much appreciated.
    – j0h
    Apr 3, 2022 at 23:12
  • Just small details to add: getty normally prompts the user for username and reads it. The login program is then invoked using exec() call replacing the getty process. The username retrieved by getty is given to login as a parameter. --- After certain number of failed login attempts the program login exits and the getty process is automatically started anew by the system service manager (systemd or init in older systems). The same automatic restart happens when the session is ended. --- linux.die.net/sag/login-via-terminal.html Apr 4, 2022 at 9:34
  • @pabouk-Ukrainestaystrong thanks - I have added your reference and clarified the role of getty Apr 4, 2022 at 11:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .