High Voltage Code

Electronics and programming tutorials. Learn by building things!

Headless Raspberry Pi: Remote Linux Workstation

Posted on Sep 5th 2019 by Joseph

We all know that Raspberry Pi can be used as a regular computer, but if you're using your Pi for home automation, robotics or similar project it is more convenient to use it without any screen or a keyboard. This is called a headless setup.

So in this guide, we're going to install Raspbian OS without connecting any extra peripherals and tell Raspberry Pi to automatically connect to our Wifi network.

Then I'm going to show you how we can use SSH (Secure Shell) to remotely connect to Pi's terminal or use Windows built-in Remote Desktop Connection app to connect to the Pi's desktop.

Getting the right Raspbian!

Alright, head to Raspberry Pi's official page and download Raspbian image that suits your needs.

As for me, I personally like the Lite version as I don't use most of the pre-installed stuff nor I use Pi's desktop. In case you actually want the GUI(graphical user interface), download the Raspbian Buster with desktop.

Raspbian

At the time of writing this, Raspbian Buster is the latest version of Raspbian.

Burn your image to SD card. You can read the official quick guide here, but I personally use Win32DiskImager

Win32DiskManager

It is very simple to use, just select your SD card, select the image you want to burn, click Write and you're done.

Make sure you actually selected the correct SD card!

At this point, you have your Raspbian ready to boot, but since we're going for a headless setup, there are few things we need to do before we put the SD card into our Raspberry Pi.

Enable SSH and Wifi!

We have to enable SSH and preconfigure Wifi settings. To do that, let's navigate to our SD card's boot partition.

Inside SD

Create two new files called ssh without any extension and wpa_supplicant.conf

For ssh simply create new text file, rename it to ssh and delete .txt extension. Same for wpa_supplicant.conf, but mind the .conf extension.

files

The SSH file can be blank. Our Raspberry Pi will simply look for such file during the boot and will enable the SSH if it exists.

As for Wifi open wpa_supplicant.conf with your favourite text editor and paste this:

country=LT 
update_config=1
ctrl_interface=/var/run/wpa_supplicant
        
network={
    scan_ssid=1
    ssid="YOURROUTERSSID"
    psk="YOURPASS"
}

Change your country (ISO2 country code), Wifi name (ssid) and password(psk) values accordingly.

Time to boot!

Insert the SD card into your Raspberry Pi and let's start our little machine.

Raspberry Pi should successfully connect to your Wifi network upon boot and have SSH enabled.

To check my Raspberry Pi's IP address I simply navigate to my router's config page in a web browser(e.g http://192.168.1.1) and look for connected devices, but there are other ways to do that, like using this free tool called Wireless Network Watcher.

Ok, so to connect to Raspberry Pi, I use Putty. Again very simple SSH client. Download, install, launch it, type in Raspberry Pi's IP address and click "Open".

putty

Answer yes to security question.

A new terminal window will pop up asking for login and password. The default user is pi and the password is raspberry

Now you should see something like this:

Login

Change your password as instructed.

And there you go, we're in our Raspbery Pi's terminal!

Pi's Remote Desktop from Windows !

Now for those who prefer working from Pi's Desktop I suggest installing xrdp which is an open-source Remote Desktop Protocol server.

Install it with the command below:

sudo apt-get install xrdp

Now on your Windows machine launch Remote Desktop Connection app, enter the IP of your Raspberry Pi, then when prompted enter your user (pi by default) and password and you should see something like this.

Remote Desktop

Sharing Pi's Home directory !

Now while you can use tools like FileZilla to download/upload files to your Raspberry Pi, I wanted to show you how you can do that much easier from your Windows PC without any extra tools. As simple as drag and drop.

Alright, so to enable such thing in your Raspberry Pi's terminal first do:

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

With that done, let's get Samba with:

sudo apt-get install samba

When promted with this:

Samba WINS

Choose No and continue with installation.

Next we have to add something to Samba's config.

sudo nano /etc/samba/smb.conf

At the bottom of the smb.conf add these lines (just copy-paste)

[pi]
 comment=pi
 path=/home/pi
 browseable=Yes
 writeable=Yes
 only guest=No
 create mask=0740
 directory mask=0750
 public=no

Ctrl+O -> Enter -> Ctrl+X to save and exit the file if you're using nano text editor.

Now we have to create Samba user that will be used when connecting to Raspberry Pi from Windows machine.

sudo smbpasswd -a pi

Mind that this is not the actual pi we're using to connect to Raspberry Pi, so the password can be different as well.

Now we can navigate to our Raspberry Pi from anywhere in our Windows as it was another drive.

Tip: You can actually map it as a network drive.

windows

You can use the IP address (as shown in the picture above) or default hostname like so:

\\<your-pi-ip-address>

or:

\\raspberrypi

When prompted for username and password, type in pi and your newly created password and not the actual password of your Raspberry Pi (the one you created with sudo smbpasswd -a pi).

Only prompted when you're logging in for the first time.

And voila! Now you can manage your Raspberry Pi files directly from Windows!

Raspbbery Pi as a Windows Filesystem

And that is all I wanted to show you in this guide. I hope you found it useful and as always leave you comments and questions below.

Thanks for reading and I'll see you soon!

If you liked this post, consider sharing it with your friends!
Joseph (Juozas)

Software developer with sick passion for electronics!

NEWSLETTER
Subscribe to get all the latest updates on new projects and other news from High Voltage Code!