Link Search Menu Expand Document

Pi Lab

Table of contents

Setup Pi imager

  1. Download the Raspberry Pi Imager to the local PC where you plug your SD card
    • Using command to install: sudo apt install rpi-imager
  2. Mac user, spotlight search and run Raspberry Pi Imager

  3. Select OS » SD card » Write

  4. Insert SD card to Pi
    • Note: power supply level is key to boot up the pi, you might see pi is on but nothing comes up on the monitor

First time loading

  1. Wait until Cloud-Init fully loaded, then login
     Default login and password: ubuntu 
         * first time login will prompt for password update 
    
  2. Run sudo touch /etc/cloud/cloud-init.disabled to disable cloud-init

Config network and using Wifi for ssh

  • Note: all config files are space sensitive
  1. Run below command to config

     echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
    
  2. Open 01-netcfg.yaml

     sudo vim /etc/netplan/01-netcfg.yaml
    
  3. Add below content to 01-netcfg.yaml, ensure the indent space.

     network:
     version: 2
     renderer: networkd
     wifis:
         wlan0:
         dhcp4: true
         dhcp6: true
         optional: true
         access-points: 
             "my-wiki-name":
             password: "**********"
    
  4. Run the below commands to enable the wifi network

     sudo netplan generate
     sudo netplan apply
     reboot
    

Hostname change & local hosts

  1. Change hostname run: sudo vim /etc/hostname
  2. Location for host file: /etc/hosts

Change to root user

sudo -i

Install net-tools

apt install net-tools 
    # error: Could not get lock /var/lib/dpkg/lock-frontend 
    # solution run below command: 
sudo killall apt apt-get

Get hostname and IP from the Pi

ifconfig 
    # Output of network 
hostname -I 
    # Output: hostname: 192.168.0.1

Change users

  1. Run sudo -i to change to root, use passwd to change password
  2. Add new user: adduser new-user-name
  3. See user privilege: visudo
  4. User privilege specification

     root    ALL=(ALL:ALL) ALL   
    
  5. Add below to visudo to give new user with root privilege

     new-user-name   ALL=(ALL:ALL) ALL
    

SSH into raspberry PI