This is the Udacity project 6 about the Configuring the Linux the server.
Server IP Address 13.126.48.184
port : 2200
Hosted site Url http://13.126.48.184.xip.io/
First open puttygen and then load the lightsail1.pem to genarate private key
It is saved as privatekey.ppk
Now open putty give the static ip:13.126.48.184 and port:2200
Now go to ssh and in ssh goto to auth load the privatekey
login as : ubuntu
su - grader
password for grader:sai
mkdir .ssh
creates .ssh directory
touch .ssh/authorized_keys
create authorized_keys in .ssh folder
nano .ssh/authorized_keys
In git bash ssh-keygen
.ssh file will be created with id_rsa files
now copy the contents of id_rsa.pub file (microsoft office file) and paste it in the grader.
sudo apt-get update
sudo apt-get upgrade
sudo adduser grader
This will add new user Password for this user : sai
sudo nano /etc/sudoers
Below the Root user append the following line
grader ALL=(ALL:ALL) ALL
This will grant sudo permission to grader
On your local machine in terminal/command prompt
ssh-keygen
This will generate public and private ssh keys which is saved to .ssh folder
Then in your virtual machine change to newly created user
su - grader
Create a new directory .ssh and new file authorized_keys in that directory
mkdir .ssh
sudo nano .ssh/authorized_keys
Copy the public key with .pub extension to authorized_keys and save the file
chmod 700 .ssh
chmod 644 .ssh/authorized_keys
- 700 will give read write and execute permission to user.
- 644 prevent other user from writting in to file. Then restart ssh server
service ssh restart
Now from your log in to grader with private key generated
ssh -i .ssh/id_rsa [email protected]
sudo nano /etc/ssh/sshd_config
Change port 22 to port 2200
Restart the ssh server
service ssh restart
Note: Before Logging using ssh add custom TCP port 2200 under lightsaail firewall in networking tab in lightsail instance console
Now Login using command like this
ssh -i .ssh/id_rsa -p 2200 [email protected]
sudo nano /etc/ssh/sshd_config
make change PermitRootLogin no
Goto amazon aws lightsail account
Goto networking then change firewall as follows
Custom UDP 123
Custom TCP 2200
Configurating Ufw firewall
sudo ufw allow 2200/tcp
sudo ufw allow 80/tcp
sudo ufw allow 123/udp
sudo ufw enable
This will allow all required ports and enables the ufw
After that
sudo ufw status
It will display all allowed ports
In terminal
sudo apt-get install apache2
Now mod_wsgi
sudo apt-get install python-setuptools libapache2-mod-wsgi
Enable mod_wsgi
sudo a2enmod wsgi
Creating a flask app
In /var/www directory create a new folder
sudo mkdir FlaskApp
Install git
sudo apt-get install git
move to the FlaskApp cd FlaskApp
In that direcory clone your github repository
sudo git clone 'https://github.com/ratnakumarikunisetti/buid-itemcatalog1.git'
Renaming the repository to FlaskApp
Then rename app.py file to __init__.py
Make Following changes in init.py
PROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))
json_url = os.path.join(PROJECT_ROOT, 'client_secrets.json')
CLIENT_ID = json.load(open(json_url))['web']['client_id']
Use json_url instead client_secrets.json in script
Install Postgres sudo apt-get install postgresql
login to postgres sudo su - postgres
postgres shell psql
create user CREATE USER catalog WITH PASSWORD 'password';
permit user to createdb ALTER USER catalog CREATEDB;
Create a db name catalog with user catalog CREATE DATABASE catalog WITH OWNER catalog;
connect to db \c catalog
revoke all permission to public REVOKE ALL ON SCHEMA public FROM public;
Give schema permission to user catalog GRANT ALL ON SCHEMA public TO catalog;
exit from db and postgres \q and exit
Change the database connection in both database_setup.py and __init__.py
as engine = create_engine('postgresql://catalog:password@localhost/catalog')
Now we are ready with our applicatiom
sudo nano /etc/apache2/sites-available/FlaskApp.conf
In this add the following code
<VirtualHost *:80>
ServerName 13.126.48.184
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>
Enable the virtual host
sudo a2ensite FlaskApp
Disabling the default apache2 page
sudo a2dissite 000-default.conf
```
cd /var/www/FlaskApp
sudo nano flaskapp.wsgi
```
Add the following code
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp/")
from FlaskApp import app as application
application.secret_key = 'Add your secret key'
save and exit
Deploying flask app with apache2 is referred from [Digital ocean] (https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps)
You can either install all modules on your machine or create a virtual environment for the project and install the modules
pip install flask sqlalchemy psycopg2 requests oauth2client
-
Go to Google Cloud Plateform.
-
Click
APIs & services
on left menu. -
Click
Credentials
. -
Create an OAuth Client ID (under the Credentials tab), and add http://13.126.48.184.xip.io as authorized JavaScript origins.
-
Add the below three links as authorized javascript origins
-
Download the corresponding JSON file, open it et copy the contents.
-
Open
/var/www/FlaskApp/FlaskApp/client_secret.json
and paste the previous contents into the this file. -
Replace the client ID in app.js file in the project directory.
Restart apache2 server
sudo service apache2 restart #my lightsaildefaultprivate key-ap-south-1.pem
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAwBQAKY1XXBdlba92c4vvIzeC6mj7qtqQRjCFyRm7SU7McTe+
bLw1rCO9abxm+mPD3gB6dEGru4RmuZpvEjj/JhsXk9nq+PCtrRzvuKyPHF5AqUK3
Ju0WLovN3F8fRbRMwbg80aF6YLwDBJu1Xml6MztiaKazhsN8UWsJgwM05L7IvqBV
8tC6qfCOPjgq/ya6VovuQc+Y9xp0jOUws/XWNK/6f585UfXRzZOxdsiZyOIagkqp
3wsNhsuboerthzlsIWiFyOZ9f3DgztdtVt10cNfhC6bxAYFhJr25xokZhOnvnjoy
rmiFDtsr/YgPa7ltzJCtDhQYszlB8IIa0ZSoGQIDAQABAoIBACUKNlXM+dG6eUbD
lVYG4CCsbcSCZjW2XCgM51+2ZJVoaqhSlZgmWztM0RP4zuruHjFLalHM8C8DA0Q7
cbvT3fAdPVi3p0ZGM1e0ws2cCSTxUArT4LnS8nobX6FlfoRUlpCs1J2gRBcvam2T
EVCZioUiqIGB1BDi1bBlsbnf/m01v4Xm66tyUXmRh97u27jSBrG6YyIe+IKEC9Fk
Lg8D/gzwIHTt+YUhjsdSzbr1GONw5q0jmKWmD9P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