Linux terminal chatting

Source: Internet
Author: User

Why do I need to generate a pair of terminal device files such as SSH, and a terminal such as tty or serial port or slip only has one device file? This has to begin with the nature of the terminal, in fact, terminals such as serial ports or s that comply with lip rules are essentially the same as tty/console terminals, except that tty device lines are connected by bus such as PCI and AGP, the terminal devices are keyboards, monitors, printers, and so on. The serial port connection terminal is connected through interfaces such as RS232. These terminals only extend the keyboard and display, later, the design idea of X Window used this idea, but the terminal evolved completely into a Graphics Server. In the past, the terminal could only display characters, input characters, and X terminals could draw pictures, display different images and any operation on these images. From the terminal's perspective, the X system will understand why xterm is an X client rather than a server.
Now we want to consider the Pseudo Terminal used by SSH. If you fully understand the working principle of openvpn, it is much easier to understand the SSH Pseudo Terminal. Such terminals use the SSH protocol to communicate with the host, SSH is an application layer protocol. Therefore, users who log on to the SSH terminal must be shielded from the information "data arrives at the application layer", which makes them feel that the data is directly driven by the device, that is to say, when users remotely connect to a Linux host using SSH press the keyboard, they feel that the keyboard is the same when the Linux host press the keyboard, rather than making them feel that the key information first reaches the sshd daemon process at the application layer of the Linux host, then, "in a certain way" is used to simulate "It seems like hitting the keyboard on a Linux host". For example, you can write key information to the input device. In short, after the data reaches sshd, it must enter the kernel again in some way, and then return the data from the kernel to a specific application in the user space. In turn, if a character is written to/dev/ttyn on the/dev/ttyn terminal, the character directly enters the kernel, then, the data is transmitted to the system bus through the driver or from the serial port to the output device. Instead, if the SSH Pseudo Terminal is used, once a data is written to/dev/pts/n, logically, data can be directly sent to a remote host, for example, in the securecrt window of a Windows host. However, the data needs to arrive at the kernel and then return to the sshd of the user space, then, the data is sent to the display window of the remote host through the socket, which requires a channel between the kernel and sshd. The character device is OK, just like openvpn. Therefore, ssh essentially establishes a "virtual physical channel" that sends data to sshd, which is equivalent to entering the physical channel, such as connecting to a remote RS232 interface or the local AGP bus, this physical channel is implemented by the SSH protocol. The end-to-end on-ramp of the channel is implemented through a pair of terminals, which are actually a pair of pipelines. Data written from one end can be read from the other end, bash writes data from/dev/pts/N, then sshd is read from/dev/ptmx, and vice versa.
In openvpn, an upstream/downstream tunnel is established between the virtual network interface card and the openvpn process in the user space through a character device, in contrast, ssh establishes an on-ramp through a terminal that is essentially a pipe. Note that the SSH terminal does not have a off-ramp, because the data is directly displayed after it arrives on a Windows machine or another machine.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.