Update: Now you can remote control Pi graphically through the internet easily, added steps to do that.
1 — Download Raspbian
Your Pi needs an OS. Download Raspbian from Raspberrypi.org ‘s download section: https://www.raspberrypi.org/downloads/raspbian/
2 — Flash it onto an SD card
You need to flash this downloaded image to the micro SD card. Assuming your laptop has a SD card slot, you need a flashing software like etcher. Go ahead and download from: https://etcher.io/
3—Configure WiFi
Its easier to make two devices talk to each other if they are in the same network. An ethernet cable can easily make your laptop’s network available to the Pi. But we don’t have one. So we are going to add a file to the SD card so that the Pi boots with a wifi pre-configured.
The SD card mounts as two volumes boot
and rootfs
. Open the boot
volume and create a file named wpa_supplicant.conf
On booting the RPi, this file will be copied to /etc/wpa_supplicant
directory in /rootfs
partition. The copied file tells the Pi the WiFi setup information. This would overwrite any existing wifi configuration, so if you had already configured wifi on the pi, then that will be overwritten.
A typical wpa_supplicant.conf
file is as follows
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=«your_ISO-3166-1_two-letter_country_code»
network={
ssid="«your_SSID»"
psk="«your_PSK»"
key_mgmt=WPA-PSK
}
Your SSID is your wifi’s name. To find out SSID on ubuntu, you can use theiwgetid
command. The psk is the wifi password and your country code can be found here: https://www.wikiwand.com/en/ISO_3166-1_alpha-2#/Officially_assigned_code_elements
so replace all the «item»
fields in the above text
4 — Enable SSH
We will later access the Pi using a secured shell (SSH), SSH is disabled by default in raspbian. To enable SSH, create a file named ssh
in the boot
partition. If you are on linux, use the touch
command to do that.
5 — Find Pi’s ipaddress
Before switching on your raspberry pi, we need to findout the existing devices connected to the network. Make sure your laptop is connected to the same wifi network as the one you configured on pi above.
Run the command hostname -I
to find out your laptops’ ipaddress. Say it is 192.168.1.8
then when connected your pi’s ip would be 192.168.1.x
Run the command nmap -sn 192.168.1.0/24
to findout existing devices in the network in range 0 to 24 for the last portion of ipaddress. I get
Starting Nmap 7.01 ( https://nmap.org ) at 2018-07-03 18:39 IST
Nmap scan report for 192.168.1.1
Host is up (0.0020s latency).
Nmap scan report for 192.168.1.8
Host is up (0.000097s latency).
Nmap done: 256 IP addresses (5 hosts up) scanned in 2.58 seconds
Remove the micro SD card from your laptop and insert it into Pi. Power it up using a power source (5v regular android charger) and try nmap -sn 192.168.1.0/24
again, to see which ipaddress newly appears
Starting Nmap 7.01 ( https://nmap.org ) at 2018-07-03 18:39 IST
Nmap scan report for 192.168.1.1
Host is up (0.0020s latency).
Nmap scan report for 192.168.1.2
Host is up (0.040s latency).
Nmap scan report for 192.168.1.8
Host is up (0.000097s latency).
Nmap done: 256 IP addresses (5 hosts up) scanned in 2.58 seconds
so 192.168.1.2
should be the ip address of the pi.
6— SSH into the Pi
To create a secured shell connection, in linux we can use the ssh
command. If you are on windows, try downloading PuttY from https://www.putty.org/
To connect to Pi you need the default username and password of the device. On first boot, the username and password would be as follows.
username : pi
password: raspberry
now you can do
ssh [email protected]
Type in y
when asked if you sure to continue connecting with the device. Then when asked for password, type in the pass.
You should now be inside Pi’s SSH. Smile :) we should savour such small victories
7— Change default password
Its a good practice to change the password to something else. You can use the passwd
command to do that.
pi@raspberrypi:~ $ passwd
Changing password for pi.
(current) UNIX password: raspberry
Enter new UNIX password: iwonttellyou
Retype new UNIX password: iwonttellyou
passwd: password updated successfully
8 — See the screen
Sometimes it doesn’t feel right if we can’t use the mouse. For that we need to look into the Raspbian desktop.
We need to setup VNC (Virtual Network Connection) to see and control Pi graphically. Let’s do that.
sudo apt-get update
sudo apt-get install -y realvnc-vnc-server realvnc-vnc-viewer
These commands would update Pi’s softwares and install realvnc which will be used to setup remote sessions.
9— Access Pi remotely
On the raspberry pi’s ssh prompt, type in vncserver
to start the service. This will print an ipaddress where you can access the desktop remotely, note that down. Mine says
New desktop is raspberrypi:1 (192.168.1.2:1)
To access the remote desktop, you need a vncviewer (client) for your laptop. Fortunately RealVNC is available for a lot of OSes, pick one for your OS from https://www.realvnc.com/en/connect/download/viewer/
If you are on debian/ubuntu, you might have to do some additional step after downloading the executable.
cd ~/Downloads
chmod +x VNC-Viewer-6.17.1113-Linux-x64
mv VNC-Viewer-6.17.1113-Linux-x64 ~
cd ~
./VNC-Viewer-6.17.1113-Linux-x64
RealVNC viewerHere we are changing the file mode of the downloaded executable to make it installable. We are also moving the executable from the downloads folder to the home folder.
Once RealVNC viewer is installed, add the raspberry pi device to the connections (File > New connection). Enter the pi’s desktop identifier (192.168.1.2:1
), give it a friendly name, click Ok. Enter pi’s username and password when prompted. That’s it, you should now see the desktop. Give me a five!