Print QR Code on Remote Monitor

Print QR Code on Remote Monitor

It is possible to print QR Codes on a console using for instance this solution. There are other methods available on github too, but all of them end up displaying UTF8 chars. Therefore, I think that the challenge is in displaying a stdout on the TTY1 from the remote host

The remote host is a linux deployment without X, it has connectivity, allows me to ssh, I'm able to become a super-user and it has a local monitor connected displaying the login prompt on TTY1 (which is where I want to print the QR code).

答案1

To print to another terminal, you just print to /dev/ttyN or /dev/pts/N (where N is a number). If you want TTY1 then use /dev/tty1.

As a regular user you cannot print to a terminal that is not yours. In general you need sudo. However sudo qrencode -t ascii foo > /dev/tty1 is not a good method because it's your unelevated shell who tries to open /dev/tty1 before sudo starts. These are proper ways:

qrencode -t ascii foo | sudo tee /dev/tty1
sudo sh -c 'qrencode -t ascii foo > /dev/tty1'

Note the latter method runs sh and qrencode as root, while the former method runs only tee as root, nothing more. Prefer the former method then. Add >/dev/null after tee /dev/tty1 to suppress printing to your tty.

相关内容