Frequently Asked Question
Sometimes it may be necessary to transfer files between your local machine and the virtual machine. This guide shows how to transfer files for a Linux local machine by using the scp command. This guide uses following terms interchangeably:
- local machine - local system -> refers to the device being used
- remote machine - remote system - remote host -> virtual machine
2. Secure Copy - SCP
SCP (secure copy) is a command-line utility that allows you to securely copy files and directories between two locations.
With scp, you can copy a file or directory:
- From your local system to a remote system.
- From a remote system to your local system.
- Between two remote systems from your local system.
Basic syntax for scp is:
scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2
OPTION- scp options such as cipher, ssh configuration, ssh port, limit, recursive copy …etc.
[user@]SRC_HOST:]file1- Source file.
[user@]DEST_HOST:]file2- Destination file.
Local files should be specified using an absolute or relative path while remote file names should include a user and host specification.
scp provides a number of options that control every aspect of its behavior. The most widely used options are:
-PSpecifies the remote host ssh port.
-pPreserves files modification and access times.
-qUse this option if you want to suppress the progress meter and non-error messages.
-C. This option will force
scpto compresses the data as it is sent to the destination machine.
-rThis option will tell
scpto copy directories recursively.
scp command relies on
ssh for data transfer, so it requires an ssh key or password to authenticate on the remote systems.
How to create SSH keys?
How to install OpenSSH on Windows 10?
The colon (
:) is how
scp distinguish between local and remote locations.
To be able to copy files you must have at least read permissions on the source file and write permission on the target system.
Be careful when copying files that share the same name and location on both systems,
scp will overwrite files without warning.
When transferring large files, it is recommended to run the
scp command inside a screen or tmux session.
2.1 Copy from local machine to remote machine
scp /local/directory firstname.lastname@example.org:/remote/file.txt or scp /local/directory email@example.com:/remote/file.txt or scp /local/directory firstname.lastname@example.org:/remote/file.txt
2.2 Copy from remote machine to local machine
scp email@example.com:/remote/file.txt /local/directory or scp firstname.lastname@example.org:/remote/file.txt /local/directory or scp email@example.com:/remote/file.txt /local/directory
2.3 Copy from remote machine to another remote machine
scp firstname.lastname@example.org:/remote/file.txt email@example.com:/remote/directory or scp firstname.lastname@example.org:/remote/file.txt email@example.com:/remote/directory or scp firstname.lastname@example.org:/remote/file.txt email@example.com:/remote/directory