Getting Espresso SFTP to Work with an Amazon EC2 Instance

I recently set up an Amazon EC2 instance (using Ubuntu) and needed to get Espresso IDE to work over SFTP. Here’s what I did to get everything set up. 

Initial Steps
To begin, ssh to your instance using Amazon’s instructions. This tutorial assumes you’ve already got your user’s account set-up how you want it. If you need help with that, there are many tutorials out there. Here’s a pretty good one to get you started. If you’re doing this as the default user (in the case of Ubuntu servers, “ubuntu”), make sure you set a password using the passwd command.

Setting Permissions
Once you’re connected, cd to the folder you’re planning to edit and change the permissions using these three commands:

sudo find . -type f -exec chmod 664 {} \;
sudo find . -type d -exec chmod 775 {} \;
sudo find . -type d -exec chmod g+s {} \;

That finds files and sets them to 665, directories and sets them to 775, and then (g+s) sets up the directories so that all new files will have their group set to the directory’s group (useful for working in a collaborative environment). If you have PHP installed, here’s a script that will take care of it on new directories:
if ($argc < 2 || $argc > 2) {
$scriptname = __FILE__;
echo "usage: php $scriptname /path/to/directory \n";
} else {
$dir = $argv[1];
if (file_exists($dir)) {
exec("find $dir -type f -exec chmod 664 {} \;");
exec("find $dir -type d -exec chmod 775 {} \;");
exec("find $dir -type d -exec chmod g+s {} \;");
echo "Permissions change complete. \n";
} else {
echo "$dir is not a valid directory\n";

Install SSH Key
Now that the permissions are correct, you need to get your SSH key installed. Using Amazon’s instructions, you SSH to your instance like this:

ssh -i MyKey.pem user@example.com

Since Espresso doesn’t allow you to specify a key location, you need to install it. If you copied your key to a new machine (using Dropbox, for instance), you may need to set the permissions to 0400 using

chmod 0400 MyKey.pem

Then add it to your list of keys.

ssh-add -K MyKey.pem

Espresso Set-up
Now, go to Espresso. Start or open your project and click “Settings.” You should now have the option to set up a server. Set it up using these options:

Protocol: SFTP
Port: 22
Server: your domain name or elastic IP
Username: your username
Password: your user’s Linux password
Remote Path: the path to the folder (e.g., /var/www/html/myproject )

Click the grey X (top right) to get back to the main screen. You should see your server in the left-pane under “PUBLISH.” Click it. Click the big cloud. You should now be able to add/edit files to the directory. Espresso occasionally errors out during the connection process so try it a few times before assuming you missed a step.