How to copy from a remote server to a local machine in Linux
In Linux, we use the scp command to securely copy files and folder between two servers.
The basic syntax of scp command is as follows:
scp [OPTIONS] [SRC_ADDRS]:[file|directory] [DST_ADDRS]:[file|directory]
where
OPTIONS: These are different flags/options enabled/disabled during the copy operation.SRC_ADDRSdanDST_ADDRS: This isusername@ip_address.[file|directory]: The file or directory path.
How to copy a file
We’ll use the following command to copy a file from a remote host to local host.
According to the syntax explained above, let’s assume the following:
usernameisremoteuserip_addressis10.12.13.1- The source file path is
/home/Documents/test_doc.txt - The destination file path is
/User/educative/Downloads/test_doc_copy.txt
scp remoteuser@10.12.13.1:/home/Documents/test_doc.txt /User/educative/Downloads/test_doc_copy.txt
How to copy a directory
We’ll use the following command to copy the contents of the directory in a recursive way from a remote host to local host.
According to the above syntax, let’s assume the following:
usernameisremoteuserip_addressis10.12.13.1- The source directory path is
/home/Documents/test_dir - The destination file path is
/User/educative/Downloads
scp -r remoteuser@10.12.13.1:/home/Documents/test_dir /User/educative/Downloads
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved