Code Monkey home page Code Monkey logo

linux-server-configuration's Introduction

IP Address: 13.234.116.153

APP URL: http://13.234.116.153.xip.io/

SSH command: ssh -i Pemfile.pem -p 2200 [email protected]


1. Connect to AWS Lighstail instance

Connect using ssh -i Lightsail.pem [email protected] where xxx.xxx.xxx.xxx is the public IP address.

2. Configure ports and firewall

2.1. Change SSH port from 22 to 2200

  • Run sudo vim /etc/ssh/sshd_config to edit the file. Change port 22 to 2200
  • Restart the ssh service by running sudo service ssh restart

2.2. Configure UFW firewall

  • Run sudo ufw default deny incoming to block all incoming connections
  • Run sudo ufw default allow outgoing to allow outgoing connections
  • Run sudo ufw allow 123/udp to allow NTP on port 123
  • Run sudo ufw allow ssh to allow SSH on port 2200
  • Run sudo ufw deny 22 to block the default SSH port 22
  • Run sudo ufw allow 2200/tcp so that the new SSH port works
  • Run sudo ufw enable to enable UFW firewall

Configure Lightsail instance to update SSH and NTP ports. Reconnect to the instance using ssh -i Lightsail.pem -p 2200 [email protected]

3. Create a new user 'grader'

This user has sudo rights.

  • Create a user using sudo adduser grader. Give a password and fill required details
  • Create /etc/sudoers.d/grader file and add grader ALL=(ALL) NOPASSWD:ALL to give it sudo rights
  • Create a folder ~/.ssh and give it permission 700
  • Generate new SSH key-pair by running ssh-keygen -t rsa
  • Create a new file ~/.ssh/authorized_keys and give it permission 600
  • Copy the contents of ~/.ssh/id_rsa.pub inside ~/.ssh/authorized_keys
  • Copy the contents of ~/.ssh/id_rsa to a file in your local machine and save it as grader.pem
  • Delete both the ~/.ssh/id_rsa.pub and ~/.ssh/id_rsa files
  • Disconnect from the instance and reconnect as grader by running ssh -i grader.pem -p 2200 [email protected]

4. Install and configure Apache server

Run sudo apt-get install apache2 to install Apache server. It will be running on port 80 by default. Confirm by visiting the public address of the instance via browser.

The instructions on this site was followed exactly to configure Apache.

The Apache config file /etc/apache2/sites-available/FlaskApp.conf looks as:

<VirtualHost *:80>
		ServerName http://13.234.116.153.xip.io/
		ServerAdmin [email protected]
		WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
		<Directory /var/www/FlaskApp/FlaskApp/>
			Order allow,deny
			Allow from all
		</Directory>
		Alias /static /var/www/FlaskApp/FlaskApp/static
		<Directory /var/www/FlaskApp/FlaskApp/static/>
			Order allow,deny
			Allow from all
		</Directory>
		ErrorLog ${APACHE_LOG_DIR}/error.log
		LogLevel warn
		CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

5. Install python and its dependencies

Install the following:

  • Run sudo apt-get install python python-pip to install python and pip
  • Run sudo pip install --upgrade pip to upgrade pip
  • Run sudo apt-get install flask packaging oauth2client passlib flask-httpauth psycopg2-binary requests to install necessary python modules

6. Install Postgres

Run the below commands by activating virtual environment

  • Run sudo apt-get install postgresql to install Postgres
  • Switch user to postgres using sudo su - postgres
  • Run psql to connect to Postgres via its terminal
  • Create a role using CREATE ROLE grader WITH LOGIN;
  • Give role the authority to create a database by running ALTER ROLE catalog CREATEDB;
  • Give the role grader a password by running \password grader. Then run exit to return to the previous user
  • Run createdb catalog to create a database. This will be owned by grader

7. Setup the Catalog Project

  • Run git clone https://github.com/Sidsector9/FSND-Item-Catalog.git . inside /var/www/FlaskApp/FlaskApp
  • Rename the file server-catalog.py to __init__.py
  • Delete all the files ending in .pyc
  • Replace app.run(host='0.0.0.0', port=5000) to app.run() inside __init__.py
  • Search-replace credentials.json to /var/www/FlaskApp/FlaskApp/credentials.json in all the files
  • Search-replace sqlite:///catalog.db to postgresql://grader:<PASSWORD>@localhost/catalog in all the files

8. Fill up the category table

Only Items can be added, edited and deleted, categories can't.

  • Run sudo su - postgres
  • Run psql
  • Run \c catalog to connect to the catalog database
  • Run INSERT INTO category (id, name, slug) VALUES (val1, val2, val3); to fill up the category

Articles referred:

linux-server-configuration's People

Contributors

sidsector9 avatar

Watchers

James Cloos avatar  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.