Transfer files to a Linux instance using SCP
One way to transfer files between your local computer and a Linux instance is to use the secure copy protocol (SCP). This section describes how to transfer files with SCP. The procedure is similar to the procedure for connecting to an instance with SSH.
Before you connect to your Linux instance using SCP, complete the following tasks:
-
Complete the general prerequisites.
-
Check that your instance has passed its status checks. It can take a few minutes for an instance to be ready to accept connection requests. For more information, see View status checks.
-
-
Allow inbound SSH traffic from your IP address.
Ensure that the security group associated with your instance allows incoming SSH traffic from your IP address. For more information, see Rules to connect to instances from your computer.
-
Install an SCP client.
Most Linux, Unix, and Apple computers include an SCP client by default. If yours doesn't, the OpenSSH project provides a free implementation of the full suite of SSH tools, including an SCP client. For more information, see https://www.openssh.com
.
The following procedure steps you through using SCP to transfer a file using the instance's public DNS name, or the IPv6 address if your instance has one.
To use SCP to transfer files between your computer and your instance
-
Determine the location of the source file on your computer and the destination path on the instance. In the following examples, the name of the private key file is
key-pair-name.pem
, the file to transfer ismy-file.txt
, the username for the instance is ec2-user, the public DNS name of the instance isinstance-public-dns-name
, and the IPv6 address of the instance isinstance-IPv6-address
.-
(Public DNS) To transfer a file to the destination on the instance, enter the following command from your computer.
scp -i
/path/key-pair-name
.pem/path/my-file.txt
ec2-user
@instance-public-dns-name
:path/
-
(IPv6) To transfer a file to the destination on the instance if the instance has an IPv6 address, enter the following command from your computer. The IPv6 address must be enclosed in square brackets (
[ ]
), which must be escaped (\
).scp -i
/path/key-pair-name
.pem/path/my-file.txt
ec2-user
@\[instance-IPv6-address
\]:path/
-
-
If you haven't already connected to the instance using SSH, you see a response like the following:
The authenticity of host 'ec2-198-51-100-1.compute-1.amazonaws.com (10.254.142.33)' can't be established. RSA key fingerprint is 1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f. Are you sure you want to continue connecting (yes/no)?
(Optional) You can optionally verify that the fingerprint in the security alert matches the instance fingerprint. For more information, see (Optional) Get the instance fingerprint.
Enter
yes
. -
If the transfer is successful, the response is similar to the following:
Warning: Permanently added 'ec2-198-51-100-1.compute-1.amazonaws.com' (RSA) to the list of known hosts. my-file.txt 100% 480 24.4KB/s 00:00
-
To transfer a file in the other direction (from your Amazon EC2 instance to your computer), reverse the order of the host parameters. For example, you can transfer
my-file.txt
from your EC2 instance to the a destination on your local computer asmy-file2.txt
, as shown in the following examples.-
(Public DNS) To transfer a file to a destination on your computer, enter the following command from your computer.
scp -i
/path/key-pair-name
.pemec2-user
@instance-public-dns-name
:path/my-file.txt path/my-file2.txt
-
(IPv6) To transfer a file to a destination on your computer if the instance has an IPv6 address, enter the following command from your computer. The IPv6 address must be enclosed in square brackets (
[ ]
), which must be escaped (\
).scp -i
/path/key-pair-name
.pemec2-user
@\[instance-IPv6-address
\]:path/my-file.txt path/my-file2.txt
-