Connect to a remote Linux host using SSH without a password

Source: Internet
Author: User
SSH does not enter a password to connect to a remote Linux host: public/private key verification. The public key is used for encryption, and the private key is used to decrypt data encrypted with the matched public key. Generate a key pair on the local machine, place the public key to the remote host, and then initiate an SSH connection from the local machine. The remote host's sshd generates a random number and uses this public key for encryption and then sends it to the local machine, the local machine uses the private key for decryption and sends the result back. After the verification result of the remote host is correct, you are allowed to log on.

Steps:
Note: The key must match the SSH system on the remote Linux host. OpenSSH is the default SSH System in Linux, so the content here is only applicable to OpenSSH.
1. Generate a key pair.
(1) Linux
$ Ssh-keygen-T RSA
This command generates a key pair: id_rsa and id_rsa.pub. They are saved in ~ by default ~ /. Ssh/directory. You can change id_rsa.pub to local_rsa.pub to avoid the same name as id_rsa.pub on the remote host. During the generation process, pass phrase is required. This is used to protect the use of the private key. That is, you must enter this password every time you use the private key, therefore, do not enter any characters here. Press enter directly.
(2) Windows + putty
You must use putty-gen.exe to generate a key. After running putty-gen.exe, click "generate" to generate the key and click "Save Private Key" to save the key that can be used by putty, such as test. PPK. The pass phrase part is the same as the previous one. In the text box under the "Public Key for passing into OpenSSH authorized_keys file" line, the public key content is copied to a blank text file to save the file, such as test. Pub.

2. Upload the public key.
Upload the generated public key, such as test. Pub, to the remote host ~ In the/. Ssh directory, append the content of test. Pub to the end of the authorized_keys file.

3. Remote Host SSH settings
Authorized_keys must be accessible only by the Owner:
$ Chmod go-rwx ~ /. Ssh/authorized_keys
In addition, in order not to enter pass phrase every time a connection is initiated:
$ Ssh-agent $ Shell
$ Ssh-add
(NOTE: Refer to the SSH settings of mpich. I am not sure if mpich is not used .)

4. Connection
(1) Linux
On a Linux terminal, enter SSH remote_machine_name to initiate an SSH connection. The remote system performs public key authentication.
(2) Windows + putty
In the session auth option, select the private key file generated in the previous step and click "open ". Enter the user name if required.

 

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.