SSH into a raspberry pi and connect pi to wifi

This quick post is on two important things in pi.

Enable wifi and connect to internet

Open the file for network interfaces, and look for a section called wlan0, or add this section-

vi /etc/network/interfaces

auto wlan0

allowhotplug wlan0

iface wlan0 inet dhcp

    wpascanssid 1

    wpaapscan 1

    wpakeymgmt WPAPSK

    wpaproto RSN WPA

    wpapairwise CCMP TKIP

    wpagroup CCMP TKIP

    wpassid “My Secret SSID”

    wpapsk “My SSID PSK”

The most important entries are wpassid and wpa–psk. Update your network name and password here. The values are case sensitive.

Thats all. You can restart your pi and you should be able to connect to the wifi network.

$> sudo restart

$> ping

SSH into the raspberry pi from another box

Get your hostname/ip address from pi –

Use these commands on your raspberry pi console :

$> hostname
$> ifconfig

Use this ip address to ssh into the raspberry pi from a different computer. Us the username pi to connect to pi. The default password is raspberry.

$> ssh pi@

That should be all to ssh into your raspberry pi.


Sometimes you might see this error while ssh’ing into the pi.

ssh: connect to host port 22: Connection refused

This should be due to –

  • wrong userid/password
  • wrong ip address
  • ssh is not enabled on the pi

While the first 2 are straight forward, you might have to make quick changes on your pi for the 3rd cause.

$> sudo raspi-config

This should open a blue config screen and you could go to the advanced settings section, to find SSH connections enable/disable. Enable ssh on pi and exit. That should be all.


1 thought on “SSH into a raspberry pi and connect pi to wifi”

  1. Pingback: How to create a raspberry pi powered car, remote controlled via mobile phone – ConfusedCoders

Leave a Reply

Your email address will not be published. Required fields are marked *