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.

Creating a user for the app<br />

So now you’ve got the beginnings of a pretty good environment set up for your application,<br />

but you don’t have your application on the server yet. To do this, you need to<br />

undertake a process referred to as deployment. Through this process you’ll put your<br />

application’s code on the server and be one step closer to letting people use the<br />

application.<br />

When you deploy, you’ll use a user without root privileges to run the application,<br />

just in case. Call this user the same as your (imaginary) domain: ticketeeapp.com.<br />

14.3 Creating a user for the app<br />

You’re calling this user ticketeeapp.com because if you wanted to deploy more than<br />

one application to your server, there will be no confusion as to which user is responsible<br />

for what. When you set up a database later on, this username will be the same as<br />

your database name. This is for convenience’s sake, but also because the database will<br />

be owned by a user with the same name, allowing this account and none other (bar<br />

the database super user) to access it. It’s all quite neat.<br />

To begin to set up this user, run these commands:<br />

sudo useradd ticketeeapp.com -s /bin/bash -m -d /home/ticketeeapp.com<br />

sudo chown -R ticketeeapp.com /home/ticketeeapp.com<br />

sudo passwd ticketeeapp.com<br />

You’ve used a couple of options to the useradd command. The -s option sets the shell<br />

for the user to /bin/bash (the standard shell found in most UNIX-based operating systems)<br />

and the -d option sets their home directory to /home/ticketeeapp.com, while<br />

the -m option makes sure that the user’s home directory exists. The second command,<br />

chown (short for change owner), changes the owner of the /home/ticketeeapp.com<br />

directory to be the ticketeeapp.com user. The final command, passwd, prompts you to<br />

set a password for this user, which you should set to something complex (that you’ll be<br />

able to remember) to stop people hacking your ticketeeapp.com user. 15<br />

To make this account even more secure, you can switch to key-based authentication.<br />

14.3.1 Key-based authentication<br />

In this next step, you’ll set up a key that will allow you to log in as your user and<br />

deploy on your server without a password. This is called key-based authentication and<br />

requires two files: a private key and a public key. The private key goes on the developer’s<br />

computer and should be kept private, as the name implies, because it is the key<br />

to gain access to the server. The public key file can be shared with anybody and is used<br />

by a server to authenticate a user’s private key.<br />

You’ll use a key-based authentication for your server because it is incredibly secure<br />

versus a password authentication scheme. To quote the official Ubuntu instructions<br />

on this 16 :<br />

15 Even though this won’t matter in a short while (when you turn off password authentication and switch to the<br />

more secure key-based authentication), it’s still good practice to always secure any user account on any system<br />

with a strong password.<br />

16 https://help.ubuntu.com/community/SSH/OpenSSH/Configuring.<br />

391

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

Saved successfully!

Ooh no, something went wrong!