Skip to content

Instantly share code, notes, and snippets.

@jcarter62
Last active February 21, 2020 19:59
Show Gist options
  • Select an option

  • Save jcarter62/998ee21f1ae296f970c0e8973f6c1ebc to your computer and use it in GitHub Desktop.

Select an option

Save jcarter62/998ee21f1ae296f970c0e8973f6c1ebc to your computer and use it in GitHub Desktop.
Ubuntu 18.04 - Python Setup

#Ubuntu Server Setup

Things to do:

[ ] Update Available Package Lists:

# sudo apt-get update

Upgrade installed packages:
# sudo apt-get upgrade

Other Tasks:
# sudo apt-get autoremove

Discover Packages: [https://packages.ubuntu.com][https://packages.ubuntu.com]

Add user to system:

sudo adduser <name>

##Give sudo access to a user: Link to reference

/etc/sudoers.d contains a file for each account allowed. You will create a file in the folder /etc/sudoers.d, named the same as your new user.

Example, user named joe

# sudo -i
# adduser joe
# cd /etc/sudoers.d
# touch joe
# vi joe

Add the following to this file joe

joe ALL=(ALL) NOPASSWD:ALL

Notice that the first word is the same as the user name. Login as this new user, then execute sudo -i. You should not see the password prompt.

SSH Keypairs

On any system: Generate key pairs

# ssh-keygen

Save to file, which will create a private and public key, key pair. For example if you save the pair to a file such as ~/.ssh/linuxclass

On the remote system. Login as the non-admin user such as

Install public key

# cd ~
# mkdir .ssh
# touch .ssh/authorized_keys
# vi .ssh/authorized_keys

paste the linuxclass.pub into the authorized_keys as one line, then save the file.

# chmod 700 .ssh
# chmod 644 .ssh/authorized_keys

On local system:

# ssh -p 2222 <student>@localhost -i ~/.ssh/linuxclass

Disable password logins:

# sudo vi /etc/ssh/sshd_config

Find the line similar to:

PasswordAuthentication yes

-- change it to --

PasswordAuthentication no


Deploy Flask app to Apache: https://www.bogotobogo.com/python/Flask/Python_Flask_HelloWorld_App_with_Apache_WSGI_Ubuntu14.php

Edit the file:

/etc/apache2/envvars

Add line:

export APP_DIR=/home/..../path2app/

Apache Config information:

<VirtualHost *:80>
  ServerName MY_SERVER_NAME

  WSGIDaemonProcess appname threads=5 home=${APP_DIR}
  WSGIScriptAlias / "${APP_DIR}your_app.wsgi"

  <Directory "${APP_DIR}">
    Options Indexes FollowSymLinks MultiViews ExecCGI
    AllowOverride None
    Require all granted
    WSGIProcessGroup appname
    WSGIApplicationGroup %{GLOBAL}
  </Directory>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment