Three Simple Ways to Transfer Files Between Host and Virtual Machine
Learn three practical methods—FTP, disk‑image tools, and SMB sharing—to move files between your host OS and a Linux virtual machine, complete with installation steps, configuration commands, and tips for both Windows and Linux environments.
Overview
File exchange between a host OS (typically Windows) and a Linux virtual machine can be achieved with three reliable approaches: FTP/SFTP using vsftpd, mounting the VM’s virtual disk with a disk‑image utility, and sharing a directory via Samba (SMB).
Method 1 – FTP/SFTP with vsftpd
Install the FTP server package and configure it to allow authenticated local users only.
sudo apt-get update
sudo apt-get install vsftpdEdit /etc/vsftpd.conf (e.g., with sudo vi /etc/vsftpd.conf) and set the following options:
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_root=/home/USERNAME/ftp
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_listCreate the chroot list and the shared subdirectory:
sudo touch /etc/vsftpd.chroot_list
echo "USERNAME" | sudo tee -a /etc/vsftpd.chroot_list
mkdir -p /home/USERNAME/ftp/share
chmod 755 /home/USERNAME/ftp # remove write permission for the FTP root if desiredRestart the service to apply changes: sudo systemctl restart vsftpd Clients such as FileZilla, Xftp, or the built‑in FTP module of MobaXterm can connect to ftp://VM_IP using the same username/password. For encrypted transfer, use SFTP (the OpenSSH server is typically already present; connect to sftp://VM_IP).
Method 2 – Mounting the Virtual Disk
When the VM is powered off, a disk‑image tool (e.g., DiskGenius, Ext2IFS, or the open‑source guestmount from libguestfs) can open the .vmdk or .qcow2 file and expose its filesystem to the host.
Launch the tool and choose “Open Virtual Disk”.
Select the VM’s disk file, for example G:\VMware\SysU16\Ubuntu16.04.vmdk.
The tool mounts the Linux partitions as read‑write volumes; you can then copy files to or from the share directory you created in Method 1.
On Windows 10, ensure that the BIOS/UEFI settings allow the tool to access ext* partitions; otherwise use a Linux host or the guestmount command line.
Method 3 – Samba (SMB) Share
Install Samba on the Linux VM and expose a directory. sudo apt-get install samba samba-common Create the shared directory and give it full permissions (adjust as needed for security):
mkdir -p /home/USERNAME/share
chmod 777 /home/USERNAME/share # for testing; replace with stricter ACLs in productionEdit /etc/samba/smb.conf and append a share definition:
[share]
path = /home/USERNAME/share
browsable = yes
writable = yes
guest ok = no # set to yes for password‑less access
read only = noAdd a Samba user (the password can be the same as the Linux account):
sudo smbpasswd -a USERNAME
sudo smbpasswd -e USERNAME # enable the accountRestart the Samba daemon: sudo systemctl restart smbd From a Windows host, open File Explorer and enter \\VM_IP\share. Supply the Samba credentials when prompted, or enable guest ok = yes to allow anonymous access.
Choosing a Method
Use FTP/SFTP for quick network‑based transfers, especially when the VM is running. Use the disk‑image approach for one‑off bulk copies while the VM is shut down. Use Samba when you need seamless Windows‑style file browsing and frequent bidirectional access.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
