How to change virtual ttys in Linux and OpenBSD with console commands?

In Linux one presses Alt-F1, Alt-F2 etc to change virtual ttys.

In OpenBSD one shall use Ctrl-Alt-F1 etc instead.

Are there are console commands for these two operating systems that can be issued to achieve this goal? Using key presses sometimes interfere when an OS is being run as guest inside another one using some virtual machine.


Yes, you can using the chvt command. This needs sudo privileges to run.

CHVT(1)

NAME

chvt - change foreground virtual terminal

SYNOPSIS

chvt N

DESCRIPTION

The command chvt N makes /dev/ttyN the foreground terminal.
(The corresponding screen is created if it did not exist yet.
To get rid of unused VTs, use deallocvt )
The key combination (Ctrl-)LeftAlt-FN (with N in the range 1-12) usually has a similar effect.

You can find the virtual terminal you're currently on via the fgconsole command. This too requires sudo privileges to run.