Creating and using a Linux virtual machine in the cloud from an iPhone
With the recent release of Panic's Prompt 2, an SSH client for iOS, I thought it'd be fun to see how easy it is to create a new Linux virtual machine in the cloud (from thin air!), then connect to it and do stuff with it, using nothing but a smartphone. It turns out to be pretty straightforward.
For this brief adventure, I'm going to use Google Compute Engine, Prompt 2, and my iPhone 6+, just because that's my jam right now. The steps are likely similar with other hosting providers and mobile SSH clients.1. Get Prompt 2
Prompt 2 is an SSH client for the iPad and iPhone from Panic Inc. They also make a surprisingly useful version of their file transfer app, Transmit, for iOS as well. Prompt 2 and Transmit are $10 each, or you can get them in an App Store bundle for $17.http://panic.com/prompt/http://panic.com/transmit-ios/
If you're on an iPhone, the first thing you'll want to do is increase Prompt's font size. Open Prompt, then tap the gear icon for Settings, then Font Size. With the large font size on my iPhone 6+, I get 104 characters wide in landscape (horizontal) mode and 59 characters wide in portrait (upright) mode. Medium and small sizes are also available, though they're likely more useful on an iPad.
You can eliminate the on-screen keyboard and reclaim some vertical space with a portable Bluetooth keyboard, such as the iWerkz ($35) or an Apple wireless keyboard. The on-screen keyboard is passable, and Prompt is sure to include meta keys and such. But for longer sessions, I'd want real keys.http://www.amazon.com/iWerkz-Universal-Foldable-Bluetooth-44652RD/dp/B00DWMPMFG2. Create a Google Cloud project
From your favorite mobile browser (I've tried this with Safari and Chrome), go to the Google Developers Console at https://console.developers.google.com/
and sign in with your Google account or register a new one (free). The Console isn't optimized for mobile yet, but apart from a couple of minor issues, I had no difficulty using it from the phone for this purpose.
Tap Create Project (free). In the dialog that opens, adjust the default values if you wish, then confirm. The Console creates your new project in a few seconds. When it's done, you see the dashboard for the project.
If you have an existing billing account set up for another project, it will be used automatically. If you have multiple billing accounts, you can pick one in the dialog when you create the project. If you've never set up billing with Google Cloud before, do so now. Tap Billing & settings in the sidebar nav, then tap "Enable billing" and follow the prompts. (I didn't actually test the new-billing flow on the phone, so ymmv.)3. Create and install an SSH key pair
In Prompt, tap the gear icon to open Settings, then select Keys. As instructed, tap the + icon, then tap Generate New Key. Give the key a name, then enter a passphrase. You will need the passphrase whenever you use the key to connect to the server, so don't forget it. This passphrase is not
sent to the server, it is used solely to protect the private key on your phone.
Tap Generate. When Prompt is done generating your key, tap Copy Public Key. This copies the public half of a public-private key pair to the iPhone clipboard.
Switch back to the browser. In the Console's sidebar, expand Compute, then Compute Engine, then select Metadata. This one time only, Console takes a moment to initialize and enable Compute Engine for the project. When it is done, it shows the Metadata panel.
Select the SSH Keys tab, then tap the Add SSH key button. You should see one text field prompting for the "entire key data." Tap it, then tap and hold to paste the public key data into this field, but don't
submit just yet. At the end of the long crazy-looking value, type a space, then the username you want to use. (I like a short username, like "dan".) Tap "Done" to install the key.
You only need to do this step once. Both Prompt and your Google Cloud project will remember this key pair until you explicitly tell them to forget it.4. Create an instance
Still in the Console, select VM instances from the sidebar (under Compute, Compute Engine). With this new project, you see a welcome screen with a convenient button to create your first instance.
Tap the "Create an instance" button. In the new instance form, set the zone appropriate for your location, and set the machine type to "f1-micro." The f1-micro machine type is the cheapest at $0.012/hour in the US, or $6/mo with the sustained use discount. Instances are billed by the minute, with a 10 minute minimum.
Adjust the other settings to taste. The defaults get you a fresh disk image with Debian 7, and the disk is deleted along with the instance. You can opt to preserve the disk image between uses, with storage currently $0.04 per GB per month on a standard disk. With persistent snapshots, you're only billed for the occupied space on the disk.
When ready, click "Create." (This incurs the minimum 10-minute charge.) In a few seconds, the new instance will be ready and running, and you'll see it in a list of active instances.5. Connect to the instance
Before leaving the Console, notice the IP address assigned to the instance. Due to a minor glitch in the Console, this value is difficult to select and copy to the clipboard in a mobile browser. You can either select a bunch of stuff around the address then paste it into Notes for editing, or just switch back and forth between Prompt when entering the address.
Switch back to Prompt. Tap Quick Connect. In the SSH field, enter the IP address. In the Username field, enter the username you associated with the public key. Important: tap the purple key next to the Password field, then select the key you installed. The purple key appears inverted (white with a purple background) when it is selected.
Before doing anything else, tap Save this Server. If you don't, you'll have to re-enter this information the next time you connect to this server.
Tap Connect. The terminal-based display appears, along with a text prompt for "Passphrase for 'foo':" (where 'foo' is your username). Enter the passphrase you used when you generated the key, then hit Enter. If successful, you should now see a shell prompt.Troubleshooting keys
The Console installs the SSH keys on the instance automatically, but it can take a minute after the instance has started for keys to be copied. If after entering the passphrase you get a message like "Key file was not accepted by the server" or "Password authentication not allowed," wait a minute or so and try again.
If it's still not working, you may be entering the key's passphrase incorrectly. (This results in the same "Key file was not accepted" message.) Double-check your passphrase. If you're still stuck, delete the key in Prompt and in the Console's Metadata tab then make and install a new one. You can't recover a key's passphrase.6. Delete the instance
If you're just playing around, don't forget to delete the instance when you're done, so you don't get charged for time you don't use. From the Console, Compute, Compute Engine, select VM instances, then tap the checkbox next to the instance, then tap the "Delete" button at the top.
Note that if you left "Delete boot disk when instance is deleted" checked when you created the instance, you will lose the disk. If you've changed your mind, before deleting the instance, select the instance, then scroll down to Disks and change the value.
By deleting the instance, you give up the "ephemeral" IP address assigned to the instance. If you want to connect to a new instance later, you may need to edit Prompt's saved server profile with the new address after the instance has started. Alternatively you can set up static IPs and hostnames, but that's another topic.More to try
Try installing software for Debian. Run "sudo apt-get update" first to fetch the software catalogs, the run commands such as "sudo apt-get install ..." to get packages. "gcc" and "emacs" are plenty for a fun afternoon, but maybe that's just me. :) This form factor is probably a good excuse to learn vim...
Try editing the instance's network settings to allow HTTP traffic: select the instance, then scroll down to Network and check the box. Then install and run a web server ("apache2"). Or just install Python ("python") and start a SimpleHTTPServer. Or heck, install the Google Cloud SDK, write an App Engine app, and deploy it to the same project you're using to run your mobile virtual workstation.