TTY Autologin: Difference between revisions

From Alpine Linux
(→‎By using agetty: The inittab was overwriten on each reboot in my case)
Line 15: Line 15:
== By using agetty (CLI Proxmox) ==
== By using agetty (CLI Proxmox) ==


Install {{pkg|agetty}}: {{cmd|# apk add agetty}}
Proxmox (8.3.2) host has a setup_init script for Alpine linux at {{path|/usr/share/perl5/PVE/LXC/Setup/Alpine.pm}} that overwrites all changes to tty lines in {{path|/etc/inittab}}.


Create new file {{path|/etc/init.d/autologin}}
Modify the script at {{path|/usr/share/perl5/PVE/LXC/Setup/Alpine.pm}} and add the following lines in setup_init (not to modify the {{path|/etc/inittab}} file if it contains the word "agetty").
<pre>#!/sbin/openrc-run
<pre>...
my $inittab = $self->ct_file_get_contents($filename);


name="autologin"
--->
description="Enable autologin on tty1"
56:  if ($inittab =~ /agetty/) {
57:        return;
58:    }
<----


command="/sbin/agetty"
my @lines = grep {
command_args="--autologin root --noclear 38400 tty1"
...
pidfile="/run/${name}.pid
</pre>
</pre>


Make it executable
Changes are marked with current line numbers.
{{cmd|# chmod +x /etc/init.d/autologin}}


Create the autologin service
After running the LXC container perform the following steps in it:
{{cmd| #rc-update add autologin default}}


You can now reboot and login directly to root.
# Install {{pkg|agetty}}: {{cmd|# apk add agetty}}
# Modify this line in {{path|/etc/inittab}}
<pre>
tty1::respawn:/sbin/agetty --autologin root --noclear 38400 tty1
</pre>


ps: The {{path|/etc/inittab}} modification did not work for me as the file was overwriten on each boot.
After a reboot the container will perform an autologin.


== By making your own autologin wrapper ==
== By making your own autologin wrapper ==

Revision as of 22:25, 11 March 2025

This page documents how to setup autologin to tty. Once configured, when computer is powered on, you will be logged in automatically without typing password. Note that, if someone else starts up your computer, they will be able to access your account and your personal data.

By using agetty

Install agetty:

# apk add agetty

Edit /etc/inittab to use agetty
Example for the virtual terminal tty1:
tty1::respawn:/sbin/agetty --autologin root tty1 linux

Example inittab entry for a serial terminal on ttys01:
ttyS0::respawn:/sbin/agetty --autologin root ttyS0 vt100

Tip: You can change the `tty1` or `ttyS0` to a different serial port or virtual terminal as you please. `root` can be changed to a different user as well. Finally the terminal type (`linux` and `vt100` in our examples) can be changed to a wide variety of serial terminals.

By using agetty (CLI Proxmox)

Proxmox (8.3.2) host has a setup_init script for Alpine linux at /usr/share/perl5/PVE/LXC/Setup/Alpine.pm that overwrites all changes to tty lines in /etc/inittab.

Modify the script at /usr/share/perl5/PVE/LXC/Setup/Alpine.pm and add the following lines in setup_init (not to modify the /etc/inittab file if it contains the word "agetty").

...
my $inittab = $self->ct_file_get_contents($filename);

--->
56:   if ($inittab =~ /agetty/) {
57:        return;
58:    }
<----

my @lines = grep {
...

Changes are marked with current line numbers.

After running the LXC container perform the following steps in it:

  1. Install agetty:

    # apk add agetty

  2. Modify this line in /etc/inittab
tty1::respawn:/sbin/agetty --autologin root --noclear 38400 tty1

After a reboot the container will perform an autologin.

By making your own autologin wrapper

Create a script, called autologin, around /bin/login and moving it in /usr/sbin/ and editing /etc/inittab to specify the use of /usr/sbin/autologin instead of /bin/login.

  1. Create and edit the autologin wrapper script /usr/sbin/autologin as follows:

    Contents of /usr/sbin/autologin

    #!/bin/sh exec login -f root
  2. Remember to make the scripts executable:

    # chmod +x /usr/sbin/autologin

  3. The script executes 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, its username can be used instead.
  4. Open /etc/inittab and replace ":respawn:/sbin/getty" with ":respawn:/sbin/getty -n -l /usr/sbin/autologin" for each TTY you want to enable 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
  5. To perform such a replacement on all TTYs, the following command can be used:

    # sed -i 's@:respawn:/sbin/getty@:respawn:/sbin/getty -n -l /usr/sbin/autologin@g' /etc/inittab

    "@" is used as a delimiter
    The -i flag edits the file in-place

Use greetd

The Greetd display manager has a text based greeter that can be configured to autologin.

See also