Connecting remotely

Not every project you will do will require you to use a display directly attached to the Banana Pi. You can connect to the device remotely from one of your other computers on the network and run the Pi headless (with no display). This is accomplished using SSH. By default, SSH is installed on Raspbian and Bananian out-of-the-box. For this, you will need to make sure that the Banana Pi is connected to the same network as your computer.

SSH from Windows

Windows does not come with an SSH client out-of-the-box. You need to download one. The most common application for this is called PuTTY. PuTTY is a free application you can download from its website (http://www.chiark.greenend.org.uk/~sgtatham/putty/). The application does quite a bit when you get right down to it but we just need the bare-bones configuration.

SSH from Windows
  1. To connect to a remote computer you will need its IP address. You can get this if you currently have a display connected to the Banana Pi by opening the terminal emulator and running the command:
    ifconfig
  2. This will produce a bunch of output that will include the information for each of your network interfaces. If you are wired; you will look for eth0, and if you are wireless; you will look for wlan0. The IP address you need will be preceded by inet. The output of the command looks like this:
    eth0      Link encap:Ethernet  HWaddr 02:07:05:01:d2:44
              inet addr:192.168.1.6  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::7:5ff:fe01:d244/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:86523 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1649 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:9430022 (8.9 MiB)  TX bytes:115701 (112.9 KiB)
              Interrupt:117 Base address:0xc000
    
    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    
  3. From this output you can see that the IP address we need is 192.168.1.6. We can enter this IP into the Host Name input field on PuTTY. When you connect, you will be prompted for the username and password and will be put into a command line session running on the Banana Pi.
  4. If you need the IP address and do not have direct access to the Banana Pi you can generally get this information from your router, or there are various applications you can download to get this information from.

SSH from Linux or the Mac

For your benefit, if you are using a Mac computer or Linux you have a terminal emulator built in. Although you can download PuTTY on Linux, you don't need to, because all you need to do is run the SSH command. On either Mac or Linux open up your bash terminal and run this command:

Share this:

ssh user@ipaddress

The user is whichever user you plan to run as, and the IP address is specific to your device within your network. For example, if my IP address is 192.168.1.6 and I want to connect as root, I will run the command like so:

Now I will be logged in as root. You will be prompted to remember the connection and be asked for the password. You can create an SSH key to automatically log you in, but for what we are doing this won't be necessary for now.

SSH remotely

It is possible to connect to your device over SSH from outside your network but this is something that is specific to your network. One thing that is common and that you will need to do, is forward the port you want to use for SSH (commonly 22) and route that connection to the Pi. This of course will open up a hole in your firewall and allow traffic over that port for that device. This means you will need to secure your connection in more ways such as by changing the default port, adding a new user, and restricting root access. This is useful for projects where you need to remotely connect such as file servers or remote web servers.

Depending on the applications you plan to run remotely you will need to open different ports. If you are accessing the Pi over SSH you will need port 22; if you are running a web server you will need 80, 8080, or whatever port you have decided on. By default, if you are using it as a remote database server for MySQL, you will need 3365. These ports are all configurable but you will need to take this into consideration depending on what you plan on running.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.62.25