Difference between revisions of "EBC Exercise 02 Out-of-the-Box, Bone"

From eLinux.org
Jump to: navigation, search
m (Added ping command for on-campus users)
m (Set Up Git: Added apt update)
 
(22 intermediate revisions by 5 users not shown)
Line 2: Line 2:
 
{{YoderHead}}
 
{{YoderHead}}
  
{{EBC3.8}}'''These instructions are for the 3.8 kernel.'''  [[EBC Exercise 02 Out-of-the-Box, Bone 3.2 Kernel]] has instructions for the 3.2 kernel.
+
{{EBC3.8}}'''These instructions are for the 3.8 and newer kernels.'''  [[EBC Exercise 02 Out-of-the-Box, Bone 3.2 Kernel]] has instructions for the 3.2 kernel.
  
== Getting Started ==
+
== Local Internet Connection, Cloud 9 ==
We'll be running the 3.8 kernel, check out these [http://beagleboard.org/Getting%20Started instructions] for getting started. Then come back here to get your network set up.
+
One of the slickest features of the Bone is its ability to access the Internet through the USB (tether) connection. Plug a USB cable into your bone and plug the other end into your host computer and wait for the Bone to boot up. Once the lights settle down to a heartbeat pattern point a browser on your host computer to '''192.168.7.2'''.  Here you will see the Cloud 9 IDE (integrated development environment).
 +
This is being served up by the Bone over a local internet connection.  Go and explore it.
  
== Internet Connection ==
+
== Internet Connection to the Outside World ==
 
+
Once the Bone can connect to the host, the host can be used for forward requests from the Bone to the Internet. Follow the instructions below to set up your host and Bone so the bone can access the internet through your host.
One of the slickest features of the Bone is its ability to access the Internet through the USB (tether) connection. You should have already used it following the instructions above. Below shows how to set up your host and Bone so the bone can access the internet through your host.
 
  
 
=== Linux ===
 
=== Linux ===
==== ifconfig ====
+
==== See your networks with ip a ====
 
Run:
 
Run:
  
  host$ '''ifconfig'''
+
  host$ '''ip a'''
  eth0    Link encap:Ethernet  HWaddr 00:18:8b:72:b8:c2 
+
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
          inet addr:137.112.41.109 Bcast:137.112.41.255  Mask:255.255.255.0
+
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
          inet6 addr: fe80::218:8bff:fe72:b8c2/64 Scope:Link
+
    inet 127.0.0.1/8 scope host lo
          UP BROADCAST RUNNING MULTICAST MTU:1500  Metric:1
+
        valid_lft forever preferred_lft forever
          RX packets:8481193 errors:0 dropped:0 overruns:0 frame:0
+
    inet6 ::1/128 scope host
          TX packets:1871287 errors:0 dropped:0 overruns:0 carrier:0
+
        valid_lft forever preferred_lft forever
          collisions:0 txqueuelen:1000  
+
  2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
          RX bytes:3172154531 (3.1 GBTX bytes:203188180 (203.1 MB)
+
    link/ether 00:0c:29:8c:63:ea brd ff:ff:ff:ff:ff:ff
          Interrupt:19
+
    inet 172.16.105.242/24 brd 172.16.105.255 scope global dynamic noprefixroute ens33
 +
        valid_lft 6327sec preferred_lft 6327sec
 +
    inet6 2605:a000:1c02:ec:5936:3599:8ce1:c3cb/64 scope global temporary dynamic
 +
        valid_lft 86396sec preferred_lft 14396sec
 +
    inet6 2605:a000:1c02:ec:a067:7cb0:fd3e:7d13/64 scope global dynamic mngtmpaddr noprefixroute
 +
        valid_lft 86396sec preferred_lft 14396sec
 +
    inet6 fe80::9d5f:d5d0:6460:d5cd/64 scope link noprefixroute
 +
        valid_lft forever preferred_lft forever
 +
3: enx40bd32e49bc1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
 +
    link/ether 40:bd:32:e4:9b:c1 brd ff:ff:ff:ff:ff:ff
 +
    inet 192.168.6.1/30 brd 192.168.6.3 scope global dynamic noprefixroute enx40bd32e49bc1
 +
        valid_lft 103sec preferred_lft 103sec
 +
    inet6 fe80::6f61:86ba:523e:c1d5/64 scope link noprefixroute
 +
        valid_lft forever preferred_lft forever
 +
4: enx40bd32e49bbe: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
 +
    link/ether 40:bd:32:e4:9b:be brd ff:ff:ff:ff:ff:ff
 +
    inet 192.168.7.1/30 brd 192.168.7.3 scope global dynamic noprefixroute enx40bd32e49bbe
 +
        valid_lft 103sec preferred_lft 103sec
 +
    inet6 fe80::9603:1b84:ebd5:7c9c/64 scope link noprefixroute
 +
        valid_lft forever preferred_lft forever
 +
 
 +
 
 +
==== ssh and changing the password ====
 +
You'll see two new networks have appeared, '''enx40bd32e49bc1'''  and '''enx40bd32e49bbe''' in my case. The IP address of your host is '''192.168.7.1'''.  There's a good chance the Bone is at '''192.168.7.''2'''''.  Try connecting to it.  The default password is '''temppwd'''.
 +
host$ '''ssh debian@192.168.7.2'''
 +
bone$
 +
You are now logged into the Bone through the network.  This is much faster than the serial port (.115M vs. 100M) and supports many interesting network operations.  
 +
 
 +
Take a look around. What do you find?
 +
 
 +
Since everyone knows the default password, change it to something else.
 +
 
 +
bone$ '''passwd'''
 +
Changing password for debian.
 +
(current) UNIX password:
 +
Enter new UNIX password:
 +
Retype new UNIX password:
 +
passwd: password updated successfully
 +
 
 +
The only problem is, the Beagle doesn't know how to access the Internet through the host. Get back to the host computer:
 +
 
 +
bone$ '''exit'''
 +
 
 +
==== Setting up shortcuts to make life easier ====
 +
We'll be ssh'ing from the host to the bone often, here are some shortcuts I use so instead of typing '''ssh debian@192.168.7.2''' and a password every time, I can enter '''ssh bone''' and no password.
 +
 
 +
First edit '''/etc/hosts''' and add a couple of lines.
 +
 
 +
host$ '''sudo nano /etc/hosts'''
 +
 
 +
You may use whatever editor you want.  I suggest '''nano''' since it's easy to figure out.  Add the following to the end of /etc/hosts and quit the editor.
 +
 
 +
192.168.7.2    bone
 +
192.168.8.1     bone2
 +
 
 +
Now you can connect with
 +
host$ '''ssh debian@bone'''
 +
 
 +
Let's make it so you don't have to enter '''debian'''.  On your host computer, put the following in '''~/.ssh/config'''
 +
 
 +
Host bone
 +
  User debian
 +
  UserKnownHostsFile /dev/null
 +
  StrictHostKeyChecking no
 
   
 
   
  eth4    Link encap:Ethernet HWaddr d4:94:a1:39:ff:ff  
+
  Host bone2
          inet addr:192.168.7.1 Bcast:192.168.7.3 Mask:255.255.255.252
+
  User debian
          inet6 addr: fe80::d694:a1ff:fe39:ffff/64 Scope:Link
+
  UserKnownHostsFile /dev/null
          UP BROADCAST RUNNING MULTICAST  MTU:1500 Metric:1
+
  StrictHostKeyChecking no
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
+
 
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
+
These say that whenever you login to bone or bone2, login as '''debian'''.
          collisions:0 txqueuelen:1000
+
Now you can enter.
          RX bytes:2775 (2.7 KBTX bytes:1234 (1.2 KB)
+
 
   
+
host$ '''ssh bone'''
  lo      Link encap:Local Loopback  
+
 
          inet addr:127.0.0.1 Mask:255.0.0.0
+
One last thing, let's make it so you don't have to add a password.
          inet6 addr: ::1/128 Scope:Host
+
Back to your host.
          UP LOOPBACK RUNNING MTU:16436 Metric:1
+
 
          RX packets:37315 errors:0 dropped:0 overruns:0 frame:0
+
host$ '''ssh-keygen'''
          TX packets:37315 errors:0 dropped:0 overruns:0 carrier:0
+
Accept all the defaults and then
          collisions:0 txqueuelen:0
+
host$ '''ssh-copy-id bone'''
          RX bytes:3665320 (3.6 MB) TX bytes:3665320 (3.6 MB)
+
Now all you have to enter is
 +
  host$ '''ssh bone'''
 +
and no password is required.
 +
If you, especially virtual machine users, get an error says "sign_and_send_pubkey: signing failed: agent refused operation", you can solve this by entering
 +
  host$ '''ssh-add'''
 +
which adds the private key identities to the authentication agent. Then you should be able to
 +
host$ '''ssh bone'''
 +
without problems.
 +
 
 +
==== Setting up a root login ====
 +
By default the image we are running doesn't allow a root loginYou can also '''sudo''' from debian, but sometimes it's nice to login as root. Here's how to setup root so you can login from your host without a password.
 +
 
 +
host$ '''ssh bone'''
 +
  bone$ '''sudo bash'''
 +
root@bone# '''nano /etc/ssh/sshd_config'''
 +
 
 +
Search for the line
 +
  #PermitRootLogin prohibit-password
 +
and change it to
 +
PermitRootLogin yes
 +
 
 +
(The # symbol indicates a comment and must be removed in order for the setting to take effect.)  
 +
 
 +
Save the file and quit the editor. Restart ssh so it will reread the file.
 +
  root@bone# '''systemctl restart sshd'''
 +
 
 +
And assign a password to root.
 +
  root@bone# '''passwd'''
 +
 
 +
Now open another window on your host computer and enter:
 +
  host$ '''ssh-copy-id root@bone'''
 +
and enter the root passwordTest it with:
 +
host$ '''ssh root@bone'''
 +
You should be connected without a password. Now go back to the Bone and turn off the root password access.
 +
 
 +
root@bone# '''nano /etc/ssh/sshd_config'''
 +
Restore the line:
 +
  #PermitRootLogin prohibit-password
 +
and restart sshd.
 +
  root@bone# '''systemctl restart sshd'''
 +
root@bone# '''exit'''
 +
bone$ '''exit'''
 +
 
 +
You should now be able to got back to your host computer and login as root on the bone without a password.
 +
  host$ '''ssh root@bone'''
  
==== ssh ====
+
You have access to your bone without passwords only from you host computer.  Try it from another computer and see what happens.
You'll see a new network has appeared, '''eth4''' in my case. The IP address of your host is '''192.168.7.1'''.  There's a good chance the Bone is at '''192.168.7.''2'''''.  Try connecting to it.
 
host$ '''ssh -X root@192.168.7.2'''
 
beagle$
 
You are now logged into the Bone through the network.  This is much faster than the serial port (.115M vs. 100M) and supports many interesting network operations.  The only problem is, the Beagle doesn't know how to access the Internet through the host. Get back to the host computer by entering RETURN ~ ^Z.  That is, hit RETURN, then ~ (it's up there near the ESC key) and then Ctrl-Z.  This gets you back to your host, but leaves the ssh connection running.
 
  
==== host.ipForward.sh ====
+
==== Set Up Git ====
Copy the following lines into a file call '''host.ipForward.sh'''
 
  
<pre>
+
We need to run some files that are in the class '''git''' repository.  We'll learn more about using git later.  Here I'll just show you how to get the files. Here we are installing these files on your host computer, later we'll install them on your Beagle.
#!/bin/bash
 
# These are the commands to run on the host to setup IP masquerading so the Beagle
 
#  can access the Internet through the USB connection.
 
# Inspired by http://thoughtshubham.blogspot.com/2010/03/internet-over-usb-otg-on-beagleboard.html
 
  
if [ $# -eq 0 ] ; then
+
On my host computer I had to run
echo "Usage: $0 interface (such as eth0 or wlan0)"
 
exit 1
 
fi
 
  
interface=$1
+
host$ '''sudo apt update'''
hostAddr=192.168.7.1
+
host$ '''sudo apt install git'''
beagleAddr=192.168.7.2
 
ip_forward=/proc/sys/net/ipv4/ip_forward
 
  
if [ `cat $ip_forward` == 0 ]
+
==== Get the Files ====
  then
 
    echo "You need to set IP forwarding. Edit /etc/sysctl.conf using:"
 
    echo "$ sudo gedit /etc/sysctl.conf"
 
    echo "and uncomment the line  \"net.ipv4.ip_forward=1\""
 
    echo "to enable forwarding of packets. Then run the following:"
 
    echo "$ sudo sysctl -p"
 
    exit 1
 
  else
 
    echo "IP forwarding is set on host."
 
fi
 
# Setup  IP masquerading on the host
 
sudo iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -o $interface -j MASQUERADE
 
  
# Check to see what nameservers the host is using and copy these to the same
+
It only takes one command to pull down all the files.
#  file on the Beagle
 
# This makes it so you can connect to the Beagle without using your password.
 
ssh-copy-id root@$beagleAddr
 
# Save the /etc/resolv.conf on the Beagle in case we mess things up.
 
ssh root@$beagleAddr "mv -n /etc/resolv.conf /etc/resolv.conf.orig"
 
# Copy the resolv.conf file to the Beagle.  Now the Beagle will use the
 
# same name servers as the host.
 
cat - << EOF > /tmp/resolv.conf
 
# This is installed by host.ipForward.sh on the host
 
# Mark A. Yoder, 25-Aug-2013
 
search rose-hulman.edu dhcp.rose-hulman.edu wlan.rose-hulman.edu
 
  
EOF
+
host$ '''git clone https://github.com/MarkAYoder/BeagleBoard-exercises.git exercises --depth=1'''
 +
(The whole repo is some 700M.  Using '''--depth=1''' you only get the recent history and it only takes 200M.)
  
# Use the campus name servers if on compus, otherwise use the Google name servers
+
This will take a while since it's getting all the course files, including pdf files of the course PowerPoint.
if ifconfig | grep "addr:137.112."; then
 
cat - << EOF >> /tmp/resolv.conf
 
nameserver 137.112.18.59
 
nameserver 137.112.5.28
 
nameserver 137.112.4.196
 
EOF
 
else
 
cat - << EOF >> /tmp/resolv.conf
 
nameserver 8.8.8.8
 
nameserver 8.8.4.4
 
EOF
 
fi
 
scp /tmp/resolv.conf root@$beagleAddr:/etc
 
# Tell the beagle to use the host as the gateway.
 
ssh root@$beagleAddr "/sbin/route add default gw $hostAddr"
 
</pre>
 
  
==== Running host.ipForward.sh ====
+
==== Running ipMasquerade.sh ====
Now run:
+
Now that the files are installed, run:
  host$ '''chmod +x host.ipForward.sh'''
+
  host$ '''cd exercises/setup'''
  host$ '''./host.ipForward.sh ''eth0'''''
+
  host$ '''./ipMasquerade.sh ''ens33'''''
This will give you instructions on how to set up your host and will remotely set up your Beagle.
+
Plug in for ''ens33'' whatever is returned when you run '''ip a'''.
 +
This will give you instructions on how to set up your host.
 
Note: If you are using a wireless connection you should use
 
Note: If you are using a wireless connection you should use
  
  host$ '''./host.ipForward.sh ''wlan0'''''
+
  host$ '''./ipMasquerade.sh ''wlp16s0'''''
 +
where ''wlp16s0'' is what is returned by '''ip a''' for your wireless connection on your host.
  
Once ./host.ipForward.sh has been run you can:
+
Once ./ipMasquerade.sh has been run you can:
  host$ '''fg'''
+
  host$ '''./firstssh.sh'''
ssh -X root@192.168.7.2
+
Now you should have network access on the Bone.
(Hit RETURN)
+
  bone$ '''ping -c2 google.com'''
  beagle$ '''ping google.com'''
 
  
You should see Google responding. Hit Ctrl-C to stop.
+
You should see Google responding.
  
 
Congratulations!  Your Beagle is now on the network through your host computer.
 
Congratulations!  Your Beagle is now on the network through your host computer.
 +
 +
You will have to run '''ipMasquerade.sh''' only after rebooting your host computer and run '''firstssh.sh''' after rebooting your bone. Once '''firstssh''' has be run you should ssh from your host with the standard ssh command.
  
 
====Troubleshooting====
 
====Troubleshooting====
Line 141: Line 199:
 
If you get an unknown host response when attempting to ping google.com, and you are off campus, try pinging the Google DNS by IP address. Run:
 
If you get an unknown host response when attempting to ping google.com, and you are off campus, try pinging the Google DNS by IP address. Run:
  
  beagle$ '''ping 8.8.8.8'''
+
  bone$ '''ping 8.8.8.8'''
  
 
If you are on campus, run:
 
If you are on campus, run:
  
  beagle$ '''ping 137.112.5.28'''
+
  bone$ '''ping 137.112.5.28'''
  
 
If you now see responses by pinging a specific IP, it is possible that a firewall on your host computer is blocking the Beagle's access to the DNS when attempting to ping by domain name. On Ubuntu/Mint, run:
 
If you now see responses by pinging a specific IP, it is possible that a firewall on your host computer is blocking the Beagle's access to the DNS when attempting to ping by domain name. On Ubuntu/Mint, run:
Line 158: Line 216:
 
Repeat this exercise and attempt to ping Google by domain name again. If you now receive responses, then the firewall was indeed the issue. Otherwise, the internet is your friend. Use your host computer to try and find a solution. Feel free to add solutions here when you find them
 
Repeat this exercise and attempt to ping Google by domain name again. If you now receive responses, then the firewall was indeed the issue. Otherwise, the internet is your friend. Use your host computer to try and find a solution. Feel free to add solutions here when you find them
  
=== OSX ===
+
=====NetworkManager Issues=====
 +
 
 +
If you continue to have problems with '''firstssh.sh''' and receive errors regarding the network manager command line tool (nmcli) such as:
 +
mv: cannot stat '/etc/resolv.conf'
 +
or
 +
nmcli failed, trying older 'list' instead of 'show'
 +
nmncli failed again, giving up. . .
 +
then you may have success with the following solution.
 +
 
 +
Access your bone with '''ssh bone''' and check to see which network interface is tethered to your host. It should be usb0, already assigned the ip address of '''192.168.7.2.''' If so, simply enter the following in the command line:
 +
bone$ '''route add default gw 192.168.7.1'''
 +
 
 +
Now return to your host machine and check what your internet facing interface is. It should be some '''eno''' interface for a wired connection or '''wlp''' interface for wireless. Your Bone should be on one of the usb ports, starting with '''enx''' and showing an ip address for your host machine of '''192.168.7.1.''' The example commands below will use '''wlp''' in place of the internet facing interface and '''enx''' in place of the Bone interface.
 +
host$ '''iptables --table nat --append POSTROUTING --out-interface wlp -j MASQUERADE'''
 +
host$ '''iptables --append FORWARD --in-interface enx -j ACCEPT'''
 +
host$ '''echo 1 > /proc/sys/net/ipv4/ip_forward'''
 +
 
 +
You should now ssh into your Bone and see if the routing change has worked. These commands are essentially what the '''ipMasquerade.sh''' and '''firstssh.sh''' scripts already do, but I started to encounter problems with them and had more success performing the operations manually.
 +
 
 +
=== OS X ===
 
I haven't checked these instructions this year.  Please report your results and update if needed.
 
I haven't checked these instructions this year.  Please report your results and update if needed.
  
Line 171: Line 248:
  
 
  host$ '''screen /dev/ttyusb*B 115200'''
 
  host$ '''screen /dev/ttyusb*B 115200'''
  beagle$ '''udhcpc -i usb0'''
+
  bone$ '''udhcpc -i usb0'''
  beagle$ '''ping google.com'''
+
  bone$ '''ping google.com'''
  
 
This is all nicely shown [http://www.youtube.com/watch?v=Cf9hnscbSK8&feature=youtu.be here] in this silent YouTube movie.
 
This is all nicely shown [http://www.youtube.com/watch?v=Cf9hnscbSK8&feature=youtu.be here] in this silent YouTube movie.
Line 222: Line 299:
 
Login as root and run the following:
 
Login as root and run the following:
  
  beagle$ '''echo "nameserver 8.8.8.8" > /etc/resolv.conf'''
+
  bone$ '''echo "nameserver 8.8.8.8" > /etc/resolv.conf'''
  beagle$ '''echo "nameserver 8.8.8.4" >> /etc/resolv.conf'''
+
  bone$ '''echo "nameserver 8.8.8.4" >> /etc/resolv.conf'''
  beagle$ '''/sbin/route add default gw 192.168.7.1'''
+
  bone$ '''/sbin/route add default gw 192.168.7.1'''
  beagle$ '''ping google.com'''
+
  bone$ '''ping google.com'''
  
 
If 'ping:unknown host google.com' occurs, run this instead:
 
If 'ping:unknown host google.com' occurs, run this instead:
  
  beagle$ '''echo "nameserver 137.112.4.196" > /etc/resolv.conf'''
+
  bone$ '''echo "nameserver 137.112.4.196" > /etc/resolv.conf'''
  beagle$ '''/sbin/route add default gw 192.168.7.1'''
+
  bone$ '''/sbin/route add default gw 192.168.7.1'''
  beagle$ '''ping google.com'''
+
  bone$ '''ping google.com'''
  
 
Congratulations, you now have a connection from your BeagleBone through your Linux host to the Internet.
 
Congratulations, you now have a connection from your BeagleBone through your Linux host to the Internet.
  
 
{{YoderFoot}}
 
{{YoderFoot}}

Latest revision as of 14:01, 15 August 2019

thumb‎ Embedded Linux Class by Mark A. Yoder


3.8 Kernel

These instructions are for the 3.8 and newer kernels. EBC Exercise 02 Out-of-the-Box, Bone 3.2 Kernel has instructions for the 3.2 kernel.

Local Internet Connection, Cloud 9

One of the slickest features of the Bone is its ability to access the Internet through the USB (tether) connection. Plug a USB cable into your bone and plug the other end into your host computer and wait for the Bone to boot up. Once the lights settle down to a heartbeat pattern point a browser on your host computer to 192.168.7.2. Here you will see the Cloud 9 IDE (integrated development environment). This is being served up by the Bone over a local internet connection. Go and explore it.

Internet Connection to the Outside World

Once the Bone can connect to the host, the host can be used for forward requests from the Bone to the Internet. Follow the instructions below to set up your host and Bone so the bone can access the internet through your host.

Linux

See your networks with ip a

Run:

host$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:8c:63:ea brd ff:ff:ff:ff:ff:ff
    inet 172.16.105.242/24 brd 172.16.105.255 scope global dynamic noprefixroute ens33
       valid_lft 6327sec preferred_lft 6327sec
    inet6 2605:a000:1c02:ec:5936:3599:8ce1:c3cb/64 scope global temporary dynamic 
       valid_lft 86396sec preferred_lft 14396sec
    inet6 2605:a000:1c02:ec:a067:7cb0:fd3e:7d13/64 scope global dynamic mngtmpaddr noprefixroute 
       valid_lft 86396sec preferred_lft 14396sec
    inet6 fe80::9d5f:d5d0:6460:d5cd/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: enx40bd32e49bc1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 40:bd:32:e4:9b:c1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.6.1/30 brd 192.168.6.3 scope global dynamic noprefixroute enx40bd32e49bc1
       valid_lft 103sec preferred_lft 103sec
    inet6 fe80::6f61:86ba:523e:c1d5/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
4: enx40bd32e49bbe: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
    link/ether 40:bd:32:e4:9b:be brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.1/30 brd 192.168.7.3 scope global dynamic noprefixroute enx40bd32e49bbe
       valid_lft 103sec preferred_lft 103sec
    inet6 fe80::9603:1b84:ebd5:7c9c/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever


ssh and changing the password

You'll see two new networks have appeared, enx40bd32e49bc1 and enx40bd32e49bbe in my case. The IP address of your host is 192.168.7.1. There's a good chance the Bone is at 192.168.7.2. Try connecting to it. The default password is temppwd.

host$ ssh debian@192.168.7.2
bone$ 

You are now logged into the Bone through the network. This is much faster than the serial port (.115M vs. 100M) and supports many interesting network operations.

Take a look around. What do you find?

Since everyone knows the default password, change it to something else.

bone$ passwd
Changing password for debian.
(current) UNIX password:
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

The only problem is, the Beagle doesn't know how to access the Internet through the host. Get back to the host computer:

bone$ exit

Setting up shortcuts to make life easier

We'll be ssh'ing from the host to the bone often, here are some shortcuts I use so instead of typing ssh debian@192.168.7.2 and a password every time, I can enter ssh bone and no password.

First edit /etc/hosts and add a couple of lines.

host$ sudo nano /etc/hosts

You may use whatever editor you want. I suggest nano since it's easy to figure out. Add the following to the end of /etc/hosts and quit the editor.

192.168.7.2     bone
192.168.8.1     bone2

Now you can connect with

host$ ssh debian@bone

Let's make it so you don't have to enter debian. On your host computer, put the following in ~/.ssh/config

Host bone
  User debian
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no

Host bone2
  User debian
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no

These say that whenever you login to bone or bone2, login as debian. Now you can enter.

host$ ssh bone

One last thing, let's make it so you don't have to add a password. Back to your host.

host$ ssh-keygen

Accept all the defaults and then

host$ ssh-copy-id bone

Now all you have to enter is

host$ ssh bone

and no password is required. If you, especially virtual machine users, get an error says "sign_and_send_pubkey: signing failed: agent refused operation", you can solve this by entering

host$ ssh-add

which adds the private key identities to the authentication agent. Then you should be able to

host$ ssh bone

without problems.

Setting up a root login

By default the image we are running doesn't allow a root login. You can also sudo from debian, but sometimes it's nice to login as root. Here's how to setup root so you can login from your host without a password.

host$ ssh bone
bone$ sudo bash
root@bone# nano /etc/ssh/sshd_config

Search for the line

#PermitRootLogin prohibit-password

and change it to

PermitRootLogin yes

(The # symbol indicates a comment and must be removed in order for the setting to take effect.)

Save the file and quit the editor. Restart ssh so it will reread the file.

root@bone# systemctl restart sshd

And assign a password to root.

root@bone# passwd

Now open another window on your host computer and enter:

host$ ssh-copy-id root@bone

and enter the root password. Test it with:

host$ ssh root@bone

You should be connected without a password. Now go back to the Bone and turn off the root password access.

root@bone# nano /etc/ssh/sshd_config

Restore the line:

#PermitRootLogin prohibit-password

and restart sshd.

root@bone# systemctl restart sshd
root@bone# exit
bone$ exit

You should now be able to got back to your host computer and login as root on the bone without a password.

host$ ssh root@bone

You have access to your bone without passwords only from you host computer. Try it from another computer and see what happens.

Set Up Git

We need to run some files that are in the class git repository. We'll learn more about using git later. Here I'll just show you how to get the files. Here we are installing these files on your host computer, later we'll install them on your Beagle.

On my host computer I had to run

host$ sudo apt update
host$ sudo apt install git

Get the Files

It only takes one command to pull down all the files.

host$ git clone https://github.com/MarkAYoder/BeagleBoard-exercises.git exercises --depth=1

(The whole repo is some 700M. Using --depth=1 you only get the recent history and it only takes 200M.)

This will take a while since it's getting all the course files, including pdf files of the course PowerPoint.

Running ipMasquerade.sh

Now that the files are installed, run:

host$ cd exercises/setup
host$ ./ipMasquerade.sh ens33

Plug in for ens33 whatever is returned when you run ip a. This will give you instructions on how to set up your host. Note: If you are using a wireless connection you should use

host$ ./ipMasquerade.sh wlp16s0

where wlp16s0 is what is returned by ip a for your wireless connection on your host.

Once ./ipMasquerade.sh has been run you can:

host$ ./firstssh.sh

Now you should have network access on the Bone.

bone$ ping -c2 google.com

You should see Google responding.

Congratulations! Your Beagle is now on the network through your host computer.

You will have to run ipMasquerade.sh only after rebooting your host computer and run firstssh.sh after rebooting your bone. Once firstssh has be run you should ssh from your host with the standard ssh command.

Troubleshooting

Unknown Host

If you get an unknown host response when attempting to ping google.com, and you are off campus, try pinging the Google DNS by IP address. Run:

bone$ ping 8.8.8.8

If you are on campus, run:

bone$ ping 137.112.5.28

If you now see responses by pinging a specific IP, it is possible that a firewall on your host computer is blocking the Beagle's access to the DNS when attempting to ping by domain name. On Ubuntu/Mint, run:

host$ sudo ufw disable
Firewall stopped and disabled on system startup

You should get a response, such as above, that the firewall will be disabled upon next startup. After saving anything important, restart your host through the start menu or run:

host$ reboot

Repeat this exercise and attempt to ping Google by domain name again. If you now receive responses, then the firewall was indeed the issue. Otherwise, the internet is your friend. Use your host computer to try and find a solution. Feel free to add solutions here when you find them

NetworkManager Issues

If you continue to have problems with firstssh.sh and receive errors regarding the network manager command line tool (nmcli) such as:

mv: cannot stat '/etc/resolv.conf'

or

nmcli failed, trying older 'list' instead of 'show'
nmncli failed again, giving up. . .

then you may have success with the following solution.

Access your bone with ssh bone and check to see which network interface is tethered to your host. It should be usb0, already assigned the ip address of 192.168.7.2. If so, simply enter the following in the command line:

bone$ route add default gw 192.168.7.1

Now return to your host machine and check what your internet facing interface is. It should be some eno interface for a wired connection or wlp interface for wireless. Your Bone should be on one of the usb ports, starting with enx and showing an ip address for your host machine of 192.168.7.1. The example commands below will use wlp in place of the internet facing interface and enx in place of the Bone interface.

host$ iptables --table nat --append POSTROUTING --out-interface wlp -j MASQUERADE
host$ iptables --append FORWARD --in-interface enx -j ACCEPT
host$ echo 1 > /proc/sys/net/ipv4/ip_forward

You should now ssh into your Bone and see if the routing change has worked. These commands are essentially what the ipMasquerade.sh and firstssh.sh scripts already do, but I started to encounter problems with them and had more success performing the operations manually.

OS X

I haven't checked these instructions this year. Please report your results and update if needed.

  1. go to System Preferences and select Network
  2. You should see RNDIS/...Gadget. This is the network connection to the Beagle. Select it
  3. Wait for the IP address 192.168.7.1 to appear
  4. Click Show All and select Sharing
  5. Select Internet Sharing
  6. Select RNDIS/Ethernet Gadget

In a terminal window connect to the serial port

host$ screen /dev/ttyusb*B 115200
bone$ udhcpc -i usb0
bone$ ping google.com

This is all nicely shown here in this silent YouTube movie.

Congratulations, you now have a connection from your BeagleBone to the Internet.

Windows 7

I haven't checked these either. Please report results and update if needed.

There are several ways of running ssh on Windows 7. Below are a couple of tools that you can use.

Environment Setup

You can either run ssh from a bash terminal (i.e. C:\Program Files\Git\Git Bash or C:\cygwin\Cygwin.bat), or you can add the bin directories to your path and run from the Windows command prompt (i.e. add C:\Program Files\Git\bin or C:\cygwin\bin to your path).

Note: Be careful adding multiple bin directories to your path

First time setup

  1. Run regedit
  2. Navigate to Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters
  3. Change IPEnableRouter from 0 to 1
  4. Close regedit
  5. Run services
  6. Make sure the following are set to Automatic and are started
    1. Routing and Remote Access
    2. Internet Connection Sharing (ICS)

Connecting to the Internet

After ejecting

  1. Navigate to Control Panel\Network and Internet\Network and Sharing Center\Change adapter settings
  2. Right click your wired/wireless internet connection and go to Properties
  3. Go to the Sharing tab
  4. Check the box to Allow other network users to connect through this computer's Internet connection
  5. Select your bone's local area connection for the Home networking connection (if you cannot choose the local area connection, turn your internet connection sharing off and then back on)
  6. Return to Change adapter settings
  7. Right click your Bone's internet connection and go to Properties
  8. Select Internet Protocol Version 4 (TCP/IPv4) and choose Properties
  9. Choose Obtain an IP address automatically and Obtain DNS server address automatically

Open a command prompt or bash terminal and run the following:

host$ ping 192.168.7.2

If this ping times out then disable and re-enable your bone's local area connection and try again. Once it works run the following:

host$ ssh root@192.168.7.2

Login as root and run the following:

bone$ echo "nameserver 8.8.8.8" > /etc/resolv.conf
bone$ echo "nameserver 8.8.8.4" >> /etc/resolv.conf
bone$ /sbin/route add default gw 192.168.7.1
bone$ ping google.com

If 'ping:unknown host google.com' occurs, run this instead:

bone$ echo "nameserver 137.112.4.196" > /etc/resolv.conf
bone$ /sbin/route add default gw 192.168.7.1
bone$ ping google.com

Congratulations, you now have a connection from your BeagleBone through your Linux host to the Internet.




thumb‎ Embedded Linux Class by Mark A. Yoder