TTY Autologin: Difference between revisions

From Alpine Linux
m (Added references)
mNo edit summary
Line 43: Line 43:
== Editing /etc/inittab ==
== Editing /etc/inittab ==


{{Cmd|# sed -i 's@:respawn:/sbin/getty@:respawn:/sbin/getty -n -l /usr/sbin/autologin@g' /etc/inittab }}
Open /etc/inittab


The above command:
{{Cmd|# vi /etc/inittab }}
* replaces "'':respawn:/sbin/getty''" with "'':respawn:/sbin/getty -n -l /usr/sbin/autologin''"
 
* "'''@'''" is used as a delimiter
replace each "'':respawn:/sbin/getty''" with "'':respawn:/sbin/getty -n -l /usr/sbin/autologin''"
* The '''-i''' flag edits the file in-place
* The getty's '''-n''' flag do not prompt the user for a login name
* The getty's '''-n''' flag do not prompt the user for a login name
* The getty's '''-l''' flag invokes a custom login instead of /bin/login; in our case it is set to invoke /usr/sbin/autologin
* The getty's '''-l''' flag invokes a custom login instead of /bin/login; in our case it is set to invoke /usr/sbin/autologin

Revision as of 19:56, 10 September 2023

What follows is one from many different ways to get autologin.

How

  1. Writing a wrapper, called autologin, around /bin/login and moving it in /usr/sbin/
  2. Editing /etc/inittab specifying the use of /usr/sbin/autologin instead of /bin/login

Prerequisites

  • A C compiler
  • The musl-dev package which contains the C standard library

Example on how to assolve the prerequisites:

# apk add --repository https://dl-cdn.alpinelinux.org/alpine/edge/testing tcc # apk add musl-dev

Writing the autologin.c program

Create a file; in this example called autologin.c

# vi autologin.c

Write into it the following C program.

#include <unistd.h> int main() { execlp( "login", "login", "-f", "root", 0); }

The only thing it does is a system call to execute the login binary (part of busybox) which will be searched in PATH.

As parameters are passed:

  • -f flag which stands for "Do not authenticate (user already authenticated)"
  • username in this example is root but if you created a new user, the user username can be used instead.

Compiling the autologin.c program

If using tcc:

# tcc -o autologin autologin.c

Move the binary autologin to /usr/sbin

# mv autologin /usr/sbin/

Editing /etc/inittab

Open /etc/inittab

# vi /etc/inittab

replace each ":respawn:/sbin/getty" with ":respawn:/sbin/getty -n -l /usr/sbin/autologin"

  • The getty's -n flag do not prompt the user for a login name
  • The getty's -l flag invokes a custom login instead of /bin/login; in our case it is set to invoke /usr/sbin/autologin

Cleaning up

It is possible to remove the autologin.c file, the C compiler and the musl-dev package

# rm autologin.c # apk del tcc # apk del musl-dev

References

  1. http://littlesvr.ca/linux-stuff/articles/autologinconsole/autologinconsole.php
  2. https://wiki.gumstix.com/index.php/AutoLogin