First, Introduction
First, SSH key introduction
To learn about SSH key, first get familiar with SSH, about SSH can refer to "The initial use of SSH". The SSH key pair allows you to easily log on to the SSH server without entering a password. SSH key pairs always appear in pairs, a public key, a private key. The public key is free to be placed on the SSH server you need to connect to, and the private key must be kept well. 1. What is public key login
Public key login, many times also said public key authentication, the principle of key login: First, the user will own the public key stored in the need to log on to the remote machine, and then log in, the remote host to send a user a random string, and then the user uses their own private key to encrypt the string, and Finally, the remote host uses the stored public key to decrypt, if the decryption succeeds, then the user is trustworthy, allows to log in, does not prompt to enter the password.
Note:
1, the server will write the client's public key to the end of the ~/.ssh/authorized_keys file.
2. The public and private keys generate 2 on the client side (login) . What is password login
Password login, that is, log in when you need to enter a login password.
1. The client makes a request to the server
2. The server returns its own public key to the client;
3. The client uses the server's public key to encrypt the login information, and then sends the information to the server;
4. The server receives the client to transmit the login information, decodes with own private key, if the result is correct, then agrees to log in, establishes the connection.
The principle of realization is as follows:
Note:
1. Public and private keys generate two on the server , generate public and private keys
The Ssh-keygen command, which generates a public and private key, is generated by default to the user's home directory. SSH folder
The private key defaults to be saved in the ~/.ssh/id_rsa
Public key defaults will be saved in ~/.ssh/id_rsa.pub
The format of the command is as follows:
Ssh-keygen-f filename-t rsa-c "dequan@example.com"
Parameter resolution:
-f Specifies the name of the file to generate the file
-T setting method, the value is RSA, that is, asymmetric encryption, or DSA, that is, digital signature and authentication
-c Specifies the note information in the public key
Iii. case of using public key login
Now, I will log on to the IP-192.168.13.139 machine from the IP-192.168.13.143 machine to the public key login mode.
By default, if you do not enter a password, you cannot log on, as follows:
1, storage public key
Stores the public key, which is about to 192.168.13.143 the public key generated above, stored in the home directory of root users on 192.168.13.139, as follows:
Appends the contents of the public key to the. ssh/authorized_keys file in the root user's home directory above 192.168.13.139, which needs to be created manually if the file does not exist. 2. Re-login
Perform the following command to log on
SSH root@192.168.13.139
You can see that this time you do not need to enter a password, you can complete the login.
More information: http://www.findme.wang/blog/detail/id/376.html