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 />

At this stage, you’ll be prompted for a password, which is the complex one you set up<br />

a little earlier. Enter it here and the file will be copied over to the server.<br />

Add this key to the ~/.ssh/authorized_keys file on the server by using this:<br />

cat ~/.ssh/[your_name]_key.pub >> ~/.ssh/authorized_keys<br />

This command will append the key to ~/.ssh/authorized_keys if that file already exists,<br />

or create the file and then fill it with the content if it doesn’t. Either way, you’re going<br />

to have a ~/.ssh/authorized_keys file, which means that you’ll be able to SSH to this<br />

server without using your complex password. If you disconnect from the server and<br />

then reconnect, you shouldn’t be prompted for your password. This means that the<br />

authentication is working.<br />

Finally, change the permissions on this ~/.ssh/authorized_keys file so that only the<br />

user it belongs to can read it:<br />

chmod 600 ~/.ssh/authorized_keys<br />

With that set, change into the application’s user account by running sudo su<br />

ticketeeapp.com and run the same steps, beginning with mkdir ~/.ssh and ending<br />

with disconnecting and reconnecting without password prompt. Remember to<br />

change user in the scp command to be the ticketeeapp.com user this time around.<br />

If both of these accounts are working without password authentication, then you<br />

may as well turn it off!<br />

14.3.2 Disabling password authentication<br />

You’ve just implemented key-based authentication on your system for both the<br />

accounts you have, thus removing the need for any kind of password authentication.<br />

To secure your server against possible password attacks, it’s a good idea to turn off<br />

password authentication altogether.<br />

To do this, open /etc/ssh/sshd_config using sudo nano /etc/ssh/sshd_config 18<br />

and add PasswordAuthentication no where it would otherwise say #Password-<br />

Authentication yes (the # symbol indicates a commented line, just like Ruby). You<br />

can find this line by pressing Ctrl+W, typing in PasswordAuth, and pressing Enter.<br />

This configures your SSH server to not accept password authentication.<br />

Towards the top of this file there’s a line that says PermitRootLogin yes. Change<br />

this line to read PermitRootLogin no instead, so that it blocks all SSH connections for<br />

the root user, increasing the security further.<br />

NOTE There is also /etc/ssh/ssh_config, which is a little confusing... two<br />

files with nearly identical names. The file you just edited is the file for the<br />

SSH server (or daemon, hence the d at the end), while the ssh_config file is<br />

for the SSH client. Make sure you’re editing the right one.<br />

Last, quit nano by pressing Ctrl+X and then Y to confirm that you do want to quit and<br />

save. Next, you need to restart the SSH daemon by using this command:<br />

18 nano is the basic editor that comes with Ubuntu.<br />

393

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

Saved successfully!

Ooh no, something went wrong!