A new Ubuntu22.04 system was installed on the local virtual machine, and it was found that copying and pasting files or directly dragging files between windows and Ubuntu often failed.
A more convenient transmission method for special records
1. Sharing folders to each other and creating soft links
(1) This method needs to enable the shared folder function in the virtual machine.
Note: The ubuntu system in the virtual machine must be powered on, otherwise the setting is gray and the next step cannot be performed
1. Settings: Virtual Machine -> Settings -> Options -> Shared Folders,
2. Select Always Enabled,
3. Add a path for Ubuntu and Windows shared files.
As shown below:
After adding the shared folder, click "OK".
1) The path in Windows is the path when adding a shared folder, as shown in the figure: virtual machine shared folder
2) The path of the shared folder in Ubuntu is: /mnt/hgfs/ virtual machine shared folder
Among them, the directory of the virtual machine shared folder is the shared directory created in Windows, and the specific name of the directory is up to you.
Disadvantages of shared folders : due to system differences, some special files in ubuntu, such as symbolic link files, will report errors in shared folders under windows. But if you use samba (I'm not used to it, so I won't introduce it) shared folders won't work.
Note: After the shared folder is set up, the following problems may occur:
The /mnt/hgfs directory in Ubuntu is empty, that is, no shared folders are displayed
The solution is as follows:
method one:
1. Output the name of the shared folder
vmware-hgfsclient
2. Installation command
sudo apt-get install open-vm-tools
3. Mount
sudo vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other
It will fail after restarting, and it needs to be mounted once each time
Solve the problem that the shared folder fails after restarting
Enter /etc/fstab
vim /etc/fstab
and edit, add a line at the end:
.host:/ /mnt/hgfs fuse.vmhgfs-fuse allow_other 0 0
Method Two:
Use the following command to install, and press the enter key all the way down.
sudo apt-get install open-vm-dkms
Use the following command to see the directory shared with windows in the /mnt/hgfs directory. If you need to automatically mount the shared directory after booting, you need to add the command at the end of /etc/init.d/open-vm-tools .
sudo mount -t vmhgfs .host:/ /mnt/hgfs //host:/处2个空格
(2), Ubuntu creates a soft connection
When using the same file in different directories, you don’t need to put a file that must be the same in every required directory, just put the file in a fixed directory, and then put it in other directories Just use the ln command to link (link) it, so you don't have to take up disk space repeatedly.
ln
Function: Create a synchronous link for a certain file in another location
//创建链接 src(源文件目录) dst(目标文件目录)
ln -s src dst //软链接 -s 是代号(symbolic)的意思
ln src dst //硬链接
//删除链接
rm dst
Examples are as follows:
// 创建软链接
sudo ln -s /home/fbbqt/desktop/VMware /home/fbbqt/download // 把“VMware”文件夹放到“download”目录下
// 删除软链接
sudo rm /home/fbbqt/download
There are two points to note here:
1. The ln command will maintain the synchronization of each linked file, that is, no matter which one you change, the same changes will occur in other files;
2. The ln link is soft There are two types of link and hard link (without parameter -s ):
1), the soft link will only generate a mirror image of the file at the location you selected, and will not occupy disk space
2), the hard link will be at the location you selected Generate a file with the same size as the source file
Whether it is a soft link or a hard link, the file keeps changing synchronously. The most commonly used parameter for this command is -s ,
2. Remote connection method (this article uses MobaXterm)
mobaxterm can connect to Ubuntu through ssh and sftp .
1. ssh connection method
2. sftp connection method
How to use mobaxterm to connect and how to use mobaxterm please search online by yourself, and I won’t explain it here.
If you find that you cannot connect to the virtual machine using mobaxterm, the reason is that the virtual machine has not installed the ssh service
Install the ssh service and start it. The default state of the sshd service program is to start automatically
sudo apt-get install openssh-server
If it does not start automatically, use the following command to start
/etc/init.d/sshd
Commands for the sshd service
service sshd start //Start
service sshd stop //stop
service sshd status //View status
The figure below is the running state