Vanstechelman.eu
   

Changing virtual terminals

Changing virtual terminals is already a fairly easy combination of keypresses in a standard Linux installation. If are you are in X, you would use Ctrl+Alt plus the function key of the terminal number to change to. Switching back is easy, just select Ctl+Alt+F7. Outside of X it's one less keypress - Alt+F2.
Like most things in a Unix-like environment, there is more than one way to accomplish your goal. This one is no different. The sys-apps/kbd ebuild installs a chvt binary which lets you change terminals with one command. The only argument it takes is an integer value of which one you want to switch to.

+-------------------------------------------------------------------------+ 
| Code Listing 1:                                                         | 
| Changing terminals with chvt                                            | 
+-------------------------------------------------------------------------+ 
|                                                                         | 
|# chvt 1                                                                 | 
|                                                                         | 
+-------------------------------------------------------------------------+ 

If you are in X, you can only execute the command as root, otherwise it will not work. It will work as any user outside of X, though. If you're interested in a workaround, you can use app-admin/sudo to allow your user(s) to run chvt from inside an X11 session.

+-------------------------------------------------------------------------+ 
| Code Listing 2:                                                         | 
| Adding sudo access to chvt                                              | 
+-------------------------------------------------------------------------+ 
|                                                                         | 
|$ echo "%users $HOSTNAME=/usr/bin/chvt" >> /etc/sudoers                  | 
|                                                                         | 
+-------------------------------------------------------------------------+

Warning: Be sure you know what you are doing when modifying sudo permissions, since you are giving root access to run certain commands.