Logo

dev-resources.site

for different kinds of informations.

SCP: Sending files between servers using SSH

Published at
6/22/2021
Categories
scp
ssh
linux
Author
vndlovu
Categories
3 categories in total
scp
open
ssh
open
linux
open
Author
7 person written this
vndlovu
open
SCP: Sending files between servers using SSH

SCP or Secure Copy is a useful program for sending files between two or more computers over a secure shell (SSH) connection. In this post, I’ll show you how to use SCP to send files from your local computer to a remote, copy files from a remote computer to your local or copy files between two servers.

An SCP command has the following basic structure:

scp [OPTION] [user@src_host:] file1 [user@dest_host"] file2
Enter fullscreen mode Exit fullscreen mode

Where OPTION refers to the optional flags you can pass to scp such as the following:

  • -P remote host SSH port
  • -p preserve file modification and access times
  • -q quiet
  • -C compress
  • -r copy directories recursively

The colon ( : ) that comes after the host IP address or domain name is important.

Sending a file from the local computer to a remote computer

scp file.txt [email protected]:/path/to/remote/dir

Copy a file from the remote computer to the local computer

scp [email protected]:/path/to/file.txt /local/directory

Copy files between TWO remote computers

scp [email protected]:/path/to/file.txt [email protected]:/path/to/file/location

Secure copy to an EC2 instance without password

scp -i mykey.pem somefile.txt [email protected]:/

Featured ones: