beaglebone.txt 67KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177
  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]].
  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.
  162. #+BEGIN_SRC: bash
  163. adduser /username/
  164. adduser /username/ sudo
  165. #+END_SRC
  166. 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.
  167. Remove the default debian user.
  168. #+BEGIN_SRC: bash
  169. userdel -r debian
  170. #+END_SRC
  171. ** Text editor
  172. For an editor which is less erratic than vi when used within a remote console such as Terminator.
  173. #+BEGIN_SRC: bash
  174. apt-get update
  175. apt-get install emacs
  176. #+END_SRC
  177. ** Alter ssh configuration
  178. Altering the ssh configuration will make it a little more secure than the standard Debian settings.
  179. #+BEGIN_SRC: bash
  180. emacs /etc/ssh/sshd_config
  181. #+END_SRC
  182. Check the following values:
  183. #+BEGIN_SRC: bash
  184. PermitRootLogin no
  185. X11Forwarding no
  186. ServerKeyBits 4096
  187. Protocol 2
  188. PermitEmptyPasswords no
  189. StrictModes yes
  190. #+END_SRC
  191. Append the following:
  192. #+BEGIN_SRC: bash
  193. Ciphers aes256-ctr,aes192-ctr,aes128-ctr
  194. MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
  195. KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
  196. #+END_SRC
  197. CTRL-X CTRL-S to save, then CTRL-X CTRL-C to exit.
  198. #+BEGIN_SRC: bash
  199. service ssh restart
  200. #+END_SRC
  201. To test the new settings log out by typing "exit" a couple of times, then log back in again with:
  202. #+BEGIN_SRC: bash
  203. ssh -vvv myusername@192.168.1.60
  204. #+END_SRC
  205. and check that some number of bits are set within a 4096 bit sized key:
  206. #+BEGIN_SRC: bash
  207. debug2: bits set: */4096
  208. #+END_SRC
  209. ** Set the host name
  210. #+BEGIN_SRC: bash
  211. emacs /etc/hostname
  212. #+END_SRC
  213. CTRL-X CTRL-S to save, then CTRL-X CTRL-C to exit.
  214. also issue the command
  215. #+BEGIN_SRC: bash
  216. hostname /myhostname/
  217. #+END_SRC
  218. You may also need to assign the same hostname separately via your router's web interface.
  219. ** Install NTP
  220. To synchronise time.
  221. #+BEGIN_SRC: bash
  222. apt-get install ntp
  223. #+END_SRC
  224. ** Install fail2ban
  225. #+BEGIN_SRC: bash
  226. apt-get install fail2ban
  227. #+END_SRC
  228. ** Getting onto the web
  229. 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.
  230. Select "/dynamic DNS/" then click "/quick cron example/"
  231. An example would look like:
  232. #+BEGIN_SRC: bash
  233. 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 &
  234. #+END_SRC
  235. Edit /etc/crontab and append that to the end of the file.
  236. 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.
  237. ** install Email
  238. #+BEGIN_VERSE
  239. /If you knew what I know about email, you might not use it/
  240. -- Ladar Levison
  241. #+END_VERSE
  242. 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.
  243. Exim4 seems much easier to install and configure than Postfix.
  244. #+BEGIN_SRC: bash
  245. aptitude install exim4 sasl2-bin swaks libnet-ssleay-perl
  246. #+END_SRC
  247. You will be prompted to remove postfix. Say yes and yes again.
  248. #+BEGIN_SRC: bash
  249. dpkg-reconfigure exim4-config
  250. #+END_SRC
  251. Settings as follows:
  252. #+BEGIN_SRC: bash
  253. internet site
  254. System mail name: mydomainname.com
  255. IP addresses to listen on: blank
  256. Destinations: mydomainname.com
  257. Domains to relay mail: blank
  258. Smarthost Relay: 192.168.1.0/60 (the range of addresses on your LAN)
  259. Dial on demand = no
  260. Maildir format in home directory
  261. Split configuration = no
  262. Root and postmaster: root email
  263. #+END_SRC
  264. To test the installation:
  265. #+BEGIN_SRC: bash
  266. telnet 192.168.1.60 25
  267. ehlo xxx
  268. quit
  269. #+END_SRC
  270. #+BEGIN_SRC: bash
  271. emacs /etc/default/saslauthd
  272. #+END_SRC
  273. set START=yes then save and exit.
  274. #+BEGIN_SRC: bash
  275. /etc/init.d/saslauthd start
  276. emacs exim-gencert
  277. #+END_SRC
  278. #+BEGIN_SRC: bash
  279. #!/bin/sh -e
  280. if [ -n "$EX4DEBUG" ]; then
  281. echo "now debugging $0 $@"
  282. set -x
  283. fi
  284. DIR=/etc/exim4
  285. CERT=$DIR/exim.crt
  286. KEY=$DIR/exim.key
  287. # This exim binary was built with GnuTLS which does not support dhparams
  288. # from a file. See /usr/share/doc/exim4-base/README.Debian.gz
  289. #DH=$DIR/exim.dhparam
  290. if ! which openssl > /dev/null ;then
  291. echo "$0: openssl is not installed, exiting" 1>&2
  292. exit 1
  293. fi
  294. # valid for ten years
  295. DAYS=3650
  296. if [ "$1" != "--force" ] && [ -f $CERT ] && [ -f $KEY ]; then
  297. echo "[*] $CERT and $KEY exists!"
  298. echo " Use \"$0 --force\" to force generation!"
  299. exit 0
  300. fi
  301. if [ "$1" = "--force" ]; then
  302. shift
  303. fi
  304. #SSLEAY=/tmp/exim.ssleay.$$.cnf
  305. SSLEAY="$(tempfile -m600 -pexi)"
  306. cat > $SSLEAY <<EOM
  307. RANDFILE = $HOME/.rnd
  308. [ req ]
  309. default_bits = 4096
  310. default_keyfile = exim.key
  311. distinguished_name = req_distinguished_name
  312. [ req_distinguished_name ]
  313. countryName = Country Code (2 letters)
  314. countryName_default = GB
  315. countryName_min = 2
  316. countryName_max = 2
  317. stateOrProvinceName = State or Province Name (full name)
  318. localityName = Locality Name (eg, city)
  319. organizationName = Organization Name (eg, company; recommended)
  320. organizationName_max = 64
  321. organizationalUnitName = Organizational Unit Name (eg, section)
  322. organizationalUnitName_max = 64
  323. commonName = Server name (eg. ssl.domain.tld; required!!!)
  324. commonName_max = 64
  325. emailAddress = Email Address
  326. emailAddress_max = 40
  327. EOM
  328. echo "[*] Creating a self signed SSL certificate for Exim!"
  329. echo " This may be sufficient to establish encrypted connections but for"
  330. echo " secure identification you need to buy a real certificate!"
  331. echo " "
  332. echo " Please enter the hostname of your MTA at the Common Name (CN) prompt!"
  333. echo " "
  334. openssl req -config $SSLEAY -x509 -sha256 -newkey rsa:4096 -keyout $KEY -out $CERT -days $DAYS -nodes
  335. #see README.Debian.gz*# openssl dhparam -check -text -5 512 -out $DH
  336. rm -f $SSLEAY
  337. chown root:Debian-exim $KEY $CERT $DH
  338. chmod 640 $KEY $CERT $DH
  339. echo "[*] Done generating self signed certificates for exim!"
  340. echo " Refer to the documentation and example configuration files"
  341. echo " over at /usr/share/doc/exim4-base/ for an idea on how to enable TLS"
  342. echo " support in your mail transfer agent."
  343. #+END_SRC
  344. Save and exit
  345. #+BEGIN_SRC: bash
  346. chmod +x exim-gencert
  347. ./exim-gencert
  348. #+END_SRC
  349. 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.
  350. #+BEGIN_SRC: bash
  351. emacs /etc/exim4/exim4.conf.template
  352. #+END_SRC
  353. Append the following:
  354. #+BEGIN_SRC: bash
  355. login_saslauthd_server:
  356. driver = plaintext
  357. public_name = LOGIN
  358. server_prompts = "Username:: : Password::"
  359. # don't send system passwords over unencrypted connections
  360. server_condition = ${if saslauthd{{$auth1}{$auth2}}{1}{0}}
  361. server_set_id = $auth1
  362. .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
  363. server_advertise_condition = ${if eq{$tls_cipher}{}{}{*}}
  364. .endif
  365. #+END_SRC
  366. Search for the line *.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME* and above it insert the line:
  367. #+BEGIN_SRC: bash
  368. MAIN_HARDCODE_PRIMARY_HOSTNAME = mydomainname.com
  369. #+END_SRC
  370. Save and exit.
  371. #+BEGIN_SRC: bash
  372. emacs /etc/exim4/exim4.conf.template
  373. #+END_SRC
  374. Add the line:
  375. #+BEGIN_SRC: bash
  376. MAIN_TLS_ENABLE = true
  377. #+END_SRC
  378. Save and exit.
  379. #+BEGIN_SRC: bash
  380. emacs /etc/default/exim4
  381. change SMTPLISTENEROPTIONS to:
  382. SMTPLISTENEROPTIONS='-oX 465:25 -oP /var/run/exim4/exim.pid'
  383. #+END_SRC
  384. save and exit
  385. #+BEGIN_SRC: bash
  386. emacs /etc/exim4/exim4.conf.template
  387. under the section "main/03_exim4-config_tlsoptions"
  388. Add the following:
  389. tls_on_connect_ports=465
  390. #+END_SRC
  391. save and exit
  392. #+BEGIN_SRC: bash
  393. adduser myusername sasl
  394. addgroup Debian-exim sasl
  395. /etc/init.d/exim4 restart
  396. mkdir /etc/skel/Maildir
  397. #+END_SRC
  398. ** Spam filtering
  399. #+BEGIN_SRC: bash
  400. apt-get install spamassassin exim4-daemon-heavy
  401. emacs /etc/default/spamassassin
  402. #+END_SRC
  403. Set ENABLED=1 then save and exit.
  404. #+BEGIN_SRC: bash
  405. emacs /etc/exim4/exim4.conf.template
  406. #+END_SRC
  407. uncomment or change according to your configuration
  408. #+BEGIN_SRC: bash
  409. # For spam scanning, there is a similar option that defines the interface to
  410. # SpamAssassin. You do not need to set this if you are using the default, which
  411. # is shown in this commented example. As for virus scanning, you must also
  412. # modify the acl_check_data access control list to enable spam scanning.
  413. spamd_address = 127.0.0.1 783
  414. #+END_SRC
  415. add spam header in the /acl_check_data/ section:
  416. #+BEGIN_SRC: bash
  417. ### acl/40_exim4-config_check_data
  418. #################################
  419. # This ACL is used after the contents of a message have been received. This
  420. # is the ACL in which you can test a message's headers or body, and in
  421. # particular, this is where you can invoke external virus or spam scanners.
  422. acl_check_data:
  423. ...
  424. ...
  425. ...
  426. # See the exim docs and the exim wiki for more suitable examples.
  427. #
  428. # warn
  429. # spam = Debian-exim:true
  430. # add_header = X-Spam_score: $spam_score\n\
  431. # X-Spam_score_int: $spam_score_int\n\
  432. # X-Spam_bar: $spam_bar\n\
  433. # X-Spam_report: $spam_report
  434. # put headers in all messages (no matter if spam or not)
  435. warn spam = nobody:true
  436. add_header = X-Spam-Score: $spam_score ($spam_bar)
  437. add_header = X-Spam-Report: $spam_report
  438. # add second subject line with *SPAM* marker when message
  439. # is over threshold
  440. warn spam = nobody
  441. add_header = Subject: ***SPAM (score:$spam_score)*** $h_Subject:
  442. #+END_SRC
  443. Save and exit.
  444. Then restart
  445. #+BEGIN_SRC: bash
  446. exit
  447. emacs ~/.procmailrc
  448. #+END_SRC
  449. The text should look like the following.
  450. #+BEGIN_SRC: sh
  451. MAILDIR=$HOME/Maildir
  452. DEFAULT=$MAILDIR/
  453. LOGFILE=$HOME/log/procmail.log
  454. LOGABSTRACT=all
  455. # get spamassassin to check emails
  456. :0fw: .spamassassin.lock
  457. * < 256000
  458. | spamc
  459. # strong spam are discarded
  460. :0
  461. * ^X-Spam-Level: \*\*\*\*\*\*
  462. /dev/null
  463. # weak spam are kept just in case - clear this out every now and then
  464. :0
  465. * ^X-Spam-Level: \*\*\*\*\*
  466. .0-spam/
  467. # if it wasn't detected as spam, but is to a fake address, then we
  468. # know it is spam, so learn from that
  469. :0
  470. * !^(From|To|cc|bcc)[ :].*($USER|root|webmaster|admin|postmaster).*@acooke\.org
  471. * !^(From|To|cc|bcc)[ :].*@isti\.com
  472. # add mailing lists below
  473. * !^From[ :].*(snowmail_daily@...|Section@...|rforno@...|alert@...).*
  474. {
  475. # save in case of screw-ups, mailing lists, etc
  476. :0 c
  477. .0-spam/
  478. :0
  479. .learn-spam/
  480. }
  481. # otherwise, marginal spam goes here for revision
  482. :0
  483. * ^X-Spam-Level: \*\*
  484. .spam/
  485. #+END_SRC
  486. Save and exit.
  487. #+BEGIN_SRC: bash
  488. su
  489. emacs /usr/bin/filterspam
  490. #+END_SRC
  491. Add the following contents:
  492. #+BEGIN_SRC: bash
  493. #!/bin/bash
  494. USERNAME=$1
  495. MAILDIR=/home/$USERNAME/Maildir/.learn-spam
  496. if [ ! -d "$MAILDIR" ]; then
  497. exit
  498. fi
  499. for f in `ls $MAILDIR/cur`
  500. do
  501. spamc -L spam < "$MAILDIR/cur/$f" > /dev/null
  502. rm "$MAILDIR/cur/$f"
  503. done
  504. for f in `ls $MAILDIR/new`
  505. do
  506. spamc -L spam < "$MAILDIR/new/$f" > /dev/null
  507. rm "$MAILDIR/new/$f"
  508. done
  509. #+END_SRC
  510. Save and exit.
  511. #+BEGIN_SRC: bash
  512. emacs /usr/bin/filterham
  513. #+END_SRC
  514. Add the following contents:
  515. #+BEGIN_SRC: bash
  516. #!/bin/bash
  517. USERNAME=$1
  518. MAILDIR=/home/$USERNAME/Maildir/.learn-ham
  519. if [ ! -d "$MAILDIR" ]; then
  520. exit
  521. fi
  522. for f in `ls $MAILDIR/cur`
  523. do
  524. spamc -L ham < "$MAILDIR/cur/$f" > /dev/null
  525. rm "$MAILDIR/cur/$f"
  526. done
  527. for f in `ls $MAILDIR/new`
  528. do
  529. spamc -L ham < "$MAILDIR/new/$f" > /dev/null
  530. rm "$MAILDIR/new/$f"
  531. done
  532. #+END_SRC
  533. Save and exit.
  534. #+BEGIN_SRC: bash
  535. emacs /etc/crontab
  536. #+END_SRC
  537. Append the following, replacing *myusername* with your username.
  538. #+BEGIN_SRC: bash
  539. */3 * * * * root /usr/bin/filterspam myusername
  540. */3 * * * * root /usr/bin/filterham myusername
  541. #+END_SRC
  542. Save and exit.
  543. #+BEGIN_SRC: bash
  544. chmod 655 /usr/bin/filterspam /usr/bin/filterham
  545. service spamassassin restart
  546. service exim4 restart
  547. service cron restart
  548. #+END_SRC
  549. ** Install dovecot
  550. #+BEGIN_SRC: bash
  551. aptitude -y install dovecot-common dovecot-pop3d dovecot-imapd
  552. #+END_SRC
  553. #+BEGIN_SRC: bash
  554. emacs /etc/dovecot/dovecot.conf
  555. #+END_SRC
  556. # line 26: change ( if not listen IPv6 port )
  557. listen = *
  558. #+BEGIN_SRC: bash
  559. emacs /etc/dovecot/conf.d/10-auth.conf
  560. #+END_SRC
  561. # line 9: uncomment and change ( allow plain text auth )
  562. disable_plaintext_auth = no
  563. # line 99: add
  564. auth_mechanisms = plain login
  565. #+BEGIN_SRC: bash
  566. emacs /etc/dovecot/conf.d/10-mail.conf
  567. #+END_SRC
  568. # line 30: uncomment and add
  569. mail_location = maildir:~/Maildir
  570. #+BEGIN_SRC: bash
  571. service dovecot restart
  572. #+END_SRC
  573. ** Mutt email client
  574. #+BEGIN_SRC: bash
  575. apt-get install mutt lynx abook
  576. exit
  577. mkdir ~/.mutt
  578. echo "text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^ //’; copiousoutput; needsterminal; nametemplate=%s.html" > ~/.mutt/mailcap
  579. #+END_SRC
  580. Save and exit.
  581. #+BEGIN_SRC: bash
  582. sudo 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:
  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. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  684. <Directory "/usr/lib/cgi-bin">
  685. AllowOverride All
  686. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  687. Order allow,deny
  688. Allow from all
  689. </Directory>
  690. ErrorLog ${APACHE_LOG_DIR}/error.log
  691. # Possible values include: debug, info, notice, warn, error, crit,
  692. # alert, emerg.
  693. LogLevel warn
  694. CustomLog ${APACHE_LOG_DIR}/access.log combined
  695. </VirtualHost>
  696. <IfModule mod_ssl.c>
  697. <VirtualHost *:443>
  698. ServerAdmin myusername@mydomainname.com
  699. ServerName mydomainname.com
  700. DocumentRoot /var/www/mydomainname.com/htdocs
  701. <Directory />
  702. Options FollowSymLinks
  703. AllowOverride All
  704. </Directory>
  705. <Directory /var/www/mydomainname.com/htdocs/>
  706. Options All
  707. AllowOverride All
  708. Order allow,deny
  709. allow from all
  710. </Directory>
  711. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  712. <Directory "/usr/lib/cgi-bin">
  713. AllowOverride All
  714. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  715. Order allow,deny
  716. Allow from all
  717. </Directory>
  718. ErrorLog ${APACHE_LOG_DIR}/error.log
  719. # Possible values include: debug, info, notice, warn, error, crit,
  720. # alert, emerg.
  721. LogLevel warn
  722. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  723. # SSL Engine Switch:
  724. # Enable/Disable SSL for this virtual host.
  725. SSLEngine on
  726. # A self-signed certificate
  727. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  728. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  729. # Options based on bettercrypto.org
  730. SSLProtocol All -SSLv2 -SSLv3
  731. SSLHonorCipherOrder On
  732. SSLCompression off
  733. # Add six earth month HSTS header for all users ...
  734. Header add Strict-Transport-Security "max-age=15768000"
  735. # If you want to protect all subdomains , use the following header
  736. # ALL subdomains HAVE TO support https if you use this !
  737. # Strict-Transport-Security: max-age=15768000 ; includeSubDomains
  738. # 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’
  739. # SSL Engine Options:
  740. # Set various options for the SSL engine.
  741. # o FakeBasicAuth:
  742. # Translate the client X.509 into a Basic Authorisation. This means that
  743. # the standard Auth/DBMAuth methods can be used for access control. The
  744. # user name is the `one line' version of the client's X.509 certificate.
  745. # Note that no password is obtained from the user. Every entry in the user
  746. # file needs this password: `xxj31ZMTZzkVA'.
  747. # o ExportCertData:
  748. # This exports two additional environment variables: SSL_CLIENT_CERT and
  749. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  750. # server (always existing) and the client (only existing when client
  751. # authentication is used). This can be used to import the certificates
  752. # into CGI scripts.
  753. # o StdEnvVars:
  754. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  755. # Per default this exportation is switched off for performance reasons,
  756. # because the extraction step is an expensive operation and is usually
  757. # useless for serving static content. So one usually enables the
  758. # exportation for CGI and SSI requests only.
  759. # o StrictRequire:
  760. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  761. # under a "Satisfy any" situation, i.e. when it applies access is denied
  762. # and no other module can change it.
  763. # o OptRenegotiate:
  764. # This enables optimized SSL connection renegotiation handling when SSL
  765. # directives are used in per-directory context.
  766. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  767. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  768. SSLOptions +StdEnvVars
  769. </FilesMatch>
  770. <Directory /usr/lib/cgi-bin>
  771. SSLOptions +StdEnvVars
  772. </Directory>
  773. # SSL Protocol Adjustments:
  774. # The safe and default but still SSL/TLS standard compliant shutdown
  775. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  776. # the close notify alert from client. When you need a different shutdown
  777. # approach you can use one of the following variables:
  778. # o ssl-unclean-shutdown:
  779. # This forces an unclean shutdown when the connection is closed, i.e. no
  780. # SSL close notify alert is send or allowed to received. This violates
  781. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  782. # this when you receive I/O errors because of the standard approach where
  783. # mod_ssl sends the close notify alert.
  784. # o ssl-accurate-shutdown:
  785. # This forces an accurate shutdown when the connection is closed, i.e. a
  786. # SSL close notify alert is send and mod_ssl waits for the close notify
  787. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  788. # practice often causes hanging connections with brain-dead browsers. Use
  789. # this only for browsers where you know that their SSL implementation
  790. # works correctly.
  791. # Notice: Most problems of broken clients are also related to the HTTP
  792. # keep-alive facility, so you usually additionally want to disable
  793. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  794. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  795. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  796. # "force-response-1.0" for this.
  797. BrowserMatch "MSIE [2-6]" \
  798. nokeepalive ssl-unclean-shutdown \
  799. downgrade-1.0 force-response-1.0
  800. # MSIE 7 and newer should be able to use keepalive
  801. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  802. </VirtualHost>
  803. </IfModule>
  804. #+END_SRC
  805. Then to enable the site:
  806. #+BEGIN_SRC: bash
  807. a2ensite
  808. a2dissite default
  809. a2dissite default-ssl
  810. a2enmod rewrite
  811. a2enmod headers
  812. #+END_SRC
  813. Ensure that "NameVirtualHost *:443" is added to /etc/apache2/ports.conf. It should look something like the following:
  814. #+BEGIN_SRC: bash
  815. NameVirtualHost *:80
  816. Listen 80
  817. <IfModule mod_ssl.c>
  818. NameVirtualHost *:443
  819. Listen 443
  820. </IfModule>
  821. <IfModule mod_gnutls.c>
  822. NameVirtualHost *:443
  823. Listen 443
  824. </IfModule>
  825. #+END_SRC
  826. Create a self-signed certificate. The passphrase isn't important and will be removed, so make it easy (such as "password").
  827. #+BEGIN_SRC: bash
  828. emacs makecert
  829. #+END_SRC
  830. Enter the following:
  831. #+BEGIN_SRC: bash
  832. #!/bin/bash
  833. HOSTNAME=$1
  834. openssl genrsa -des3 -out $HOSTNAME.key 1024
  835. openssl req -new -x509 -nodes -sha1 -days 3650 -key $HOSTNAME.key -out $HOSTNAME.crt
  836. openssl rsa -in $HOSTNAME.key -out $HOSTNAME.new.key
  837. cp $HOSTNAME.new.key $HOSTNAME.key
  838. rm $HOSTNAME.new.key
  839. cp $HOSTNAME.key /etc/ssl/private
  840. chmod 400 /etc/ssl/private/$HOSTNAME.key
  841. cp $HOSTNAME.crt /etc/ssl/certs
  842. shred -zu $HOSTNAME.key $HOSTNAME.crt
  843. a2enmod ssl
  844. service apache2 restart
  845. #+END_SRC
  846. Save and exit.
  847. #+BEGIN_SRC: bash
  848. chmod +x makecert
  849. ./makecert mydomainname.com
  850. #+END_SRC
  851. 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.
  852. ** Social Networking
  853. #+BEGIN_VERSE
  854. /Facebook is not your friend, it is a surveillance engine./
  855. -- Richard Stallman
  856. #+END_VERSE
  857. *** Installation
  858. #+BEGIN_SRC: bash
  859. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  860. #+END_SRC
  861. Enter an admin password for MySQL.
  862. Create a mysql database.
  863. #+BEGIN_SRC: bash
  864. mysql -u root -p
  865. create database friendica;
  866. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'password';
  867. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  868. quit
  869. #+END_SRC
  870. You may need to fix Git SSL problems.
  871. #+BEGIN_SRC: bash
  872. git config --global http.sslVerify true
  873. apt-get install ca-certificates
  874. cd ~/
  875. emacs .gitconfig
  876. #+END_SRC
  877. The .gitconfig file should look something like this:
  878. #+BEGIN_SRC: bash
  879. [http]
  880. sslVerify = true
  881. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  882. [user]
  883. email = myusername@mydomainname.com
  884. name = yourname
  885. #+END_SRC
  886. Get the source code.
  887. #+BEGIN_SRC: bash
  888. export HOSTNAME=mydomainname.com
  889. cd /var/www/$HOSTNAME
  890. mv htdocs htdocs_old
  891. git clone https://github.com/friendica/friendica.git htdocs
  892. chmod -R 755 htdocs
  893. chown -R www-data:www-data htdocs
  894. chown -R www-data:www-data htdocs/view/smarty3
  895. git clone https://github.com/friendica/friendica-addons.git htdocs/addon
  896. #+END_SRC
  897. 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.
  898. Install the poller.
  899. #+BEGIN_SRC
  900. emacs /etc/crontab
  901. #+END_SRC
  902. and append the following, changing mydomainname.com to whatever your domain is.
  903. #+BEGIN_SRC
  904. */10 * * * * root cd /var/www/mydomainname.com/htdocs; /usr/bin/php include/poller.php
  905. #+END_SRC
  906. Save and exit, then restart cron.
  907. #+BEGIN_SRC: bash
  908. service cron restart
  909. #+END_SRC
  910. *** Backups
  911. 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.
  912. #+BEGIN_SRC: bash
  913. emacs /etc/cron.daily/friendicabackup
  914. #+END_SRC
  915. Enter the following
  916. #+BEGIN_SRC: bash
  917. #!/bin/sh
  918. MYSQL_PASSWORD=<mysql root password>
  919. umask 0077
  920. # Backup the database
  921. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_daily.sql
  922. # Make the backup readable only by root
  923. chmod 600 /var/backups/friendica_daily.sql
  924. #+END_SRC
  925. Save and exit.
  926. #+BEGIN_SRC: bash
  927. chmod 600 /etc/cron.daily/friendicabackup
  928. chmod +x /etc/cron.daily/friendicabackup
  929. emacs /etc/cron.weekly/friendicabackup
  930. #+END_SRC
  931. Enter the following
  932. #+BEGIN_SRC: bash
  933. #!/bin/sh
  934. MYSQL_PASSWORD=<mysql root password>
  935. umask 0077
  936. # Backup the database
  937. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_weekly.sql
  938. # Make the backup readable only by root
  939. chmod 600 /var/backups/friendica_weekly.sql
  940. #+END_SRC
  941. Save and exit.
  942. #+BEGIN_SRC: bash
  943. chmod 600 /etc/cron.weekly/friendicabackup
  944. chmod +x /etc/cron.weekly/friendicabackup
  945. #+END_SRC
  946. *** Recommended configuration
  947. **** Admin
  948. 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.
  949. 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.
  950. Under the *themes* section select a few themes, including mobile themes which are suitable for phones or tablets.
  951. 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.
  952. 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]].
  953. **** Settings
  954. Each user has their own customisable settings, typically available either via an icon or by an entry on a drop down menu.
  955. Under *additional features* enable "/richtext editor/", "/post preview/", "/group filter/", "/network filter/", "/edit sent posts/" and "/dislike posts/".
  956. Under *display settings* select your desktop and mobile themes.
  957. 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.
  958. *** To access from an Android device
  959. **** App
  960. 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.
  961. 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.
  962. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  963. **** Mobile Theme
  964. 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.
  965. ** Install a Blog
  966. 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.
  967. 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.
  968. Download flatpress.
  969. #+BEGIN_SRC: bash
  970. wget http://freedombone.uk.to/flatpress.tar.gz
  971. #+END_SRC
  972. Verify the download:
  973. #+BEGIN_SRC: bash
  974. md5sum flatpress.tar.gz
  975. 6ad5c230a5cb1ac096ff657f1b138cc7 flatpress.tar.gz
  976. #+END_SRC
  977. Extract and install it.
  978. #+BEGIN_SRC: bash
  979. tar -xzvf flatpress.tar.gz
  980. cd flatpress-*
  981. cp -r * /var/www/$HOSTNAME/htdocs
  982. rm -rf flatpress-*
  983. rm -f flatpress.tar.gz
  984. #+END_SRC
  985. 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
  986. ** Install a VoIP server
  987. #+BEGIN_VERSE
  988. /Our core principles, whether in software or sovereignty, have always been about freedom and dignity, for all people, on an equal basis/
  989. -- David Sugar
  990. #+END_VERSE
  991. Packages for the GNU/Linux distribution Debian 7.x Wheezy are available by adding the line
  992. #+BEGIN_SRC: bash
  993. emacs /etc/apt/sources.list
  994. #+END_SRC
  995. Append the following line:
  996. #+BEGIN_SRC: bash
  997. deb http://dev.gnutelephony.org/archive/ wheezy/
  998. #+END_SRC
  999. Save and exit.
  1000. 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
  1001. #+BEGIN_SRC: bash
  1002. apt-get install gnutelephony-keyring
  1003. #+END_SRC
  1004. After that it will be happy to accept it as a signed repository. The verification keys can also be directly fetched with
  1005. #+BEGIN_SRC: bash
  1006. wget http://dev.gnutelephony.org/archive/wheezy/public.key
  1007. #+END_SRC
  1008. and manually added instead with
  1009. #+BEGIN_SRC: bash
  1010. apt-key add public.key
  1011. #+END_SRC
  1012. To make sure you have all dependencies, do
  1013. #+BEGIN_SRC: bash
  1014. apt-get update;apt-get dist-upgrade
  1015. #+END_SRC
  1016. Before we install anything, let's inspect what is available to us by using
  1017. #+BEGIN_SRC: bash
  1018. dpkg -l sipwitch
  1019. #+END_SRC
  1020. to see the main application. The columns will indicate if the package is installed, which version and a description of the package. Then do
  1021. #+BEGIN_SRC: bash
  1022. dpkg -l sipwitch-*
  1023. #+END_SRC
  1024. 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.
  1025. To install only the main application, do
  1026. #+BEGIN_SRC: bash
  1027. apt-get install sipwitch
  1028. #+END_SRC
  1029. and to install all supporting plugins:
  1030. #+BEGIN_SRC: bash
  1031. apt-get install sipwitch-plugin-scripting sipwitch-plugin-subscriber sipwitch-plugin-forward sipwitch-plugin-zeroconf
  1032. #+END_SRC
  1033. Add your user into the sipwitch group
  1034. #+BEGIN_SRC: bash
  1035. groupadd sipwitch
  1036. usermod -aG sipwitch myusername
  1037. #+END_SRC
  1038. Then edit the configuration
  1039. #+BEGIN_SRC: bash
  1040. emacs /etc/sipwitch.conf
  1041. #+END_SRC
  1042. Change the *mapped* value from 200 to 4, since we don't want to be serving huge numbers of calls.
  1043. #+BEGIN_SRC: bash
  1044. export HOSTNAME=mydomainname.com
  1045. touch /etc/sipwitch.d/$HOSTNAME.xml
  1046. chmod 600 /etc/sipwitch.d/$HOSTNAME.xml
  1047. emacs /etc/sipwitch.d/$HOSTNAME.xml
  1048. #+END_SRC
  1049. It should look something like the following:
  1050. #+BEGIN_SRC: bash
  1051. <provision>
  1052. <user id="myusername">
  1053. <secret>yourpassword</secret> <extension>201</extension> <display>Your full name</display>
  1054. </user>
  1055. <user id="anotherusername">
  1056. <secret>anotherpassword</secret> <extension>202</extension> <display>Another full name</display>
  1057. </user>
  1058. </provision>
  1059. #+END_SRC
  1060. Save and exit.
  1061. #+BEGIN_SRC: bash
  1062. service sipwitch restart
  1063. #+END_SRC
  1064. To test:
  1065. #+BEGIN_SRC: bash
  1066. sipw -x9 -f
  1067. #+END_SRC
  1068. ** Install an IRC server
  1069. #+BEGIN_SRC: bash
  1070. apt-get install ircd-hybrid
  1071. #+END_SRC
  1072. This will install the IRC server and run it on ports (6666.6669) TCP
  1073. You can connect to the server by visiting 127.0.0.1 with your irc client
  1074. ————————————————————————————————
  1075. Because hybrid doesn’t support OpenSSL by default, you have to do a manual patch to get it working
  1076. 1- First we OpenSSL package for ssl certificate
  1077. #+BEGIN_SRC: bash
  1078. sudo apt-get install openssl libssl-dev
  1079. #+END_SRC
  1080. 2- Second we need hybrid source to patch it:
  1081. #+BEGIN_SRC: bash
  1082. mkdir hybrid; cd hybrid
  1083. apt-get install openssl libssl-dev
  1084. apt-get source ircd-hybrid
  1085. #+END_SRC
  1086. To enable SSL
  1087. #+BEGIN_SRC: bash
  1088. emacs ircd-hybrid-*/debian/rules
  1089. #+END_SRC
  1090. Add at the top:
  1091. #+BEGIN_SRC: bash
  1092. USE_OPENSSL = 1
  1093. #+END_SRC
  1094. So the file should looks like:
  1095. #+BEGIN_SRC: bash
  1096. 1# ...
  1097. 2# Some useful stuff to edit here.
  1098. 3# Beware: TOPICLEN may not exceed 390.
  1099. 4NICKLEN = 15
  1100. 5TOPICLEN = 350
  1101. 6MAXCLIENTS = 200
  1102. 7USE_OPENSSL = 1
  1103. 8# ...
  1104. #+END_SRC
  1105. Rebuild the deb-file and install it:
  1106. #+BEGIN_SRC: bash
  1107. cd ircd-hybrid-*
  1108. apt-get install build-essential debhelper dpatch docbook-to-man flex bison libpcre3-dev
  1109. dpkg-buildpackage -rfakeroot -uc -b
  1110. cd ..
  1111. dpkg -i ircd-hybrid_*.deb
  1112. #+END_SRC
  1113. Edit connect, listen and operator:
  1114. #+BEGIN_SRC: bash
  1115. emacs /etc/ircd-hybrid/ircd.conf
  1116. #+END_SRC
  1117. Edit the connect section.
  1118. #+BEGIN_SRC: c
  1119. connect {
  1120. /* name: the name of the server */
  1121. name = "myircdomainname.com";
  1122. /* host: the host or IP to connect to. If a hostname is used it
  1123. * must match the reverse dns of the server.
  1124. */
  1125. host = "127.0.0.1";
  1126. /* passwords: the passwords we send (OLD C:) and accept (OLD N:).
  1127. * The remote server will have these passwords reversed.
  1128. */
  1129. send_password = "password";
  1130. accept_password = "password";
  1131. /* compressed: controls whether traffic is compressed via ziplinks.
  1132. * By default this is disabled
  1133. */
  1134. compressed = yes;
  1135. };
  1136. /* listen {}: contain information about the ports ircd listens on (OLD P:) */
  1137. listen {
  1138. /* port: the specific port to listen on. if no host is specified
  1139. * before, it will listen on all available IPs.
  1140. *
  1141. * ports are seperated via a comma, a range may be specified using ".."
  1142. */
  1143. /* port: listen on all available IPs, ports 6665 to 6669 */
  1144. host = "127.0.0.1";
  1145. port = 6665 .. 6669;
  1146. /* sslport: ports to accept ONLY ssl connections on */
  1147. flags = ssl;
  1148. port = 6697
  1149. };
  1150. #+END_SRC
  1151. Generate a password for the IRC operator using mkpasswd tool
  1152. #+BEGIN_SRC: bash
  1153. mkpasswd -Hmd5
  1154. #+END_SRC
  1155. Search for operator block and change it to look like this:
  1156. #+BEGIN_SRC: c
  1157. # ...
  1158. operator {
  1159. /* name: the name of the oper */
  1160. name = "root";
  1161. /* user: the user@host required for this operator. CIDR is not
  1162. * supported. multiple user="" lines are supported.
  1163. */
  1164. user = "*@*";
  1165. /* password: the password required to oper. By default this will
  1166. * need to be encrypted using '/usr/bin/mkpasswd'.
  1167. * WARNING: Please do not mix up the 'mkpasswd' program from
  1168. * /usr/sbin with this one. If you are root, typing 'mkpasswd'
  1169. * will run that one instead and you will receive a strange error.
  1170. *
  1171. * MD5 is supported. If you want to use it, use mkpasswd -Hmd5.
  1172. */
  1173. password = "#MD5 PASSWORD HERE#";
  1174. # ...
  1175. #+END_SRC
  1176. Save and exit.
  1177. #+BEGIN_SRC: bash
  1178. service ircd-hybrid restart
  1179. #+END_SRC
  1180. Now open ports 6665 to 6669 on your internet router/firewall.
  1181. After connecting to IRC server you should see something like this:
  1182. #+BEGIN_SRC: bash
  1183. 23:50 -!- - hybrid7.debian.local Message of the Day -
  1184. 23:50 -!- - _,met$$$$$gg. ircd-hybrid 7.2.2
  1185. 23:50 -!- - ,g$$$$$$$$$$$$$$$P. -----------------
  1186. 23:50 -!- - ,g$$P"" """Y$$.".
  1187. 23:50 -!- - ,$$P' `$$$. If you are seeing this, you have
  1188. 23:50 -!- - ',$$P ,ggs. `$$b: installed the ircd-hybrid package and
  1189. 23:50 -!- - `d$$' ,$P"' . $$$ you are now connected to your new IRC
  1190. 23:50 -!- - $$P d$' , $$P server -- congratulations.
  1191. 23:50 -!- - $$: $$. - ,d$$'
  1192. 23:50 -!- - $$; Y$b._ _,d$P' Since you have just installed the
  1193. 23:50 -!- - Y$$. `.`"Y$$$$P"' package, there are some things you
  1194. 23:50 -!- - `$$b "-.__ should do before going any further:
  1195. 23:50 -!- - `Y$$b
  1196. 23:50 -!- - `Y$$. 1. Edit /etc/ircd-hybrid/ircd.conf to
  1197. 23:50 -!- - `$$b. suit your needs. Beware some options have
  1198. 23:50 -!- - `Y$$b. been removed or moved into other blocks in
  1199. 23:50 -!- - `"Y$b._ the configuration file since
  1200. 23:50 -!- - `"""" ircd-hybrid 7.0.3.
  1201. 23:50 -!- -
  1202. 23:50 -!- - 2. Edit /etc/ircd-hybrid/ircd.motd (this
  1203. 23:50 -!- - MOTD) to suit your needs. You are free
  1204. 23:50 -!- - to use this Debian swirl under the
  1205. 23:50 -!- - Debian Open Use Logo License. :)
  1206. 23:50 -!- -
  1207. 23:50 -!- - 3. Restart the server using invoke-rc.d
  1208. 23:50 -!- - ircd-hybrid restart.
  1209. 23:50 -!- -
  1210. 23:50 -!- - -- Joshua Kwan
  1211. 23:50 -!- - -- Aurélien GÉRÔME
  1212. 23:50 -!- End of /MOTD command.
  1213. #+END_SRC
  1214. We can change the motd message by editing */etc/ircd-hybrid/ircd.motd*
  1215. Hint: Don’t forget to restart the service */etc/init.d/ircd-hybrid restart*
  1216. Now if your have ever used IRC before you will be familiar with NickServ and ChanServ, well these are addons services for IRC and they come in vary useful when configuring chat channels and users.
  1217. We we will use hybserv and to install it:
  1218. #+BEGIN_SRC: bash
  1219. apt-get install hybserv
  1220. #+END_SRC
  1221. Then edit /etc/hybserv/hybserv.conf to look like this, remember to change #MD5 PASSWORD HERE# to the other password we setup earlier:
  1222. #+BEGIN_SRC: bash
  1223. O:*@*:#MD5 PASSWORD HERE#:root:segj
  1224. A:YOUR NAME
  1225. N:irc.example.com:Hybrid services
  1226. S:password:127.0.0.1:6667
  1227. #+END_SRC
  1228. now we need to restart the ircd and hybrid server to make things work:
  1229. #+BEGIN_SRC: bash
  1230. /etc/init.d/ircd-hybrid restart
  1231. /etc/init.d/hybserv restart
  1232. #+END_SRC
  1233. And that’s it you should have a Basic IRC server running with the NickServ and ChanServ bots running.
  1234. HERE is a Comparison of Internet Relay Chat services.
  1235. Try to connect to the IRC and identify yourself as an operator.
  1236. ** Install Gopher
  1237. 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.
  1238. To set up a gopher server:
  1239. #+BEGIN_SRC: bash
  1240. apt-get install build-essential
  1241. wget http://freedombone.uk.to/geomyidae-current.tgz
  1242. #+END_SRC
  1243. Verify the download:
  1244. #+BEGIN_SRC: bash
  1245. md5sum geomyidae-current.tgz
  1246. 3d8bb8601f37ca953b00fc2445ab5abe geomyidae-current.tgz
  1247. #+END_SRC
  1248. Then extract and install it.
  1249. #+BEGIN_SRC: bash
  1250. tar -xzvf geomyidae-current.tgz
  1251. cd geomyidae-*
  1252. make
  1253. make install
  1254. mkdir -p /var/gopher
  1255. #+END_SRC
  1256. 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.
  1257. #+BEGIN_SRC: bash
  1258. emacs /etc/init.d/gopher
  1259. #+END_SRC
  1260. Enter the following:
  1261. #+BEGIN_SRC: bash
  1262. #! /bin/sh
  1263. ### BEGIN INIT INFO
  1264. # Provides: gopher
  1265. # Required-Start: $remote_fs $syslog
  1266. # Required-Stop: $remote_fs $syslog
  1267. # Default-Start: 2 3 4 5
  1268. # Default-Stop: 0 1 6
  1269. # Short-Description: Gopher daemon
  1270. # Description: Gopher daemon
  1271. ### END INIT INFO
  1272. # Do NOT "set -e"
  1273. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  1274. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  1275. DESC="Gopher daemon"
  1276. NAME=geomyidae
  1277. DAEMON=/usr/bin/$NAME
  1278. DAEMON_ARGS="-l /var/log/geomyidae.log -b /var/gopher -p 70"
  1279. PIDFILE=/var/run/$NAME.pid
  1280. SCRIPTNAME=/etc/init.d/$NAME
  1281. # Exit if the package is not installed
  1282. [ -x "$DAEMON" ] || exit 0
  1283. # Read configuration variable file if it is present
  1284. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  1285. # Load the VERBOSE setting and other rcS variables
  1286. . /lib/init/vars.sh
  1287. # Define LSB log_* functions.
  1288. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  1289. # and status_of_proc is working.
  1290. . /lib/lsb/init-functions
  1291. #
  1292. # Function that starts the daemon/service
  1293. #
  1294. do_start()
  1295. {
  1296. # Return
  1297. # 0 if daemon has been started
  1298. # 1 if daemon was already running
  1299. # 2 if daemon could not be started
  1300. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  1301. || return 1
  1302. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  1303. $DAEMON_ARGS \
  1304. || return 2
  1305. # Add code here, if necessary, that waits for the process to be ready
  1306. # to handle requests from services started subsequently which depend
  1307. # on this one. As a last resort, sleep for some time.
  1308. }
  1309. #
  1310. # Function that stops the daemon/service
  1311. #
  1312. do_stop()
  1313. {
  1314. # Return
  1315. # 0 if daemon has been stopped
  1316. # 1 if daemon was already stopped
  1317. # 2 if daemon could not be stopped
  1318. # other if a failure occurred
  1319. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  1320. RETVAL="$?"
  1321. [ "$RETVAL" = 2 ] && return 2
  1322. # Wait for children to finish too if this is a daemon that forks
  1323. # and if the daemon is only ever run from this initscript.
  1324. # If the above conditions are not satisfied then add some other code
  1325. # that waits for the process to drop all resources that could be
  1326. # needed by services started subsequently. A last resort is to
  1327. # sleep for some time.
  1328. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  1329. [ "$?" = 2 ] && return 2
  1330. # Many daemons don't delete their pidfiles when they exit.
  1331. rm -f $PIDFILE
  1332. return "$RETVAL"
  1333. }
  1334. #
  1335. # Function that sends a SIGHUP to the daemon/service
  1336. #
  1337. do_reload() {
  1338. #
  1339. # If the daemon can reload its configuration without
  1340. # restarting (for example, when it is sent a SIGHUP),
  1341. # then implement that here.
  1342. #
  1343. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  1344. return 0
  1345. }
  1346. case "$1" in
  1347. start)
  1348. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  1349. do_start
  1350. case "$?" in
  1351. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  1352. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  1353. esac
  1354. ;;
  1355. stop)
  1356. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  1357. do_stop
  1358. case "$?" in
  1359. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  1360. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  1361. esac
  1362. ;;
  1363. status)
  1364. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  1365. ;;
  1366. #reload|force-reload)
  1367. #
  1368. # If do_reload() is not implemented then leave this commented out
  1369. # and leave 'force-reload' as an alias for 'restart'.
  1370. #
  1371. #log_daemon_msg "Reloading $DESC" "$NAME"
  1372. #do_reload
  1373. #log_end_msg $?
  1374. #;;
  1375. restart|force-reload)
  1376. #
  1377. # If the "reload" option is implemented then remove the
  1378. # 'force-reload' alias
  1379. #
  1380. log_daemon_msg "Restarting $DESC" "$NAME"
  1381. do_stop
  1382. case "$?" in
  1383. 0|1)
  1384. do_start
  1385. case "$?" in
  1386. 0) log_end_msg 0 ;;
  1387. 1) log_end_msg 1 ;; # Old process is still running
  1388. *) log_end_msg 1 ;; # Failed to start
  1389. esac
  1390. ;;
  1391. *)
  1392. # Failed to stop
  1393. log_end_msg 1
  1394. ;;
  1395. esac
  1396. ;;
  1397. *)
  1398. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  1399. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  1400. exit 3
  1401. ;;
  1402. esac
  1403. :
  1404. #+END_SRC
  1405. Save and exit. Then start the gopher service.
  1406. #+BEGIN_SRC: bash
  1407. chmod +x /etc/init.d/gopher
  1408. update-rc.d gopher defaults
  1409. service gopher start
  1410. #+END_SRC
  1411. 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:
  1412. #+BEGIN_SRC: bash
  1413. gopher://mydomainname.com
  1414. #+END_SRC
  1415. There is a browser addon for Gopher called "overbite". Installing that should enable you to view your site.
  1416. ** Install a Wiki
  1417. Dokuwiki is based upon flat files, and so is easy to move from one server to another without a lot of database complications.
  1418. Download the wiki.
  1419. #+BEGIN_SRC: bash
  1420. wget http://freedombone.uk.to/dokuwiki.tgz
  1421. #+END_SRC
  1422. Verify it.
  1423. #+BEGIN_SRC: bash
  1424. md5sum dokuwiki.tgz
  1425. 9f35055848429659fd63cda1cfea5a48 dokuwiki.tgz
  1426. #+END_SRC
  1427. Then extract and install it.
  1428. #+BEGIN_SRC: bash
  1429. export HOSTNAME=mywikidomainname.com
  1430. tar -xzvf dokuwiki.tgz
  1431. mv /var/www/$HOSTNAME/htdocs /var/www/$HOSTNAME/htdocs_old
  1432. mv dokuwiki /var/www/$HOSTNAME/htdocs
  1433. #+END_SRC
  1434. Edit the Apache configuration for your wiki site.
  1435. #+BEGIN_SRC: bash
  1436. emacs /etc/apache2/sites-available/$HOSTNAME
  1437. #+END_SRC
  1438. The settings should look something like the following.
  1439. #+BEGIN_SRC: bash
  1440. <VirtualHost *:80>
  1441. ServerAdmin myusername@mywikidomainname.com
  1442. ServerName mydomainname.com
  1443. DocumentRoot /var/www/mywikidomainname.com/htdocs
  1444. <Directory /var/www/mywikidomainname.com/htdocs>
  1445. order deny,allow
  1446. allow from all
  1447. </Directory>
  1448. <LocationMatch "/(data|conf|bin|inc)/">
  1449. order allow,deny
  1450. deny from all
  1451. satisfy all
  1452. </LocationMatch>
  1453. <Directory />
  1454. Options FollowSymLinks
  1455. AllowOverride All
  1456. </Directory>
  1457. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1458. <Directory "/usr/lib/cgi-bin">
  1459. AllowOverride All
  1460. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1461. Order allow,deny
  1462. Allow from all
  1463. </Directory>
  1464. ErrorLog ${APACHE_LOG_DIR}/error.log
  1465. # Possible values include: debug, info, notice, warn, error, crit,
  1466. # alert, emerg.
  1467. LogLevel warn
  1468. CustomLog ${APACHE_LOG_DIR}/access.log combined
  1469. </VirtualHost>
  1470. <IfModule mod_ssl.c>
  1471. <VirtualHost *:443>
  1472. ServerAdmin myusername@mywikidomainname.com
  1473. ServerName mywikidomainname.com
  1474. DocumentRoot /var/www/mywikidomainname.com/htdocs
  1475. <Directory /var/www/mywikidomainname.com/htdocs>
  1476. order deny,allow
  1477. allow from all
  1478. </Directory>
  1479. <LocationMatch "/(data|conf|bin|inc)/">
  1480. order allow,deny
  1481. deny from all
  1482. satisfy all
  1483. </LocationMatch>
  1484. <Directory />
  1485. Options FollowSymLinks
  1486. AllowOverride All
  1487. </Directory>
  1488. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1489. <Directory "/usr/lib/cgi-bin">
  1490. AllowOverride All
  1491. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1492. Order allow,deny
  1493. Allow from all
  1494. </Directory>
  1495. ErrorLog ${APACHE_LOG_DIR}/error.log
  1496. # Possible values include: debug, info, notice, warn, error, crit,
  1497. # alert, emerg.
  1498. LogLevel warn
  1499. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  1500. # SSL Engine Switch:
  1501. # Enable/Disable SSL for this virtual host.
  1502. SSLEngine on
  1503. # A self-signed certificate
  1504. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  1505. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  1506. # SSL Engine Options:
  1507. # Set various options for the SSL engine.
  1508. # o FakeBasicAuth:
  1509. # Translate the client X.509 into a Basic Authorisation. This means that
  1510. # the standard Auth/DBMAuth methods can be used for access control. The
  1511. # user name is the `one line' version of the client's X.509 certificate.
  1512. # Note that no password is obtained from the user. Every entry in the user
  1513. # file needs this password: `xxj31ZMTZzkVA'.
  1514. # o ExportCertData:
  1515. # This exports two additional environment variables: SSL_CLIENT_CERT and
  1516. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  1517. # server (always existing) and the client (only existing when client
  1518. # authentication is used). This can be used to import the certificates
  1519. # into CGI scripts.
  1520. # o StdEnvVars:
  1521. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  1522. # Per default this exportation is switched off for performance reasons,
  1523. # because the extraction step is an expensive operation and is usually
  1524. # useless for serving static content. So one usually enables the
  1525. # exportation for CGI and SSI requests only.
  1526. # o StrictRequire:
  1527. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  1528. # under a "Satisfy any" situation, i.e. when it applies access is denied
  1529. # and no other module can change it.
  1530. # o OptRenegotiate:
  1531. # This enables optimized SSL connection renegotiation handling when SSL
  1532. # directives are used in per-directory context.
  1533. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  1534. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  1535. SSLOptions +StdEnvVars
  1536. </FilesMatch>
  1537. <Directory /usr/lib/cgi-bin>
  1538. SSLOptions +StdEnvVars
  1539. </Directory>
  1540. # SSL Protocol Adjustments:
  1541. # The safe and default but still SSL/TLS standard compliant shutdown
  1542. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  1543. # the close notify alert from client. When you need a different shutdown
  1544. # approach you can use one of the following variables:
  1545. # o ssl-unclean-shutdown:
  1546. # This forces an unclean shutdown when the connection is closed, i.e. no
  1547. # SSL close notify alert is send or allowed to received. This violates
  1548. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  1549. # this when you receive I/O errors because of the standard approach where
  1550. # mod_ssl sends the close notify alert.
  1551. # o ssl-accurate-shutdown:
  1552. # This forces an accurate shutdown when the connection is closed, i.e. a
  1553. # SSL close notify alert is send and mod_ssl waits for the close notify
  1554. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  1555. # practice often causes hanging connections with brain-dead browsers. Use
  1556. # this only for browsers where you know that their SSL implementation
  1557. # works correctly.
  1558. # Notice: Most problems of broken clients are also related to the HTTP
  1559. # keep-alive facility, so you usually additionally want to disable
  1560. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  1561. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  1562. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  1563. # "force-response-1.0" for this.
  1564. BrowserMatch "MSIE [2-6]" \
  1565. nokeepalive ssl-unclean-shutdown \
  1566. downgrade-1.0 force-response-1.0
  1567. # MSIE 7 and newer should be able to use keepalive
  1568. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  1569. </VirtualHost>
  1570. </IfModule>
  1571. #+END_SRC
  1572. Enable your site with:
  1573. #+BEGIN_SRC: bash
  1574. a2ensite
  1575. #+END_SRC
  1576. then select the domain name and reload.
  1577. #+BEGIN_SRC: bash
  1578. service apache2 reload
  1579. #+END_SRC
  1580. and alter permissions:
  1581. #+BEGIN_SRC: bash
  1582. chmod -R 755 /var/www/$HOSTNAME/htdocs
  1583. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs
  1584. #+END_SRC
  1585. Open a browser and visit http://$HOSTNAME/install.php, then fill out the details. Once everything has been accepted without errors:
  1586. #+BEGIN_SRC: bash
  1587. rm /var/www/$HOSTNAME/htdocs/install.php
  1588. #+END_SRC
  1589. ** Install Tripwire
  1590. 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.
  1591. #+BEGIN_SRC: bash
  1592. apt-get install tripwire
  1593. export HOSTNAME=mydomainname.com
  1594. cd /etc/tripwire
  1595. cp arm-local.key $HOSTNAME-local.key
  1596. cp site.key $HOSTNAME-site.key
  1597. tripwire --init
  1598. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  1599. tripwire --check --interactive
  1600. #+END_SRC
  1601. you will be asked for two passphrases ("site" and "local"). Make a note of these.
  1602. If you subsequently install any more packages or make configuration changes then update the policy again with:
  1603. #+BEGIN_SRC: bash
  1604. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  1605. #+END_SRC
  1606. Also, to look for any rootkits.
  1607. #+BEGIN_SRC: bash
  1608. apt-get install rkhunter
  1609. #+END_SRC
  1610. * Router/Firewall ports
  1611. The following ports on your internet router/firewall should be forwarded to the BBB.
  1612. | Protocol | Port/s |
  1613. |----------+------------|
  1614. | Gopher | 70 |
  1615. | HTTP | 80 |
  1616. | HTTPS | 443 |
  1617. | IMAP | 143 |
  1618. | IRC | 6665..6669 |
  1619. | SIP | 5060 |
  1620. | SMTP | 25 |
  1621. | SMTP | 587 |
  1622. | SMTPS | 465 |
  1623. | SSH | 22 |
  1624. * Hints and Tips
  1625. ** Messaging security
  1626. 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.
  1627. ** Restrictive/hostile user environments
  1628. 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:
  1629. http://www.coralbits.com/oterm/
  1630. https://github.com/davidmoreno/onion
  1631. ** Moving Domains
  1632. 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:
  1633. #+BEGIN_SRC: bash
  1634. find /var/www/mynewdomain/htdocs -type f -exec sed -i 's@myolddomain@mynewdomain@g' {} \;
  1635. #+END_SRC
  1636. ** MySql foo
  1637. *** Backup all databases
  1638. To back up all mysql databases:
  1639. #+BEGIN_SRC: bash
  1640. mysqldump -u root -p --all-databases --events > /var/backups/databasebackup.sql
  1641. #+END_SRC
  1642. *** Restoring a particular mysql database
  1643. To restore yesterday's friendica backup:
  1644. #+BEGIN_SRC: bash
  1645. mysql -D friendica -o < /var/backups/friendica_daily.sql
  1646. #+END_SRC
  1647. To restore yesterday's mediawiki backup:
  1648. #+BEGIN_SRC: bash
  1649. mysql -D wikidb -o < /var/backups/wikidb_daily.sql
  1650. #+END_SRC
  1651. *** Removing mysql server
  1652. If you manage to screw up sql server completely then it can be fully deleted with:
  1653. #+BEGIN_SRC: bash
  1654. ps aux | grep mysql
  1655. #+END_SRC
  1656. and use /kill -9 <pid>/ to kill all mysql processes.
  1657. #+BEGIN_SRC: bash
  1658. sudo apt-get remove --purge mysql\*
  1659. apt-get clean
  1660. updatedb
  1661. #+END_SRC