Debian/Ubuntu 配置tty自动登录

基于systemd服务控制,配置getty服务文件。可以控制开放自动登录的端口和登录用户,本文以root登录ttyS0为例

  1. 终端输入命令

    systemctl enable [email protected]
    

    这将会创建一个软链接/etc/systemd/system/getty.target.wants/[email protected] -> /lib/systemd/system/[email protected],为getty服务的配置文件

  2. 修改配置文件/etc/systemd/system/getty.target.wants/[email protected]

    ...
    [Service]
    # origin config
    ExecStart=-/sbin/agetty --noclear %I $TERM
    # new config
    ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM
    
  3. 重启生效

附:源服务配置文件

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Getty on %I
Documentation=man:agetty(8) man:systemd-getty-generator(8)
Documentation=http://0pointer.de/blog/projects/serial-console.html
After=rc-local.service

# If additional gettys are spawned during boot then we should make
# sure that this is synchronized before getty.target, even though
# getty.target didn't actually pull it in.
Before=getty.target
IgnoreOnIsolate=yes

# IgnoreOnIsolate causes issues with sulogin, if someone isolates
# rescue.target or starts rescue.service from multi-user.target or
# graphical.target.
Conflicts=rescue.service
Before=rescue.service

# On systems without virtual consoles, don't start any getty. Note
# that serial gettys are covered by [email protected], not this
# unit.
ConditionPathExists=/dev/tty0

[Service]
# the VT is cleared by TTYVTDisallocate
ExecStart=-/sbin/agetty --autologin root --noclear %I $TERM
Type=idle
Restart=always
RestartSec=0
UtmpIdentifier=%I
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
TTYVTDisallocate=yes
KillMode=process
IgnoreSIGPIPE=no
SendSIGHUP=yes

你可能感兴趣的:(Others,ubuntu,linux,运维)