27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

392 CHAPTER 14 Deployment<br />

To be as hard to guess as a normal SSH key, a password would have to contain 634<br />

random letters and numbers.<br />

—OpenSSH Configuring<br />

Not many people today would be willing to use a password containing 634 random letters<br />

and numbers! Considering the average password length is 8 characters, this a vast<br />

improvement over password-based authentication.<br />

You’re going to enable this key-based authentication for both your current user<br />

and your ticketeeapp.com. For now, use the same key generated for use with GitHub;<br />

however, it’s recommended that a different key be used for the server.<br />

Public keys are stored at a file called .ssh/authorized_keys located in the user’s<br />

home directory, the user being the user you will connect as through SSH. When the<br />

user attempts to connect to the server, the private and public keys are used to confirm<br />

the user’s identity. 17 Because the chances against two users having the same public and<br />

private key are so astronomically high, it is generally accepted as a secure means of<br />

authentication.<br />

In this instance, you’ll create two of these ~/.ssh/authorized_keys files: one for each<br />

user. In each case, create the ~/.ssh directory before creating authorized_keys. Begin<br />

with the user you’re currently logged in as.<br />

Let’s create the ~/.ssh directory now using this command:<br />

mkdir ~/.ssh<br />

Now you need to copy over the public key from your local computer to the ~/.ssh directory<br />

on the server, which you can do by running this command on your local system:<br />

# NOTE: Run this on your *local* machine, not the server!<br />

scp ~/.ssh/id_rsa.pub user@your-server:~/.ssh/[your_name]_key.pub<br />

If you’re using Vagrant…<br />

Vagrant already has a ~/.ssh/authorized_keys file, so there’s no need to re-create<br />

it. Overwriting this file may cause vagrant ssh to no longer work.<br />

You will also need to forward the SSH port from the virtual machine launched by<br />

Vagrant to a local port in order to connect without using Vagrant. While you’re here,<br />

forward the HTTP port (80) as well so that you can access it from the outside. Go into<br />

the Ubuntu directory that you created at the beginning of this chapter, open Vagrant-<br />

File, and add this inside the Vagrant::Config.run block:<br />

config.vm.forward_port "ssh", 22, 2200<br />

config.vm.forward_port "http", 80, 4567<br />

To connect to this server, use port 2200 for SSH and port 4567 for HTTP. When you<br />

use the scp command, the port can be specified using the -P (capital p) option and<br />

ssh using -p (lowercase p), with the port number specified directly after this option.<br />

In places where these commands are used, substitute your-server with localhost<br />

and user with vagrant.<br />

17 For a good explanation of how this process works, check this page: http://unixwiz.net/techtips/ssh-agentforwarding.html#agent.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!