4

I have booted up linux machine sitting at console login screen. Now I connect to that machine via ssh and I want to log user to displayed tty. Basically I want to bypass the login prompt in the console and go to the shell.

However what I do not want is auto-login on boot, I want to manually trigger the login via ssh.

How to do that?

3
  • 1
    Is this a systemd system? Aug 5, 2017 at 12:29
  • yes (12 more charactes to go... sigh :/)
    – graywolf
    Aug 5, 2017 at 13:28
  • You would need to redirect the output of the ssh session to the console tty. Aug 5, 2017 at 13:37

2 Answers 2

5

openvt (a.k.a. open) executes a given program in a given tty. Default program is your shell. Default tty is the first available. If you want to use a specific tty, you have to ensure it is not already used (by getty or an X session for example). The best is to use the default and to switch to the terminal with the -s option.

# openvt -l -s
2
  • Couldn't get a file descriptor referring to the console. = make sure to use sudo because of the #
    – aaa
    Jun 16, 2022 at 15:57
  • @aaa You are right, what the OP wants to do (access to a local console by bypassing the login shell) requires root privileges
    – xhienne
    Oct 12, 2023 at 9:25
0

You can configure one getty for autologin, disable this one and start it via SSH:

systemctl cat getty@tty4 gives you output like this (openSUSE Tumbleweed here):

[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

You have to override some of these settings:

systemctl cat getty@tty4

[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin username --noclear %I $TERM
ExecStartPost=/usr/bin/chvt 4
KillMode=none

Then you disable it: systemctl disable getty@tty4

Via SSH you run:

systemctl start getty@tty4 ; systemctl stop getty@tty4

The stop makes sure that you can actually logout (otherwise the shell would be restarted).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .