Can I copy files to Amazon EC2 without a PEM file (using AWS CLI)?

Viewed 2879

I used to use the below scp command to copy files from my local machine to instances earlier.

scp -i /path/to/pem/file /path/to/source user@ip-address:/path/to/destination

But for a new instance, I do not have access to the PEM file. We are using AWS CLI to manage access to new instances and hence, there is no need for a PEM file. Is there a way to copy files using AWS CLI as well?

PS: I'm using Ubuntu 20.10 (if that helps)

2 Answers

You can use AWS Systems Manager Session Manager to copy files using scp:

With SSH protocol tunneling using Session Manager, you do not need an access server or an open inbound port for SSH-based access and SCP-based file copy. This reduces cost and improves your security posture when using SSH and SCP.

So I got some help and found that there are three steps to this process.

  1. Start a secure FTP connection with the instance using the following command: msftp <user>@<instance_id>

  2. Use 'put' to copy your files to the instance using: put /path/to/source /path/to/destination

  3. exit

Similarly, use get instead of put to copy files from the instance to your local machine. Remember to use the -r flag if you're copying directories!

Related