SSH and EC2 using private keys
I have used Amazon EC2 for a few years. We often use RightScale on top of EC2 to manage things. We always use private keys to login rather than passwords. I nearly always connect like this:
ssh -i ~/my_private_key root@my_ec2_instance
SCP and EC2 using private keys
At first I didn’t have a simple way to upload files from my laptop to my EC2 instance. I would upload files via FTP from my machine to an FTP server somewhere. Then I would SSH to the EC2 instance. Then I would FTP the file down to that instance. It worked. But it’s a lot more painful than it ought to be. Eventually I learned the correct way to do it in one step:
scp -i ~/my_private_key /Users/mdahlman/temp/messages.json root@my_ec2_instance:/tmp
FileZilla and EC2 using private keys
The above ‘scp’ example works well. It saves me all of the FTP shenanigans I was going through before. But sometimes a GUI is simpler to use. I use FileZilla for many similar tasks. But I could not get FileZilla to do an scp copy when the connection had to use a private key to connect. First, FileZilla completely rejected the idea of adding the ability to transfer files via SCP.
So I gave up. Eventually I realized that this is not true. It would be nice if the FileZilla folks would update that rejected feature request to indicate that the feature was indeed added at a later time.
Later someone let me know that FileZilla can indeed use SCP despite the above issue. So I un-gave-up. It worked immediately for a server with a username and password. But I could not figure out how to use a private key. I googled, and I ranted.
I re-un-gave-up. It worked! It’s written from a Window-centric standpoint. But it contains the key information. For the benefit of other Mac OS X users, here are the Mac-ified version of what to do.
FileZilla (on Mac OS X) and EC2 using private keys
Starting point: you already know how to connect to your EC2 server via SSH using your private key. If you don’t, then Google up some other article explaining what to do. If you do, then read on.
Open the SiteManager (File → Site Manager…). Create a new Site with the protocol SFTP and logon type Normal. I use the default port 22, so I didn’t bother entering it. Click OK to save it. (Don’t click Connect. It won’t work yet.)
Now the good part: define your private key!
FileZilla → Preferences… In the section SFTP add a keyfile. In my case it had to convert the format of my keyfile. But it did this automatically, so I didn’t need to know any extra details. That’s it.
Then connect to the newly defined site. I can browse the files on my EC2 instances then upload and download to my heart’s content.