Introduction: Raspberry Pi Online SSH (easy Way)

Raspberry pi is a mini computer that can be carried easily. Usually people use Raspberry Pi as an embedded platform. And mostly people control or developing something with their Raspberry Pi using SSH protocol. because it much more simple and doesn't take many space. Some people also already use their raspberry pi as an IOT platform. The IOT platform could be located far away from ourselves and if there's an error we need to debug the raspberry pi from a long distance. In this tutorial I will show you you can ssh your Raspberry Pi from anywhere in the world.

Step 1: Setting It Up

I hope you guys already know how to setup a raspberry pi and connect it to the internet.

If you don't know there tons of tutorial here in instructables or in google.

here is one of them:

https://www.raspberrypi.org/help/noobs-setup/

For this tutorial I use Raspbian OS because it is the most common OS used for the raspberry pi

If you manage to reach the raspberry pi terminal then we are ready to go to the next step

Step 2: Putty or Any SSH Client

Windows user cannot use SSH directly to a linux machine. You need an SSH client to do that.

You can download a simple ssh client called putty here:

http://www.chiark.greenend.org.uk/~sgtatham/putty/...

Once you done download putty. get back to the raspberry pi terminal and type:

$ifconfig

That command will show you Raspberry Pi's IP address.

Open putty choose SSH and then enter the Raspberry Pi's local IP address then click open.

Now you don't need a monitor for the raspberry pi anymore. you can control it using your PC or laptop.

Step 3: Ngrok

Ngrok is secure tunnelling platform to make your device online. With this plaftorm you can make your web aplication or any aplication goes online with a very simple way.

https://ngrok.com/

To use Ngrok you need to download ngrok application to your raspberry pi. and to do that use the following command:

pi@raspberry~$sudo wget https://dl.ngrok.com/ngrok_2.0.19_linux_arm.zip

and then unzip it using:

pi@raspberry~$unzip ngrok_2.0.19_linux_arm.zip

That it, that's the whole installation process. now you can use ngrok. To try using ngrok. if you have a web server/application that already active in certain port (for example:80) then use the following

pi@raspberry~$./ngrok 80

Now your web app can be access online from any where

Step 4: Online SSH

at ngrok website go to:

https://dashboard.ngrok.com/user/login

and then click sign up to get an authtoken key. this token is necessary if you want your own custom domain doing an online SSH

after you manage to login you will get an authtoken key which a combination of a lot character.

You need to embed this token to your raspberry pi using:

pi@raspberrypi~$./ngrok yourauthtoken

change the yourauthtoken with your own key that you get from ngrok website. You only need to this once for your raspberry pi.

now you can make your raspberry pi system to be controlled online using

pi@raspberrypi~$./ngrok tcp 22

If your tunnel status is online the congratulations now you can open your raspberry pi terminal anywhere.

To open SSH online first open a new putty from any computer that connected to the internet. then enter your ngrok address and port like in the picture

Step 5: Summary

With tutorial I hope you can solve a few problem regarding controlling the raspberry pi online.

I use this setup daily to debug my cctv camera in my house from my office while trying another home automation setup.

Best Regards

Hendra

Comments

author
gtoal made it!(author)2017-04-30

It looks like the ngrok service is running a reverse tunnel for you, but since it is a service that isn't under your control, you're basically trusting them that they won't sniff or MITM your traffic. A better solution is to do the same thing explicitly yourself, by having a machine of your own outside your firewall and reverse-tunnel to it yourself from the machine you need to access which is inside a firewall somewhere. Setting up the reverse tunnel is a 1-liner, something like this, issued on the firewalled machine during startup:

export AUTOSSH_GATETIME=0

autossh -f -N -p allowed_port -R 10001:localhost:22 myusername@mypublichost -oLogLevel=error -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no

('allowed_port' is any port that your host can use to listen for ssh connections on; and you can use any number you prefer instead of 10001)

then when you want to connect to the firewalled machine, from your relay host just do: ssh -p 10001 myusername@localhost

author
SouravM17 made it!(author)2016-08-12

i recommend just port forwarding your raspberry pi on port 22 and using an online ssh tool, like this one here:

https://tools.bartlweb.net/webssh/

author
gtoal made it!(author)2017-04-30

Doesn't this just do a terminal session to a machine at bartlweb.net which then ssh's out to your target? So in principle, that machine could log all your plaintext traffic, passwords etc. You're placing a lot of faith in a complete stranger.

author
IgorG2 made it!(author)2016-07-17

This is wrong:

`./ngrok yourauthtoken`

Linux does not recognize this as a valid command!

author
malini25 made it!(author)2016-03-18

Hi

I followed all the steps shown. And i also entered in the putty. But i use vnc viewer to access my Pi terminal which asks for an ip address. What to do about that? Which ip address should i give?

author
EvgenijB made it!(author)2016-03-04

Hello.I have Raspbery with localhost site. I want to have access from anywhere to it. When I am using Putty for start ngrok - it is works fine - but it shows a window (Ctrl + C to quit). But I have a question: may I start ngrok in tray? Because when it shows ngrok status message - I lose access to command menu, to MySQL etc

author
chalei made it!(author)2016-03-04

yes you can open multiple putty session. leave the ngrok as it is and then you can open new putty session with the same ip

author
dgm3 made it!(author)2015-06-05

so great mr.chalei!! where do you come from?

author
chalei made it!(author)2015-06-14

Thank You

I am from an area called the teluk dragon

author
CarlN1 made it!(author)2015-06-12

How can I add

ngrok tcp 22

to /etc/rc.local?

I would like to have it started with system boot.

author
chalei made it!(author)2015-06-13

if you want to have an online and started it at system boot. you can try using weaved instead of ngrok. Because ngrok has a few limitation if you are using the free service.

this is the tutorial on how to download and use weaved:

https://developer.weaved.com/portal/members/betapi.php

author
CarlN1 made it!(author)2015-06-13

Thank you very much for your proposal.

But isn't it possible with "screen"? I just don't know how.

author
chalei made it!(author)2015-06-14

If you mean by "screen" is the Desktop screen/GUI of the raspbian. yes it can, in weaved you will find a section about VNC. VNC is use for remotely access your raspberry pi Desktop screen/GUI

author
seamster made it!(author)2015-06-02

Nicely done. Thanks for sharing this!

author
chalei made it!(author)2015-06-03

Thank you, I Hope it helps :)