Category: Raspberry Pi

About Raspberry Pi

  • Setup Web Server

    Install Apache2

    Install Apache2 web server.

    $ sudo apt install apache2
    $ sudo systemctl start apache2
    $ sudo systemctl enable apache2

    Configure Firewall

    $ sudo ufw http

    Check the configuration

    Visit

    http://192.168.10.108

    from a Web browser. The IP address should be modified to yours.

    Enable User Directory

    $ sudo a2enmod userdir

    Make User Directory

    $ mkdir /home/user/public_html
    $ chmod o+rw /home/user/public_html
  • Change SSH Port Number

    Configure Firewall

    First, you should allow a secret port number to access the server.

    $ sudo ufw allow 80022
    $ sudo ufw reload

    Configure SSHd Setting

    $ sudo vi /etc/ssh/sshd_config

    Edit the “Port” option to your allowed port number.

    Port 80022

    Restart SSHd server

    $ sudo systemctl restart sshd

    Edit local config file

    Edit the configuration file on the local machine.

    $ vi ~/.ssh/config
    Host raspberrypi
        HostName 192.168.10.108
        IdentifyFiles ~/.ssh/id_rsa
        User <<user-name>>
        Port 80022

    Login with config file

    $ ssh raspberrypi

    Delete rule of 22 port

    $ sudo ufw status numbered
    $ sudo ufw delete <<Rule number for Port 22>>

  • Set up the Firewall

    Enable UFW

    You should enable firewall to block dangerous access from outside. To enable UFW,

    $ sudo systemctl enable ufw

    Check the status of the fiewall

    $ sudo ufw status numbered

    Allow SSH connection

    $ ssh ufw allow ssh

    Activate the firewall

    $ sudo ufw enable
  • Key Authentication

    Generate a key (on Local)

    $ ssh keygen -t rsa -b 4096

    Copy the key on server

    $ ssh-copy-id -i ~/.ssh/id_rsa.pub user@192.168.10.108

    Login with the key

    $ ssh user@192.168.10.108 -i ~/.ssh/id_rsa

    Set Key Authentication Only

    $ sudo vi /etc/ssh/sshd_config 

    Notice: The file to edit is sshd_config not ssh_config.

    In the file, edit below option from yes to no.

    PasswordAuthentication no

    After edit the file, you must restart sshd.

    $ sudo systemctl restart sshd

    On Windows client

    On windows client, install ssh-copy-id command first. By using chocolatey, type the command on PowerShell as Administrator.

    > choco install ssh-copy-id
  • Login with SSH

    Login Raspberry Pi with SSH

    $ ssh ubuntu@<your ip address>

    For example

    $ ssh ubuntu@192.168.10.108

    Rename ubuntu user

    For security rename ubuntu user to another one.

    Change user name

    $ sudo usermod -l user ubuntu
    $ sudo usermod -d /home/user -m user
    $ sudo groupmod -n user ubuntu
    $ sudo exit

  • Install Ubuntu on Raspberry Pi

    Install Ubuntu

    Insert the SD card to Raspberry Pi and turn on the switch.

    After while, the installation will finish automatically.

    Initial account

    Initial account of Ubuntu on Raspberry Pi is

    • user name: ubuntu
    • password: ubuntu

    Change the password

    For security issue, you should change the password as soon as possible.

    $ sudo password <secret-password>

    Update the system

    Update the system for security issue.

    $ sudo apt update
    $ sudo apt upgrade

    In shortly.

    $sudo apt update && sudo apt upgrade -y
  • Raspberry Pi Imager for Ubuntu

    Download the Imager from the site.

    Download the Imager from the raspberrypi.org site.

    https://raspberrypi.org/software/

    Install the Imager on Linux

    Install the Imager on Ubuntu.

    $ sudo dpkg -i imager_amd64.deb

    Run the Imager

    Insert a SD card to the PC and run the imager.

    $ sudo rpi-imager
  • Markdown

    Heading <h> (#)

    # Heading1
    ## Heading2
    ### Heading3
    #### Heading4
    ##### Heading5
    ###### Heading6

    Break <br> (2 spaces)

    line1␣␣
    line2␣␣

    Paragraph <p> (blank line)

    Paragraph1
    Paragraph2

    Horizontal Rules <hr> (—, ___, ***)

    ---

    Emphasis <em>,<strong> (*, _)

    * emphasis *
    ** strong **

    Orderd List <ol> (1. )

    1. list1
    1. list2
    1. list3

    Any numbers are acceptable. If all the numbers are set to 1, then numbers are automatically order properly.

    Unorderd List <ul> (+, -, *)

    + list1
    + list2
    + list3

    Preformatted Text <pre> (4 Spaces, Tab)

    ␣␣␣␣This is a
    ␣␣␣␣Preformatted
    ␣␣␣␣Document.

    Blockquote <blockquote> (>, >>)

    > Quote
    >> Sub Quote
    > Quote

    Code <code> (‘ )

    'printf("Hello\n");'