Transferring Files Between host and VM
Although VM is running on the host, they are isolated logically. This means the host can not directly access files in the VM, and vice versa. Therefore, a way is needed to transfer files from/to the VM.
Host Configuration
Now keep the VM on and go back to the host. According to the type of your host operating system, you will perform different configuration.
For GNU/Linux and Mac users
Thanks to Unix Philosophy, you can use one command to achieve the transferring.
To transfer files from host to VM, issue the following command in the host:
tar cj file | ssh username@ip_addr 'tar xvjf -'
where file
is the file to transfer in the host, username
and ip_addr
are the same as mentioned in the Logging in via SSH section. You will be asked to enter your VM user password. If everything is fine, the file
will be transferred to the home directory of the VM.
To transfer files from VM to host, issue the following command in the host:
ssh username@ip_addr 'tar cj file' | tar xvjf -
where file
is the file to transfer in the VM, username
and ip_addr
are the same as mentioned in the Logging in via SSH section. You will be asked to enter your VM user password. If everything is fine, the file
will be transferred to the home directory of the host.
For Windows users
Download the latest release version of psftp.exe
here. Run psftp.exe
, and connect to the VM by the following command:
open ip_addr
where ip_addr
is the same as mentioned in the Logging in via SSH section. Then enter your VM user name as well as the password, as if logging in via ssh
. We list some useful commands in psftp.exe
:
cd change your remote working directory
exit finish your SFTP session
get download a file from the server to your local machine
help give help
lcd change local working directory
lpwd print local working directory
ls list remote files
put upload a file from your local machine to the server
pwd print your remote working directory
Under our situation, "local machine" stands for the host, "server" and "remote" stand for the VM. For more details about the command, refer to help COMMAND
.
- New a text file with casual contents in the host.
- Transfer the text file to the VM.
- Modify the content of the text file in the VM.
- Transfer the modified file back to the host.
Check whether the content of the modified file you get after the last step is expected. If it is the case, you are done!