Detailed explanation of SCP command to directly transfer files between Linux virtual machine and development board (as well as common errors, virtual machine network errors, etc.)

Detailed explanation of scp command

scp [选项] 源文件/目录 目标地址:目标路径
  • scp: This is a command used to copy files under Linux. It supports secure transfer of files between the local system and the remote system through the SSH protocol.

  • Options: Different options can be used according to your needs, here are some common options:

    • -r: Recursive copy, used to copy directories and their contents.
    • -P:Specify the port number of the remote SSH server, for example -P 2222.
    • -i:Specifies the private key file used for authentication.
    • -v: Verbose mode, outputs detailed transmission information, which can be used for debugging.
  • Source file/directory: This is the path to the file or directory you want to transfer. Can be local files/directories or remote files/directories, depending on their location.

  • Destination address: This is the address of the remote system, usually a combination of username and hostname or IP address, in the format of user@hostnameor user@ip_address.

  • Target path: The path where the file is stored on the remote system, which can be an absolute or relative path. Usually the target user's home directory or other directory.

Example:

  1. Copy local files local_file.txtto the user's home directory on the remote system:

    scp local_file.txt user@hostname:~
    
  2. Recursively copy a local directory local_directoryto a specified directory on the remote system:

    scp -r local_directory user@hostname:/path/to/remote/directory
    
  3. Copy files from remote system to local system:

    scp user@hostname:/path/to/remote/file local_destination_directory/
    
  4. Connect to the remote system using a different port number:

    scp -P 2222 local_file.txt user@hostname:/path/to/remote/directory
    
  5. Authenticate using private key file:

    scp -i private_key.pem local_file.txt user@hostname:/path/to/remote/directory
    

These examples cover common scp usage, and you can tailor the commands to meet your file transfer needs. Please make sure you have the appropriate permissions to read and write the file, as well as the correct SSH configuration, in order to use scp successfully.

Operation demonstration

Requirement description: I want to transfer the files compiled under Linux to the development board for running.
First, make sure that the development board and the Linux host are in the same LAN. You can use ifconfig to check the IP address of the machine and the IP address of the development board (before checking the P address, first Make sure your development board is connected to the router. If your virtual machine cannot obtain the address under the same router as the development board, please see the FAQ below.) Check the virtual machine address. Check the development board address. Use
-v
Insert image description here
to

transfer the file
Insert image description here
. If it is a folder, Remember to use -r

common problem

Virtual machine DNS server IP address problem

The virtual machine and the development board may not be in the same LAN due to campus network or network configuration reasons. The
solution is to connect the computer and the development board to the router backend and configure the virtual machine. Method 1:
The host uses a wired connection and the virtual machine uses a wireless network card to connect.
Insert image description here
Configure the virtual network editor.
Insert image description here
Insert image description here
And use
Insert image description here
method 2
to build the basic environment

No response or timeout after entering the command

This is usually an IP address error and can be tested using the Ping command before trying to connect.
Insert image description here

Guess you like

Origin blog.csdn.net/Systemmax20/article/details/132918689