我已经在控制台登录屏幕上启动了 Linux 机器。现在我通过 ssh 连接到该机器,我想将用户登录到显示的 tty。基本上我想绕过控制台中的登录提示并转到 shell。
但是我不想要的是启动时自动登录,我想通过 ssh 手动触发登录。
怎么做?
答案1
openvt
(又名open
)在给定的tty
.默认程序是您的 shell。默认tty
是第一个可用的。如果您想使用特定的tty
,您必须确保它尚未被使用(getty
例如被 X 会话使用)。最好是使用默认值并使用该-s
选项切换到终端。
# openvt -l -s
答案2
您可以配置一个 getty 以进行自动登录,禁用该 getty 并通过 SSH 启动它:
systemctl cat getty@tty4
给你这样的输出(这里是 openSUSE Tumbleweed):
[Service]
# the VT is cleared by TTYVTDisallocate
ExecStart=-/sbin/agetty --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
您必须覆盖其中一些设置:
systemctl cat getty@tty4
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin username --noclear %I $TERM
ExecStartPost=/usr/bin/chvt 4
KillMode=none
然后你禁用它:systemctl disable getty@tty4
通过 SSH 你运行:
systemctl start getty@tty4 ; systemctl stop getty@tty4
这stop
确保您实际上可以注销(否则 shell 将重新启动)。