Skip to content

Instantly share code, notes, and snippets.

@chadfurman
Last active May 2, 2017 14:16
Show Gist options
  • Select an option

  • Save chadfurman/0022ee88b271791b9cc9 to your computer and use it in GitHub Desktop.

Select an option

Save chadfurman/0022ee88b271791b9cc9 to your computer and use it in GitHub Desktop.
Coffee-Shop Development for Under $500

Coffee-Shop Development for Under $500

Do you have a great desktop, but don't want to shell out premium dollars for a MacBook Pro, only to have security concerns around your beautiful laptop getting stolen? If you feel great when you accomplish something complex, and you want a super-inexpensive backup computer that gives you both freedom and power to develop from your favorite cafe, read on!

In the early days, web development meant local file changes which were sent to the server via FTP. Shelling into the remote server directly was rarely ideal – but technology has come a long way. Chromebooks, starting around $170, have up to 13 hours of battery life and weigh just about 2 lbs. The operating system is designed to run a web browser and nothing else: even your file storage is in the cloud. Enter Cloud9.

Cloud9's web-based IDE is strikingly powerful, feature-rich, and performant on a Chromebook 11. C9 has Goto Anything, rather comprehensive Vim support, and many other power-user accessories. While the public-facing https://c9.io requires a premium subscription for SSH workspaces (which once was $9 a month and is now $19 a month), Cloud9 does offer a downloadable package that you can host yourself.

Note: Cloud9's standalone ("host it yourself") version is their alpha SDK for non-commercial purposes. There may be dragons. Always feel free to fork the project and send pull requests if you find-and-fix any bugs.

Overview

  1. Assumptions and Conventions
  2. Set Up Cloud9
  3. Set Up an SSH Server
  4. Key-Based Authentication
  5. Establish SSH Tunnel Local Port Forwarding
  6. Open a Project in Cloud9
  7. SOCKSv5 for DNS Resolution
  8. Embrace Victory

Assumptions and Conventions

For this article, we will assume that you already have a working development environment (complete with Node and Git) hosted on a server you can install onto. This server could be your home workstation, a DigitalOcean droplet, or something else. Additionally, I assume you have working knowledge of your operating system of choice, as well as some command-line fu.


http://memegenerator.net/instance/64225164

Set Up Cloud9

http://muppet.wikia.com/wiki/Cloud_Nine


http://muppet.wikia.com/wiki/Cloud_Nine

You can set up Cloud9 anywhere on your server. The first step is to pick a location and clone down the self-hosted version of Cloud9 (they call it their "SDK"). I'm installing mine in my home directory.

$ cd /home/<user>

$ git clone git://github.com/c9/core.git c9

The installation is taken care of by the install script that comes with the repo, so let's go into our newly created c9 folder and run the install script.

$ cd c9

$ scripts/install-sdk.sh

Assuming no unforseen complications, the install script will complete, and return you to your command line. To test that everything works, you can simply run the c9 server:

$ node server.js

You should see a line that says something like: Connect server listening at http://127.0.0.1:8181 – type this full URL (including the :8181) into your browser. You should see your new c9 development environment!

Hit Ctrl+C in the terminal window to stop the process for now.

Set Up an SSH Server

Note: If you want to have a more secure server, I recommend following the DigitalOcean initial server setup tutorial.

A basic SSH server in Debian 8 is relatively simple to set up. If the SSH server is not already installed for you during setup (or you're simply not sure), the package is called openssh-server and can be installed through aptitude.

$ su -c 'apt-get install openssh-server'

You now should be able to SSH into your server with the following command:

$ ssh localhost

If you are greeted with a welcome message and a command prompt, you are successfully logged in, and your SSH server is ready for the next steps.

Wait! One thing I do recommend doing is forwarding external requests from port 443 to port 22 locally via your router firewall. This varies from router to router, but will allow you to tunnel into your dev machine during that long Amtrak commute, or really anywhere else that blocks all non-HTTP outbound traffic. Alternatively, have SSH start on port 443. If you host HTTPS services locally, you may enounter some difficulties with this approach.

Key-Based Authentication

Unless you somehow remember a 4096-bit passphrase (roughly 512 characters), your password is not as secure as a 4096-bit SSH key. Using a public key to log in to your server is preferred, so I will show you how to set one up!

First, we need to generate SSH keys. We will be running the following set of commands on your server, where you just installed SSH. We do this because we need ssh-keygen, as well as the ability to authorize our keys.

We'll generate RSA keys with a block size of 4096 (DSA limits us to 1024). Be sure to provide a strong passphrase on the off-chance your Chromebook gets hacked (cough HTML5 local storage). Accept the default key location for convenience.

$ ssh-keygen -t rsa -b 4096

This should place your public key in /home/<user>/.ssh/id_rsa.pub and your private key in /home/<user>/.ssh/id_rsa.

We need to authorize the key – just cat the .pub to your authorized_keys file:

$ cat /home/<user>/.ssh/id_rsa.pub >> /home/<user>/.ssh/authorized_keys

Now we can disable password authentication in your sshd_config file, restart the SSH server, and test our new key-based login:

$ su -c 'echo "PasswordAuthentication no" >> /etc/ssh/sshd_config'

$ su -c 'service sshd restart'

$ ssh localhost

If you get Permission denied (publickey), that means that you did not authorize your SSH key, or you entered the wrong SSH key password.

Establish SSH Tunnel Local Port Forwarding

Finally, we get to turn on our beautiful Chromebook!

http://articles.mercola.com/sites/articles/archive/2011/01/10/trouble-sleeping-caused-by-glowing-gadgets.aspx

Please start by installing the Secure Shell extension by Google.

Open the extension, and fill in the username and the IP address for your server. If you don't know your server's IP address, chances are it's your home PC, and so open up a web browser on your desktop and navigate to WhatsMyIP.org.

Note: If your IP address changes now and then, try FreeDNS, No-IP, or ChangeIP.

You'll also need to fill in the SSH arguments field with the following values: -L 9000:localhost:9191 – doing this will create what is called a "local port forward", allowing us to access the remote port 9191 (on our server) via the Chromebook's local port 9000. This is a critical step!

Note: I also fill in port 443 for my SSH server – the default port is 22.

I recommend a USB stick for moving the private key to your Chromebook. We will need to copy our SSH key onto our Chromebook and import it as an identity in the SSH client.

When you've filled all of this in, hit Connect, and enter the password for your private key.

Open a Project in Cloud9

After successful login, we're going to want to restart our c9 server, this time with a few additional arguments.

$ cd /home/<user>/c9

$ node server.js -w/path/to/the/project/you/want/to/work/on -p 9191 --auth <username>:<password>

The -w flag tells our server to use the given path as the project root. There's a bug where if you type -w /path/to/project (note the space), then a blank folder is created in the c9 root directory. It is recommended to use -w with no space – this only applies to the -w flag.

The -p flag specifies the port number we want to listen on. The listen port 9191 has to match with our local port forward settings, or you won't be able to access your IDE.

The --auth <username>:<password> flag establishes a basic-auth security wall just in case. You can use any username and password you want here – it does not have to match any server-side or client-side information.

With our server running, minimize the SSH client, and navigate to http://localhost:9000 on your Chromebook.

Note: I did intentionally say 9000 in this URL – remember, local port 9000 forwards to our server's port 9191!

At this point, you should be able to do development by navigating to http://localhost:9000 and using the IDE.

SOCKSv5 for DNS Resolution

If you're doing web development, you'll want to set up a SOCKSv5 proxy with the SSH arguments -D 8080 -C -N (-D is a dynamic forward, -C is for compression, -N means we don't need a command prompt). This will allow you to resolve domain names via your /etc/hosts file for Apache and NGINX.

You'll also want to install Proxy SwitchySharp, because the Chrome OS UI only allows for SOCKSv4 configuration which will not resolve DNS on the server (i.e., your /etc/hosts entries will be ignored).

Embrace Victory

I hope you enjoyed this article, please feel free to email feedback to chad{a.t}chadfurman{d.o.t}com.


Thanks go out to my friends and fellows at Clevertech for their help in making this article (and life in general) better than I could by myself. Special thanks to Jordan, Roger, Gábor, Andres, Nifty Lettuce, Lloyd, Michelle, and Kuty, who provided direct emotional support, edits, and suggestions.

@gaborluk

gaborluk commented Jan 6, 2016

Copy link
Copy Markdown

Nice job, Chad, the article is super-clear and comprehensive.

I've taken the liberty of doing a proofreading pass on it, and you can see my changes here. Basically just correcting grammar, typos, and inconsistencies.

Beyond those, I would recommend to make three more changes, for a really professionally looking article:

  • I'd remove smileys everywhere. Your pleasant attitude comes across just fine without them.
  • I'd replace all images with better-quality ones which also come without watermarks. For custom-made images that feature highlighting and arrows added by you, I'd redo them using Skitch.
  • I'd remove this one paragraph, as it overexplains the point and breaks the flow:
    For example, # apt-get install openssh-server would mean to type apt-get install openssh-server as a privileged user.

Let me know if I can help you with anything.

@freekrai

freekrai commented Jan 7, 2016

Copy link
Copy Markdown

I'd also touch on using the --auth username:password argument.

Also, when you use -w /path/to/the/project/you/want/to/work/on there is a bug currently that it will actually create a blank folder in the folder you've installed cloud9 and then create the path from there.

It is recommend to use -w/path/to/the/project/you/want/to/work/on, and that is only on the -w argument currently.

@chadfurman

Copy link
Copy Markdown
Author

@freekrai @gaborluk @niftylettuce @jordandenison @codeandrop your suggestions were fantastic, thank you!

  • I've included the great grammar edits by @gaborluk
  • Removed smileys
  • Removed bit about # and $
  • Updated screenshots using shutter (Skitch is not available in Linux)
  • Noted the --auth flag for c9
  • Noted the bug with -w
  • Mentioned Alpha status of c9 stand-alone in the intro
  • Added block about Key-based authentication
  • Added note about dynamic IP address services
  • Updated to use su -c '...'
  • Revised local port forwarding clarification
  • Added thank-yous in the footer

@chadfurman

Copy link
Copy Markdown
Author
  • Revised opening paragraph

@kutyshalev

Copy link
Copy Markdown

A good title that is likely to be retweeted might be "Coffee Shop Development for < $500".

I'd start with the pain point which might be:

  • Don't want to shell out premium dollars for macbook pro
  • Security concerns around laptops getting stolen
  • Have a great desktop, but don't want to spend resources on a mobile equivalent (macbook pro)

And this solution accomplishes all that AND

  • great backup
  • super inexpensive
  • feels great to accomplish something complex

All that gives you the "flavor" of building trust with the reader explaining what this is meant for before diving into the details.

@chadfurman

Copy link
Copy Markdown
Author

Thank you @kutyshalev! I've revised my opening paragraph to communicate these points. Great stuff!

@gaborluk

Copy link
Copy Markdown

@chadfurman, I've made a final proofreading pass on the article. Beyond some grammatical and style changes, I did two things:

  • I removed the bold from the first sentence. You don't need extra attention there, it's the first line of the article, it gets attention by definition, and the unnecessary emphasis is too much visual clutter.
  • I removed the link from your email address, both because it's unexpected, and, more importantly, because it makes selecting the address much harder, resulting in accidental navigation.

Here's the updated version.

@chadfurman

Copy link
Copy Markdown
Author

Thanks, @gaborluk! The extra pop for the first sentence was a suggestion from @kuty - I believe it was to help hook the reader emotionally? I might keep that. Everything else is great! I thank you, good sir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment