Introduction to the SSH (Secure Shell) protocol

Source: Internet
Author: User
Tags session id dns spoofing

Concept

SSH means that the secure SHELL,SSH protocol family is developed by the network Working Group of the IETF (Internet Engineering Task Force), The content SSH protocol of SSH Protocol is a security protocol based on application layer and transport layer.
Traditional network service programs, such as FTP, pop, and telnet, are inherently unsafe because they transmit data, user accounts, and user passwords in clear text on the network, and are vulnerable to man-in-the-middle (man-in-the-middle) attacks. Is that there is another person or a machine posing as a real server to receive data from a user to the server, and then passing the data to the real server as a user.
SSH (Secure Shell) is a relatively reliable protocol for providing security for Telnet sessions and other network services at the moment. The SSH protocol can effectively prevent the information leakage problem in the process of remote management. With SSH, all transmitted data can be encrypted and DNS spoofing and IP spoofing are prevented.
SSH, there is an additional benefit is that the data is compressed, so you can speed up the transmission. SSH has many functions, which can replace Telnet, and can provide a secure "channel" for FTP, POP, and even PPP.


Protocol History

The original SSH protocol was developed by a Finnish company. But because of the limitations of copyright and encryption algorithms and so on, many people now turn to OpenSSH. OpenSSH is an alternative to SSH package and is free of charge.

Basic Framework

The main part of the SSH protocol Framework is three protocols:

1. Transport Layer Protocol
The Transport Layer Protocol (the transport Layer Protocol) provides support for server authentication, data confidentiality, information integrity, etc.
2. User Authentication Protocol
The User authentication protocol (the Users authentication Protocol) provides the server with the identity of the client;
3. Connection Agreement
The Connection Agreement (the Connection Protocol) uses the encrypted information tunnel as a plurality of logical channels and is provided to the higher level application protocol;
4. It also provides extended support for many high-level network security application protocols.
Various high-level application protocols can be relatively independent of the SSH base system and rely on this basic framework to use the security mechanism of SSH through connection protocols.


Security authentication for SSH

In the client's view, SSH provides two levels of security authentication.


The first level (password-based security authentication), knowing the account number and password, allows you to log on to the remote host, and all transmitted data will be encrypted. However, there may be other servers posing as real servers that cannot be avoided by ' man-in-the-middle ' attacks.
The second level (security validation based on the key) relies on the key, which means you have to create a pair of keys for yourself and put public keys on the server you need to access. The client software sends a request to the server requesting security verification with your key. After the server receives the request, first look for your public key in the user root directory of the server and compare it to the public key you sent over. If two keys are identical, the server encrypts the "Challenge" (challenge) with the public key and sends it to the client software. Thus avoiding being attacked by ' middleman '.
On the server side, SSH also provides security authentication.
In the first scenario, the host distributes its public key to the relevant client, the client uses the public key of the host to encrypt the data when it accesses the host, and the host uses its own private key to decrypt the data, thus realizing the master key authentication and determining the reliable identity of the client.
In the second scenario, there is a key authentication center in which all service providers submit their public key to the certification center, and any host that acts as a client can simply save a public key to the authentication center. In this mode, the client must access the authentication center before accessing the server host.

the process of working with SSH
In the entire communication process, the server side and the client are experiencing the following five phases for secure connection to SSH:

1, version number negotiation phase, SSH currently includes the SSH1 and SSH2 two versions, the two sides through version consultation to determine the use of the version
2, the key and algorithm negotiation phase, SSH supports a variety of encryption algorithms, both sides based on both the end and the End-to-end support algorithm, negotiated the final use of the algorithm
3, the authentication phase, SSH client to the server to initiate authentication requests, server-side authentication to the client
4, the session request stage, after the authentication passes, the client sends the session request to the server side
5, interactive session phase, after the session request through, the server side and the client to interact with the information
1. Version number negotiation phase
1, the server opens Port 22, waits for the client to connect.
2, the client initiates the TCP initial connection request to the server side, after the TCP connection establishes, the server sends the first message to the client, including the version flag string, the format is "the ssh-< Master Protocol version number >.< the protocol version number >-< the software version number >", The protocol version number consists of a major version number and a minor version number, and the software version number is used primarily for debugging.
3, the client received the message, resolve the packet, if the server-side protocol version number is lower than their own, and the client can support the lower version of the server side, use the server side of the low version protocol number, otherwise use their own protocol version number.
4, client Response Server A message, including the client decided to use the protocol version number. The server compares the version number sent by the client to determine whether it can work with the client.
5. If the negotiation succeeds, enter the key and algorithm negotiation phase, otherwise the server side disconnects the TCP connection.
Note: The version number negotiation phase message is transmitted in clear text mode.

2. Key and algorithm negotiation phase
1, server-side and the client sent the algorithm to negotiate the message to the end, the message contains its own supported public key algorithm list, encryption algorithm list, MAC (message authentication code, messages authentication code) algorithm list, compression algorithm list, etc.
2, the server side and the client based on the End-to-end and local support algorithm list to get the final use of the algorithm.
3. The server side and the client use the DH Exchange (Diffie-hellman Exchange) algorithm, the master key equivalent parameter, to generate the session key and conversation ID.

With the above steps, the server-side and the client get the same session key and conversation ID.
For subsequent data transmission, both ends are encrypted and decrypted using the session key, guaranteeing the security of the data transfer
At the authentication stage, the session ID is used at both ends for the authentication process.
Note:

Before the negotiation phase, the server side has generated RSA or DSA key pairs, which are primarily used to participate in the generation of session keys.

3. Authentication phase
1, the client sends the authentication request to the server, the authentication request contains the user name, the authentication method, with the authentication method related content (for example: Password authentication, the content is the password).
2, server-side authentication to the client, if authentication fails, send a certificate failure message to the client, which contains a list of methods that can be authenticated again. The
client chooses an authentication method from the list of authentication methods to authenticate again.
The process is repeated until the authentication is successful or the authentication count reaches the upper limit, and the server closes the connection.
SSH provides two authentication methods:
Password Authentication:
The client sends a password authentication request to the server, encrypts the username and password and sends it to the server; The server decrypts the information and obtains the user name and password in clear text, Compares the saved user name and password on the device and returns a message that the authentication succeeded or failed.
publickey Authentication : A digital signature method is used to authenticate the client. At present, digital signatures can be realized by using two public key algorithms of RSA and DSA on the device. The client sends a PUBLICKEY authentication request containing the username, public key, and public key algorithm to the server side. The server checks the public key for legality, and if it is not, sends a failure message directly; otherwise, the server authenticates the client with a digital signature and returns the message that the authentication succeeded or failed
SSH2.0 also provides password-publickey authentication and any Authentication:
password-publickey Authentication: Specifies that the user's authentication method is satisfied at the same time as password and PublicKey certification. A client version is a SSH1 user who can log on by one of the certifications, and a client version of SSH2 must have both authentication to log in.
Any authentication: Specifies that the user's authentication method can be password or publickey.
4. Session Request phase
1, server waits for client request,
2, after authentication pass, client sends session request to server,
3, Server processing client request. When the request is processed successfully, the server responds to the client ssh_smsg_success packet and SSH enters the interactive session phase, otherwise the response to the Ssh_smsg_failure package indicates that the server processing request failed or the request was not recognized.


5. Interactive session Phase
In this mode, data is transmitted in two directions: the command that the client will execute is encrypted and transmitted to the server; The server receives the message, decrypts it, executes the command, encrypts the result and sends it back to the client; The client decrypts the results received and displays them on the terminal.


Extensible capabilities of the SSH protocol

A large number of scalable redundancy capabilities are designed in the SSH protocol framework, such as user-defined algorithms, customer-defined key rules, and high-level extended functional application protocols. Most of these extensions follow the relevant provisions of the IANA (Internet assigned Numbers authority), especially in important parts, such as naming conventions and message encoding.

Related Article

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.