GithubHelp home page GithubHelp logo

udacity-fsnd2015-p5's Introduction

Udacity Full Stack Nanodegree Project 5 - Linux Server Configuration

Project Location

TODO: check links

Table of Contents

Create grader Account

Give grader SUDO

Create SSH Keys

  • Create SSH key with the command ssh-keygen on your local machine(OSX or Linux).

  • Create an .ssh direcory in /home/grader/ on the server with mkdir .ssh.

  • CD into the the directory just created with cd ~/.ssh/.

  • Create an authorized_keys file in the .ssh dirctory with touch authorized_keys.

  • Paste the public key into /home/grader/.ssh/authorized_keys

  • Set directory permissions

    • Using chmod set ~/.ssh to 700 with chmod 700 /home/grader/.ssh/.
    • Again, using chmod set the authorized_keys file to 644 with chmod 644 /home/grader/.ssh/authorized_keys.
  • Check owner and group of ~/.ssh and ~/.ssh/authorized_keys.

  • If the owner and group are not grader, set them to grader with chown -R grader:grader /home/grader/.ssh/

  • Check to ensure you can log into the grader account with ssh -i ~/.ssh/grader.rsa [email protected].

    • Recheck you followed the steps above in the event of an issue or Google the error message. This how I figured out that password login was disabled on my instance already.
  • Resources used for this step.

Update Packages

  • Use the following commands to update the packages on the server.

    • sudo apt-get update
    • sudo apt-get upgrade. Type "Y" when asked if you would like to proceed.
  • Resources used in this step.

Configure Timezone

  • Check the current timezone with date.

  • If you do not see UTC in the output, change the timezone with dpkg-reconfigure tzdata.

    • Select "None of the above" from the first menu.
    • Select "UTC" at the second menu.
  • You can improve the accuracy of the clock by installing ntp with sudo apt-get install ntp.

  • Resources used for this step.

Change SSH Security Improvements

  • Use nano to edit the SSH config file with sudo nano /etc/ssh/sshd_config.
  • Change the default port from 22 to 2200 by changing the following
# What ports, IPs and protocols we listen for
Port 22

to

 # What ports, IPs and protocols we listen for
 Port 2200
  • Check to see that password login is disabled.

    • You should see the following in the file. If set to "yes" change it to "no" and save the file.

      # Change to no to disable tunnelled clear text passwords
      PasswordAuthentication no
      
  • Disable ssh login for root user by changing "yes" to "no" on the following line

PermitRootLogin yes
  • Restart ssh with sudo service ssh restart.

  • Exit the root session with exit and log back in as grader.

    ssh -i ~/.ssh/grader.rsa [email protected] -p 2200

Configure Firewall

  • Check the status of the firewall with sudo ufw status.

  • Ensure that by default inbound connections are denied with sudo ufw default deny incoming.

  • Ensure the all outbound connections are allowed with sudo ufw default allow outgoing.

  • Open ports for SSH, HTTP, and NTP with the following commands.

    • sudo ufw allow 2200/tcp
    • sudo ufw allow www
    • sudo ufw allow ntp
  • Activate the firewall with sudo ufw enable.

  • Resources used for this step.

Install your application

Install Apache

  • Check to see if Apache is installed with apache2 -v

  • If Apache is installed you will see something like this:

    Server version: Apache/2.4.7 (Ubuntu)

    Server built: Jan 14 2016 17:45:23

  • If you do not have Apache installed you will see a message like this:

    The program 'apache2' is currently not installed. To run 'apache2' please ask your administrator to install the package 'apache2-bin'

  • To install Apache use the following commands: sudo apt-get update sudo apt-get install apache2

  • If you have installed Apache correctly you should see this page at the public IP address.

    Apache Default Page

  • Resources used for this step.

Install mod_wsgi

Install PostgreSQL

  • Install PostgreSQL:

    sudo apt-get update
    sudo apt-get install postgresql postgresql-contrib
  • And while we are at it, let's install libpq-dev. It is required to build psycopg2.

    sudo apt-get install libpq-dev
  • Ensure remote connections are disabled.

    sudo nano /etc/postgresql/9.3/main/pg_hba.conf

    • The default configuration disables remote connections by default. Here is a cleaned up version of the section that controls connections.
Type Database User Address Method
local all postgres peer
local all all peer
host all all 127.0.0.1/32 md5
host all all ::1/128 md5

The host IPs point to local addresses by default.

Install Catalog App

  • Install git:

    sudo apt-get install -y git
  • Move to the directory where the app will be installed and clone app:

    cd /var/www/
    sudo mkdir catalog
    cd catalog
    sudo git clone https://github.com/larrytooley/Udacity-FSND2015-P3.git catalog
  • Configure and Enable New Virtual host

    • Create a new configuration file:

      sudo nano /etc/apache2/sites-available/catalog.conf
    • Add this code to catalog.conf:

      <VirtualHost *:80>
                  ServerName http://ec2-52-40-51-21.us-west-2.compute.amazonaws.com/
                  ServerAdmin [email protected]
                  WSGIScriptAlias / /var/www/catalog/catalog.wsgi
                  <Directory /var/www/catalog/catalog/>
                          Order allow,deny
                          Allow from all
                  </Directory>
                  Alias /static /var/www/catalog/catalog/static
                  <Directory /var/www/catalog/catalog/static/>
                          Order allow,deny
                          Allow from all
                  </Directory>
                  ErrorLog ${APACHE_LOG_DIR}/error.log
                  LogLevel warn
                  CustomLog ${APACHE_LOG_DIR}/access.log combined
      </VirtualHost>
      
  • Enable the virtual host:

    sudo a2ensite catalog
  • Create a .wsgi file:

    cd /var/www/catalog
    sudo nano catalog.wsgi
    
  • Add code to file:

    #!/usr/bin/python
    import sys
    import logging
    logging.basicConfig(stream=sys.stderr)
    sys.path.insert(0,"/var/www/catalog/")
    from catalog import app as application
    application.secret_key = 'Add your secret key'
  • I generated application.secret_key locally and substituted it in the file:

    python
    import os
    os.urandom(24)
  • Restart apache2

    sudo service apache2 restart
  • Secure .git

    • Create an .htaccess file in the .git directory:

      cd /var/www/catalog/catalog/.git
      sudo nano .htaccess
    • Add the following code to the file:

      Order allow,deny
      Deny from all
  • Resources used for this step:

  • Install Dependancies

    sudo pip install flask httplib2 requests oauth2client sqlalchemy psycopg2
  • Rename the main application file to init.py.

  • Update the database connection to use PostgreSQL by change the reference to SQLite to the following to the db_model.py and __init.__py:

    'postgresql://catalog:<password>@localhost/catalog'
  • Create the database schema.

    • Run the following to create the database schema:

      python db_model.py
  • Install Dependancies:

    sudo apt-get install python-pip
    sudo pip install virtualenv
    cd /var/www/catalog/catalog/
    sudo virtualenv venv
    source venv/bin/activate
    sudo pip install Flask
    deactivate
  • Update client_secret.

    • Use the full file path in the init.py file.
    /var/www/catalog/catalog/client_secret.json
    sudo nano client_secret.json
  • Go to http://ec2-52-10-176-92.us-west-2.compute.amazonaws.com/ and use app.

Project Guide

udacity-fsnd2015-p5's People

Contributors

larrytooley avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.