Get the App
SLTechnology News&Howtos  ›  Development  › 

How to configure ssh to log in to a remote host without entering a password

Shulou Source: shulou.com Published: 2022-06-03 06:08:24 09月22日 Update

This article is about how to configure ssh to log in to remote hosts without entering a password. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Environment:

Local host: ha01

Eth0: 192.168.1.100 / / external IP address

Remote host: ha02

Eth0: 192.168.1.200 / / external IP address

Local host ha01 configuration:

The code is as follows:

[root@ha01 /] # cd / etc/ssh

[root@ha01 ssh] # ssh-keygen-t rsa-N "" (this step generates a key public-private key pair, where-N "" indicates that the key pair phrase is empty)

Generating public/private rsa key pair.

Enter file in which to save the key (/ root/.ssh/id_rsa):

Your identification has been saved in / root/.ssh/id_rsa.

Your public key has been saved in / root/.ssh/id_rsa.pub.

The key fingerprint is:

82:2c:74:43:8e:16:f4:ef:ac:91:0f:d7:6f:a6:f3:59 root@ha01

Copy the public key to the remote host (original method):

If the / root/.ssh/authorized_keys file does not exist on the ha02 server

The code is as follows:

[root@ha01 ssh] # scp / root/.ssh/id_rsa.pub root@192.168.1.200:/root/.ssh/authorized_keys

If the authorized_keys file exists

Execute on ha01:

The code is as follows:

[root@ha01 ssh] # scp / root/.ssh/id_rsa.pub root@192.168.1.200:/root/.ssh/

Execute on ha02:

The code is as follows:

[root@ha02 /] # cat / root/.ssh/id_rsa.pub > > / root/.ssh/authorized_keys

Copy the public key to the remote host (new method):

You can use ssh-copy-id to copy public keys to remote hosts conveniently and securely

Execute on ha01:

The code is as follows:

[root@ha01 ssh] # ssh-copy-id-I ~ / .ssh/id_rsa.pub root@192.168.1.200

SSH login test:

The code is as follows:

[root@ha01 ssh] # ssh ha02

Last login: Fri Apr 8 10:41:28 2011 from ha01

Thank you for reading! This is the end of the article on "how to configure ssh to log on to a remote host without entering a password". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Host code key login configuration password input content address file method more article external good original practical security public and private article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Technology OPPO Reno Shulou Information Huawei