Virtual machine network configuration and a clever way to transfer (send) files to the local

Written in front: This method is more tricky. Because pscp is used to transfer files on the host (win11 system) terminal, there are many problems to be solved and the time is tight, so it is necessary to export the files in the virtual machine in time for the experiment report;

1. Introduction

1. First, let's understand the SSH protocol

SSH is the abbreviation of Secure Shell, which is a security protocol based on the application layer;
SSH is a more reliable protocol that provides security for remote login sessions and other network services;
using the SSH protocol can effectively prevent information during remote management from Leakage problem;
SSH Baidu Encyclopedia

2. Secondly, we need to know that SSH software is divided into client openssh-client and server openssh-server

If you just want to remotely log in to other machines, you only need to install the client openssh-client;
if you want to open the SSH service on this machine, you need to install the server openssh-server;

SSH software needs to meet the conditions to access the Linux virtual machine:

  1. The Host system and the Liunx virtual machine system are located in the same virtual network created by Virtualbox (the default network setting of the virtual machine is NAT);
  2. The openssh-server (and openssh-sftp-server) package needs to be installed in the Linux virtual machine (or select the SSH Server component when installing the Linux system);
  3. Install and use SSH client software (such as PuTTY) in the Host system to remotely connect to the Linux virtual machine system - the commands entered in the SSH client will be executed on the virtual machine, and the command output will be returned to the SSH client for display;

2. Configure the network

1. First check whether ssh is installed in the virtual machine.insert image description here If no command is executed, it means that ssh is not installed. Execute the following code to download and install;

sudo apt-get install openssh-server ;

2. After installation, configure the virtual machine network.
Select "Network" in the left column of the settings, click Advanced, and then click Port Forwarding;

insert image description here
Click the plus button in the upper right corner to enter the input settings in the new rule line

Name: SSH ; Protocol: TCP ; Host port and subsystem port number: 22; Click ok to confirm;

insert image description here
3. After setting the ssh protocol, open the host computer to configure the SSH Server service.
You need to download Putty, fill in 127.0.0.1 for the IP address, fill in 22 for the port, and click open;
insert image description here

127.0.0.1 is called the local loopback address;
related links: Miaoqu explains what 127.0.0.1 is ;

Click "Yes" to accept the certificate of the SSH server in the virtual machine;
insert image description here
at this time, the SSH client pops up a login prompt, and then enter the user and password in the virtual machine system (the password is also not displayed), and the enter connection is successful; simple
execution Look at the executable file hello in the hello_world file;
insert image description here

3. Transfer files

1. Method 1 (unsuccessful)
According to what I learned online, I used the pscp command to transfer files but encountered many problems:
for example: 1. How to obtain the virtual machine ip address; 2. The ifconfig command cannot be found in the virtual machine; 3. Transmission error;

1. Obtain the virtual machine ip address: enter ficonfig or ip addr in the terminal. However, the previous prompt could not find the command. After finding the information, enter the command apt install net-tools to download the tool, but the problem is still there. So use the second type of input ip addr to obtain success;
2. The transmission error is reported as shown in the figure below, to be resolved;

insert image description here
2. Method 2 (trick method)

Go back to the virtual machine, click on the browser to directly search the mailbox (this time I used the qq mailbox, send the file directly with the mailbox and then download and open it in the host machine) Finally, the
insert image description here
file was successfully opened with Notepad, ok completed!
insert image description here

Finally: I encountered a lot of troubles this time, and I haven't solved it yet, but I'm glad I found a simpler method and learned a lot of new knowledge. So keep going! Go, go, go!

Guess you like

Origin blog.csdn.net/qq_51247028/article/details/121969362