DEV Community

arafatruetbd
arafatruetbd

Posted on

How to Copy Files from AWS EC2 to Windows Using SCP

If you’ve been working with AWS EC2 instances, you might often need to transfer files from your Linux-based EC2 instance to your local Windows machine. For example, you might want to download a database dump, logs, or any project files.

In this post, I’ll show you simple and effective way to copy files from your AWS EC2 instance to Windows:

  • Using the command-line tool scp

Prerequisites

  • An AWS EC2 instance running Linux (like Ubuntu)
  • Your EC2 private key file (.pem file) downloaded from AWS
  • The public IP address or DNS of your EC2 instance
  • Basic knowledge of using terminal on Windows

Using SCP from Windows Terminal or PowerShell

scp (secure copy) allows you to securely copy files between a remote server and your local machine.

Step 1: Open PowerShell or Command Prompt

Windows 10 and 11 come with OpenSSH client installed by default, which includes the scp command. If you don’t have it, you can install it from Windows Features.

Step 2: Run the scp command

Use the following syntax to copy your file from EC2:

scp -i C:\path\to\your-key.pem ubuntu@<EC2-IP>:/home/ubuntu/demo.sql C:\path\to\save\
Enter fullscreen mode Exit fullscreen mode
  • Replace C:\path\to\your-key.pem with the full path to your .pem file.
  • Replace <EC2-IP> with your EC2 instance’s public IP or DNS.
  • /home/ubuntu/demo.sql is the path to the file on the EC2 server.
  • C:\path\to\save\ is the destination folder on your Windows PC.

Example:

scp -i C:\Users\YourUser\Downloads\mykey.pem ubuntu@18.222.33.44:/home/ubuntu/demo.sql C:\Users\YourUser\Desktop\
Enter fullscreen mode Exit fullscreen mode

You will get the file copied directly to your desktop.


Troubleshooting Tips

  • Make sure your EC2 security group allows SSH (port 22) from your IP.
  • Your .pem file permissions should be secure (e.g., chmod 400 on Linux/macOS). On Windows, just keep it safe.
  • Use the correct username: most Ubuntu EC2 instances use ubuntu, Amazon Linux uses ec2-user.

Conclusion

Transferring files between AWS EC2 and Windows is straightforward once you know the tools. Use scp for quick command-line transfers. This Method relies on SSH, which ensures secure and encrypted file transfers.

Happy coding and cloud managing! 🚀


If you liked this guide or want me to cover more AWS and Docker tips, follow me for updates!


Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.