Many times, we need to copy files (folders) between two Linux/Unix hosts, but we need to manually enter the password
For example, if you back up the database file of the server (sysadmin) to the client (yanggang), you are prompted to enter the password!
Sysadmin @ host :~ // Ssh $ scp/home/sysadmin/top800/top800_database. SQL yanggang@192.168.1.22:/home/yanggang/top800/
Yanggang@192.168.1.22's password:
If you write scripts for automatic data backup, it is obvious that manual password input is unreliable.
Therefore, we need to find a method that automatically enters the password or does not need to enter the password when copying data from two machines.
Therefore, Linux uses the public key and key to Establish a trust relationship between the two machines without a password.
Linux/Unix dual-host build trust
1. Go to the. ssh directory on the server (sysadmin) and client (yanggang) respectively.
The following uses the client (yanggang) as an example:
Cd ~ /. Ssh
2. Execute the Key Generation Command
Ssh-keygen-t rsa
3 view ~ /. Ssh key generation File
Id_rsa is the key and id_rsa.pub is the public key.
4. The client (yanggang) establishes a trust relationship with the server (sysadmin ).
Yanggang@192.168.1.22 scp:/home/yanggang/. ssh/id_rsa.pub authorized_keys
Yanggang@192.168.1.22's password:
That is, copy the client's public key (id_rsa.pub) to the server (sysadmin) and change id_rsa.pub to authorized_keys.
In this case, you need to enter the password (the trust relationship has not been established before). After the trust relationship between the client and the server is established, the client can no longer enter the password, you can copy data from the server (Step 5 below)
5. The server (sysadmin) establishes a trust relationship with the client (yanggang ).
Scp sysadmin@192.168.1.11:/home/sysadmin/. ssh/id_rsa.pub authorized_keys
In this case, you can directly copy the file (id_rsa.pub) from the server without using the data password)
At this point, the server does not need to copy data from the client and the data password again (if you copy data from the client in Step 4 above, you do not need to enter the password again)
Yanggang@192.168.1.22 scp:/home/yanggang/. ssh/id_rsa.pub authorized_keys
There is no yanggang@192.168.1.22's password:
6. Test (back up the database on the server to the client)
Scp/home/sysadmin/top800/top800_database. SQL yanggang@192.168.1.22:/home/yanggang/top800/
Copy files between two hosts and no password is required
The dual-host trust relationship has been established!
Knowledge Development:
Scp does not require a password
A simple way to configure the trust between hosts