in Internet of Things IoT by
How do you run Raspberry pi in headless mode?

2 Answers

0 votes
by

You can use SSH into Raspberry Pi and run in headless mode. Latest Raspbian OS has inbuilt VNC server installed with that you can take remote desktop on Raspberry Pi.

0 votes
by

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  and  . Open the  volume and create a file named  On booting the RPi, this file will be copied to  directory in  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  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 the 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  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  in the  partition. If you are on linux, use the  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  to find out your laptops’ ipaddress. Say it is  then when connected your pi’s ip would be 

Run the command  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  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  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  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 : 
password: 

now you can do

ssh [email protected]

Type in  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  command to do that.

[email protected]:~ $ 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  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 viewer

Here 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 ( ), 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!

Raspberry Pi’s Remote desktop

10 — Remote control from the internet

No more port forwarding and fiddling with router settings, Team Viewer has released a version for Arm based devices and we are gonna use that. Yaay!

Start by SSHing into your headless device and from the terminal do

wget https://download.teamviewer.com/download/linux/teamviewer-host_armhf.deb

Once downloaded you can install it using:

sudo apt install teamviewer-host_armhf.deb

You can  the teamviewer deb file after installation.

Now now, how do I setup a remote session with this?

After installing we should have a  cli tool installed on the pi. Lets check if the teamviewer daemon is running.

teamviewer daemon status

Should return a lot of text in which you will find “active (running)” in it.

In you don’t find that, try

sudo teamviewer daemon start

Once that’s done, let’s do the setup. You need a teamview account. If you don’t have one, go to https://login.teamviewer.com/LogOn#register and create one. After that type in

sudo teamviewer setup

accept any license terms and input the emailid and password you gave in the signup process. Since this is the first time you are trying to remote control this device from this account, you should get an email to Add device to trusted list

Click on the link in the email to do that. If required, try the setup command again and in the end you should get this nice text

*** You have successfully added this computer to your Computers & Contacts. You can now access it with a simple double click in your Computers & Contacts list. ***

Open (or install) team viewer in your laptop. Sign In. You should see the Raspberry Pi device listed under “your computers”. Simply double click and start controlling it over the internet.

Related questions

0 votes
asked Dec 17, 2019 in Internet of Things IoT by Robindeniel
0 votes
asked Dec 17, 2019 in Internet of Things IoT by Robindeniel
0 votes
asked Dec 14, 2021 in Internet Of Things Prime by sharadyadav1986
...