beaglebone.txt 66KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162
  1. #+TITLE: FreedomBone
  2. #+AUTHOR: Bob Mottram
  3. #+EMAIL: bob@robotics.uk.to
  4. #+KEYWORDS: freedombox, debian, beaglebone, friendica, email, web server, home server, internet, censorship, surveillance
  5. #+DESCRIPTION: Turn the Beaglebone Black into a personal communications server
  6. #+BEGIN_CENTER
  7. *How to turn the Beaglebone Black into a FreedomBox-like personal communications server*
  8. #+END_CENTER
  9. #+BEGIN_CENTER
  10. [[[[file:images/freedombone.jpg]]]]
  11. #+END_CENTER
  12. #+BEGIN_CENTER
  13. Copyright (C) 2014 Bob Mottram
  14. 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.
  15. 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/fuzzgun/freedombone][Github]].
  16. #+END_CENTER
  17. * Introduction
  18. #+BEGIN_VERSE
  19. /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./
  20. -- Edward J. Snowden
  21. #+END_VERSE
  22. ** What is FreedomBone?
  23. 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.
  24. 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.
  25. ** Do I need any prior knowledge?
  26. 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.
  27. ** Why should I do this?
  28. 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).
  29. 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.
  30. 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.
  31. ** After it's installed will it need a lot of maintenance?
  32. 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.
  33. ** Is it secure?
  34. Nothing is totally secure or infallible. You could have the most secure technology and yet still use easy to guess passwords. 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.
  35. 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 an impenetrable information fortress.
  36. ** Will running a server all the time affect my electricity bill?
  37. 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.
  38. * Inventory
  39. These instructions assume that you have the following ingredients.
  40. ** A BeagleBone Black (BBB)
  41. 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.
  42. ** An internet connection
  43. 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.
  44. ** microSD card
  45. 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.
  46. 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.
  47. ** 5V/1A power supply
  48. 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.
  49. ** An ethernet patch cable
  50. Just an ordinary cat5 or cat6 cable that you can get from most electrical/computer stores.
  51. * Installing Debian onto the microSD card
  52. 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.
  53. Download the image.
  54. #+BEGIN_SRC: bash
  55. wget http://freedombone.uk.to/debian-7.2-console-armhf-2013-11-15.tar.xz
  56. #+END_SRC
  57. Verify it.
  58. #+BEGIN_SRC: bash
  59. md5sum debian-7.2-console-armhf-2013-11-15.tar.xz
  60. 0a448f55d14f64c5a7eb3d7cb2c54185 debian-7.2-console-armhf-2013-11-15.tar.xz
  61. #+END_SRC
  62. Uncompress it.
  63. #+BEGIN_SRC: bash
  64. tar xJf debian-7.2-console-armhf-2013-11-15.tar.xz
  65. cd debian-7.2-console-armhf-2013-11-15
  66. #+END_SRC
  67. Create the disk image, where sdX is the name of the flash drive (probably it will be sdb or sdc).
  68. #+BEGIN_SRC: bash
  69. sudo apt-get install u-boot-tools
  70. sudo ./setup_sdcard.sh --mmc /dev/sdX --uboot bone --swap-file 1024
  71. #+END_SRC
  72. Once completed then safely remove the microSD card via your file manager (usually right click and "safely remove" or "eject").
  73. * Setup
  74. #+BEGIN_VERSE
  75. /Build the tools for a future you would want to live in/
  76. -- Kurt Opsahl
  77. #+END_VERSE
  78. ** Things to be aware of
  79. *** A note on ssh
  80. 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:
  81. #+BEGIN_SRC: bash
  82. ssh-keygen -R <IP address>
  83. #+END_SRC
  84. *** Passwords
  85. 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.
  86. ** Initial
  87. Plug the microSD card into the BBB and Connect the USB cable to your laptop/desktop, then login via ssh.
  88. #+BEGIN_SRC: bash
  89. ssh debian@192.168.7.2
  90. #+END_SRC
  91. The default password is /temppwd/
  92. Then log in as root:
  93. #+BEGIN_SRC: bash
  94. su
  95. #+END_SRC
  96. The default password is /root/
  97. The first thing to do is to change the passwords from their defaults.
  98. #+BEGIN_SRC: bash
  99. passwd
  100. #+END_SRC
  101. 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.
  102. #+BEGIN_SRC: bash
  103. nano /etc/network/interfaces
  104. #+END_SRC
  105. The resulting interfaces file should look like this:
  106. #+BEGIN_SRC: bash
  107. # This file describes the network interfaces available on your system
  108. # and how to activate them. For more information, see interfaces(5).
  109. # The loopback network interface
  110. auto lo
  111. iface lo inet loopback
  112. # The primary network interface
  113. allow-hotplug eth0
  114. iface eth0 inet static
  115. address 192.168.1.60
  116. netmask 255.255.255.0
  117. gateway 192.168.1.254
  118. dns-nameservers 213.73.91.35 85.214.20.141
  119. # Example to keep MAC address between reboots
  120. #hwaddress ether DA:AD:CE:EF:CA:FE
  121. # WiFi Example
  122. #auto wlan0
  123. #iface wlan0 inet dhcp
  124. # wpa-ssid "essid"
  125. # wpa-psk "password"
  126. # Ethernet/RNDIS gadget (g_ether)
  127. # ... or on host side, usbnet and random hwaddr
  128. # Note on some boards, usb0 is automaticly setup with an init script
  129. # in that case, to completely disable remove file [run_boot-scripts] from the boot partition
  130. #iface usb0 inet static
  131. # address 192.168.7.2
  132. # netmask 255.255.255.0
  133. # network 192.168.7.0
  134. # gateway 192.168.7.1
  135. #+END_SRC
  136. CTRL-O followed by ENTER to save, then CTRL-X to exit.
  137. 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.
  138. "gateway 192.168.1.254" should be the IP address of the router.
  139. Note that setting the DNS servers with dns-nameservers is important because some home routers do not allow you to change the DNS settings.
  140. Edit resolv.conf.
  141. #+BEGIN_SRC: bash
  142. nano /etc/resolv.conf
  143. #+END_SRC
  144. It should look something like the following:
  145. #+BEGIN_SRC: bash
  146. domain localdomain
  147. search localdomain
  148. nameserver 213.73.91.35
  149. nameserver 85.214.20.141
  150. #+END_SRC
  151. CTRL-O followed by ENTER to save, then CTRL-X to exit.
  152. 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.
  153. 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".
  154. ** Add a user
  155. Ssh back in to the BBB and login as root. In this example the BBB's IP address is 192.168.1.60.
  156. #+BEGIN_SRC: bash
  157. ssh-keygen -f "/home/myusername/.ssh/known_hosts" -R 192.168.1.60
  158. ssh debian@192.168.1.60
  159. su
  160. #+END_SRC
  161. 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.
  162. #+BEGIN_SRC: bash
  163. adduser myusername
  164. #+END_SRC
  165. 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.
  166. Remove the default debian user.
  167. #+BEGIN_SRC: bash
  168. userdel -r debian
  169. #+END_SRC
  170. ** Text editor
  171. For an editor which is less erratic than vi when used within a remote console such as Terminator.
  172. #+BEGIN_SRC: bash
  173. apt-get update
  174. apt-get install emacs
  175. #+END_SRC
  176. ** Alter ssh configuration
  177. Altering the ssh configuration will make it a little more secure than the standard Debian settings.
  178. #+BEGIN_SRC: bash
  179. emacs /etc/ssh/sshd_config
  180. #+END_SRC
  181. Check the following values:
  182. #+BEGIN_SRC: bash
  183. PermitRootLogin no
  184. X11Forwarding no
  185. ServerKeyBits 4096
  186. Protocol 2
  187. PermitEmptyPasswords no
  188. StrictModes yes
  189. #+END_SRC
  190. Append the following:
  191. #+BEGIN_SRC: bash
  192. Ciphers aes256-ctr,aes192-ctr,aes128-ctr
  193. MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
  194. KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
  195. #+END_SRC
  196. CTRL-X CTRL-S to save, then CTRL-X CTRL-C to exit.
  197. #+BEGIN_SRC: bash
  198. service ssh restart
  199. #+END_SRC
  200. To test the new settings log out by typing "exit" a couple of times, then log back in again with:
  201. #+BEGIN_SRC: bash
  202. ssh -vvv myusername@192.168.1.60
  203. #+END_SRC
  204. and check that some number of bits are set within a 4096 bit sized key:
  205. #+BEGIN_SRC: bash
  206. debug2: bits set: */4096
  207. #+END_SRC
  208. ** Set the host name
  209. #+BEGIN_SRC: bash
  210. emacs /etc/hostname
  211. #+END_SRC
  212. CTRL-X CTRL-S to save, then CTRL-X CTRL-C to exit.
  213. also issue the command
  214. #+BEGIN_SRC: bash
  215. hostname /myhostname/
  216. #+END_SRC
  217. You may also need to assign the same hostname separately via your router's web interface.
  218. ** Install NTP
  219. To synchronise time.
  220. #+BEGIN_SRC: bash
  221. apt-get install ntp
  222. #+END_SRC
  223. ** Install fail2ban
  224. #+BEGIN_SRC: bash
  225. apt-get install fail2ban
  226. #+END_SRC
  227. ** Getting onto the web
  228. 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.
  229. Select "/dynamic DNS/" then click "/quick cron example/"
  230. An example would look like:
  231. #+BEGIN_SRC: bash
  232. 4,9,14,19,24,29,34,39,44,49,54,59 * * * * root sleep 29 ; wget -O - http://free\ dns.afraid.org/dynamic/update.php?ABCKDNRCLFHENSLKNFEGSBFLFF== >> /\ tmp/freedns_mysubdomain_us_to.log 2>&1 &
  233. #+END_SRC
  234. Edit /etc/crontab and append that to the end of the file.
  235. 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.
  236. ** install Email
  237. #+BEGIN_VERSE
  238. /If you knew what I know about email, you might not use it/
  239. -- Ladar Levison
  240. #+END_VERSE
  241. Email is not very secure, but its usefulness and ubiquity mean that it's likely to continue as a primary communications method for many years to come. You can encrypt the contents of email using PGP/GPG, but very few people do that and even for those that do the metadata (the From/To/CC/BCC) is always transmitted in the clear as a fundamental aspect of the protocol, allowing an attacker to easily construct detailed models of people's social network and life patterns even without knowing the content.
  242. Exim4 seems much easier to install and configure than Postfix.
  243. #+BEGIN_SRC: bash
  244. aptitude install exim4 sasl2-bin swaks libnet-ssleay-perl
  245. #+END_SRC
  246. You will be prompted to remove postfix. Say yes and yes again.
  247. #+BEGIN_SRC: bash
  248. dpkg-reconfigure exim4-config
  249. #+END_SRC
  250. Settings as follows:
  251. #+BEGIN_SRC: bash
  252. internet site
  253. System mail name: mydomainname.com
  254. IP addresses to listen on: blank
  255. Destinations: mydomainname.com
  256. Domains to relay mail: blank
  257. Smarthost Relay: 192.168.1.0/60 (the range of addresses on your LAN)
  258. Dial on demand = no
  259. Maildir format in home directory
  260. Split configuration = no
  261. Root and postmaster: root email
  262. #+END_SRC
  263. To test the installation:
  264. #+BEGIN_SRC: bash
  265. telnet 192.168.1.60 25
  266. ehlo xxx
  267. quit
  268. #+END_SRC
  269. #+BEGIN_SRC: bash
  270. emacs /etc/default/saslauthd
  271. #+END_SRC
  272. set START=yes then save and exit.
  273. #+BEGIN_SRC: bash
  274. /etc/init.d/saslauthd start
  275. emacs exim-gencert
  276. #+END_SRC
  277. #+BEGIN_SRC: bash
  278. #!/bin/sh -e
  279. if [ -n "$EX4DEBUG" ]; then
  280. echo "now debugging $0 $@"
  281. set -x
  282. fi
  283. DIR=/etc/exim4
  284. CERT=$DIR/exim.crt
  285. KEY=$DIR/exim.key
  286. # This exim binary was built with GnuTLS which does not support dhparams
  287. # from a file. See /usr/share/doc/exim4-base/README.Debian.gz
  288. #DH=$DIR/exim.dhparam
  289. if ! which openssl > /dev/null ;then
  290. echo "$0: openssl is not installed, exiting" 1>&2
  291. exit 1
  292. fi
  293. # valid for ten years
  294. DAYS=3650
  295. if [ "$1" != "--force" ] && [ -f $CERT ] && [ -f $KEY ]; then
  296. echo "[*] $CERT and $KEY exists!"
  297. echo " Use \"$0 --force\" to force generation!"
  298. exit 0
  299. fi
  300. if [ "$1" = "--force" ]; then
  301. shift
  302. fi
  303. #SSLEAY=/tmp/exim.ssleay.$$.cnf
  304. SSLEAY="$(tempfile -m600 -pexi)"
  305. cat > $SSLEAY <<EOM
  306. RANDFILE = $HOME/.rnd
  307. [ req ]
  308. default_bits = 4096
  309. default_keyfile = exim.key
  310. distinguished_name = req_distinguished_name
  311. [ req_distinguished_name ]
  312. countryName = Country Code (2 letters)
  313. countryName_default = GB
  314. countryName_min = 2
  315. countryName_max = 2
  316. stateOrProvinceName = State or Province Name (full name)
  317. localityName = Locality Name (eg, city)
  318. organizationName = Organization Name (eg, company; recommended)
  319. organizationName_max = 64
  320. organizationalUnitName = Organizational Unit Name (eg, section)
  321. organizationalUnitName_max = 64
  322. commonName = Server name (eg. ssl.domain.tld; required!!!)
  323. commonName_max = 64
  324. emailAddress = Email Address
  325. emailAddress_max = 40
  326. EOM
  327. echo "[*] Creating a self signed SSL certificate for Exim!"
  328. echo " This may be sufficient to establish encrypted connections but for"
  329. echo " secure identification you need to buy a real certificate!"
  330. echo " "
  331. echo " Please enter the hostname of your MTA at the Common Name (CN) prompt!"
  332. echo " "
  333. openssl req -config $SSLEAY -x509 -sha256 -newkey rsa:4096 -keyout $KEY -out $CERT -days $DAYS -nodes
  334. #see README.Debian.gz*# openssl dhparam -check -text -5 512 -out $DH
  335. rm -f $SSLEAY
  336. chown root:Debian-exim $KEY $CERT $DH
  337. chmod 640 $KEY $CERT $DH
  338. echo "[*] Done generating self signed certificates for exim!"
  339. echo " Refer to the documentation and example configuration files"
  340. echo " over at /usr/share/doc/exim4-base/ for an idea on how to enable TLS"
  341. echo " support in your mail transfer agent."
  342. #+END_SRC
  343. Save and exit
  344. #+BEGIN_SRC: bash
  345. chmod +x exim-gencert
  346. ./exim-gencert
  347. #+END_SRC
  348. This will generate the certificate used for email authentication. You will be asked for various details, the most important of which is the server name, which should be your domain name.
  349. #+BEGIN_SRC: bash
  350. emacs /etc/exim4/exim4.conf.template
  351. #+END_SRC
  352. Append the following:
  353. #+BEGIN_SRC: bash
  354. login_saslauthd_server:
  355. driver = plaintext
  356. public_name = LOGIN
  357. server_prompts = "Username:: : Password::"
  358. # don't send system passwords over unencrypted connections
  359. server_condition = ${if saslauthd{{$auth1}{$auth2}}{1}{0}}
  360. server_set_id = $auth1
  361. .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
  362. server_advertise_condition = ${if eq{$tls_cipher}{}{}{*}}
  363. .endif
  364. #+END_SRC
  365. Search for the line *.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME* and above it insert the line:
  366. #+BEGIN_SRC: bash
  367. MAIN_HARDCODE_PRIMARY_HOSTNAME = mydomainname.com
  368. #+END_SRC
  369. Save and exit.
  370. #+BEGIN_SRC: bash
  371. emacs /etc/exim4/exim4.conf.template
  372. #+END_SRC
  373. Add the line:
  374. #+BEGIN_SRC: bash
  375. MAIN_TLS_ENABLE = true
  376. #+END_SRC
  377. Save and exit.
  378. #+BEGIN_SRC: bash
  379. emacs /etc/default/exim4
  380. change SMTPLISTENEROPTIONS to:
  381. SMTPLISTENEROPTIONS='-oX 465:25 -oP /var/run/exim4/exim.pid'
  382. #+END_SRC
  383. save and exit
  384. #+BEGIN_SRC: bash
  385. emacs /etc/exim4/exim4.conf.template
  386. under the section "main/03_exim4-config_tlsoptions"
  387. Add the following:
  388. tls_on_connect_ports=465
  389. #+END_SRC
  390. save and exit
  391. #+BEGIN_SRC: bash
  392. adduser myusername sasl
  393. addgroup Debian-exim sasl
  394. /etc/init.d/exim4 restart
  395. mkdir /etc/skel/Maildir
  396. #+END_SRC
  397. ** Spam filtering
  398. #+BEGIN_SRC: bash
  399. apt-get install spamassassin exim4-daemon-heavy
  400. emacs /etc/default/spamassassin
  401. #+END_SRC
  402. Set ENABLED=1 then save and exit.
  403. #+BEGIN_SRC: bash
  404. emacs /etc/exim4/exim4.conf.template
  405. #+END_SRC
  406. uncomment or change according to your configuration
  407. #+BEGIN_SRC: bash
  408. # For spam scanning, there is a similar option that defines the interface to
  409. # SpamAssassin. You do not need to set this if you are using the default, which
  410. # is shown in this commented example. As for virus scanning, you must also
  411. # modify the acl_check_data access control list to enable spam scanning.
  412. spamd_address = 127.0.0.1 783
  413. #+END_SRC
  414. add spam header in the /acl_check_data/ section:
  415. #+BEGIN_SRC: bash
  416. ### acl/40_exim4-config_check_data
  417. #################################
  418. # This ACL is used after the contents of a message have been received. This
  419. # is the ACL in which you can test a message's headers or body, and in
  420. # particular, this is where you can invoke external virus or spam scanners.
  421. acl_check_data:
  422. ...
  423. ...
  424. ...
  425. # See the exim docs and the exim wiki for more suitable examples.
  426. #
  427. # warn
  428. # spam = Debian-exim:true
  429. # add_header = X-Spam_score: $spam_score\n\
  430. # X-Spam_score_int: $spam_score_int\n\
  431. # X-Spam_bar: $spam_bar\n\
  432. # X-Spam_report: $spam_report
  433. # put headers in all messages (no matter if spam or not)
  434. warn spam = nobody:true
  435. add_header = X-Spam-Score: $spam_score ($spam_bar)
  436. add_header = X-Spam-Report: $spam_report
  437. # add second subject line with *SPAM* marker when message
  438. # is over threshold
  439. warn spam = nobody
  440. add_header = Subject: ***SPAM (score:$spam_score)*** $h_Subject:
  441. #+END_SRC
  442. Save and exit.
  443. Then restart
  444. #+BEGIN_SRC: bash
  445. exit
  446. emacs ~/.procmailrc
  447. #+END_SRC
  448. The text should look like the following.
  449. #+BEGIN_SRC: sh
  450. MAILDIR=$HOME/Maildir
  451. DEFAULT=$MAILDIR/
  452. LOGFILE=$HOME/log/procmail.log
  453. LOGABSTRACT=all
  454. # get spamassassin to check emails
  455. :0fw: .spamassassin.lock
  456. * < 256000
  457. | spamc
  458. # strong spam are discarded
  459. :0
  460. * ^X-Spam-Level: \*\*\*\*\*\*
  461. /dev/null
  462. # weak spam are kept just in case - clear this out every now and then
  463. :0
  464. * ^X-Spam-Level: \*\*\*\*\*
  465. .0-spam/
  466. # if it wasn't detected as spam, but is to a fake address, then we
  467. # know it is spam, so learn from that
  468. :0
  469. * !^(From|To|cc|bcc)[ :].*($USER|root|webmaster|admin|postmaster).*@acooke\.org
  470. * !^(From|To|cc|bcc)[ :].*@isti\.com
  471. # add mailing lists below
  472. * !^From[ :].*(snowmail_daily@...|Section@...|rforno@...|alert@...).*
  473. {
  474. # save in case of screw-ups, mailing lists, etc
  475. :0 c
  476. .0-spam/
  477. :0
  478. .learn-spam/
  479. }
  480. # otherwise, marginal spam goes here for revision
  481. :0
  482. * ^X-Spam-Level: \*\*
  483. .spam/
  484. #+END_SRC
  485. Save and exit.
  486. #+BEGIN_SRC: bash
  487. su
  488. emacs /usr/bin/filterspam
  489. #+END_SRC
  490. Add the following contents:
  491. #+BEGIN_SRC: bash
  492. #!/bin/bash
  493. USERNAME=$1
  494. MAILDIR=/home/$USERNAME/Maildir/.learn-spam
  495. if [ ! -d "$MAILDIR" ]; then
  496. exit
  497. fi
  498. for f in `ls $MAILDIR/cur`
  499. do
  500. spamc -L spam < "$MAILDIR/cur/$f" > /dev/null
  501. rm "$MAILDIR/cur/$f"
  502. done
  503. for f in `ls $MAILDIR/new`
  504. do
  505. spamc -L spam < "$MAILDIR/new/$f" > /dev/null
  506. rm "$MAILDIR/new/$f"
  507. done
  508. #+END_SRC
  509. Save and exit.
  510. #+BEGIN_SRC: bash
  511. emacs /usr/bin/filterham
  512. #+END_SRC
  513. Add the following contents:
  514. #+BEGIN_SRC: bash
  515. #!/bin/bash
  516. USERNAME=$1
  517. MAILDIR=/home/$USERNAME/Maildir/.learn-ham
  518. if [ ! -d "$MAILDIR" ]; then
  519. exit
  520. fi
  521. for f in `ls $MAILDIR/cur`
  522. do
  523. spamc -L ham < "$MAILDIR/cur/$f" > /dev/null
  524. rm "$MAILDIR/cur/$f"
  525. done
  526. for f in `ls $MAILDIR/new`
  527. do
  528. spamc -L ham < "$MAILDIR/new/$f" > /dev/null
  529. rm "$MAILDIR/new/$f"
  530. done
  531. #+END_SRC
  532. Save and exit.
  533. #+BEGIN_SRC: bash
  534. emacs /etc/crontab
  535. #+END_SRC
  536. Append the following, replacing *myusername* with your username.
  537. #+BEGIN_SRC: bash
  538. */3 * * * * root /usr/bin/filterspam myusername
  539. */3 * * * * root /usr/bin/filterham myusername
  540. #+END_SRC
  541. Save and exit.
  542. #+BEGIN_SRC: bash
  543. chmod 655 /usr/bin/filterspam /usr/bin/filterham
  544. service spamassassin restart
  545. service exim4 restart
  546. service cron restart
  547. #+END_SRC
  548. ** Install dovecot
  549. #+BEGIN_SRC: bash
  550. aptitude -y install dovecot-common dovecot-pop3d dovecot-imapd
  551. #+END_SRC
  552. #+BEGIN_SRC: bash
  553. emacs /etc/dovecot/dovecot.conf
  554. #+END_SRC
  555. # line 26: change ( if not listen IPv6 port )
  556. listen = *
  557. #+BEGIN_SRC: bash
  558. emacs /etc/dovecot/conf.d/10-auth.conf
  559. #+END_SRC
  560. # line 9: uncomment and change ( allow plain text auth )
  561. disable_plaintext_auth = no
  562. # line 99: add
  563. auth_mechanisms = plain login
  564. #+BEGIN_SRC: bash
  565. emacs /etc/dovecot/conf.d/10-mail.conf
  566. #+END_SRC
  567. # line 30: uncomment and add
  568. mail_location = maildir:~/Maildir
  569. #+BEGIN_SRC: bash
  570. service dovecot restart
  571. #+END_SRC
  572. ** Mutt email client
  573. #+BEGIN_SRC: bash
  574. apt-get install mutt lynx abook
  575. exit
  576. mkdir ~/.mutt
  577. echo "text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^ //’; copiousoutput; needsterminal; nametemplate=%s.html" > ~/.mutt/mailcap
  578. #+END_SRC
  579. Save and exit.
  580. #+BEGIN_SRC: bash
  581. su
  582. emacs /etc/Muttrc
  583. #+END_SRC
  584. Append the following:
  585. #+BEGIN_SRC: bash
  586. set mbox_type=Maildir
  587. set folder="~/Maildir"
  588. set mask="!^\\.[^.]"
  589. set mbox="~/Maildir"
  590. set record="+.Sent"
  591. set postponed="+.Drafts"
  592. set spoolfile="~/Maildir"
  593. auto_view text/x-vcard text/html text/enriched
  594. set editor="emacsclient %s"
  595. macro index S "<tag-prefix><save-message>=.learn-spam<enter>" "move to learn-spam"
  596. macro pager S "<save-message>=.learn-spam<enter>" "move to learn-spam"
  597. macro index H "<tag-prefix><copy-message>=.learn-ham<enter>" "copy to learn-ham"
  598. macro pager H "<copy-message>=.learn-ham<enter>" "copy to learn-ham"
  599. #+END_SRC
  600. Save and exit.
  601. #+BEGIN_SRC: bash
  602. emacs /etc/mail/spamassassin/local.cf
  603. #+END_SRC
  604. Uncomment *use_bayes*, *bayes_auto_learn*
  605. Save and exit, then run:
  606. #+BEGIN_SRC: bash
  607. service spamassassin restart
  608. #+END_SRC
  609. Now to add an address book:
  610. #+BEGIN_SRC: bash
  611. emacs ~/.muttrc
  612. #+END_SRC
  613. Append the following:
  614. #+BEGIN_SRC: bash
  615. set alias_file=~/.mutt-alias
  616. source ~/.mutt-alias
  617. set query_command= "abook --mutt-query '%s'"
  618. macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
  619. #+END_SRC
  620. Then save and exit.
  621. #+BEGIN_SRC: bash
  622. touch ~/.mutt-alias
  623. #+END_SRC
  624. Finally you can then type *mutt* to get access to your email. Hence as a fallback, or if you prefer as the primary way of accessing email, you can ssh into the BBB and use the mutt command line email client. Ssh clients are available for all operating systems, and also you should be reasonably protected from passive surveillance between wherever you are and the BBB (although not between the BBB and the wider internet), which can be useful if you are for example using an Android tablet from a cafe or railway station.
  625. To use the address book system open an email and then to add the sender to the address list press the A key. It will ask you for an alias which may be used the next time you want to send a mail. Alternatively you may just edit the *~/.mutt-alias* file directly to add email addresses.
  626. Some useful keys to know are:
  627. | ESC / | Search for text within message contents |
  628. | "/" | Search for text within headers |
  629. | * | Move to the last message |
  630. | TAB | Move to the next unread message |
  631. | d | Delete a message |
  632. | u | Undelete a mail which is pending deletion |
  633. | $ | Delete all messages selected and check for new messages |
  634. | a | Add to the address book |
  635. | m | Send a new mail |
  636. | S | Mark a message as spam |
  637. | H | Mark a message as ham |
  638. ** K9 email client
  639. *** Incoming server settings
  640. * Select settings/account settings
  641. * Select Fetching mail/incoming server
  642. * Enter your username and password
  643. * IMAP server should be your domain name
  644. * Security: SSL/TLS (always)
  645. * Authentication: Plain
  646. * Port: 993
  647. *** Outgoing (SMTP) server settings
  648. * Select settings/account settings
  649. * Select Sending mail/outgoing server
  650. * Set SMTP server to your domain name
  651. * Set Security to SSL/TLS (always)
  652. * Set port to 465
  653. ** Setting up a web site
  654. Edit the apache configuration so that it doesn't run out of memory if there are a lot of connections.
  655. #+BEGIN_SRC: bash
  656. su
  657. emacs /etc/apache2/apache2.conf
  658. #+END_SRC
  659. Search for MaxClients and replace the value with 20 then save and exit.
  660. In the examples below replace mydomainname.com with your own domain.
  661. #+BEGIN_SRC: bash
  662. export HOSTNAME=mydomainname.com
  663. mkdir /var/www/$HOSTNAME
  664. mkdir /var/www/$HOSTNAME/htdocs
  665. emacs /etc/apache2/sites-available/$HOSTNAME
  666. #+END_SRC
  667. The Apache configuration for the site should look something like the following. Replaye mydonainname with the site domain name.
  668. #+BEGIN_SRC: bash
  669. <VirtualHost *:80>
  670. ServerAdmin myusername@mydomainname.com
  671. ServerName mydomainname.com
  672. DocumentRoot /var/www/mydomainname.com/htdocs
  673. <Directory />
  674. Options FollowSymLinks
  675. AllowOverride All
  676. </Directory>
  677. <Directory /var/www/mydomainname.com/htdocs/>
  678. Options All
  679. AllowOverride All
  680. Order allow,deny
  681. allow from all
  682. </Directory>
  683. # Don't serve .php~ or .php# files created by emacs
  684. <Files ~ "(^#.*#|~|\.sw[op])$">
  685. Order allow,deny
  686. Deny from all
  687. </Files>
  688. <IfModule headers_module>
  689. Header set X-Content-Type-Options nosniff
  690. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  691. Header set Pragma no-cache
  692. </IfModule>
  693. <Files .htaccess>
  694. deny from all
  695. </Files>
  696. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  697. <Directory "/usr/lib/cgi-bin">
  698. AllowOverride All
  699. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  700. Order allow,deny
  701. Allow from all
  702. </Directory>
  703. ErrorLog ${APACHE_LOG_DIR}/error.log
  704. # Possible values include: debug, info, notice, warn, error, crit,
  705. # alert, emerg.
  706. LogLevel warn
  707. CustomLog ${APACHE_LOG_DIR}/access.log combined
  708. </VirtualHost>
  709. <IfModule mod_ssl.c>
  710. <VirtualHost *:443>
  711. ServerAdmin myusername@mydomainname.com
  712. ServerName mydomainname.com
  713. DocumentRoot /var/www/mydomainname.com/htdocs
  714. <Directory />
  715. Options FollowSymLinks
  716. AllowOverride All
  717. </Directory>
  718. <Directory /var/www/mydomainname.com/htdocs/>
  719. Options All
  720. AllowOverride All
  721. Order allow,deny
  722. allow from all
  723. </Directory>
  724. # Don't serve .php~ or .php# files created by emacs
  725. <Files ~ "(^#.*#|~|\.sw[op])$">
  726. Order allow,deny
  727. Deny from all
  728. </Files>
  729. <IfModule headers_module>
  730. Header set X-Content-Type-Options nosniff
  731. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  732. Header set Pragma no-cache
  733. </IfModule>
  734. <Files .htaccess>
  735. deny from all
  736. </Files>
  737. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  738. <Directory "/usr/lib/cgi-bin">
  739. AllowOverride All
  740. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  741. Order allow,deny
  742. Allow from all
  743. </Directory>
  744. ErrorLog ${APACHE_LOG_DIR}/error.log
  745. # Possible values include: debug, info, notice, warn, error, crit,
  746. # alert, emerg.
  747. LogLevel warn
  748. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  749. # SSL Engine Switch:
  750. # Enable/Disable SSL for this virtual host.
  751. SSLEngine on
  752. # A self-signed certificate
  753. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  754. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  755. # Options based on bettercrypto.org
  756. SSLProtocol All -SSLv2 -SSLv3
  757. SSLHonorCipherOrder On
  758. SSLCompression off
  759. # Add six earth month HSTS header for all users ...
  760. Header add Strict-Transport-Security "max-age=15768000"
  761. # If you want to protect all subdomains , use the following header
  762. # ALL subdomains HAVE TO support https if you use this !
  763. # Strict-Transport-Security: max-age=15768000 ; includeSubDomains
  764. # SSLCipherSuite ’EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA’
  765. # SSL Engine Options:
  766. # Set various options for the SSL engine.
  767. # o FakeBasicAuth:
  768. # Translate the client X.509 into a Basic Authorisation. This means that
  769. # the standard Auth/DBMAuth methods can be used for access control. The
  770. # user name is the `one line' version of the client's X.509 certificate.
  771. # Note that no password is obtained from the user. Every entry in the user
  772. # file needs this password: `xxj31ZMTZzkVA'.
  773. # o ExportCertData:
  774. # This exports two additional environment variables: SSL_CLIENT_CERT and
  775. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  776. # server (always existing) and the client (only existing when client
  777. # authentication is used). This can be used to import the certificates
  778. # into CGI scripts.
  779. # o StdEnvVars:
  780. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  781. # Per default this exportation is switched off for performance reasons,
  782. # because the extraction step is an expensive operation and is usually
  783. # useless for serving static content. So one usually enables the
  784. # exportation for CGI and SSI requests only.
  785. # o StrictRequire:
  786. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  787. # under a "Satisfy any" situation, i.e. when it applies access is denied
  788. # and no other module can change it.
  789. # o OptRenegotiate:
  790. # This enables optimized SSL connection renegotiation handling when SSL
  791. # directives are used in per-directory context.
  792. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  793. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  794. SSLOptions +StdEnvVars
  795. </FilesMatch>
  796. <Directory /usr/lib/cgi-bin>
  797. SSLOptions +StdEnvVars
  798. </Directory>
  799. # SSL Protocol Adjustments:
  800. # The safe and default but still SSL/TLS standard compliant shutdown
  801. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  802. # the close notify alert from client. When you need a different shutdown
  803. # approach you can use one of the following variables:
  804. # o ssl-unclean-shutdown:
  805. # This forces an unclean shutdown when the connection is closed, i.e. no
  806. # SSL close notify alert is send or allowed to received. This violates
  807. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  808. # this when you receive I/O errors because of the standard approach where
  809. # mod_ssl sends the close notify alert.
  810. # o ssl-accurate-shutdown:
  811. # This forces an accurate shutdown when the connection is closed, i.e. a
  812. # SSL close notify alert is send and mod_ssl waits for the close notify
  813. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  814. # practice often causes hanging connections with brain-dead browsers. Use
  815. # this only for browsers where you know that their SSL implementation
  816. # works correctly.
  817. # Notice: Most problems of broken clients are also related to the HTTP
  818. # keep-alive facility, so you usually additionally want to disable
  819. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  820. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  821. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  822. # "force-response-1.0" for this.
  823. BrowserMatch "MSIE [2-6]" \
  824. nokeepalive ssl-unclean-shutdown \
  825. downgrade-1.0 force-response-1.0
  826. # MSIE 7 and newer should be able to use keepalive
  827. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  828. </VirtualHost>
  829. </IfModule>
  830. #+END_SRC
  831. Then to enable the site:
  832. #+BEGIN_SRC: bash
  833. a2ensite
  834. a2dissite default
  835. a2dissite default-ssl
  836. a2enmod rewrite
  837. a2enmod headers
  838. #+END_SRC
  839. Ensure that "NameVirtualHost *:443" is added to /etc/apache2/ports.conf. It should look something like the following:
  840. #+BEGIN_SRC: bash
  841. NameVirtualHost *:80
  842. Listen 80
  843. <IfModule mod_ssl.c>
  844. NameVirtualHost *:443
  845. Listen 443
  846. </IfModule>
  847. <IfModule mod_gnutls.c>
  848. NameVirtualHost *:443
  849. Listen 443
  850. </IfModule>
  851. #+END_SRC
  852. Create a self-signed certificate. The passphrase isn't important and will be removed, so make it easy (such as "password").
  853. #+BEGIN_SRC: bash
  854. emacs makecert
  855. #+END_SRC
  856. Enter the following:
  857. #+BEGIN_SRC: bash
  858. #!/bin/bash
  859. HOSTNAME=$1
  860. openssl genrsa -des3 -out $HOSTNAME.key 1024
  861. openssl req -new -x509 -nodes -sha1 -days 3650 -key $HOSTNAME.key -out $HOSTNAME.crt
  862. openssl rsa -in $HOSTNAME.key -out $HOSTNAME.new.key
  863. cp $HOSTNAME.new.key $HOSTNAME.key
  864. rm $HOSTNAME.new.key
  865. cp $HOSTNAME.key /etc/ssl/private
  866. chmod 400 /etc/ssl/private/$HOSTNAME.key
  867. cp $HOSTNAME.crt /etc/ssl/certs
  868. shred -zu $HOSTNAME.key $HOSTNAME.crt
  869. a2enmod ssl
  870. service apache2 restart
  871. #+END_SRC
  872. Save and exit.
  873. #+BEGIN_SRC: bash
  874. chmod +x makecert
  875. ./makecert mydomainname.com
  876. #+END_SRC
  877. Enter some trivial password for the key file. The password will be removed as part of the makecert script. Note that leaving a password on the key file would mean that after a power cycle the apache server will not be able to boot properly (it would wait indefinitely for a password to be manually entered) and would look as if it had crashed.
  878. If all has gone well then there should be no warnings or errors after you run the service restart command. After that you should enable ports 80 (HTTP) and 443 (HTTPS) on your internet router/firewall, such that they are redirected to the BBB.
  879. ** Social Networking
  880. #+BEGIN_VERSE
  881. /Facebook is not your friend, it is a surveillance engine./
  882. -- Richard Stallman, Free Software Foundation
  883. #+END_VERSE
  884. *** Friendica
  885. **** Installation
  886. #+BEGIN_SRC: bash
  887. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  888. #+END_SRC
  889. Enter an admin password for MySQL.
  890. Create a mysql database.
  891. #+BEGIN_SRC: bash
  892. mysql -u root -p
  893. create database friendica;
  894. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'password';
  895. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  896. quit
  897. #+END_SRC
  898. You may need to fix Git SSL problems.
  899. #+BEGIN_SRC: bash
  900. git config --global http.sslVerify true
  901. apt-get install ca-certificates
  902. cd ~/
  903. emacs .gitconfig
  904. #+END_SRC
  905. The .gitconfig file should look something like this:
  906. #+BEGIN_SRC: bash
  907. [http]
  908. sslVerify = true
  909. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  910. [user]
  911. email = myusername@mydomainname.com
  912. name = yourname
  913. #+END_SRC
  914. Get the source code.
  915. #+BEGIN_SRC: bash
  916. export HOSTNAME=mydomainname.com
  917. cd /var/www/$HOSTNAME
  918. mv htdocs htdocs_old
  919. git clone https://github.com/friendica/friendica.git htdocs
  920. chmod -R 755 htdocs
  921. chown -R www-data:www-data htdocs
  922. chown -R www-data:www-data htdocs/view/smarty3
  923. git clone https://github.com/friendica/friendica-addons.git htdocs/addon
  924. #+END_SRC
  925. Now visit the URL of your site and you should be taken through the rest of the installation procedure. If you have trouble with "allow override" ensure that "AllowOverride" is set to "all" in your Apache settings for the site (within /etc/apache2/sites-available) and then restart the apache2 service.
  926. Install the poller.
  927. #+BEGIN_SRC
  928. emacs /etc/crontab
  929. #+END_SRC
  930. and append the following, changing mydomainname.com to whatever your domain is.
  931. #+BEGIN_SRC
  932. */10 * * * * root cd /var/www/mydomainname.com/htdocs; /usr/bin/php include/poller.php
  933. #+END_SRC
  934. Save and exit, then restart cron.
  935. #+BEGIN_SRC: bash
  936. service cron restart
  937. #+END_SRC
  938. **** Backups
  939. Make sure that the database gets backed up. By using cron if anything goes wrong then you should be able to recover the database either from the previous day or the previous week.
  940. #+BEGIN_SRC: bash
  941. emacs /etc/cron.daily/friendicabackup
  942. #+END_SRC
  943. Enter the following
  944. #+BEGIN_SRC: bash
  945. #!/bin/sh
  946. MYSQL_PASSWORD=<mysql root password>
  947. umask 0077
  948. # Backup the database
  949. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_daily.sql
  950. # Make the backup readable only by root
  951. chmod 600 /var/backups/friendica_daily.sql
  952. #+END_SRC
  953. Save and exit.
  954. #+BEGIN_SRC: bash
  955. chmod 600 /etc/cron.daily/friendicabackup
  956. chmod +x /etc/cron.daily/friendicabackup
  957. emacs /etc/cron.weekly/friendicabackup
  958. #+END_SRC
  959. Enter the following
  960. #+BEGIN_SRC: bash
  961. #!/bin/sh
  962. MYSQL_PASSWORD=<mysql root password>
  963. umask 0077
  964. # Backup the database
  965. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_weekly.sql
  966. # Make the backup readable only by root
  967. chmod 600 /var/backups/friendica_weekly.sql
  968. #+END_SRC
  969. Save and exit.
  970. #+BEGIN_SRC: bash
  971. chmod 600 /etc/cron.weekly/friendicabackup
  972. chmod +x /etc/cron.weekly/friendicabackup
  973. #+END_SRC
  974. **** Recommended configuration
  975. **** Admin
  976. To get to the admin settings you will need to be logged in with the admin email address which you specified at the beginning of the installation procedure. Depending upon the theme which you're using "/admin/" will be available either as an icon or on a drop down menu.
  977. Under the *plugins* section the main one which you may wish to enable is the NSFW plugin. With that enabled if a post contans the #NSFW tag then it will appear minimised by default and you will need to click a button to open it.
  978. Under the *themes* section select a few themes, including mobile themes which are suitable for phones or tablets.
  979. Under the *site* section give your Friendica node a name other than "/my friend network/", you can change the icon and banner text and set the default mobile theme typically to /frost-mobile/. If you don't want your node to host a lot of accounts for people you don't know then you may want to set the register policy to "/requires approval/". For security it's probably a good idea only to host accounts for people who you actually know, rather than random strangers. Also be aware that the Beaglebone does not have a great deal of computational power or bandwidth and will not function well if there are hundreds of users using your node. If you're not federating with Diaspora or other sites then you may wish to select "/only allow Friendica contacts/". That improves the security of the system, since communication between Friendica nodes is always encrypted separately and in addition to the usual SSL encryption layer - which makes life interesting for the Surveillance State and at least keeps those cryptanalysts employed.
  980. It's probably a good idea to enable "/private posts by default for new users/" and also "/don't include post content in email notifications/". Since traditional email isn't a secure system and is easily vulnerable to attack by systems such as [[https://en.wikipedia.org/wiki/XKeyscore][Xkeyscore]].
  981. **** Settings
  982. Each user has their own customisable settings, typically available either via an icon or by an entry on a drop down menu.
  983. Under *additional features* enable "/richtext editor/", "/post preview/", "/group filter/", "/network filter/", "/edit sent posts/" and "/dislike posts/".
  984. Under *display settings* select your desktop and mobile themes.
  985. Once you have connected to enough friends it's also a good idea to use the "/export personal data/" option from here. This will save a file to your local system, which you can import into another friendica node if necessary.
  986. **** To access from an Android device
  987. **** App
  988. Open a browser on your device and go to https://f-droid.org/ then download and install the F-Droid apk. If you then open F-Droid you can search for and install the Friendica app.
  989. If you are using a self-signed certificate then at the login screen scroll down to the bottom, select the SSL settings then scroll down and disable SSL certificate checks. You will then be able to log in using https, which at least gives you some protection via the encryption.
  990. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  991. **** Mobile Theme
  992. Another way to access Friendica from a mobile device is to just use the web browser. If you have selected a mobile theme within your settings then when viewing from an Android system the mobile theme will be displayed.
  993. ** Install a Blog
  994. Wordpress is the most popular blogging platform, but in practice I found it to be high maintenance with frequent security updates and breakages. More practical for a home server is Flatpress. Flatpress doesn't use a MySql database, just text files, and so is easy to relocate or reinstall.
  995. See the [[Setting up a web site]] section of this document for details of how to configure the web server for your blog's domain.
  996. Download flatpress.
  997. #+BEGIN_SRC: bash
  998. wget http://freedombone.uk.to/flatpress.tar.gz
  999. #+END_SRC
  1000. Verify the download:
  1001. #+BEGIN_SRC: bash
  1002. md5sum flatpress.tar.gz
  1003. 6ad5c230a5cb1ac096ff657f1b138cc7 flatpress.tar.gz
  1004. #+END_SRC
  1005. Extract and install it.
  1006. #+BEGIN_SRC: bash
  1007. tar -xzvf flatpress.tar.gz
  1008. cd flatpress-*
  1009. cp -r * /var/www/$HOSTNAME/htdocs
  1010. rm -rf flatpress-*
  1011. rm -f flatpress.tar.gz
  1012. #+END_SRC
  1013. Now visit your blog and follow the setup instructions, which are quite minimal. Various themes and addons are available from the Flatpress web site, http://www.flatpress.org
  1014. ** Install a VoIP server
  1015. #+BEGIN_VERSE
  1016. /Our core principles, whether in software or sovereignty, have always been about freedom and dignity, for all people, on an equal basis/
  1017. -- David Sugar, GNU Telephony
  1018. #+END_VERSE
  1019. *** The server
  1020. Sipwitch is like an introduction service or phone book for SIP VoIP clients. Once introduced the clients can then talk directly, and this means that sipwitch is very lightweight and can run on low power systems such as the BBB.
  1021. Edit your package sources:
  1022. #+BEGIN_SRC: bash
  1023. emacs /etc/apt/sources.list
  1024. #+END_SRC
  1025. Append the following line:
  1026. #+BEGIN_SRC: bash
  1027. deb http://dev.gnutelephony.org/archive/ wheezy/
  1028. #+END_SRC
  1029. Save and exit.
  1030. To load the repository the first time after adding it to the sources.list, since you do not have the verification keys already installed yet. Then do
  1031. #+BEGIN_SRC: bash
  1032. apt-get install gnutelephony-keyring
  1033. #+END_SRC
  1034. After that it will be happy to accept it as a signed repository. The verification keys can also be directly fetched with
  1035. #+BEGIN_SRC: bash
  1036. wget http://dev.gnutelephony.org/archive/wheezy/public.key
  1037. #+END_SRC
  1038. and manually added instead with
  1039. #+BEGIN_SRC: bash
  1040. apt-key add public.key
  1041. #+END_SRC
  1042. To make sure you have all dependencies, do
  1043. #+BEGIN_SRC: bash
  1044. apt-get update;apt-get dist-upgrade
  1045. #+END_SRC
  1046. Before we install anything, let's inspect what is available to us by using
  1047. #+BEGIN_SRC: bash
  1048. dpkg -l sipwitch
  1049. #+END_SRC
  1050. To see the main application. The columns will indicate if the package is installed, which version and a description of the package. Then do
  1051. #+BEGIN_SRC: bash
  1052. dpkg -l sipwitch-*
  1053. #+END_SRC
  1054. to see available supporting applications and plugins. Again, the columns will indicate if the package is installed, which version and a description of each of these.
  1055. To install only the main application, do
  1056. #+BEGIN_SRC: bash
  1057. apt-get install sipwitch
  1058. #+END_SRC
  1059. and to install all supporting plugins:
  1060. #+BEGIN_SRC: bash
  1061. apt-get install sipwitch-plugin-scripting sipwitch-plugin-subscriber sipwitch-plugin-forward sipwitch-plugin-zeroconf
  1062. #+END_SRC
  1063. Add your user into the sipwitch group
  1064. #+BEGIN_SRC: bash
  1065. groupadd sipwitch
  1066. groupadd sipusers
  1067. usermod -aG sipwitch myusername
  1068. usermod -aG sipusers myusername
  1069. #+END_SRC
  1070. Then edit the configuration
  1071. #+BEGIN_SRC: bash
  1072. emacs /etc/sipwitch.conf
  1073. #+END_SRC
  1074. Change the *mapped* value from 200 to 20, since we don't want to be serving huge numbers of calls.
  1075. Alter the *range* value to 10, since we don't need a large number of extensions. This will mean that exension numbers 200 to 209 are available.
  1076. Do not set the *realm* value, as doing so seems to prevent the server from working.
  1077. Save and exit.
  1078. Create a digest string for your username:
  1079. #+BEGIN_SRC: bash
  1080. sipwitch digest myusername
  1081. #+END_SRC
  1082. Make a note of the resulting string because you're going to use it in the users file you'll now create.
  1083. #+BEGIN_SRC: bash
  1084. export HOSTNAME=mydomainname.com
  1085. touch /etc/sipwitch.d/$HOSTNAME.xml
  1086. chmod 600 /etc/sipwitch.d/$HOSTNAME.xml
  1087. emacs /etc/sipwitch.d/$HOSTNAME.xml
  1088. #+END_SRC
  1089. It should look something like the following:
  1090. #+BEGIN_SRC: bash
  1091. <provision>
  1092. <user id="myusername">
  1093. <digest>yourdigeststring</digest>
  1094. <extension>201</extension>
  1095. <display>Your full name</display>
  1096. </user>
  1097. </provision>
  1098. #+END_SRC
  1099. Save and exit. Now edit the configuration.
  1100. #+BEGIN_SRC: bash
  1101. emacs /etc/default/sipwitch
  1102. #+END_SRC
  1103. Change "desktop" to "server", then save and exit.
  1104. Update the IP settings:
  1105. #+BEGIN_SRC: bash
  1106. iptables -A INPUT -p tcp --dport 5060 -j ACCEPT
  1107. iptables -A INPUT -p udp --dport 5060 -j ACCEPT
  1108. iptables -A INPUT -p tcp --dport 5061 -j ACCEPT
  1109. iptables -A INPUT -p udp --dport 5061 -j ACCEPT
  1110. iptables-save
  1111. #+END_SRC
  1112. Test that it's working:
  1113. #+BEGIN_SRC: bash
  1114. pkill -9 sipw
  1115. sipw -x9 -f
  1116. #+END_SRC
  1117. Then try to register with the server using a SIP client (such as Jitsi). If everything worked then use CTRL-C to exit. Then start the service.
  1118. #+BEGIN_SRC: bash
  1119. service sipwitch start
  1120. #+END_SRC
  1121. *** Clients
  1122. **** Jitsi
  1123. Download the latst version from https://jitsi.org/index.php/Main/Download
  1124. TODO
  1125. **** Twinkle client
  1126. The client should have a user profile as following:
  1127. The "user name" is the xxx id used in the <user id="xxx"> entry of /etc/sipwitch.conf
  1128. The "domain" is the yyy domain in the main config <stack><domain>yyy entry of /etc/sipwitch.conf
  1129. The SIP Authentication should have:
  1130. realm = realm as set in <registry><realm> of /etc/sipwitch.conf
  1131. authentication name = <user id="xx"> entry, same as "User Name" field.
  1132. password = value of <secret>zzz in <user> entry of /etc/sipwitch.conf
  1133. Under security tab, set "Enable ZRTP/SRTP encryption"
  1134. **** Android
  1135. TODO
  1136. CSipSimple?
  1137. ** Install an IRC server
  1138. #+BEGIN_SRC: bash
  1139. apt-get install ircd-hybrid irssi
  1140. emacs /etc/ircd-hybrid/ircd.conf
  1141. #+END_SRC
  1142. Set *name* to the name of your server, and set a description.
  1143. Set a *network_name* and *network_desc*.
  1144. Set max_clients to 20.
  1145. Within the admin section set your *name* and *email*.
  1146. Within the *listen* section set host to your fixed IP address (in the earlier
  1147. sections it was 192.168.1.60).
  1148. Within the *auth* section set user = "*@192.168.1.60" - or whatever the fixed IP address of the BBB is on your network.
  1149. Save and exit.
  1150. #+BEGIN_SRC: bash
  1151. service ircd-hybrid restart
  1152. #+END_SRC
  1153. Try to connect to the IRC and identify yourself as an operator.
  1154. In irssi:
  1155. #+BEGIN_SRC
  1156. /connect mydomainname.com
  1157. /join #mychannel
  1158. /msg -servername chanserv REGISTER #mychannel channelpassword
  1159. /msg -servername chanserv set #mychannel mlock +k channelpassword
  1160. #+END_SRC
  1161. ** Install Gopher
  1162. Gopher is an old internet protocol which originated a few years before the web and is purely text based. It can be quite fun to build a gopher site and browse the gopherverse. One thing to keep in mind is that there is no security with gopher, so any text transmitted is trivially interceptable by systems such as [[https://en.wikipedia.org/wiki/XKeyscore][Xkeyscore]] or deep packet inspection.
  1163. To set up a gopher server:
  1164. #+BEGIN_SRC: bash
  1165. apt-get install build-essential
  1166. wget http://freedombone.uk.to/geomyidae-current.tgz
  1167. #+END_SRC
  1168. Verify the download:
  1169. #+BEGIN_SRC: bash
  1170. md5sum geomyidae-current.tgz
  1171. 3d8bb8601f37ca953b00fc2445ab5abe geomyidae-current.tgz
  1172. #+END_SRC
  1173. Then extract and install it.
  1174. #+BEGIN_SRC: bash
  1175. tar -xzvf geomyidae-current.tgz
  1176. cd geomyidae-*
  1177. make
  1178. make install
  1179. mkdir -p /var/gopher
  1180. #+END_SRC
  1181. Your content should be placed within /var/gopher with the index page being named index.gph. The Gopher format is very simple - simpler than HTML - so creating pages is not much more difficult than editing a text file.
  1182. #+BEGIN_SRC: bash
  1183. emacs /etc/init.d/gopher
  1184. #+END_SRC
  1185. Enter the following:
  1186. #+BEGIN_SRC: bash
  1187. #! /bin/sh
  1188. ### BEGIN INIT INFO
  1189. # Provides: gopher
  1190. # Required-Start: $remote_fs $syslog
  1191. # Required-Stop: $remote_fs $syslog
  1192. # Default-Start: 2 3 4 5
  1193. # Default-Stop: 0 1 6
  1194. # Short-Description: Gopher daemon
  1195. # Description: Gopher daemon
  1196. ### END INIT INFO
  1197. # Do NOT "set -e"
  1198. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  1199. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  1200. DESC="Gopher daemon"
  1201. NAME=geomyidae
  1202. DAEMON=/usr/bin/$NAME
  1203. DAEMON_ARGS="-l /var/log/geomyidae.log -b /var/gopher -p 70"
  1204. PIDFILE=/var/run/$NAME.pid
  1205. SCRIPTNAME=/etc/init.d/$NAME
  1206. # Exit if the package is not installed
  1207. [ -x "$DAEMON" ] || exit 0
  1208. # Read configuration variable file if it is present
  1209. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  1210. # Load the VERBOSE setting and other rcS variables
  1211. . /lib/init/vars.sh
  1212. # Define LSB log_* functions.
  1213. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  1214. # and status_of_proc is working.
  1215. . /lib/lsb/init-functions
  1216. #
  1217. # Function that starts the daemon/service
  1218. #
  1219. do_start()
  1220. {
  1221. # Return
  1222. # 0 if daemon has been started
  1223. # 1 if daemon was already running
  1224. # 2 if daemon could not be started
  1225. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  1226. || return 1
  1227. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  1228. $DAEMON_ARGS \
  1229. || return 2
  1230. # Add code here, if necessary, that waits for the process to be ready
  1231. # to handle requests from services started subsequently which depend
  1232. # on this one. As a last resort, sleep for some time.
  1233. }
  1234. #
  1235. # Function that stops the daemon/service
  1236. #
  1237. do_stop()
  1238. {
  1239. # Return
  1240. # 0 if daemon has been stopped
  1241. # 1 if daemon was already stopped
  1242. # 2 if daemon could not be stopped
  1243. # other if a failure occurred
  1244. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  1245. RETVAL="$?"
  1246. [ "$RETVAL" = 2 ] && return 2
  1247. # Wait for children to finish too if this is a daemon that forks
  1248. # and if the daemon is only ever run from this initscript.
  1249. # If the above conditions are not satisfied then add some other code
  1250. # that waits for the process to drop all resources that could be
  1251. # needed by services started subsequently. A last resort is to
  1252. # sleep for some time.
  1253. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  1254. [ "$?" = 2 ] && return 2
  1255. # Many daemons don't delete their pidfiles when they exit.
  1256. rm -f $PIDFILE
  1257. return "$RETVAL"
  1258. }
  1259. #
  1260. # Function that sends a SIGHUP to the daemon/service
  1261. #
  1262. do_reload() {
  1263. #
  1264. # If the daemon can reload its configuration without
  1265. # restarting (for example, when it is sent a SIGHUP),
  1266. # then implement that here.
  1267. #
  1268. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  1269. return 0
  1270. }
  1271. case "$1" in
  1272. start)
  1273. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  1274. do_start
  1275. case "$?" in
  1276. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  1277. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  1278. esac
  1279. ;;
  1280. stop)
  1281. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  1282. do_stop
  1283. case "$?" in
  1284. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  1285. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  1286. esac
  1287. ;;
  1288. status)
  1289. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  1290. ;;
  1291. #reload|force-reload)
  1292. #
  1293. # If do_reload() is not implemented then leave this commented out
  1294. # and leave 'force-reload' as an alias for 'restart'.
  1295. #
  1296. #log_daemon_msg "Reloading $DESC" "$NAME"
  1297. #do_reload
  1298. #log_end_msg $?
  1299. #;;
  1300. restart|force-reload)
  1301. #
  1302. # If the "reload" option is implemented then remove the
  1303. # 'force-reload' alias
  1304. #
  1305. log_daemon_msg "Restarting $DESC" "$NAME"
  1306. do_stop
  1307. case "$?" in
  1308. 0|1)
  1309. do_start
  1310. case "$?" in
  1311. 0) log_end_msg 0 ;;
  1312. 1) log_end_msg 1 ;; # Old process is still running
  1313. *) log_end_msg 1 ;; # Failed to start
  1314. esac
  1315. ;;
  1316. *)
  1317. # Failed to stop
  1318. log_end_msg 1
  1319. ;;
  1320. esac
  1321. ;;
  1322. *)
  1323. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  1324. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  1325. exit 3
  1326. ;;
  1327. esac
  1328. :
  1329. #+END_SRC
  1330. Save and exit. Then start the gopher service.
  1331. #+BEGIN_SRC: bash
  1332. chmod +x /etc/init.d/gopher
  1333. update-rc.d gopher defaults
  1334. service gopher start
  1335. #+END_SRC
  1336. On your internet router change the firewall settings to route port 70 to the BBB, then provided that you have a gopher plugin installed within your browser then you should be able to navigate to your gopher site with:
  1337. #+BEGIN_SRC: bash
  1338. gopher://mydomainname.com
  1339. #+END_SRC
  1340. There is a browser addon for Gopher called "overbite". Installing that should enable you to view your site.
  1341. ** Install a Wiki
  1342. Dokuwiki is based upon flat files, and so is easy to move from one server to another without a lot of database complications.
  1343. Download the wiki.
  1344. #+BEGIN_SRC: bash
  1345. wget http://freedombone.uk.to/dokuwiki.tgz
  1346. #+END_SRC
  1347. Verify it.
  1348. #+BEGIN_SRC: bash
  1349. md5sum dokuwiki.tgz
  1350. 9f35055848429659fd63cda1cfea5a48 dokuwiki.tgz
  1351. #+END_SRC
  1352. Then extract and install it.
  1353. #+BEGIN_SRC: bash
  1354. export HOSTNAME=mywikidomainname.com
  1355. tar -xzvf dokuwiki.tgz
  1356. mv /var/www/$HOSTNAME/htdocs /var/www/$HOSTNAME/htdocs_old
  1357. mv dokuwiki /var/www/$HOSTNAME/htdocs
  1358. #+END_SRC
  1359. Edit the Apache configuration for your wiki site.
  1360. #+BEGIN_SRC: bash
  1361. emacs /etc/apache2/sites-available/$HOSTNAME
  1362. #+END_SRC
  1363. The settings should look something like the following.
  1364. #+BEGIN_SRC: bash
  1365. <VirtualHost *:80>
  1366. ServerAdmin myusername@mywikidomainname.com
  1367. ServerName mydomainname.com
  1368. DocumentRoot /var/www/mywikidomainname.com/htdocs
  1369. <Directory /var/www/mywikidomainname.com/htdocs>
  1370. order deny,allow
  1371. allow from all
  1372. </Directory>
  1373. <LocationMatch "/(data|conf|bin|inc)/">
  1374. order allow,deny
  1375. deny from all
  1376. satisfy all
  1377. </LocationMatch>
  1378. <Directory />
  1379. Options FollowSymLinks
  1380. AllowOverride All
  1381. </Directory>
  1382. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1383. <Directory "/usr/lib/cgi-bin">
  1384. AllowOverride All
  1385. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1386. Order allow,deny
  1387. Allow from all
  1388. </Directory>
  1389. ErrorLog ${APACHE_LOG_DIR}/error.log
  1390. # Possible values include: debug, info, notice, warn, error, crit,
  1391. # alert, emerg.
  1392. LogLevel warn
  1393. CustomLog ${APACHE_LOG_DIR}/access.log combined
  1394. </VirtualHost>
  1395. <IfModule mod_ssl.c>
  1396. <VirtualHost *:443>
  1397. ServerAdmin myusername@mywikidomainname.com
  1398. ServerName mywikidomainname.com
  1399. DocumentRoot /var/www/mywikidomainname.com/htdocs
  1400. <Directory /var/www/mywikidomainname.com/htdocs>
  1401. order deny,allow
  1402. allow from all
  1403. </Directory>
  1404. <LocationMatch "/(data|conf|bin|inc)/">
  1405. order allow,deny
  1406. deny from all
  1407. satisfy all
  1408. </LocationMatch>
  1409. <Directory />
  1410. Options FollowSymLinks
  1411. AllowOverride All
  1412. </Directory>
  1413. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1414. <Directory "/usr/lib/cgi-bin">
  1415. AllowOverride All
  1416. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1417. Order allow,deny
  1418. Allow from all
  1419. </Directory>
  1420. ErrorLog ${APACHE_LOG_DIR}/error.log
  1421. # Possible values include: debug, info, notice, warn, error, crit,
  1422. # alert, emerg.
  1423. LogLevel warn
  1424. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  1425. # SSL Engine Switch:
  1426. # Enable/Disable SSL for this virtual host.
  1427. SSLEngine on
  1428. # A self-signed certificate
  1429. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  1430. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  1431. # SSL Engine Options:
  1432. # Set various options for the SSL engine.
  1433. # o FakeBasicAuth:
  1434. # Translate the client X.509 into a Basic Authorisation. This means that
  1435. # the standard Auth/DBMAuth methods can be used for access control. The
  1436. # user name is the `one line' version of the client's X.509 certificate.
  1437. # Note that no password is obtained from the user. Every entry in the user
  1438. # file needs this password: `xxj31ZMTZzkVA'.
  1439. # o ExportCertData:
  1440. # This exports two additional environment variables: SSL_CLIENT_CERT and
  1441. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  1442. # server (always existing) and the client (only existing when client
  1443. # authentication is used). This can be used to import the certificates
  1444. # into CGI scripts.
  1445. # o StdEnvVars:
  1446. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  1447. # Per default this exportation is switched off for performance reasons,
  1448. # because the extraction step is an expensive operation and is usually
  1449. # useless for serving static content. So one usually enables the
  1450. # exportation for CGI and SSI requests only.
  1451. # o StrictRequire:
  1452. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  1453. # under a "Satisfy any" situation, i.e. when it applies access is denied
  1454. # and no other module can change it.
  1455. # o OptRenegotiate:
  1456. # This enables optimized SSL connection renegotiation handling when SSL
  1457. # directives are used in per-directory context.
  1458. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  1459. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  1460. SSLOptions +StdEnvVars
  1461. </FilesMatch>
  1462. <Directory /usr/lib/cgi-bin>
  1463. SSLOptions +StdEnvVars
  1464. </Directory>
  1465. # SSL Protocol Adjustments:
  1466. # The safe and default but still SSL/TLS standard compliant shutdown
  1467. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  1468. # the close notify alert from client. When you need a different shutdown
  1469. # approach you can use one of the following variables:
  1470. # o ssl-unclean-shutdown:
  1471. # This forces an unclean shutdown when the connection is closed, i.e. no
  1472. # SSL close notify alert is send or allowed to received. This violates
  1473. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  1474. # this when you receive I/O errors because of the standard approach where
  1475. # mod_ssl sends the close notify alert.
  1476. # o ssl-accurate-shutdown:
  1477. # This forces an accurate shutdown when the connection is closed, i.e. a
  1478. # SSL close notify alert is send and mod_ssl waits for the close notify
  1479. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  1480. # practice often causes hanging connections with brain-dead browsers. Use
  1481. # this only for browsers where you know that their SSL implementation
  1482. # works correctly.
  1483. # Notice: Most problems of broken clients are also related to the HTTP
  1484. # keep-alive facility, so you usually additionally want to disable
  1485. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  1486. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  1487. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  1488. # "force-response-1.0" for this.
  1489. BrowserMatch "MSIE [2-6]" \
  1490. nokeepalive ssl-unclean-shutdown \
  1491. downgrade-1.0 force-response-1.0
  1492. # MSIE 7 and newer should be able to use keepalive
  1493. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  1494. </VirtualHost>
  1495. </IfModule>
  1496. #+END_SRC
  1497. Enable your site with:
  1498. #+BEGIN_SRC: bash
  1499. a2ensite
  1500. #+END_SRC
  1501. then select the domain name and reload.
  1502. #+BEGIN_SRC: bash
  1503. service apache2 reload
  1504. #+END_SRC
  1505. and alter permissions:
  1506. #+BEGIN_SRC: bash
  1507. chmod -R 755 /var/www/$HOSTNAME/htdocs
  1508. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs
  1509. #+END_SRC
  1510. Open a browser and visit http://$HOSTNAME/install.php, then fill out the details. Once everything has been accepted without errors:
  1511. #+BEGIN_SRC: bash
  1512. rm /var/www/$HOSTNAME/htdocs/install.php
  1513. #+END_SRC
  1514. ** Install Owncloud
  1515. First create an apache configuration for your Owncloud site. You will need to create a new subdomain via FreeDNS. See the earlier section on [[Setting up a web site]] for details.
  1516. #+BEGIN_SRC: bash
  1517. emacs /etc/php5/apache2filter/php.ini
  1518. #+END_SRC
  1519. Set the following:
  1520. #+BEGIN_SRC: bash
  1521. post_max_size = 32M
  1522. upload_max_filesize = 32M
  1523. #+END_SRC
  1524. Restart apache.
  1525. #+BEGIN_SRC: bash
  1526. service apache2 restart
  1527. #+END_SRC
  1528. Install some dependencies:
  1529. #+BEGIN_SRC: bash
  1530. apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
  1531. apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
  1532. #+END_SRC
  1533. Download owncloud.
  1534. #+BEGIN_SRC: bash
  1535. cd /tmp
  1536. wget http://freedombone.uk.to/owncloud.tar.bz2
  1537. #+END_SRC
  1538. Verify the download:
  1539. #+BEGIN_SRC: bash
  1540. md5 owncloud.tar.bz2
  1541. f43eabb746b5e339ee70d0a6aaf4a49c
  1542. #+END_SRC
  1543. Extract the archive. This may take a couple of minutes, so don't be alarmed that the system has crashed.
  1544. #+BEGIN_SRC: bash
  1545. export HOSTNAME=myownclouddomainname.com
  1546. tar -xjf owncloud.tar.bz2
  1547. #+END_SRC
  1548. Move the extracted files to your site.
  1549. #+BEGIN_SRC: bash
  1550. cp -r owncloud /var/www/$HOSTNAME
  1551. rm -rf /var/www/$HOSTNAME/htdocs
  1552. mv /var/www/$HOSTNAME/owncloud /var/www/$HOSTNAME/htdocs
  1553. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/
  1554. chmod 775 /var/www/$HOSTNAME/htdocs
  1555. chmod 664 /var/www/$HOSTNAME/htdocs/*
  1556. chmod g+s /var/www/$HOSTNAME/htdocs
  1557. #+END_SRC
  1558. With a web browser visit your domain and enter an administrator username and password.
  1559. ** Install Tripwire
  1560. Tripwire will try to detect any intrusions into your system. It's a good idea to install it after you have installed all of the other programs which you intend to use.
  1561. #+BEGIN_SRC: bash
  1562. apt-get install tripwire
  1563. export HOSTNAME=mydomainname.com
  1564. cd /etc/tripwire
  1565. cp arm-local.key $HOSTNAME-local.key
  1566. cp site.key $HOSTNAME-site.key
  1567. tripwire --init
  1568. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  1569. tripwire --check --interactive
  1570. #+END_SRC
  1571. you will be asked for two passphrases ("site" and "local"). Make a note of these.
  1572. If you subsequently install any more packages or make configuration changes then update the policy again with:
  1573. #+BEGIN_SRC: bash
  1574. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  1575. #+END_SRC
  1576. Also, to look for any rootkits.
  1577. #+BEGIN_SRC: bash
  1578. apt-get install rkhunter
  1579. #+END_SRC
  1580. * Router/Firewall ports
  1581. The following ports on your internet router/firewall should be forwarded to the BBB.
  1582. | Protocol | Port/s |
  1583. |----------+------------|
  1584. | Gopher | 70 |
  1585. | HTTP | 80 |
  1586. | HTTPS | 443 |
  1587. | IMAP | 143 |
  1588. | IRC | 6665..6669 |
  1589. | SIP | 5060..5061 |
  1590. | SMTP | 25 |
  1591. | SMTPS | 465 |
  1592. | SSH | 22 |
  1593. * Hints and Tips
  1594. ** Messaging security
  1595. If you're connected to other friends via Friendica then the preferred way to send private messages is via Friendica's built-in messaging system. This is a lot more convenient than using GPG with ordinary email and yet still provides a similar level of protection from unwarranted interception.
  1596. ** Restrictive/hostile user environments
  1597. If you are typically operating within a restrictive of hostile environment where using ssh is not an option because everything other than web ports are blocked then you may wish to try installing oterm:
  1598. http://www.coralbits.com/oterm/
  1599. https://github.com/davidmoreno/onion
  1600. ** Moving Domains
  1601. If you're moving servers and using a different domain name or path then you can search and replace URLs within files in the following way:
  1602. #+BEGIN_SRC: bash
  1603. find /var/www/mynewdomain/htdocs -type f -exec sed -i 's@myolddomain@mynewdomain@g' {} \;
  1604. #+END_SRC
  1605. ** MySql foo
  1606. *** Backup all databases
  1607. To back up all mysql databases:
  1608. #+BEGIN_SRC: bash
  1609. mysqldump -u root -p --all-databases --events > /var/backups/databasebackup.sql
  1610. #+END_SRC
  1611. *** Restoring a particular mysql database
  1612. To restore yesterday's friendica backup:
  1613. #+BEGIN_SRC: bash
  1614. mysql -D friendica -o < /var/backups/friendica_daily.sql
  1615. #+END_SRC
  1616. To restore yesterday's mediawiki backup:
  1617. #+BEGIN_SRC: bash
  1618. mysql -D wikidb -o < /var/backups/wikidb_daily.sql
  1619. #+END_SRC
  1620. *** Removing mysql server
  1621. If you manage to screw up sql server completely then it can be fully deleted with:
  1622. #+BEGIN_SRC: bash
  1623. ps aux | grep mysql
  1624. #+END_SRC
  1625. and use /kill -9 <pid>/ to kill all mysql processes.
  1626. #+BEGIN_SRC: bash
  1627. apt-get remove --purge mysql\*
  1628. apt-get clean
  1629. updatedb
  1630. #+END_SRC