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.

396 CHAPTER 14 Deployment<br />

14.5.1 Deploy keys<br />

If your repository was private on GitHub, you would clone it with the URL of<br />

git@github.com:our_username/ticketee.git and would need to authenticate with a<br />

private key. You shouldn’t copy your private key to the server because if a malicious<br />

person gains access to the server they will also then have your private key, which may<br />

be used for other things.<br />

To solve this particular conundrum, generate another private/public key pair just<br />

for the server itself and put the public key on GitHub to be a deploy key for this repository.<br />

This will allow the server to clone the repository.<br />

To do this, run the following command as the ticketeeapp.com user on your<br />

server:<br />

ssh-keygen -t rsa<br />

Press Enter to put the key at the default ~/.ssh/id_rsa.pub location. You can enter a<br />

password for it, but if you do this you will be prompted for it on every deploy. It’s really<br />

personal preference whether or not to do this.<br />

This command will generate two new files: a public and private key. The private<br />

key should remain secret on the server and shouldn’t be shared with any external parties.<br />

The public key, however, can be given to anybody. You’re going to put this key on<br />

GitHub now.<br />

Run the cat command to get the contents of the public key file, like this:<br />

cat ~/.ssh/id_rsa.pub<br />

ssh-rsa AAAAB3NzaC1yc2EAA...<br />

You should copy the output of this command into your clipboard. Your next step is to<br />

go to the repository on GitHub and click the Admin link in the bar in the view for the<br />

repository, shown in figure 14.1.<br />

From here, press the Deploy Keys link and then paste the key into the box, calling it<br />

ticketeeapp.com to keep up with your current naming scheme, as shown in figure 14.2.<br />

When you’re done here, click the Add Key button, which will add the key you’ve<br />

specified to the list of deploy keys on GitHub. You should then be able to run a git<br />

clone command on the server using the private URL to clone your repository:<br />

git clone git@github.com:our_username/ticketee.git ~/ticketee<br />

Figure 14.1 Admin button

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

Saved successfully!

Ooh no, something went wrong!