How To Connect Raspberry Pi To Laptop Via Wifi
If you’re on this page it is probably because you have a brand new Raspberry Pi. Either that or you have an old one that you just want to connect to wifi. Either way, you are probably asking yourself, “How to connect a Raspberry Pi to a laptop via wifi?” This is pretty easy and we’re going to show you how.
- Don’t want to connect a monitor and keyboard?
- Don’t have a monitor and keyboard?
- Already have a keyboard and monitor and just want to be able to also connect over wifi?
Options:
- You can configure wifi directly on your SD card before inserting it into the Raspberry Pi.
- You can configure wifi while the system is running if you already have a connection to it.
Before you start:
- We’re assuming you’re running Rasbian and that it is already installed on your SD card. If you are running something else the instructions will probably still be similar so long as you are still running Linux. Your mileage may vary.
Add Settings Directly To SD Card
You can directly mount your SD card from whatever system you are working on. Usually, you will be doing this shortly after writing the OS to the card. Make sure the card is mounted.
Setup Wifi
Edit your wpa_supplicant.conf file. Make sure you change the SSID and password. It should look something like the snippet below. Place this in the boot directory on your SD card: /boot/wpa_supplicant.conf.
It will be copied to the correct location on boot. For example it will be copied from /boot/wpa_supplicant.conf to /etc/wpa_supplicant/wpa_supplicant.conf.
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid="SSIDHERE"
psk="PASSWORDHERE"
scan_ssid=1
}
The SSID is your wifi network and the psk is your wifi password. Note that the group netdev is being given permission to change network settings.
Setup SSH
Create an empty file named SSH in your /boot directory. This file will be found during startup and will tell the system to enable SSH. The path of the file on the system will look like this: “/boot/SSH”.
Start It Up
- Insert the card back into the Raspberry Pi.
- Start it up. It should connect to your wireless network.
- Make sure that the device you are working on (laptop, desktop, etc. ) is also connected to the same wifi network.
Find the Raspberry Pi’s IP
You will need to find you what IP address the Raspberry Pi has been assigned. One way you can do this is by running:
arp -a
This should list out MAC addresses and IPs. One of these will be your Raspberry Pi.
Connect with SSH
Connect to the Raspberry Pi using SSH. The default user should be “pi” and the default password should be “raspberry”.
If you are using Linux on your desktop you can just use any of the terminals available. One of my favorites is Gnome Terminal. If you are running OSX you can just use the terminal application and ssh from there. If you happen to be using windows you will probably have to download putty or some other ssh utility.
Command to run from Linux or OSX ( assuming your IP is 192.168.0.5 ):
ssh pi@192.168.0.5
DONE! You’re connected! But there is more you should probably do. Keep reading.
Update Users
You will want to add a new user instead of the default user “pi”. Let’s assume you will call this user “user1” instead of “pi”.
Add a user
sudo adduser user1
Set a password for the new user.
passwd user1
Add sudo access
sudo usermod –aG sudo user1
Just in case, add the new user to the netdev group so that they can change wifi settings. They could still just sudo to run commands as root but if you happen to be using a graphical tool this might come in handy.
sudo adduser user group netdev
Remove the default pi user. Be careful with this. Make sure that you can SSH and use sudo with your new user before removing the default user.
sudo deluser pi
Setup VNC
Install RealVNC:
sudo apt–get update
sudo apt–get install realvnc–vnc–server realvnc–vnc–viewer
Enable it:
sudo rasps-config
Select the following:
- “Interfacing Options”
- “P3 VNC”
- “Yes”
Now VNC should be setup on the Raspberry Pi.
You will need a VNC client. Just download one from real VNC:
If you are running Linux you can just install using a package manager. Debian or Ubuntu should work with this command but other distros may use a different package manager and different package name.
sudo apt install realvnc–vnc–viewer
References
- How To Connect Raspberry Pi To Laptop Via Wifi
- How To Connect Raspberry Pi To Laptop Via Wifi
- Raspberry Pi Without Monitor
- Setting up a Raspberry Pi headless