Skip to content

Instantly share code, notes, and snippets.

@innat
Last active November 24, 2018 15:52
Show Gist options
  • Save innat/1ca109ba4a8ec5ccc83a229de45f9115 to your computer and use it in GitHub Desktop.
Save innat/1ca109ba4a8ec5ccc83a229de45f9115 to your computer and use it in GitHub Desktop.

Task

Set-up Raspberry Pi headlessly in Laptop, no HDMI no Monitor.

Necessary Software

Basic Steps

  • Using Etcher, Write Image File On SD Card (Must Be FAT32)
  • Connect Raspbery and Laptop/PC via Ethernet and Get Gatway IP address
  • Get IP Address Used By Rapberry - Typically Find It Using Advance IP Scanner
  • Log In To Pi Using MobaXterm & (Optional) Set WiFi Configuration & Get A New IP Address (If We Don't Want To Use Ethernet Cable Further)

Details

Boot: First download RASPBIAN STRETCH ISO file, but don't use Noobs for the sake of full headless implementation. However, Rasbian Stretch is almost 5GB image file.

After booting, then we need to create an empty file and name it ssh (with no extension - preferred) and put into the SD card. However, to do this, we may need to eject and re-enter our SD card into PC/Laptop.

Laptop/PC Config: Go to Control Panel - > Network and Internet -> Network and Sharing Center

Enable Interet Connection Sharing. We'll see following section appear.

screenshot 39

Now, Power On Rapberry Pi. Connect it to Laptop/PC via Ethenet Cable. We'll see a new public unidentified network available. Click the Ethernet option. Double click on Internet Protocol V4 and We'll get the new Gatway IP address. For example: It's 192.168.137.1.

screenshot 40

OK, just remember it.

Advance IP Scanner: Here we'll use a tools that will find all the possible IP address from this Gatway address. We'll use Advance IP scanner to find it. After opening this tools type following IP address range: 192.168.137.1-192.168.137.254. And after scanning hopely we'll find the host IP address of our Pi. Let's say, it appears something like 192.168.137.49. Save it.

screenshot 41

MobaXterm: Download MobaXterm and Using host IP address (here it is 192.168.137.49), log in to pi.

screenshot 42

Needy Task: After log in, type following commands: sudo raspi-config and navigate same as following. Run: sudo raspi-config > Advanced Option > Expand Filesystem - Press OK and Finish. Reboot Necessary. After rebooting, run following command. This may take some time, couple of hours (perhaps). It's necessary.

sudo apt-get update && sudo apt-get upgrade

GUI Desktop: Without using VNC or Windows Remote Desktop, we can able to open GUI of our Ras Pi. To do this, Go the Advanced SSH settings tab of the Session Settings in MobaXterm. And choose Remote Environment LXDE Desktop from the dropdown menu. By default, it's Interactive Shell. However, X11-Forwarding in MobaXterm is enable by default. So we can bring GUI application from our Pi OS to Remote Desktop. We'll also perform it up next.

screenshot 46

After finishing, Open a new session. We'll see something following:

screenshot 47

Normally we can do almost everything. It's something like an another desktop. By this, we invoke Ras OS in GUI mode without VNC or XRDP. However, MobaXterm has VNC option too.

screenshot 48

X11 Forwarding Not a serious feature, just fancy. We can invoke some Pi application to our Remote desktop from PuTTY/Interactive Shell terminal. Type following command:

  • xclock & # For opening xclock
  • libreoffice & # For opening libreoffice
  • thonny & # For opening thonny Python IDE

WiFi Configuration We can do this from Interactive Terminal but let's open it now via LXDE Desktop. Then go to Preference -> Raspberry Pi Configuration. Set country zone to BD. And Go to WiFi settings and enter the SSID and WiFi Password. Same thing we can do simply by using Interactive Shell or PuTTy. Type:

sudo raspi-config > Network Option > Wi-Fi > SSID > Password

Now, typically we create two IP addresses - via Ethernet and WiFi. Type following command to see them:

ifconfig

screenshot 49

From Ethernet: 192.168.137.49
From Wi-Fi: 192.168.0.102

Now, Poweroff the Pi, command: sudo poweroff. Change IP address in MobaXterm session settings. Like following:

screenshot 51

A security alert may pop up, just say yes/OK.

screenshot 50

Copy-Paste: Previously It's a backpain to send and receive files between Pi and Remote Desktop. But now it's super easy. Just play around with following option.

capture

Set Static IP Address: By default, Pi set dynamic IP address. So, everytime we boot our pi, it may change its IP address. To resolve this, we can set static IP address for our pi. Check out this blog post to achieve this.


Some Basic Commands: Few commands required Super User Do or sudo to perform.

📖

  • ls -l: Lists files in the current directory, along with file size, date modified, and permissions.
  • cd /abc/xyz: Changes the current directory to the /abc/xyz directory.
  • mkdir example_directory: Creates a new directory named example_directory inside the current directory.

📖

  • ifconfig: To check the status of the wireless connection we are using (to see if wlan0 has acquired an IP address).
  • ping: Tests connectivity between two devices connected on a network.

📖

  • df -h: Shows information about the available disk space.
  • df /: Shows how much free disk space is available.
  • free: Shows how much free memory is available.
  • hostname -I: Shows the IP address of your Raspberry Pi.
  • dpkg ––get–selections: Shows all of the installed packages.
  • lsusb: Lists USB hardware connected to your Raspberry Pi.

📖

  • apt-get update: Synchronizes the list of packages on your system to the list in the repositories.
  • apt-get upgrade: Upgrades all of the software packages you have installed.
  • clear: Clears previously run commands and text from the terminal screen.
  • poweroff: To shutdown immediately
  • reboot: To reboot immediately.
  • raspi-config: Opens the configuration settings menu.

See More.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment