💾 Archived View for gemlog.blue › users › zain › 1636884542.gmi captured on 2024-08-31 at 20:25:22. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-12-04)
-=-=-=-=-=-=-
1. Add a virtual serial port to the VM
qm set <VMID> -serial0 socket
(or)
echo "serial0: socket" >> /etc/pve/qemu-server/<VMID>.conf
1. Enable a serial console
systemctl enable serial-getty@ttyS0.service systemctl start serial-getty@ttyS0.service
2. Instruct grub2 to send the boot messages on the serial port by editing `/etc/default/grub` and adding:
GRUB_CMDLINE_LINUX="quiet console=tty0 console=ttyS0,115200"
3. run `update-grub` afterward.
_TIPS_
Add in .bashrc
export SYSTEMD_EDITOR=vim
1. Run `systemctl edit serial-getty@ttyS0.service`, and add the following:
[Service] ExecStart= ExecStart=-/sbin/agetty -o '-p -- \\u' --keep-baud 115200,38400,9600 --noclear --autologin root ttyS0 $TERM
This will cause `agetty` to auto-login the `root` user, but with only this change the system will still prompt you for the root password.
-o --login-option -p --login-pause \u user -J --noclear (Do not clear the screen before prompting the login name. By deafult the screen is cleared)
2. We can configure `/etc/pam.d/login` to authenticate `root` logins on the console without a password. Add the following to the top of `/etc/pam.d/login`:
```
auth sufficient pam_listfile.so item=tty sense=allow file=/etc/securetty onerr=fail apply=root
```
This will cause the PAM stack to check for the login tty in `/etc/securetty`, and to skip other authentication mechanisms if it finds it.
3. Add the serial port to `/etc/securetty`.
```
echo ttyS0 >> /etc/securetty
```
On the host, just enter
qm terminal <VMiD>
and enter **enter** a second time to get the prompt.
qm terminal <VMiD> -iface serial1
Remember the `qm terminal` uses Ctrl-O as shortcut, so saving a file from `nano` with Ctrl-O will log you out instead.
root@zain-lab ~ # qm terminal 101011 starting serial terminal on interface serial0 (press Ctrl+O to exit) root@console ~ # root@console ~ # logout Debian GNU/Linux 10 console ttyS0 console login: root (automatic login) Last login: Thu May 6 18:14:49 UTC 2021 on ttyS0 Linux console 4.19.0-10-amd64 #1 SMP Debian 4.19.132-1 (2020-07-24) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. root@console ~ #
https://notesofaprogrammer.blogspot.com/2020/05/enabling-serial-console-on-debian-linux.html
https://unix.stackexchange.com/questions/552576/allow-passwordless-root-login-on-the-serial-console
http://www.linux-pam.org/Linux-PAM-html/sag-pam_listfile.html
https://wiki.archlinux.org/title/Systemd#Change_default_target_to_boot_into
https://www.debuntu.org/how-to-set-up-a-serial-console-on-debian/