How to copy files from Windows to Linux running in Virtual Box

eye-catch Other techs

I struggled to copy files from Windows Host to Linux running in VM.

Sponsored links

Setup the shared folder

Set up a folder path where we want to share between Windows and Linux running in VM.

Check Auto-mount and Make Permanent. Set the Mount point to make it clear where the mount point is.

Reboot the VM once the setup is done.

Sponsored links

Copy the shared files from the shared folder

The shared folder can’t be read by a non-root user.

This is because the owner of the folder is root and the group is vboxsf.

$ ls -l /home/vagrant/ | grep shared
drwxrwx---  1 root    vboxsf     0 Jun 28 07:04 shared

If we are using a non-root user, we can’t access it and thus can’t do anything with it. It’s possible to add the non-root user to vboxsf group but it’s not a good idea to do it due to security reasons.

Instead, use sudo command.

$ sudo ls -l /home/vagrant/shared/ | grep test-folder
drwxrwx--- 1 root vboxsf    0 Jun 28 07:38 test-folder

$ sudo cp -r /home/vagrant/shared/test-folder /home/vagrant/test/test-folder

Change the owner and the group

The owner and the group are still root; thus, a non-root user can’t read the copied folder.

~/test$ ls -l
total 4
drwxr-x--- 4 root root 4096 Jun 28 07:41 test-folder

Let’s change the owner and the group simultaneously with chown command with -R option. It changes the owner and group of child folders and files.

~/test$ sudo chown -R vagrant:vagrant test-folder/
~/test$ ls -l
total 4
drwxr-x--- 4 vagrant vagrant 4096 Jun 28 07:41 test-folder

Then, all the subfolders and files can be read by the non-root user.

Comments

Copied title and URL