How to files exchanged between AWS EC2 and your local machine

Copying files from local to EC2


  • We will use scp, this tool is Secure Copy or SCP is a means of securely transferring files between two machines on a network. SCP uses SSH for improved security and will prompt you if it needs a password or passphrase for authentication.
  • You'll need the scp tool and your key_name.pem file to make this.
  • By using these two resources, you can define which files do you want to copy between your EC2 instance and your local machine.
  • This is an alternative if you use Filezilla for the file exchanging.

How to transfer files from your local machine to an EC2 instance

Run this script on your local machine

$ scp -i /path/to/your/key_name.pem /path/of/yout/local/file/to/copy to/save/the/file

How to transfer files from an EC2 instance to your local machine

Run this script on your local machine.

$ scp -i /path/to/your/key_name.pem /your/local/directory/to/save/the/file

Final Notes

  • Depending on the operative system, you should change the server_username. For an Ubuntu instance, you could use ubuntu or root user.
  • Make sure the user has to read permissions on the server directory.
  • If you want to transfer all the files on a directory, use an asterisk * on the path where all the files exist. See the example below
$ scp -i /path/to/your/key_name.pem \* \

Happy coding!