1. Automatic ssh/scp Method =
A is A local host (that is, A machine used to control other hosts );
B is the remote host (that is, the Server of the controlled machine), if the ip address is 192.168.60.110;
Both system A and system B are Linux
Run the following command on:
# Ssh-keygen-t rsa (Press enter three times in a row to generate a public key and a private key in the keystore without a password)
# Ssh root@192.168.60.110 "mkdir. ssh" (password required)
# Scp ~ /. Ssh/id_rsa.pub root@192.168.60.110:. ssh/id_rsa.pub (password required)
Command on B:
# Touch/root/. ssh/authorized_keys (if this file already exists, skip this one)
# Cat/root/. ssh/id_rsa.pub>/root/. ssh/authorized_keys (append the id_rsa.pub content to authorized_keys)
Return to machine:
# Ssh root@192.168.60.110 (password not required, login successful)
2. Control n machines for Automatic Logon As described above
Then we need n pairs of keys (key and public key). The ssh-keygen command can change the name of the key pair at will, for example:
# Ssh-keygen-t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/. ssh/id_rsa):/root/. ssh/id_rsa_192.168.60.110
In this way, the private key and public key are named id_rsa_192.168.60.110 and id_rsa_192.168.60.110.pub respectively. Then, the content of the id_rsa_192.168.60.110.pub file is appended to the content of the sever ~ In the/. ssh/authorized_keys file, specify the local key using the-I parameter of the local ssh command, and log on:
# Ssh-I/root/. ssh/id_rsa_192.168.60.110 someone@192.168.60.110
The same is true for scp.
# Scp-I/root/. ssh/id_rsa_192.168.60.110 filename:/home/someone
Add the following two lines to the file. bashrc. You do not need to input such a long command every time you perform the same operation:
Alias sshcell = 'ssh-I/root/. ssh/id_rsa_192.168.60.110 110'
Alias scpcell = 'scp-I/root/. ssh/id_rsa_192.168.60.110 filename someone@192.168.60.110:/home/someone'
In this way, enter the command to implement ssh and scp Automatic Logon:
# Sshcell
# Scpcell
3. Automatic ssh/scp script
If you need to access C from A to B, then ssh and scp are required twice, which is troublesome.
Ssh Automatic Logon:
#! /Usr/bin/CT-f
Set timeout 30
Spawn ssh weiqiong @ B
Reset CT "password :"
Send "pppppp \ r"
CT "] *"
Send "ssh weiqiong @ C \ r"
Reset CT "password :"
Send "pppppp \ r"
Interact
Scp Copies files from A to C:
#! /Usr/bin/CT-f
Set timeout 300
Set file [lindex $ argv 0]
Spawn scp $ file weiqiong @ B:/home/weiqiong
Reset CT "password :"
Send "pppppp \ r"
CT "] *"
Spawn ssh weiqiong @ B
Reset CT "password :"
Send "pppppp \ r"
CT "] *"
Send "scp $ file weiqiong @ C:/home/weiqiong \ r"
Reset CT "password :"
Send "pppppp \ r"
CT "] *"
Exit
Interact
Scp Copies files from C to:
#! /Usr/bin/CT-f
Set timeout 300
Set file [lindex $ argv 0]
Spawn ssh weiqiong @ B
Reset CT "password :"
Send "pppppp \ r"
CT "] *"
Send "scp weiqiong @ C:/home/weiqiong/$ file. \ r"
Reset CT "password :"
Send "pppppp \ r"
CT "] *"
Send "exit \ r"
CT "] *"
Spawn scp weiqiong @ B:/home/weiqiong/$ file.
Reset CT "password :"
Send "pppppp \ r"
Interact
4. Create an ssh/scp Channel
For example, if my machine is A, the intermediate server is B, and the target server is C <br>
From A to B, from B to C, but A cannot directly ssh to C <br>
Now we will use ssh channel technology to directly transfer files from A to C <br>
1. ssh-L1234: C: 22 userid @ B <br>
Input B's password <br>
(Port 1234 is the idle port of host A. This Command requires the root user permission on host A. In fact, A channel is established on port 1234 of the host.) <br>
2. Open a new console and type: <br>
Scp-P1234 filename userid @ localhost: <br>
Input C's password