Switch to the wrong virtual terminal on a shared machine and you have just hijacked someone else's console with chvt. You will switch the foreground Linux virtual terminal to a chosen /dev/ttyN, confirm which version is installed, and recover if you select the wrong console. Allow about five minutes. You need a local graphical or text login with virtual terminals available; running this from an SSH session does not move your SSH client to another screen.
Safety warning: Changing the foreground terminal is immediate and can interrupt someone who is using that console. Do not test it on a shared machine without checking who is logged in. It changes the active display, not the logged-in users or their processes.
The command comes from the kbd package. This guide follows kbd 2.6.4, installed here as package version 2.6.4-2ubuntu2. Other releases may format help or diagnostics differently, so check the local binary before putting the command in a script.
$ command -v chvt
/usr/bin/chvt
$ chvt --version
chvt from kbd 2.6.4
$ chvt --help
Usage: chvt [option...] N
Options:
-h, --help print this usage message.
-V, --version print version number.
Checkpoint: the binary is present and the help output shows that one terminal number, N, is required. The only documented options are --help and --version. Do not add an option copied from a different terminal utility.
A virtual terminal is a local text console such as /dev/tty1 or /dev/tty2. On most Linux installations, the function keys switch between a small set of consoles, but the exact number depends on the machine and its display manager. The manual describes Ctrl plus LeftAlt and F1 through F12 as the usual keyboard equivalent.
Before changing anything, inspect the current session and the available device names. These checks do not switch consoles:
$ tty
/dev/pts/0
$ ls -l /dev/tty[1-9] /dev/tty[1-9][0-9] 2>/dev/null
crw--w---- 1 root tty 4, 1 ... /dev/tty1
crw--w---- 1 root tty 4, 2 ... /dev/tty2
Your tty output may be a pseudo-terminal such as /dev/pts/0. That is normal for a terminal emulator or SSH session, and it is not the target that chvt selects. Choose a real local virtual-terminal number from the device list. Replace 2 in the next example with that number.
Run chvt with the terminal number as its final argument:
$ chvt 2
The command normally prints no success message. The foreground screen should change to virtual terminal 2. If a login prompt or an existing text session is there, it remains there. chvt does not log you in, terminate the old session, or move processes between terminals.
On a local text console, the command may work as your ordinary user when that user has the required device permission. On a desktop or a restricted session, it may fail with a permission error. Only if the account is authorised to make this system-wide display change, retry with elevated privileges:
$ sudo chvt 2
Entering a password or using sudo does not make an invalid terminal number valid. Treat an unexpected authentication prompt as a reason to check the target and the account, not as a prompt to paste credentials into an untrusted script.
Once the display changes, press a key if necessary and check the console identity. This is easiest when the target console has a shell already running:
$ tty
/dev/tty2
$ printf 'console: %s\n' "$(tty)"
console: /dev/tty2
If the target shows a login prompt, log in through the normal local login process before running the check. A blank screen, a display manager, or an application already attached to that VT is not evidence that chvt failed. Check the keyboard switch back to the console you were using, commonly Ctrl plus LeftAlt and F1:
$ chvt 1
Use the actual original terminal number if it was not 1. The keyboard combination is often convenient, but chvt N is clearer in a documented procedure.
If chvt reports an error, first confirm that the argument is a number identifying a local VT and that the command is running on the machine whose screen you expect to change. Inspect the binary and package again if the command was found through an unexpected path:
$ command -v chvt
/usr/bin/chvt
$ dpkg-query -W -f='${Package} ${Version}\n' kbd
kbd 2.6.4-2ubuntu2
Do not assume that a pseudo-terminal such as /dev/pts/0 can be passed as N; the interface takes the number in /dev/ttyN. If the command succeeds but you cannot see a useful prompt, switch back to the previous VT or use the documented keyboard combination. No persistent configuration was changed, so there is nothing to undo in a file or service.
Be careful with repeated or automated calls. Each call changes the foreground display and can steal the screen from a local user. Avoid placing chvt in a startup script, service hook or unattended loop until you have tested the exact terminal numbering and arranged a local recovery path.
chvt binary and kbd version./dev/ttyN from an SSH or terminal-emulator pseudo-terminal.