User:Pedro Sá Couto/Prototyping 5th/Flask App/Raspberry Pi into NGINX server: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "'''01''' Format SDcard to FAT32 '''02''' Flash SDcard with Linux ISO :Raspbian Buster Light, https://www.raspberrypi.org/downloads/raspbian/ :you can use dd or a mounter like...")
 
No edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''01''' Format SDcard to FAT32
=RASPI CONFIG=
===01 Format SDcard to FAT32===


'''02''' Flash SDcard with Linux ISO
===02 Flash SDcard with Linux ISO===
:Raspbian Buster Light, https://www.raspberrypi.org/downloads/raspbian/
:Raspbian Buster Light, https://www.raspberrypi.org/downloads/raspbian/
:you can use dd or a mounter like etcher https://www.balena.io/etcher/  
::you can use dd or a mounter like etcher https://www.balena.io/etcher/


 
===03 Default login===
'''03''' Default login
:Login: pi
:Login: pi
:Password: raspberry
:Password: raspberry


===04 SSH config===
<pre style="color: silver; background: black;">
$ cd /boot
$ sudo touch ssh
$ sudo reboot
</pre>


'''04 SSH config
===05 Change hostname===
 
<pre style="color: silver; background: black;">
    $ cd /boot
$ sudo raspi-config
 
</pre>
    $ sudo touch ssh
:Item no. 2 on the menu: Network Options
 
    $ sudo reboot
 
 
05 Check IP address
 
    $ hostname -i
 
 
06 Change hostname
 
    Change hostname
 
    $ sudo raspi-config
 
    Item no. 2 on the menu: Network Options
 
    Renamed hostname to: <hostname>
 
 
07 Add user
 
    $ sudo adduser <username>
 
 
08 Add new user to sudo
 
    $ sudo adduser <username> sudo
 
 
09 Change su/root password
 
    $ sudo passwd root
 
 
10 Setting locale
 
    $ su
 
    $ echo "LC_ALL=en_US.UTF-8" >> /etc/environment
 
    $ echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
 
    $ echo "LANG=en_US.UTF-8" > /etc/locale.conf
 
    $ locale-gen en_US.UTF-8
 
 
09 Generate public/private keys on your machine
 
    (https://www.raspberrypi-spy.co.uk/2019/02/setting-up-ssh-keys-on-the-raspberry-pi/)
 
    $ cd ~
 
    $ mkdir .ssh
 
    $ cd .ssh
 
    $ touch authorized_keys
 
    $ touch config
 
    $ chmod 700 ~/.ssh
 
    $ chmod 600 ~/.ssh/authorized_keys
 
    $ cd ~/.ssh
 
    $ ssh-keygen
 
    $ cat id_rsa.pub >> authorized_keys
 
    $ sudo apt-get install putty-tools
 
    $ puttygen id_rsa -o id_rsa.ppk
 
 
10 Get the public key onto RPi
 
    Copy the contents of id_rsa.pub from you machine
 
    $ cat <path to id_rsa.pub>
 
    Paste and save them into authorized_keys file on RPi
 
    $ cd ~/.ssh
 
    $ sudo nano authorized_keys
 
 
11 Set static IP address
 
    (https://pimylifeup.com/raspberry-pi-static-ip-address/)
 
    Retrieve the currently defined router and IP


    $ ip r | grep default
===06 Add new user===
<pre style="color: silver; background: black;">
$ sudo adduser <username>
</pre>


    Modify the dhpcd.conf configuration
===07 Add new user to sudo===
<pre style="color: silver; background: black;">
$ sudo adduser <username> sudo
</pre>


    $ sudo nano /etc/dhcpcd.conf
===08 Change su/root password===
<pre style="color: silver; background: black;">
$ sudo passwd root
</pre>


    Change this part only
===09 Setting locale===
<pre style="color: silver; background: black;">
$ su
$ echo "LC_ALL=en_US.UTF-8" >> /etc/environment
$ echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
$ echo "LANG=en_US.UTF-8" > /etc/locale.conf
$ locale-gen en_US.UTF-8
</pre>


    # Example static IP configuration:
===10 Setting locale===
:https://www.raspberrypi-spy.co.uk/2019/02/setting-up-ssh-keys-on-the-raspberry-pi/
<pre style="color: silver; background: black;">
$ cd ~
$ mkdir .ssh
$ cd .ssh
$ touch authorized_keys
$ touch config
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
$ cd ~/.ssh
$ ssh-keygen
$ cat id_rsa.pub >> authorized_keys
$ sudo apt-get install putty-tools
$ puttygen id_rsa -o id_rsa.ppk
</pre>


    interface eth0
===11 Get the public key onto RPI===
:Copy the contents of '''id_rsa.pub''' from you machine
<pre style="color: silver; background: black;">
$ cat <path to id_rsa.pub>
</pre>
:Paste and save them into authorized_keys file on RPi
<pre style="color: silver; background: black;">
$ cd ~/.ssh
$ sudo nano authorized_keys
</pre>


    static ip_address=192.168.1.119/24
===12 Set static IP address===
 
:Check gateway
    #static ip6_address=fd51:42f8:caae:d92e::ff/64
<pre style="color: silver; background: black;">
 
$ sudo route -n
    static routers=192.168.0.1
</pre>
 
:Open etc config
    static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1
<pre style="color: silver; background: black;">
 
$ sudo vim /etc/dhcpcd.conf
 
</pre>
12 Setup fast ssh on your machine
:Paste these lines in the top
 
<pre>
    $ cd ~/.ssh
#Static IP text block
 
interface eth0
    $ nano config
static ip_address=192.168.1.75
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 8.8.4.4
</pre>


===13 Setup fast ssh on your machine===
<pre style="color: silver; background: black;">
$ cd ~/.ssh
$ nano config
</pre>
<pre>
     Host nginxhost
     Host nginxhost
        User <username>
        Hostname 192.168.1.75             
        Port 22
        Identityfile /path/to/.ssh/id_rsa
        Serveraliveinterval 30
</pre>


            User <username>
===14 Disable pwd and root login===
 
:Uncomment PasswordAuthentication and set it to no
            Hostname 192.168.1.119             
:Uncomment PermitRootLogin prohibit-password
 
<pre style="color: silver; background: black;">
            Port 22
$ sudo nano /etc/ssh/sshd_config
 
</pre>
            Identityfile /path/to/.ssh/id_rsa
:Reload SSH  
 
<pre style="color: silver; background: black;">
            Serveraliveinterval 30
$ sudo /etc/init.d/ssh restart
 
</pre>
 
:Reboot RPi
13 Disable pwd and root login
<pre style="color: silver; background: black;">
 
$ sudo reboot
    Uncomment PasswordAuthentication and set it to no
</pre>
 
    Uncomment PermitRootLogin prohibit-password
 
    $ sudo nano /etc/ssh/sshd_config
 
    Reload SSH  


    $ sudo /etc/init.d/ssh restart
===15 Remove pi user===
<pre style="color: silver; background: black;">
$ sudo pkill -u pi
$ sudo deluser pi
</pre>


    Reboot RPi
=NGINX CONFIG=


    $ sudo reboot
===01 Install NGINX===
<pre style="color: silver; background: black;">
$ sudo apt install nginx
</pre>


===02 Switch to root===
<pre style="color: silver; background: black;">
$ su
</pre>


14 Remove pi user
===03 Create a non-default mini static website===
<pre style="color: silver; background: black;">
# mkdir /var/www/<name>
# echo "OHAI" > /var/www/<name>/index.html
</pre>


    $ sudo pkill -u pi
===04 Disable nginx default site===
<pre style="color: silver; background: black;">
# rm /etc/nginx/sites-enabled/default
</pre>


     $ sudo deluser pi
===05 Create new nginx site config /etc/nginx/sites-available/<name>===
<pre style="color: silver; background: black;">
# cd /etc/nginx/sites-available
# nano <name>
</pre>
:Add this to the file
<pre>
server {
     listen 80;


    root /var/www/<name>;
    index index.html;


15 Install NGINX
    server_name <name>;
}
</pre>


    $ sudo apt install nginx
===06 Enable site===
<pre style="color: silver; background: black;">
# ln -s /etc/nginx/sites-available/partyvan /etc/nginx/sites-enabled/
# service nginx reload
</pre>

Latest revision as of 22:58, 29 March 2020

RASPI CONFIG

01 Format SDcard to FAT32

02 Flash SDcard with Linux ISO

Raspbian Buster Light, https://www.raspberrypi.org/downloads/raspbian/
you can use dd or a mounter like etcher https://www.balena.io/etcher/

03 Default login

Login: pi
Password: raspberry

04 SSH config

$ cd /boot
$ sudo touch ssh
$ sudo reboot

05 Change hostname

$ sudo raspi-config
Item no. 2 on the menu: Network Options

06 Add new user

$ sudo adduser <username>

07 Add new user to sudo

$ sudo adduser <username> sudo

08 Change su/root password

$ sudo passwd root

09 Setting locale

$ su
$ echo "LC_ALL=en_US.UTF-8" >> /etc/environment
$ echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
$ echo "LANG=en_US.UTF-8" > /etc/locale.conf
$ locale-gen en_US.UTF-8

10 Setting locale

https://www.raspberrypi-spy.co.uk/2019/02/setting-up-ssh-keys-on-the-raspberry-pi/
$ cd ~
$ mkdir .ssh
$ cd .ssh
$ touch authorized_keys
$ touch config
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
$ cd ~/.ssh
$ ssh-keygen
$ cat id_rsa.pub >> authorized_keys
$ sudo apt-get install putty-tools
$ puttygen id_rsa -o id_rsa.ppk

11 Get the public key onto RPI

Copy the contents of id_rsa.pub from you machine
$ cat <path to id_rsa.pub>
Paste and save them into authorized_keys file on RPi
$ cd ~/.ssh
$ sudo nano authorized_keys

12 Set static IP address

Check gateway
$ sudo route -n
Open etc config
$ sudo vim /etc/dhcpcd.conf 
Paste these lines in the top
#Static IP text block
interface eth0
static ip_address=192.168.1.75
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 8.8.4.4

13 Setup fast ssh on your machine

$ cd ~/.ssh
$ nano config
    Host nginxhost
        User <username>
        Hostname 192.168.1.75              
        Port 22
        Identityfile /path/to/.ssh/id_rsa
        Serveraliveinterval 30

14 Disable pwd and root login

Uncomment PasswordAuthentication and set it to no
Uncomment PermitRootLogin prohibit-password
$ sudo nano /etc/ssh/sshd_config
Reload SSH
$ sudo /etc/init.d/ssh restart
Reboot RPi
$ sudo reboot

15 Remove pi user

$ sudo pkill -u pi
$ sudo deluser pi

NGINX CONFIG

01 Install NGINX

$ sudo apt install nginx

02 Switch to root

$ su

03 Create a non-default mini static website

# mkdir /var/www/<name>
# echo "OHAI" > /var/www/<name>/index.html

04 Disable nginx default site

# rm /etc/nginx/sites-enabled/default

05 Create new nginx site config /etc/nginx/sites-available/<name>

# cd /etc/nginx/sites-available
# nano <name>
Add this to the file
server {
    listen 80;

    root /var/www/<name>;
    index index.html;

    server_name <name>;
}

06 Enable site

# ln -s /etc/nginx/sites-available/partyvan /etc/nginx/sites-enabled/
# service nginx reload