unix Is a multi-user and multi task operating system . Early computers were expensive , So we used cheap devices to connect to computers ( There was no keyboard or monitor , Use paper tape and cards for input and output ) To use the operating system , This cheap device is the terminal , It can also be regarded as a console . So we can think of the computer itself as console terminal , Cheap connectivity devices are physical terminals pty.

Linux Is a class unix system , So it also inherits the characteristics of the terminal . But then computers became cheaper , There are also monitors and keyboards , So you can use the keyboard as the input terminal , Display as output terminal , These terminals are virtual terminals , Virtual terminal is virtual console , Or a virtual device .

Linux Many kinds of virtual terminals are provided , use ttyN express , use Ctrl+Alt+F[1-6] Can switch virtual terminals , These terminal devices are recorded in /dev/ Directory .
[[email protected] ~]# ls /dev/tty tty tty12 tty17 tty21 tty26 tty30 tty35 tty4 tty44
tty49 tty53 tty58 tty62 ttyS0 tty0 tty13 tty18 tty22 tty27 tty31 tty36 tty40
tty45 tty5 tty54 tty59 tty63 ttyS1 tty1 tty14 tty19 tty23 tty28 tty32 tty37
tty41 tty46 tty50 tty55 tty6 tty7 ttyS2 tty10 tty15 tty2 tty24 tty29 tty33
tty38 tty42 tty47 tty51 tty56 tty60 tty8 ttyS3 tty11 tty16 tty20 tty25 tty3
tty34 tty39 tty43 tty48 tty52 tty57 tty61 tty9

tty Plus the value is the virtual terminal ,CTRL+ALT+F1 Indicates switch to tty1 terminal ,ctrl+alt+f2 Indicates switch to tty2 terminal , commonly Linux Only available on ctrl+alt+f[1-6] this 6 Function of switching between terminals . Two special terminals are tty and tty0,tty Indicates the terminal currently in use ,tty0 Indicates all virtual terminals currently activated . also ttySN, These represent serial terminals .

And from ssh or telnet Waiting to connect to the terminal on the computer from the network , Or command line terminal opened from graphic virtual terminal , They are called pseudo terminals , use pts/N express , The corresponding equipment is /dev/pts Values in the table of contents N file .
[[email protected] ~]# ls /dev/pts/ 0 ptmx
0 Indicates the first pseudo terminal ,1 Indicates the second pseudo terminal .

The management mode of pseudo terminal is different from that of all other terminals , It is managed by a program that connects to a computer , for example ssh The connection is made by ssh Apply for pseudo terminal resources , And require user name and password . If ssh Connection process killed , Then the pseudo terminal exits accordingly .

in addition , Some authentication programs do not always assign terminals to connection slaves , E.g. execution sudo ssh Time ,sudo Not necessarily ssh Assign pseudo terminal .

In modern times Linux upper ,console The terminal has a different meaning from the original , Its devices are mapped in /dev/console upper , All kernel output information is output to console terminal , The information output by other user programs is output to virtual terminal or pseudo terminal .

Summary :

/dev/console: Console terminal

/dev/ttyN: Virtual terminal ,ctrl+alt+f[1-6] The virtual terminal is switched

/dev/ttySN: Serial terminal

/dev/pts/N: Pseudo terminal ,ssh The command line terminal opened by the tool connecting the past live graphic terminal is the pseudo terminal .