First, the question
As above, a machine often need remote operation B machine, transfer files to B machine, each time the password is too cumbersome to enter the account, the following SSH public key can solve the problem of password-free operation.
Second, the settlement
1. The programme
SSH authentication adopts public key and private key authentication mode.
2. Step 1) A machine generates a public/private key pair [[email protected] ,~]# Ssh-keygen-T Rsa-p "'
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:
a7:e3:23:45:e4:a2:22:d0:8d:21:f8:fb:9a:18:b7:f2 [email protected]
The key ' s randomart image is:
+--[RSA 2048]----+
|. |
|o. . |
| + + O |
|. +. O |
|. . . OS. |
|. O. . O |
|...o. O |
|. + O ..... |
|. Oe. ... |
+-----------------+
1.-P Indicates the password,-p ' means the blank password, you can not use the-p parameter, this will be three return, with-P on a return.
The command will generate a pair of keys Id_rsa and id_rsa.pub under the/root/.ssh directory.
2. Commonly used SSH RSA keys:
Id_rsa private Key
Id_rsa.pub Public Key
The following command produces different types of keys
Ssh-keygen-t DSA
SSH-KEYGEN-T RSA
Ssh-keygen-t RSA1
2) b machine built. SSH Directory
[[Email protected] 203~]# mkdir. SSH
The. SSH directory does not need to be established, but not built. SSH Directory
3) Copy the public key generated by a machine to the B machine [email protected] ,~]# SCP-P 28888~/. SSH/id_rsa.pub [email protected] 192.168. 1.100:/root/. SSH/authorized_keys
The authenticity of host ' [192.168.1.100]:28888 ([192.168.1.100]:28888) ' can ' t be established.
RSA key fingerprint is d4:a5:96:40:80:cb:c6:b9:7d:28:46:43:0c:95:49:84.
Is you sure want to continue connecting (yes/no)? Yes
warning:permanently added ' [192.168.1.100]:28888 ' (RSA) to the list of known hosts.
[email protected] ' s password:
id_rsa.pub 100% 396 0.4kb/s 00:00
[email protected] ~]#
1.B machine SSH port is not the default port so you need to add the parameter "-p actual Port"
2.B Machine Save a machine public key directory is $home/.ssh, public key SCP copy is renamed to Authorized_keys
4) B Machine Change Authorized_keys (a machine public key) file permissions
[[Email protected] 203~]# chmod -/root/. SSH/authorized_keys
----------------------------
At this point, the password-free configuration is complete. If you want to B machine also password-free login a machine, such as the previous step target machine to swap.
5) Testing
SSH Password-free login
[[Email protected] ,~]# SSH-p28888-l Root 192.168. 1.100
Last login:tue June 15:02:37 from 192.168.1.8
[email protected] ~]$
SCP Free Password transfer file
[[Email protected] ,~]# SCP-P 28888-r/root/findyou.war [email protected] 192.168. 1.100:/root/
Findyou.war 100% 8005KB 7.8mb/s 00:01
[email protected] ~]#
please retain the source and the author's name if reproduced . Findyou, thank you!
Linux a machine password-free SSH login B machine