Public-key authentication is the use of a pair of cryptographic strings, a public key, which can be seen by anyone, used for encryption, and another known as a key (private key) that only the owner can see for decryption.
When using Jenkins to automatically build and remotely log on to the server for publishing applications, SSH Public key authentication is required to resolve the logon server issue.
In fact, it is very simple, only need two instructions.
"ssh-copy-id-i ~/.ssh/id_rsa.pub <IP>
Suppose there are two servers, a is the Jenkins build server, B is the application server, and a builds the application, and then uploads the package to B for publishing.
Execute Ssh-keygen-t rsa-p "on a above, two single quotes behind-p to indicate that the password is empty
After that, two files Id_rsa (private key) are created in the ~/.ssh directory, id_rsa.pub (public key)
Next continue to execute Ssh-copy-id-i ~/.ssh/id_rsa.pub <ip> on a, indicating that the public key is sent to B and sent to the ~/.SSH directory of the B server
After the use of SSH b<ip> to try to be able to password-free login B server, if you are prompted to enter passwords, there are the following reasons
A. A non-root account may not support SSH public key authentication (see if the server is limited)
B. The public key file passed over the permission is insufficient, can give this file authorization under chmod 644 Authorized_keys
C. Use the root account to execute ssh-copy-id-i ~/.ssh/id_rsa.pub <IP> This command if you need to enter a password to configure the Sshd_config
Vi/etc/ssh/sshd_config
Restart the SSHD service when you are finished modifying
Service sshd Restart
Finally, if SSH IP password-free login succeeds, the SSH public key authentication succeeds.
Next, the SSH configuration for Jenkins is as follows
Linux configuration SSH Public key authentication and Jenkins telnet for automatic publishing