Difference between revisions of "Automatic login to virtual console"

From ArchWiki
Jump to: navigation, search
(Use drop-in feature of systemd for getty autologin: added steps and made clearer)
(Fix revision 287586 by Eca (talk))
Line 9: Line 9:
 
{{Related articles end}}
 
{{Related articles end}}
  
This article describes how to automatically log in to a ''virtual console'' at the end of the [[boot process]]. This article only covers console log-ins; methods for starting an [[Xorg|X server]] are described in [[Start X at Login]].
+
This article describes how to automatically log in to a [[Wikipedia:Virtual console|virtual console]] at the end of the [[boot process]]. This article only covers console log-ins; see [[Start X at Login]] for information about automatic login into [[Xorg]].
  
== Installation ==
+
== Configuration ==
=== Use drop-in feature of systemd for getty autologin ===
+
[http://cgit.freedesktop.org/systemd/systemd/tree/NEWS#n655 Since systemd 198] unit files may now be extended via drop-in files without having to edit/override the unit files themselves, to learn more about this feature, consult [http://www.freedesktop.org/software/systemd/man/systemd.unit.html systemd.unit(5)] and search for ''Along with a unit file foo.service a directory foo.service.d/ may exist.''
+
  
There are two types of consoles: virtual and serial ones. In most cases you would want to setup up autologin on virtual console, the one which device name is ''ttyN'', where ''N'' is a number. The configuration of the autologin for the serial consoles will be slightly different. Device names of the serial consoles look like ''ttySN'', where ''N'' is a number.
+
Configuration relies on systemd [[Systemd#Editing_provided_unit_files|drop-in files]] to override the default parameters passed to ''agetty''.
  
==== Virtual console ====
+
The configuration differs for virtual and serial consoles. In most cases you would want to setup up autologin on virtual console, the one which device name is ''ttyN'', where ''N'' is a number. The configuration of the autologin for the serial consoles will be slightly different. Device names of the serial consoles look like ''ttySN'', where ''N'' is a number.
  
Create a new directory named {{ic|getty@tty1.service.d}} under {{ic|/etc/systemd/system}}:
+
=== Virtual console ===
  
# mkdir /etc/systemd/system/getty@tty1.service.d
+
Create the following file (and the leading directories):
  
Then create a new file named {{ic|autologin.conf}} and add it into the directory:
+
{{hc|/etc/systemd/system/getty@tty1.service.d/autologin.conf|2=
 
+
[Service]
{{hc|/etc/systemd/system/getty@tty1.service.d/autologin.conf|
+
2=[Service]
+
 
ExecStart=
 
ExecStart=
ExecStart=/usr/bin/agetty --autologin <username> --noclear %I 38400 linux
+
ExecStart=-/usr/bin/agetty --autologin ''username'' --noclear %I 38400 linux
 
}}
 
}}
  
Then disable getty@.service and enable getty@tty1.service
+
{{Tip|The option {{ic|1=Type=idle}} will delay the service startup until all jobs (state change requests to units) are completed. When using {{ic|1=Type=simple}}, the service will be started automatically, but boot-up messages may pollute the login prompt. This option is particularly useful when [[Start X at Login|starting X automatically]]. To use this option, add the following line into {{ic|autologin.conf}}:
 
+
Type=simple
{{bc|
+
systemctl disable getty@.service
+
systemctl enable getty@tty1.service
+
 
}}
 
}}
  
==== Serial console ====
+
If you want to use other ''tty'' than ''tty1'' see [[Systemd FAQ#Q:_How_do_I_change_the_number_of_gettys_running_by_default.3F|Systemd FAQ]].
  
# mkdir /etc/systemd/system/serial-getty@ttyS0.service.d
+
=== Serial console ===
  
The file {{ic|autologin.conf}} will also look slightly different
+
Create the following file (and the leading directories):
  
{{hc|/etc/systemd/system/serial-getty@ttyS0.service.d/autologin.conf|
+
{{hc|/etc/systemd/system/serial-getty@ttyS0.service.d/autologin.conf|2=
2=[Service]
+
[Service]
 
ExecStart=
 
ExecStart=
ExecStart=-/sbin/agetty --autologin <username> -s %I 115200,38400,9600 vt102
+
ExecStart=-/sbin/agetty --autologin ''username'' -s %I 115200,38400,9600 vt102
Type=simple
+
 
}}
 
}}
  
=== Tips ===
+
== Tips and tricks ==
====Start X at Login====
+
[[Start X at Login|starting X automatically]]. By default, {{ic|getty@.service}} uses {{ic|1=Type=idle}}, which delays the execution of agetty until all jobs (state change requests to units) are completed. By using {{ic|1=Type=simple}} {{ic|getty@.service}} will start immediately, but systemd boot-up messages might pollute the login prompt. To enable {{ic|1=Type=simple}} just add a line to {{ic|autologin.conf}}:
+
  
{{hc|/etc/systemd/system/getty@tty1.service.d/autologin.conf|
+
=== Avoiding unnecessary dmesg errors ===
2=[Service]
+
ExecStart=
+
ExecStart=-/usr/bin/agetty --autologin <username> --noclear %I 38400 linux
+
Type=simple
+
}}
+
  
 
==== Adding ttys ====
 
[[Systemd FAQ#Q:_How_do_I_change_the_number_of_gettys_running_by_default.3F|Systemd FAQ]].
 
 
== Tips & Tricks ==
 
 
=== Avoiding unnecessary dmesg errors ===
 
 
To avoid errors related to {{ic|display-manager.service}} in dmesg, you should set the default target to multi-user instead of graphical:
 
To avoid errors related to {{ic|display-manager.service}} in dmesg, you should set the default target to multi-user instead of graphical:
 
  # systemctl enable multi-user.target
 
  # systemctl enable multi-user.target
  
 
==See also==
 
==See also==
* [[Systemd#Change_default_target_to_boot_into|Change default runlevel/target to boot into]].
+
 
 +
* [[Systemd#Change_default_target_to_boot_into|Change default runlevel/target to boot into]]

Revision as of 12:15, 29 December 2013

This article describes how to automatically log in to a virtual console at the end of the boot process. This article only covers console log-ins; see Start X at Login for information about automatic login into Xorg.

Configuration

Configuration relies on systemd drop-in files to override the default parameters passed to agetty.

The configuration differs for virtual and serial consoles. In most cases you would want to setup up autologin on virtual console, the one which device name is ttyN, where N is a number. The configuration of the autologin for the serial consoles will be slightly different. Device names of the serial consoles look like ttySN, where N is a number.

Virtual console

Create the following file (and the leading directories):

/etc/systemd/system/getty@tty1.service.d/autologin.conf
[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin username --noclear %I 38400 linux
Tip:
Template error: are you trying to use the = sign? Visit Help:Template#Escape template-breaking characters for workarounds.

If you want to use other tty than tty1 see Systemd FAQ.

Serial console

Create the following file (and the leading directories):

/etc/systemd/system/serial-getty@ttyS0.service.d/autologin.conf
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin username -s %I 115200,38400,9600 vt102

Tips and tricks

Avoiding unnecessary dmesg errors

To avoid errors related to display-manager.service in dmesg, you should set the default target to multi-user instead of graphical:

# systemctl enable multi-user.target

See also