-
Notifications
You must be signed in to change notification settings - Fork 28
/
beaglebone.txt
7328 lines (5491 loc) · 236 KB
/
beaglebone.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#+TITLE: FreedomBone
#+AUTHOR: Bob Mottram
#+EMAIL: [email protected]
#+KEYWORDS: freedombox, debian, beaglebone, friendica, email, web server, home server, internet, censorship, surveillance, social network, irc, jabber
#+DESCRIPTION: Turn the Beaglebone Black into a personal communications server
#+OPTIONS: ^:nil
#+STYLE: <link rel="stylesheet" type="text/css" href="index.css" />
#+BEGIN_CENTER
*How to turn the Beaglebone Black into a FreedomBox-like personal communications server*
#+END_CENTER
[[./images/freedombone_small.jpg]]
#+BEGIN_CENTER
Copyright (C) 2014 Bob Mottram
Permission is granted to copy, distribute and/or modify this document under the terms of the [[https://gnu.org/licenses/fdl.html][GNU Free Documentation License]], Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
Source for this web site in [[https://en.wikipedia.org/wiki/Org-mode][Emacs org-mode]] format is available [[/beaglebone.txt][here]]. Comments or patches may be submitted via [[https://github.com/bashrc/freedombone][Github]].
#+END_CENTER
* Introduction
#+BEGIN_VERSE
/If you look at it from an engineering perspective, an iterative perspective, it’s clear that you have to try something rather than do nothing./
-- Edward J. Snowden
#+END_VERSE
** What is FreedomBone?
Today many of us rely upon "free" services in the cloud, such as Gmail, Facebook, Google+ and so on. It might appear that these services are indispensible infrastructure of the modern internet, but actually they're not strictly needed and the amount of value which they deliver to the average internet user is very marginal. It is possible to be a citizen of the internet and yet not use those things - to disintermediate the most well known companies and cut out their prurient or merely cringeworthy business models.
FreedomBone is a personal home communications server based upon the BeagleBone Black hardware. It's small and cheap and will allow you to use email, have your own web site and do social networking in a federated way without needing to rely upon any intermediary companies other than your ISP.
** Do I need any prior knowledge?
In these instructions only a minimal level of familiarity with Linux is assumed. It's assumed that you know the basics of the /nano/ and /emacs/ editors, but it would be simple to also use other editors if you prefer.
** Why should I do this?
You should consider doing this if you are a freedom-oriented sort of person and you want to maintain sovereignty over your information. Laws in many places in the world consider you to have relinquished any property rights over data which you put onto a server not owned by youself (i.e. owned by a third party, such as Google or Facebook).
If you don't like the idea of having all your communications intercepted and investigated by the Surveillance State then you should consider running a FreedomBone. If your profession involves maintaining confidentiality as an essential feature, such as legal or medical services, counselling, teaching or any sort of activism then you should consider running a FreedomBone. Especially if your activities include [[https://firstlook.org/theintercept/article/2014/03/20/inside-nsa-secret-efforts-hunt-hack-system-administrators/][systems administration]] or [[http://www.spiegel.de/international/germany/gchq-and-nsa-targeted-private-german-companies-a-961444.html][software engineering for any communications-related systems]] then it is highly likely that you have already been targeted and "tasked" by the surveillance apparatus.
As Eben Moglen noted in his now famous [[https://www.youtube.com/watch?v=QOEMv0S8AcA]["Freedom in The Cloud"]] talk the simple fact of you keeping your own internet logs (found in the /var/log directory) puts a certain amount of power in your hands and takes it away from parties who would otherwise sell that information without your knowledge or permission to advertisers or other shady outfits who may not have your best interests at heart.
** After it's installed will it need a lot of maintenance?
So long as the hardware is ok the amount of maintenance needed should be very small. Unlike on Windows based systems you don't need to defragment drives or mess about with anti-virus programs. I ran a similar Sheevaplug system between 2010 and 2013 with only occasional software updates or reboots, and uptime was probably 99% or better.
** Is it secure?
Nothing is totally secure or infallible. You could have the most secure technology and yet still use easy to guess passwords. In general any software described as "uncrackable" or "guaranteed secure" is likely to be bogus and should be treated with suspicion. No matter what the hype may claim, all software has bugs so it's really a question of whether your communications are more secure or less secure. Using something like Freedombone will be likely to increase your degree of communications security to a level which is above average.
This system will not defend you from an attacker who is actively trying to block or corrupt your communications, but I assume that doesn't apply in the majority of cases. Another thing to be aware of is that running a FreedomBone could make you more vulnerable to traffic analysis, since the server is associated with your home address and isn't a giant aggregation of users somewhere in the cloud. You need to weigh this alongside the additional legal protection which owning the server and having it in your own home gives you.
FreedomBone should be far more secure than using popular cloud-based services which have spying built into them as a core feature (although not one which is typically advertised), but it is not necessarily any kind of impenetrable information fortress.
This project is not only about security. It's also about having independence and at least in the realm of information being able to have more control over your own life, without having gatekeepers, censors or companies in the middle. That's the way that the internet was designed to be in the first place.
** Will running a server all the time affect my electricity bill?
Hardly at all. The BeagleBone Black consumes very little power - less than 5W. It would even be potentially possible to run it from a solar panel.
** Can I use a Raspberry Pi or Cubieboard instead?
These instructions are not highly specific to the Beaglebone Black and so will likely also work on other single board computers (SBCs) such as the [[https://en.wikipedia.org/wiki/Raspberry_pi][Raspberry Pi]] or [[https://en.wikipedia.org/wiki/Cubieboard][Cubieboard]]. The original Raspberry Pi only had 256MB of RAM and so the performance of some services may be more limited. The Beaglebone Black was chosen mainly because of its low cost, relatively good CPU performance for the price (by the standards of 2013) and also low electricity consumption. The Cubieboard is also another good alternative, with the A20 version having similar specifications but twice as much RAM as the BeagleBone Black.
** Why should I trust the packages or source code downloaded from this site?
If you're particularly security conscious then you shouldn't. Binary or source packages have only been included here for convenience and to avoid confusion. "/Go and find a Debian installation for the BeagleBone Black somewhere on the web/" is too vague an instruction for my liking, and I've attempted to keep things as concise and unambiguous as possible - particularly with an average or new Linux user in mind.
However, for maximum security for those software systems which are not already packaged within the Debian repositories then seek out the original sources and verify the hashes independently.
It's worth adopting an attitude of "/trust but verify/". Don't let fear of mass surveillance and [[https://www.techdirt.com/articles/20140207/08354426130/gchq-has-entire-program-dirty-tricks-including-honeypots-using-journalists-deleting-online-accounts.shtml]["dirty tricks"]] paralyse you into trusting nothing and consequently doing nothing. Doing nothing means that the surveillance apparatus has succeeded in keeping you under observation at all times.
** Do I need to have a static IP address?
This is often a question which people ask about running a server from home. The answer is that you don't need a static IP address. In the vast majority of cases you will have a dynamic IP address issued by your ISP, which may change from time to time. How then does the DNS system know how to resolve your domain name correctly? To do this you need to use a dynamic IP address system, such as [[http://freedns.afraid.org/][freeDNS]]. The details of that are explained [[Getting onto the web][here]]. Other services are available, but they're not usually /free as in beer/. In this guide a static IP address of 192.168.1.60 is only used within your /local network/ (i.e. not the big bad internet of public IP addresses), so that your internet router can be set up to send incoming traffic to the right computer.
* Inventory
#+BEGIN_VERSE
/You can’t help someone just by making a wish to do so, you have to take action./
-- Dalai Lama
#+END_VERSE
These instructions assume that you have the following ingredients.
** A BeagleBone Black (BBB)
It should come with a suitable USB cable for the initial setup. To make things look nicer you may also want to get a case for it.
** An internet connection
It is assumed that the most common situation is via a router installed at home. The router should have ethernet sockets on it and a web interface which allows you to forward ports (sometimes under the "firewall" settings), so that you can forward ssh and web traffic to the BBB.
** microSD card
To use as the main storage for the BBB. 16 or 32GB is fine, and can be obtained quite cheaply. Try to use Sandisk (class 10 or better) where possible and avoid cheaper cards which often have poor performance.
You may also need an SD card adaptor or USB card reader in order to flash the operating image to the microSD card. For instance, many laptops have an SD card slot but not a microSD slot.
** 5V/2A power supply
With a plug suitable for powering the BBB. If you have some device with a USB socket nearby you may also be able to just use that for electrical power. However, powering from the USB cable alone might result in crashes when the system is under load, depending upon how many milliamps can be supplied by the USB hub/socket. If the system crashes due to running out of power then you will see that the LEDs on the BBB are continuously on, rather than flashing. One way to test whether the board has enough power is to try compiling a Linux kernel on it, but any CPU and disk intensive program will also suffice as a test.
[[http://beagleboard.org/Support/FAQ][beagleboard.org]] gives the following advice on power supplies:
#+BEGIN_VERSE
/Power over USB is sufficient as long as the software and system running perform some management to keep it under the USB current limit threshold. For simplicity and maximum capability, powering over the 5V barrel connector is typically recommended./
/The power adapter is required to provide 5V over a 5.5mm outer diameter and 2.1mm inner diameter barrel connector (a barrel connector length of 9.5mm is more than sufficient). The recommended supply current is at least 1.2A (or 6W), but at least 2A (or 10W) is recommended if you are going to connect up anything over the USB./
#+END_VERSE
The plug should be /centre positive/, meaning that the centre/tip is positive and the outer part is negative.
** An ethernet patch cable
Just an ordinary cat5 or cat6 cable that you can get from most electrical/computer stores.
* Installing Debian onto the microSD card
** Beaglebone Black
The Debian Linux OS will be installed onto a small flash drive. It's a good idea to do this rather than using the internal flash, because it will allow you to easily create backups of the entire system if necessary using the dd command.
Download the image.
#+BEGIN_SRC: bash
cd ~/
wget http://freedombone.uk.to/debian-7.2-console-armhf-2013-11-15.tar.xz
#+END_SRC
Verify it.
#+BEGIN_SRC: bash
sha256sum debian-7.2-console-armhf-2013-11-15.tar.xz
262ea96d6bff530ad545e001eb2aa50b26a999c02f0c0e2e5f8536edf21c973a debian-7.2-console-armhf-2013-11-15.tar.xz
#+END_SRC
Uncompress it.
#+BEGIN_SRC: bash
tar xJf debian-7.2-console-armhf-2013-11-15.tar.xz
cd debian-7.2-console-armhf-2013-11-15
#+END_SRC
Create the disk image, where sdX is the name of the flash drive (probably it will be sdb or sdc). An easy way to find out the device name of the flash drive is to enter the command:
#+BEGIN_SRC: bash
ls /dev/sd*
#+END_SRC
then plug in the flash drive and type the same command again. You'll be able to see the difference. Once you know the device name then you can proceed to install the image onto the flash drive.
#+BEGIN_SRC: bash
sudo apt-get install u-boot-tools dosfstools git-core kpartx wget parted
sudo ./setup_sdcard.sh --mmc /dev/sdX --uboot bone --swap-file 1024
#+END_SRC
Once completed then safely remove the microSD card via your file manager (usually right click and "safely remove" or "eject").
** Cubieboard
The Debian Linux OS will be installed onto a small flash drive. It's a good idea to do this rather than using the internal flash, because it will allow you to easily create backups of the entire system if necessary using the dd command.
Download the Cubieboard image from http://cubian.org/downloads/
#+BEGIN_SRC: bash
sudo apt-get install p7zip-full
7z x CUBIAN_IMAGE.7z
#+END_SRC
Create the disk image, where sdX is the name of the flash drive (probably it will be sdb or sdc). An easy way to find out the device name of the flash drive is to enter the command:
#+BEGIN_SRC: bash
ls /dev/sd*
#+END_SRC
then plug in the flash drive and type the same command again. You'll be able to see the difference. Once you know the device name then you can proceed to install the image onto the flash drive.
#+BEGIN_SRC: bash
sudo dd if=EXTRACTED_CUBIAN_IMAGE of=/dev/sdX bs=4096; sync
#+END_SRC
* Setup
#+BEGIN_VERSE
/Build the tools for a future you would want to live in/
-- Kurt Opsahl
#+END_VERSE
** Things to be aware of
*** A note on ssh
When using ssh to log into the BBB if you get warnings of the type "/the ECDSA host key for domain differs from the key for the IP address/" then run the command:
#+BEGIN_SRC: bash
ssh-keygen -R <IP address>
#+END_SRC
*** Passwords
It's highly recommended that you use a password manager, such as KeepassX, and make all your passwords long random strings. It's also a good idea to use different passwords for different pieces of software, instead of one or two passwords for the whole system. That compartmentalises the security such that even if an attacker gains access to one system they can't necessarily get access to others.
*** HTTPS
Throughout these instructions self signed SSL certificates are used to implement access to web pages via HTTPS. The whole HTTPS security model upon which much of the internet currently rests seems broken in that it usually depends upon "trusted certificate authorities" who are not really trusted, except perhaps by the maintainers of certain web browser software. So all that HTTPS really guarantees is that you have an encrypted connection, but an encrypted connection /to who/ can be subject to doubt. As was seen in 2013 with the [[https://www.schneier.com/essay-455.html][information coming from Edward Snowden]], and also the [[http://en.wikipedia.org/wiki/Lavabit][Lavabit email service]], it's possible for companies/organisations to be compromised or bribed and SSL private keys for all users can be demanded using gagging orders or secret laws without any individual user ever being able to know that their communications is no longer secure..
Not knowing who you're really connecting to is especially true for self-signed certificates, so it is in principle possible that when logging into a site with a username and password a system such as [[http://arstechnica.com/tech-policy/2013/11/uk-spies-continue-quantum-insert-attack-via-linkedin-slashdot-pages/][Quantum Insert]], or a compromised [[http://en.wikipedia.org/wiki/Domain_Name_System][DNS service]], could be used to direct the user to a fake copy of the login screen for the purposes of obtaining their login details. While this doesn't seem to be a major problem at the time of writing it's something to keep in mind. So if you can't log in or if you log in and what you see doesn't look like your site then it's possible that such a compromise could have taken place. Using a password manager with different login details for each site is one way to ensure that if one system is compromised then the attacker can't necessarily get access to all your other stuff.
** Initial
Eject the microSD card from your computer and plug it into the BBB, then connect the USB cable between the two. You may need to wait for a couple of minutes for the BBB to boot from the card, then you can then open a terminal and login via ssh.
Note that if you're using a Cubieboard then the ssh login is different (see https://github.com/cubieplayer/Cubian/wiki/Get-started-with-Cubian) and it may be easier to directly edit the following files with the microSD card plugged into your laptop.
#+BEGIN_SRC: bash
#+END_SRC
The default password is /temppwd/
Then log in as root:
#+BEGIN_SRC: bash
su
#+END_SRC
The default password is /root/
The first thing to do is to change the passwords from their defaults.
#+BEGIN_SRC: bash
passwd
#+END_SRC
Then you will need to change the network interfaces. The main task here is to comment out the stuff related to usb0. That will enable you to plug the BBB into the back of a router and for it to be detectable on the network.
#+BEGIN_SRC: bash
nano /etc/network/interfaces
#+END_SRC
The resulting interfaces file should look like this:
#+BEGIN_SRC: bash
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.1.60
netmask 255.255.255.0
gateway 192.168.1.254
dns-nameservers 213.73.91.35 85.214.20.141
# Example to keep MAC address between reboots
#hwaddress ether DA:AD:CE:EF:CA:FE
# WiFi Example
#auto wlan0
#iface wlan0 inet dhcp
# wpa-ssid "essid"
# wpa-psk "password"
# Ethernet/RNDIS gadget (g_ether)
# ... or on host side, usbnet and random hwaddr
# Note on some boards, usb0 is automaticly setup with an init script
# in that case, to completely disable remove file [run_boot-scripts] from the boot partition
#iface usb0 inet static
# address 192.168.7.2
# netmask 255.255.255.0
# network 192.168.7.0
# gateway 192.168.7.1
#+END_SRC
CTRL-o followed by ENTER to save, then CTRL-x to exit.
In the above example "address 192.168.1.60" is a static IP address for the BBB, which will allow incoming network traffic to be directed from the router in a reliable manner. It should be outside of the DHCP range set up on the router.
"gateway 192.168.1.254" should be the IP address of the router.
Note that setting the DNS servers with dns-nameservers is important because some home routers do not allow you to change the DNS settings.
Edit resolv.conf.
#+BEGIN_SRC: bash
nano /etc/resolv.conf
#+END_SRC
It should look something like the following:
#+BEGIN_SRC: bash
domain localdomain
search localdomain
nameserver 213.73.91.35
nameserver 85.214.20.141
#+END_SRC
It's not a good idea to use the DNS servers provided by default by your ISP, since those are almost certainly subject to censorship and monitoring. Other possible IP addresses are:
| DNS IP | Organisation | Location |
|-----------------+--------------------------------+-------------|
| 85.214.73.63 | Digitalcourage | Germany |
| 87.118.100.175 | German Privacy Foundation e.V. | Germany |
| 94.75.228.29 | German Privacy Foundation e.V. | Germany |
| 85.25.251.254 | German Privacy Foundation e.V. | Germany |
| 2.141.58.13 | German Privacy Foundation e.V. | Germany |
| 213.73.91.35 | Chaos Computer Club Berlin | Germany |
| 212.82.225.7 | ClaraNet | Germany |
| 212.82.226.212 | ClaraNet | Germany |
| 58.6.115.42 | OpenNIC | Australia |
| 58.6.115.43 | OpenNIC | Australia |
| 119.31.230.42 | OpenNIC | Australia |
| 200.252.98.162 | OpenNIC | Brazil |
| 217.79.186.148 | OpenNIC | Germany |
| 81.89.98.6 | OpenNIC | Germany |
| 78.159.101.37 | OpenNIC | Germany |
| 203.167.220.153 | OpenNIC | New Zealand |
| 82.229.244.191 | OpenNIC | France |
| 82.229.244.191 | OpenNIC | Czechnya |
| 216.87.84.211 | OpenNIC | USA |
| 66.244.95.20 | OpenNIC | USA |
| 207.192.69.155 | OpenNIC | USA |
| 72.14.189.120 | OpenNIC | USA |
| 194.145.226.26 | PowerNS | Germany |
| 77.220.232.44 | PowerNS | Germany |
| 78.46.89.147 | ValiDOM | Germany |
| 88.198.75.145 | ValiDOM | Germany |
| 85.25.149.144 | Freie Unzensierte Nameserver | Germany |
| 87.106.37.196 | Freie Unzensierte Nameserver | Germany |
| 209.59.210.167 | Christoph Hochstätter | USA |
| 85.214.117.11 | Christoph Hochstätter | Germany |
| 83.243.5.253 | private | Germany |
| 88.198.130.211 | private | Germany |
| 85.10.211.244 | private | Germany |
CTRL-o followed by ENTER to save, then CTRL-x to exit.
Now disconnect the BBB from your computer and plug it into the router. You'll need an ethernet patch cable and you may also need a 5V/1A power supply for the BBB.
If you go to the web administration screen for your internet router (often it's on 192.168.2.1 or 192.168.1.254) then after a few minutes you should see the BBB appear on the network. It's name will be "arm".
If you're using a Cubieboard:
#+BEGIN_SRC: bash
nano /etc/apt/sources.list
#+END_SRC
Delete the existing sources and replace them with the sources [[Example software sources][listed here]], then save and exit. If you use the default Cubian software sources then dependency problems will occur later on.
** Add a user
Ssh back in to the BBB and login as root. In this example the BBB's IP address is 192.168.1.60.
#+BEGIN_SRC: bash
ssh-keygen -f "/home/myusername/.ssh/known_hosts" -R 192.168.1.60
su
#+END_SRC
Then make a new user. It's a bad idea to add users to the sudo group, because that then means that an attacker potentially only needs to know one password in order to get administrator access to the system. With no sudoers an attacker needs to know, or be able to obtain, two separate passwords to be able to really compromise the system.
#+BEGIN_SRC: bash
adduser myusername
#+END_SRC
Exit from the ssh login by typing "exit" a couple of times, then ssh back in as the new user. Make sure you use a difficult to guess password/phrase, or ideally a randomly generated password used together with a password manager such as KeepassX.
Remove the default debian user.
#+BEGIN_SRC: bash
userdel -r debian
#+END_SRC
** Text editor
For an editor which is less erratic than vi when used within a remote console such as Terminator.
#+BEGIN_SRC: bash
apt-get update
apt-get install emacs
update-alternatives --set editor /usr/bin/emacs23
#+END_SRC
Some basic Emacs keys which will be useful to new users are:
| Load a file | CTRL-x CTRL-f |
| Save | CTRL-x CTRL-s |
| Exit | CTRL-x CTRL-c |
** Enable backports
To enable some newer packages add backports to the repositories.
#+BEGIN_SRC: bash
echo "deb http://ftp.us.debian.org/debian wheezy-backports main" >> /etc/apt/sources.list
apt-get update
apt-get dist-upgrade
apt-get install ca-certificates
#+END_SRC
** Configure your location/language
#+BEGIN_SRC: bash
dpkg-reconfigure locales
apt-get install keyboard-configuration
reboot
#+END_SRC
After reboot is complete ssh back in as the root user, then to verify the change.
#+BEGIN_SRC: bash
locale -a
#+END_SRC
Set your time zone with:
#+BEGIN_SRC: bash
tzselect
#+END_SRC
For example, for British time:
#+BEGIN_SRC: bash
export TZ='Europe/London'
echo "export TZ='Europe/London'" >> ~/.bashrc
echo "export TZ='Europe/London'" >> /home/myusername/.bashrc
#+END_SRC
** Upgrade the kernel
Using a more recent kernel should improve stability of the system and also allow it to make use of hardware random number generation, which improves the overall security. Please note that this kernel is specific to the BBB, so if you're using a Raspberry Pi, Cubieboard or other SBC then look elsewhere on the web for information about upgrading the kernel.
#+BEGIN_SRC: bash
cd /tmp
wget http://freedombone.uk.to/kernel-3.14.tar.gz
#+END_SRC
Verify it.
#+BEGIN_SRC: bash
sha256sum kernel-3.14.tar.gz
c489a451b2ab0442ff9105c72307061cfe6858350dacceb29e094b9a20c18739
#+END_SRC
Then extract and install it.
#+BEGIN_SRC: bash
mkdir kernel-3.14
cd kernel-3.14
tar -xzvf ../kernel-3.14.tar.gz
sh install-me.sh
#+END_SRC
If you get a certificate error then edit *install-me.sh* and change the /https/ to /http/, save and try again. Once the installation has completed then you can reboot by typing:
#+BEGIN_SRC: bash
reboot
#+END_SRC
After the system has rebooted you can ssh back unto it and log in as the root user. You can check that the kernel version has changed with the command:
#+BEGIN_SRC: bash
uname -mrs
#+END_SRC
Now enable zram.
#+BEGIN_SRC: bash
editor /etc/modprobe.d/zram.conf
#+END_SRC
Add the following:
#+BEGIN_SRC: bash
options zram num_devices=1
#+END_SRC
Save and exit, then create an initialisation script.
#+BEGIN_SRC: bash
editor /etc/init.d/zram
#+END_SRC
Add the following:
#+BEGIN_SRC: bash
#!/bin/bash
### BEGIN INIT INFO
# Provides: zram
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)
# Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram
### END INIT INFO
start() {
# get the number of CPUs
num_cpus=$(grep -c processor /proc/cpuinfo)
# if something goes wrong, assume we have 1
[ "$num_cpus" != 0 ] || num_cpus=1
# set decremented number of CPUs
decr_num_cpus=$((num_cpus - 1))
# get the amount of memory in the machine
mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
mem_total=$((mem_total_kb * 1024))
# load dependency modules
modprobe zram num_devices=$num_cpus
# initialize the devices
for i in $(seq 0 $decr_num_cpus); do
echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize
done
# Creating swap filesystems
for i in $(seq 0 $decr_num_cpus); do
mkswap /dev/zram$i
done
# Switch the swaps on
for i in $(seq 0 $decr_num_cpus); do
swapon -p 100 /dev/zram$i
done
}
stop() {
# get the number of CPUs
num_cpus=$(grep -c processor /proc/cpuinfo)
# set decremented number of CPUs
decr_num_cpus=$((num_cpus - 1))
# Switching off swap
for i in $(seq 0 $decr_num_cpus); do
if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
swapoff /dev/zram$i
sleep 1
fi
done
sleep 1
rmmod zram
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL
#+END_SRC
Save and exit, then reboot again.
#+BEGIN_SRC: bash
chmod +x /etc/init.d/zram
update-rc.d zram defaults
service zram start
reboot
#+END_SRC
After the system has rebooted ssh back into it and become the root user, then to check that the changes were successful:
#+BEGIN_SRC: bash
dmesg | grep zram
#+END_SRC
Should show something like:
#+BEGIN_SRC: bash
[ 507.322337] zram: Created 1 device(s) ...
[ 507.651151] Adding 505468k swap on /dev/zram0. Priority:100 extents:1 across:505468k SS
#+END_SRC
** Random number generation
#+BEGIN_VERSE
/Near as I can tell, the answer on what has been requested is everything: deliberate weakenings of encryption algorithms, deliberate weakenings of random number generations, copies of master keys, encryption of the session key with an NSA-specific key … everything./
-- Bruce Schneier, on the 2013 leaked NSA documents
#+END_VERSE
The security of encryption depends upon the randomness of the random source used on your system. If it isn't very random then it may be far more vulnerable to cryptanalysis, and it's known that in the past some dubious agencies have encouraged the use of flawed random number generators to assist with their prurient activities. Randomness - typically referred to as /entropy/ - is often gathered from factors such as the timing of key presses or mouse movements, but since the BBB won't have such devices plugged into it this reduces the amount of entropy available.
*** On the Beaglebone Black
Computers can't really generate truly random numbers by themselves, since they're deterministic and so operate in a highly predictable manner. Fortunately, the BBB has an onboard hardware random number generator, which is a physical process which behaves randomly and which can then be read into the computer and stored for later use in encryption algorithms.
Information on exactly how the hardware random number generator on the Beaglebone AM335x CPU works [[http://e2e.ti.com/support/arm/sitara_arm/f/791/t/292794.aspx][seems hard to come by]], but we can later use some software to verify that it does indeed produce random numbers and hasn't been deliberately weakened.
If you are using a Beaglebone and have updated the kernel then install:
#+BEGIN_SRC: bash
apt-get install rng-tools
editor /etc/default/rng-tools
#+END_SRC
Uncomment *HRNGDEVICE=/dev/hwrng*, save and exit then restart the daemon.
#+BEGIN_SRC: bash
service rng-tools restart
#+END_SRC
Your BBB will now use hardware to generate random numbers.
*** On other Single Board Computers
If you are not using a Beaglebone (a Cubieboard for example), or if you didn't update the kernel, then you can still improve the random number generation by installing:
#+BEGIN_SRC: bash
apt-get install haveged
#+END_SRC
*** Verifying random number quality
#+BEGIN_VERSE
/Living in a surveillance state is exactly like being guilty until proven guilty./
-- Mohammad Tarakiyee
#+END_VERSE
You can check how much randomness (entropy) is available with:
#+BEGIN_SRC: bash
cat /proc/sys/kernel/random/entropy_avail
#+END_SRC
Ideally it should be in the range 1000-4096. If it is persistently below 500 then there may be a problem with your system which could make it less secure.
To verify that random number generation is good on the BBB run:
#+BEGIN_SRC: bash
cat /dev/hwrng | rngtest -c 1000
#+END_SRC
You should see something like this, with zero or a small number of failures:
#+BEGIN_SRC: bash
rngtest: starting FIPS tests...
rngtest: bits received from input: 20000032
rngtest: FIPS 140-2 successes: 1000
rngtest: FIPS 140-2 failures: 0
rngtest: FIPS 140-2(2001-10-10) Monobit: 0
rngtest: FIPS 140-2(2001-10-10) Poker: 0
rngtest: FIPS 140-2(2001-10-10) Runs: 0
rngtest: FIPS 140-2(2001-10-10) Long run: 0
rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
rngtest: input channel speed: (min=3.104; avg=26.015; max=18.626)Gibits/s
rngtest: FIPS tests speed: (min=160.281; avg=165.696; max=168.792)Mibits/s
rngtest: Program run time: 115987 microseconds
#+END_SRC
*** Cryptotronix Hashlet
#+BEGIN_VERSE
/One must acknowledge with cryptography no amount of violence will ever solve a math problem./
-- Jacob Appelbaum
#+END_VERSE
An optional extra is the [[http://cryptotronix.com/products/hashlet/][Cryptotronix Hashlet]] which also has hardware random number generation capability via the [[./Atmel-8740-CryptoAuth-ATSHA204-Datasheet.pdf][Atmel ATSHA204]] chip.
Install the hashlet [[./images/hashlet_installed.jpg][like this]] on the BBB, then install some dependencies.
#+BEGIN_SRC: bash
apt-get install git build-essential libgcrypt11-dev texinfo
#+END_SRC
Download the source code.
#+BEGIN_SRC: bash
cd /tmp
git clone https://github.com/bashrc/hashlet.git
#+END_SRC
Now install the driver.
#+BEGIN_SRC: bash
cd hashlet
chmod o+rw /dev/i2c*
./autogen.sh
make check
make install
#+END_SRC
To check the initial state of the device:
#+BEGIN_SRC: bash
hashlet --bus=/dev/i2c-2 state
#+END_SRC
It should return the message "/Factory/". This is intended to provide an indication that the hardware hasn't been tampered with by [[https://en.wikipedia.org/wiki/Tailored_Access_Operations][TAO]] or other shady outfits in transit. If /i2c-2/ fails then try /i2c-1/ or /i2c-0/.
#+BEGIN_SRC: bash
hashlet --bus=/dev/i2c-2 personalize
#+END_SRC
Nothing should be returned by this command, but a file called ~/.hashlet will be generated which is the private key of the device. This personalization process is a one-time operation which physically alters the hardware, so it would not be trivial to reset the device back to "Factory" again. To make sure it's only accessible by the root user:
#+BEGIN_SRC: bash
chmod 400 ~/.hashlet
#+END_SRC
Now create a daemon which will create a random number generator device */dev/hashletrng*.
#+BEGIN_SRC: bash
editor /usr/bin/hashletd
#+END_SRC
#+BEGIN_SRC: bash
#!/bin/sh
PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
I2CBUS=2
BYTES=32
DEVICE=/dev/hashletrng
# create a device
if [ ! -e ${DEVICE} ]; then
chmod o+rw /dev/i2c*
mknod ${DEVICE} p
fi
while :
do
hashlet --bus=/dev/i2c-${I2CBUS} --Bytes ${BYTES} random-bytes > ${DEVICE}
done
#+END_SRC
Save and exit. Now create an init script to run it.
#+BEGIN_SRC: bash
editor /etc/init.d/hashlet
#+END_SRC
Add the following:
#+BEGIN_SRC: bash
#!/bin/bash
# /etc/init.d/hashlet
### BEGIN INIT INFO
# Provides: hashlet
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: hashlet
# Description: Creates a random number generator device
### END INIT INFO
# Author: Bob Mottram <[email protected]>
#Settings
SERVICE='hashlet'
LOGFILE='/dev/null'
COMMAND="/usr/bin/hashletd"
USERNAME='root'
NICELEVEL=19
HISTORY=1024
INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
hashlet_start() {
echo "Starting $SERVICE..."
su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
}
hashlet_stop() {
echo "Stopping $SERVICE"
su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
}
#Start-Stop here
case "$1" in
start)
hashlet_start
;;
stop)
hashlet_stop
;;
restart)
hashlet_stop
sleep 10s
hashlet_start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0
#+END_SRC
Save and exit, then start the daemon.
#+BEGIN_SRC: bash
chmod +x /usr/bin/hashletd
chmod +x /etc/init.d/hashlet
update-rc.d hashlet defaults
service hashlet start
#+END_SRC
Then to obtain some random bytes:
#+BEGIN_SRC: bash
cat /dev/hashletrng
#+END_SRC
The rate of entropy generation by the Hashlet seems very slow compared to */dev/hwrng*, and this is most likely because of the I2C interface. So it's probably a good idea to keep hwrng as the main random source and only use the Hashlet's random number generator for any ancillary stuff.
** Alter ssh configuration
#+BEGIN_VERSE
/The privacy rights of US persons in international communications are significantly diminished, if not completely eliminated, when those communications have been transmitted to or obtained from non-US persons located outside the United States./
-- US Department Of Justice
#+END_VERSE
Altering the ssh configuration will make it a little more secure than the standard Debian settings.
#+BEGIN_SRC: bash
editor /etc/ssh/sshd_config
#+END_SRC
Check the following values:
#+BEGIN_SRC: bash
PermitRootLogin no
X11Forwarding no
ServerKeyBits 4096
Protocol 2
PermitEmptyPasswords no
StrictModes yes
TCPKeepAlive no
#+END_SRC
Append the following:
#+BEGIN_SRC: bash
ClientAliveInterval 60
ClientAliveCountMax 3
Ciphers aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
#+END_SRC
CTRL-x CTRL-s to save, then CTRL-x CTRL-c to exit. Now clear out any pre-existing host keys and reconfigure the ssh server.
#+BEGIN_SRC: bash
rm /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
service ssh restart
#+END_SRC
To test the new settings log out by typing "exit" a couple of times, then log back in again with:
#+BEGIN_SRC: bash
ssh -vvv [email protected]
#+END_SRC
and check that some number of bits are set within a 4096 bit sized key:
#+BEGIN_SRC: bash
debug2: bits set: */4096
#+END_SRC
** Getting onto the web
Create a subdomain on [[http://freedns.afraid.org][freeDNS]]. You may need to click on "/subdomains/" a couple of times. FreeDNS is preferred because it is one of the few domain name providers which supports genuinely free (as in beer) accounts. So if your budget is tiny or non-existent you can still participate as a first class citizen of the internet. If you do have money to spend there is also a premium option.
Select "/dynamic DNS/" then click "/quick cron example/"
An example would look like:
#+BEGIN_SRC: bash
4,14,24,34,44,54 * * * * root sleep 29 ; /usr/bin/timeout 200 wget -O - https://free\ dns.afraid.org/dynamic/update.php?ABCKDNRCLFHENSLKNFEGSBFLFF== >> /dev/null 2>&1 &
#+END_SRC
It's important to make sure that you change the *http* to *https*, since this will help to prevent a potential attacker from hijacking your site and redirecting it to a fake version for the purposes of obtaining your login details.
Edit */etc/crontab* and append that to the top of the file, underneath the heading line which looks like this:
#+BEGIN_SRC: bash
# m h dom mon dow user command
#+END_SRC
In general the most frequently run crontab entries should be at the top. Then save and exit.
Via your router's firewall settings you should now open port 22 (secure shell). This will allow you to ssh into your BBB from any location - not just your own local network.
The freeDNS subdomain which you just created will hereafter just be refered to as "/your domain name/".
If you have multiple freedns subdomains then you may want to rationalise that a little within */etc/crontab*. Rather than listing them all individually create a script:
#+BEGIN_SRC: bash
editor /usr/bin/dynamicdns
#+END_SRC
Add however many freedns subdomains you have.
#+BEGIN_SRC: bash
#!/bin/bash
# subdomain name 1
wget -O - https://freedns.afraid.org/dynamic/update.php?<subdomain code 1>== >> /dev/null 2>&1
# subdomain name 2
wget -O - https://freedns.afraid.org/dynamic/update.php?<subdomain code 2>== >> /dev/null 2>&1
...
#+END_SRC
Save and exit, then make the script runnable and only readable by the root user.
#+BEGIN_SRC: bash
chmod 600 /usr/bin/dynamicdns
chmod +x /usr/bin/dynamicdns
#+END_SRC
Then within */etc/crontab*
#+BEGIN_SRC: bash
editor /etc/crontab
#+END_SRC
You can replace the multiple freedns entries with a single line:
#+BEGIN_SRC: bash
*/10 * * * * root /usr/bin/timeout 200 /usr/bin/dynamicdns
#+END_SRC
Then save and exit and restart the cron daemon.
#+BEGIN_SRC: bash
service cron restart
#+END_SRC
If you want to know what a typical /crontab/ file might look like then see the [[Example crontab file]]
** Set the host name
#+BEGIN_SRC: bash
editor /etc/hostname
#+END_SRC
CTRL-x CTRL-s to save, then CTRL-x CTRL-c to exit.
Also issue the command, replacing /mydomainname.com/ with your domain name.
#+BEGIN_SRC: bash
hostname mydomainname.com
#+END_SRC
You may also need to assign the same hostname separately via your router's web interface.
#+BEGIN_SRC: bash
editor /etc/hosts
#+END_SRC
Append the following, replacing /mydomainname.com/ with your domain name.
#+BEGIN_SRC: bash
127.0.1.1 mydomainname.com
#+END_SRC
If you then run the command:
#+BEGIN_SRC: bash
hostname -f
#+END_SRC
it should return your domain name.
** Install time synchronisation
#+BEGIN_VERSE
/You may delay, but time will not./
-- Benjamin Franklin
#+END_VERSE
It's convenient to have the clock on your server automatically synchronised with other servers on the internet so that you don't need to set the clock manually. The usual way of doing this is via [[https://en.wikipedia.org/wiki/Network_Time_Protocol][NTP]], but that method uses unencrypted signals which could potentially be interfered with in order to mess up your system. /tlsdate/ provides a slightly more secure way of setting the date and time over a SSL/TLS connection to a known good time source.
First install some prerequisites.
#+BEGIN_SRC: bash
apt-get install build-essential automake git pkg-config autoconf libtool libssl-dev
apt-get remove ntpdate
#+END_SRC
Now download and install tlsdate.
#+BEGIN_SRC: bash
mkdir ~/build
cd ~/build
git clone https://github.com/ioerror/tlsdate.git
cd ~/build/tlsdate
./autogen.sh
./configure
make
make install
#+END_SRC