Connecting your Raspberry Pi to the Internet and Accessing It Remotely

Learn how to connect your Raspberry Pi to the internet, enable SSH access and connect to it remotely from any device. This guide will walk you through setting up a VPN server on your Raspberry Pi and …


Updated October 11, 2023

Need help with your Raspberry Pi?
Contact Me!

Do you love silly Raspberry Pi Projects?
Check out my this YouTube Channel!


Learn how to connect your Raspberry Pi to the internet, enable SSH access and connect to it remotely from any device. This guide will walk you through setting up a VPN server on your Raspberry Pi and accessing it using an SSH client.

Step 1: Connecting Your Raspberry Pi to the Internet

Before you can access your Raspberry Pi remotely, you need to make sure it is connected to the internet. You can do this by connecting it to a Wi-Fi network or using an Ethernet cable to connect it directly to your router.

  1. First, open up the terminal on your Raspberry Pi and update the system:
sudo apt-get update && sudo apt-get upgrade
  1. If you want to use Wi-Fi, type the following command and follow the prompts to connect to your network:
sudo raspi-config
  1. If you are using Ethernet, make sure that it is connected securely and then run ifconfig in the terminal to check if you have an IP address assigned by your router.

Step 2: Enable SSH Access

SSH (Secure Shell) allows you to connect to your Raspberry Pi remotely using a secure connection. To enable SSH, follow these steps:

  1. Open the raspi-config tool again by typing:
sudo raspi-config
  1. Navigate to Interfacing Options and then select SSH. Choose Enable and then Finish to save your changes.

  2. To confirm that SSH is running, type:

systemctl status ssh

If it says active (running), you’re good to go! If not, try restarting the service with:

sudo systemctl start ssh

Step 3: Setting up a VPN Server

To access your Raspberry Pi securely from any location, we will set up a VPN server. This will encrypt all traffic and make sure that no one can snoop on your data.

  1. First, update the system again:
sudo apt-get update && sudo apt-get upgrade
  1. Install OpenVPN by typing:
sudo apt-get install openvpn easy-rsa
  1. Generate keys and certificates for your VPN server:
cd /etc/openvpn/easy-rsa/
source vars
./clean-all
./build-ca
./build-key-server server
./build-dh
openvpn --genkey --secret keys/ta.key
  1. Create a new configuration file for your VPN server:
sudo nano /etc/openvpn/server.conf
  1. Add the following lines to the config file and save it (replace your_ip with your public IP address):
port 11943
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh2048.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 208.67.2222.222"
push "dhcp-option DNS 208.67.220.220"
keepalive 10 120
tls-auth ta.key 0
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
  1. Edit the server section in /etc/default/openvpn:
sudo nano /etc/default/openvpn
  1. Uncomment and change the line to:
AUTOSTART="all"
  1. Start the VPN server:
sudo systemctl start openvpn@server
  1. Enable it at boot:
sudo systemctl enable openvpn@server
  1. Configure your router to forward port 11943 (or any other port you chose) to the Raspberry Pi’s IP address.

Step 4: Connecting from a Remote Device

To connect to your Raspberry Pi remotely, you will need an SSH client. Here are some options for different operating systems:

  1. Open the SSH client and connect to your Raspberry Pi using its public IP address (the one you forwarded in step 3). If you are using a VPN, use the IP address of your VPN server.
ssh pi@your_ip -p 11943
  1. Enter your Raspberry Pi’s username and password when prompted (default is pi with password raspberry).

Now you have successfully accessed your Raspberry Pi remotely! You can run commands, transfer files, or even use a remote desktop application to work on it just like if you were sitting in front of it.

Remember: Always keep your Raspberry Pi and its services updated, and ensure that only trusted devices have access to your VPN. Happy tinkering!