beaglebone.txt 72KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346
  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.
  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. 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. *** Installation
  885. #+BEGIN_SRC: bash
  886. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  887. #+END_SRC
  888. Enter an admin password for MySQL.
  889. Create a mysql database.
  890. #+BEGIN_SRC: bash
  891. mysql -u root -p
  892. create database friendica;
  893. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'password';
  894. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  895. quit
  896. #+END_SRC
  897. You may need to fix Git SSL problems.
  898. #+BEGIN_SRC: bash
  899. git config --global http.sslVerify true
  900. apt-get install ca-certificates
  901. cd ~/
  902. emacs .gitconfig
  903. #+END_SRC
  904. The .gitconfig file should look something like this:
  905. #+BEGIN_SRC: bash
  906. [http]
  907. sslVerify = true
  908. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  909. [user]
  910. email = myusername@mydomainname.com
  911. name = yourname
  912. #+END_SRC
  913. Get the source code.
  914. #+BEGIN_SRC: bash
  915. export HOSTNAME=mydomainname.com
  916. cd /var/www/$HOSTNAME
  917. mv htdocs htdocs_old
  918. git clone https://github.com/friendica/friendica.git htdocs
  919. chmod -R 755 htdocs
  920. chown -R www-data:www-data htdocs
  921. chown -R www-data:www-data htdocs/view/smarty3
  922. git clone https://github.com/friendica/friendica-addons.git htdocs/addon
  923. #+END_SRC
  924. 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.
  925. Install the poller.
  926. #+BEGIN_SRC
  927. emacs /etc/crontab
  928. #+END_SRC
  929. and append the following, changing mydomainname.com to whatever your domain is.
  930. #+BEGIN_SRC
  931. */10 * * * * root cd /var/www/mydomainname.com/htdocs; /usr/bin/php include/poller.php
  932. #+END_SRC
  933. Save and exit, then restart cron.
  934. #+BEGIN_SRC: bash
  935. service cron restart
  936. #+END_SRC
  937. *** Backups
  938. 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.
  939. #+BEGIN_SRC: bash
  940. emacs /etc/cron.daily/friendicabackup
  941. #+END_SRC
  942. Enter the following
  943. #+BEGIN_SRC: bash
  944. #!/bin/sh
  945. MYSQL_PASSWORD=<mysql root password>
  946. umask 0077
  947. # Backup the database
  948. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_daily.sql
  949. # Make the backup readable only by root
  950. chmod 600 /var/backups/friendica_daily.sql
  951. #+END_SRC
  952. Save and exit.
  953. #+BEGIN_SRC: bash
  954. chmod 600 /etc/cron.daily/friendicabackup
  955. chmod +x /etc/cron.daily/friendicabackup
  956. emacs /etc/cron.weekly/friendicabackup
  957. #+END_SRC
  958. Enter the following
  959. #+BEGIN_SRC: bash
  960. #!/bin/sh
  961. MYSQL_PASSWORD=<mysql root password>
  962. umask 0077
  963. # Backup the database
  964. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_weekly.sql
  965. # Make the backup readable only by root
  966. chmod 600 /var/backups/friendica_weekly.sql
  967. #+END_SRC
  968. Save and exit.
  969. #+BEGIN_SRC: bash
  970. chmod 600 /etc/cron.weekly/friendicabackup
  971. chmod +x /etc/cron.weekly/friendicabackup
  972. #+END_SRC
  973. *** Recommended configuration
  974. **** Admin
  975. 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.
  976. 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.
  977. Under the *themes* section select a few themes, including mobile themes which are suitable for phones or tablets.
  978. 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.
  979. 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]].
  980. **** Settings
  981. Each user has their own customisable settings, typically available either via an icon or by an entry on a drop down menu.
  982. Under *additional features* enable "/richtext editor/", "/post preview/", "/group filter/", "/network filter/", "/edit sent posts/" and "/dislike posts/".
  983. Under *display settings* select your desktop and mobile themes.
  984. 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.
  985. *** To access from an Android device
  986. **** App
  987. 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.
  988. 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.
  989. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  990. **** Mobile Theme
  991. 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.
  992. ** Install a Blog
  993. 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.
  994. 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.
  995. Download flatpress.
  996. #+BEGIN_SRC: bash
  997. wget http://freedombone.uk.to/flatpress.tar.gz
  998. #+END_SRC
  999. Verify the download:
  1000. #+BEGIN_SRC: bash
  1001. md5sum flatpress.tar.gz
  1002. 6ad5c230a5cb1ac096ff657f1b138cc7 flatpress.tar.gz
  1003. #+END_SRC
  1004. Extract and install it.
  1005. #+BEGIN_SRC: bash
  1006. tar -xzvf flatpress.tar.gz
  1007. cd flatpress-*
  1008. cp -r * /var/www/$HOSTNAME/htdocs
  1009. rm -rf flatpress-*
  1010. rm -f flatpress.tar.gz
  1011. #+END_SRC
  1012. 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
  1013. ** Install a VoIP server
  1014. #+BEGIN_VERSE
  1015. /Our core principles, whether in software or sovereignty, have always been about freedom and dignity, for all people, on an equal basis/
  1016. -- David Sugar, GNU Telephony
  1017. #+END_VERSE
  1018. *** The server
  1019. 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.
  1020. Edit your package sources:
  1021. #+BEGIN_SRC: bash
  1022. emacs /etc/apt/sources.list
  1023. #+END_SRC
  1024. Append the following line:
  1025. #+BEGIN_SRC: bash
  1026. deb http://dev.gnutelephony.org/archive/ wheezy/
  1027. #+END_SRC
  1028. Save and exit.
  1029. 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
  1030. #+BEGIN_SRC: bash
  1031. apt-get install gnutelephony-keyring
  1032. #+END_SRC
  1033. After that it will be happy to accept it as a signed repository. The verification keys can also be directly fetched with
  1034. #+BEGIN_SRC: bash
  1035. wget http://dev.gnutelephony.org/archive/wheezy/public.key
  1036. #+END_SRC
  1037. and manually added instead with
  1038. #+BEGIN_SRC: bash
  1039. apt-key add public.key
  1040. #+END_SRC
  1041. To make sure you have all dependencies, do
  1042. #+BEGIN_SRC: bash
  1043. apt-get update;apt-get dist-upgrade
  1044. #+END_SRC
  1045. Before we install anything, let's inspect what is available to us by using
  1046. #+BEGIN_SRC: bash
  1047. dpkg -l sipwitch
  1048. #+END_SRC
  1049. To see the main application. The columns will indicate if the package is installed, which version and a description of the package. Then do
  1050. #+BEGIN_SRC: bash
  1051. dpkg -l sipwitch-*
  1052. #+END_SRC
  1053. 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.
  1054. To install only the main application, do
  1055. #+BEGIN_SRC: bash
  1056. apt-get install sipwitch
  1057. #+END_SRC
  1058. and to install all supporting plugins:
  1059. #+BEGIN_SRC: bash
  1060. apt-get install sipwitch-plugin-scripting sipwitch-plugin-subscriber sipwitch-plugin-forward sipwitch-plugin-zeroconf
  1061. #+END_SRC
  1062. Add your user into the sipwitch group
  1063. #+BEGIN_SRC: bash
  1064. groupadd sipwitch
  1065. groupadd sipusers
  1066. usermod -aG sipwitch myusername
  1067. usermod -aG sipusers myusername
  1068. #+END_SRC
  1069. Then edit the configuration
  1070. #+BEGIN_SRC: bash
  1071. emacs /etc/sipwitch.conf
  1072. #+END_SRC
  1073. Change the *mapped* value from 200 to 20, since we don't want to be serving huge numbers of calls.
  1074. 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.
  1075. Do not set the *realm* value, as doing so seems to prevent the server from working.
  1076. Save and exit.
  1077. Create a digest string for your username:
  1078. #+BEGIN_SRC: bash
  1079. sipwitch digest myusername
  1080. #+END_SRC
  1081. Make a note of the resulting string because you're going to use it in the users file you'll now create.
  1082. #+BEGIN_SRC: bash
  1083. export HOSTNAME=mydomainname.com
  1084. touch /etc/sipwitch.d/$HOSTNAME.xml
  1085. chmod 600 /etc/sipwitch.d/$HOSTNAME.xml
  1086. emacs /etc/sipwitch.d/$HOSTNAME.xml
  1087. #+END_SRC
  1088. It should look something like the following:
  1089. #+BEGIN_SRC: bash
  1090. <provision>
  1091. <user id="myusername">
  1092. <digest>yourdigeststring</digest>
  1093. <extension>201</extension>
  1094. <display>Your full name</display>
  1095. </user>
  1096. </provision>
  1097. #+END_SRC
  1098. Save and exit. Now edit the configuration.
  1099. #+BEGIN_SRC: bash
  1100. emacs /etc/default/sipwitch
  1101. #+END_SRC
  1102. Change "desktop" to "server", then save and exit.
  1103. Update the IP settings:
  1104. #+BEGIN_SRC: bash
  1105. iptables -A INPUT -p tcp --dport 5060 -j ACCEPT
  1106. iptables -A INPUT -p udp --dport 5060 -j ACCEPT
  1107. iptables -A INPUT -p tcp --dport 5061 -j ACCEPT
  1108. iptables -A INPUT -p udp --dport 5061 -j ACCEPT
  1109. iptables-save
  1110. #+END_SRC
  1111. Test that it's working:
  1112. #+BEGIN_SRC: bash
  1113. pkill -9 sipw
  1114. sipw -x9 -f
  1115. #+END_SRC
  1116. 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.
  1117. #+BEGIN_SRC: bash
  1118. service sipwitch start
  1119. #+END_SRC
  1120. *** Clients
  1121. **** Jitsi
  1122. Download the latst version from https://jitsi.org/index.php/Main/Download
  1123. TODO
  1124. **** Twinkle client
  1125. The client should have a user profile as following:
  1126. The "user name" is the xxx id used in the <user id="xxx"> entry of /etc/sipwitch.conf
  1127. The "domain" is the yyy domain in the main config <stack><domain>yyy entry of /etc/sipwitch.conf
  1128. The SIP Authentication should have:
  1129. realm = realm as set in <registry><realm> of /etc/sipwitch.conf
  1130. authentication name = <user id="xx"> entry, same as "User Name" field.
  1131. password = value of <secret>zzz in <user> entry of /etc/sipwitch.conf
  1132. Under security tab, set "Enable ZRTP/SRTP encryption"
  1133. **** Android
  1134. TODO
  1135. CSipSimple?
  1136. ** Install an IRC server
  1137. #+BEGIN_SRC: bash
  1138. apt-get install ircd-hybrid
  1139. #+END_SRC
  1140. This will install the IRC server and run it on ports (6666.6669) TCP
  1141. You can connect to the server by visiting 127.0.0.1 with your irc client
  1142. ————————————————————————————————
  1143. Because hybrid doesn’t support OpenSSL by default, you have to do a manual patch to get it working
  1144. 1- First we OpenSSL package for ssl certificate
  1145. #+BEGIN_SRC: bash
  1146. sudo apt-get install openssl libssl-dev
  1147. #+END_SRC
  1148. 2- Second we need hybrid source to patch it:
  1149. #+BEGIN_SRC: bash
  1150. mkdir hybrid; cd hybrid
  1151. apt-get install openssl libssl-dev
  1152. apt-get source ircd-hybrid
  1153. #+END_SRC
  1154. To enable SSL
  1155. #+BEGIN_SRC: bash
  1156. emacs ircd-hybrid-*/debian/rules
  1157. #+END_SRC
  1158. Add at the top:
  1159. #+BEGIN_SRC: bash
  1160. USE_OPENSSL = 1
  1161. #+END_SRC
  1162. So the file should looks like:
  1163. #+BEGIN_SRC: bash
  1164. 1# ...
  1165. 2# Some useful stuff to edit here.
  1166. 3# Beware: TOPICLEN may not exceed 390.
  1167. 4NICKLEN = 15
  1168. 5TOPICLEN = 350
  1169. 6MAXCLIENTS = 200
  1170. 7USE_OPENSSL = 1
  1171. 8# ...
  1172. #+END_SRC
  1173. Rebuild the deb-file and install it:
  1174. #+BEGIN_SRC: bash
  1175. cd ircd-hybrid-*
  1176. apt-get install build-essential debhelper dpatch docbook-to-man flex bison libpcre3-dev
  1177. dpkg-buildpackage -rfakeroot -uc -b
  1178. cd ..
  1179. dpkg -i ircd-hybrid_*.deb
  1180. #+END_SRC
  1181. Edit connect, listen and operator:
  1182. #+BEGIN_SRC: bash
  1183. emacs /etc/ircd-hybrid/ircd.conf
  1184. #+END_SRC
  1185. Edit the connect section.
  1186. #+BEGIN_SRC: c
  1187. connect {
  1188. /* name: the name of the server */
  1189. name = "myircdomainname.com";
  1190. /* host: the host or IP to connect to. If a hostname is used it
  1191. * must match the reverse dns of the server.
  1192. */
  1193. host = "127.0.0.1";
  1194. /* passwords: the passwords we send (OLD C:) and accept (OLD N:).
  1195. * The remote server will have these passwords reversed.
  1196. */
  1197. send_password = "password";
  1198. accept_password = "password";
  1199. /* compressed: controls whether traffic is compressed via ziplinks.
  1200. * By default this is disabled
  1201. */
  1202. compressed = yes;
  1203. };
  1204. /* listen {}: contain information about the ports ircd listens on (OLD P:) */
  1205. listen {
  1206. /* port: the specific port to listen on. if no host is specified
  1207. * before, it will listen on all available IPs.
  1208. *
  1209. * ports are seperated via a comma, a range may be specified using ".."
  1210. */
  1211. /* port: listen on all available IPs, ports 6665 to 6669 */
  1212. host = "127.0.0.1";
  1213. port = 6665 .. 6669;
  1214. /* sslport: ports to accept ONLY ssl connections on */
  1215. flags = ssl;
  1216. port = 6697
  1217. };
  1218. #+END_SRC
  1219. Generate a password for the IRC operator using mkpasswd tool
  1220. #+BEGIN_SRC: bash
  1221. mkpasswd -Hmd5
  1222. #+END_SRC
  1223. Search for operator block and change it to look like this:
  1224. #+BEGIN_SRC: c
  1225. # ...
  1226. operator {
  1227. /* name: the name of the oper */
  1228. name = "root";
  1229. /* user: the user@host required for this operator. CIDR is not
  1230. * supported. multiple user="" lines are supported.
  1231. */
  1232. user = "*@*";
  1233. /* password: the password required to oper. By default this will
  1234. * need to be encrypted using '/usr/bin/mkpasswd'.
  1235. * WARNING: Please do not mix up the 'mkpasswd' program from
  1236. * /usr/sbin with this one. If you are root, typing 'mkpasswd'
  1237. * will run that one instead and you will receive a strange error.
  1238. *
  1239. * MD5 is supported. If you want to use it, use mkpasswd -Hmd5.
  1240. */
  1241. password = "#MD5 PASSWORD HERE#";
  1242. # ...
  1243. #+END_SRC
  1244. Save and exit.
  1245. #+BEGIN_SRC: bash
  1246. service ircd-hybrid restart
  1247. #+END_SRC
  1248. Now open ports 6665 to 6669 on your internet router/firewall.
  1249. After connecting to IRC server you should see something like this:
  1250. #+BEGIN_SRC: bash
  1251. 23:50 -!- - hybrid7.debian.local Message of the Day -
  1252. 23:50 -!- - _,met$$$$$gg. ircd-hybrid 7.2.2
  1253. 23:50 -!- - ,g$$$$$$$$$$$$$$$P. -----------------
  1254. 23:50 -!- - ,g$$P"" """Y$$.".
  1255. 23:50 -!- - ,$$P' `$$$. If you are seeing this, you have
  1256. 23:50 -!- - ',$$P ,ggs. `$$b: installed the ircd-hybrid package and
  1257. 23:50 -!- - `d$$' ,$P"' . $$$ you are now connected to your new IRC
  1258. 23:50 -!- - $$P d$' , $$P server -- congratulations.
  1259. 23:50 -!- - $$: $$. - ,d$$'
  1260. 23:50 -!- - $$; Y$b._ _,d$P' Since you have just installed the
  1261. 23:50 -!- - Y$$. `.`"Y$$$$P"' package, there are some things you
  1262. 23:50 -!- - `$$b "-.__ should do before going any further:
  1263. 23:50 -!- - `Y$$b
  1264. 23:50 -!- - `Y$$. 1. Edit /etc/ircd-hybrid/ircd.conf to
  1265. 23:50 -!- - `$$b. suit your needs. Beware some options have
  1266. 23:50 -!- - `Y$$b. been removed or moved into other blocks in
  1267. 23:50 -!- - `"Y$b._ the configuration file since
  1268. 23:50 -!- - `"""" ircd-hybrid 7.0.3.
  1269. 23:50 -!- -
  1270. 23:50 -!- - 2. Edit /etc/ircd-hybrid/ircd.motd (this
  1271. 23:50 -!- - MOTD) to suit your needs. You are free
  1272. 23:50 -!- - to use this Debian swirl under the
  1273. 23:50 -!- - Debian Open Use Logo License. :)
  1274. 23:50 -!- -
  1275. 23:50 -!- - 3. Restart the server using invoke-rc.d
  1276. 23:50 -!- - ircd-hybrid restart.
  1277. 23:50 -!- -
  1278. 23:50 -!- - -- Joshua Kwan
  1279. 23:50 -!- - -- Aurélien GÉRÔME
  1280. 23:50 -!- End of /MOTD command.
  1281. #+END_SRC
  1282. We can change the motd message by editing */etc/ircd-hybrid/ircd.motd*
  1283. Hint: Don’t forget to restart the service */etc/init.d/ircd-hybrid restart*
  1284. 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.
  1285. We we will use hybserv and to install it:
  1286. #+BEGIN_SRC: bash
  1287. apt-get install hybserv
  1288. #+END_SRC
  1289. Then edit /etc/hybserv/hybserv.conf to look like this, remember to change #MD5 PASSWORD HERE# to the other password we setup earlier:
  1290. #+BEGIN_SRC: bash
  1291. O:*@*:#MD5 PASSWORD HERE#:root:segj
  1292. A:YOUR NAME
  1293. N:irc.example.com:Hybrid services
  1294. S:password:127.0.0.1:6667
  1295. #+END_SRC
  1296. now we need to restart the ircd and hybrid server to make things work:
  1297. #+BEGIN_SRC: bash
  1298. /etc/init.d/ircd-hybrid restart
  1299. /etc/init.d/hybserv restart
  1300. #+END_SRC
  1301. And that’s it you should have a Basic IRC server running with the NickServ and ChanServ bots running.
  1302. Try to connect to the IRC and identify yourself as an operator.
  1303. In irssi:
  1304. #+BEGIN_SRC
  1305. /connect -ssl irc.example.com 6667 ircpassowrd YourNick
  1306. #+END_SRC
  1307. /join #spatula
  1308. /msg -servername chanserv REGISTER #spatula channelpassword
  1309. /msg -servername chanserv set #spatula mlock +k channelpassword
  1310. ** Install Gopher
  1311. 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.
  1312. To set up a gopher server:
  1313. #+BEGIN_SRC: bash
  1314. apt-get install build-essential
  1315. wget http://freedombone.uk.to/geomyidae-current.tgz
  1316. #+END_SRC
  1317. Verify the download:
  1318. #+BEGIN_SRC: bash
  1319. md5sum geomyidae-current.tgz
  1320. 3d8bb8601f37ca953b00fc2445ab5abe geomyidae-current.tgz
  1321. #+END_SRC
  1322. Then extract and install it.
  1323. #+BEGIN_SRC: bash
  1324. tar -xzvf geomyidae-current.tgz
  1325. cd geomyidae-*
  1326. make
  1327. make install
  1328. mkdir -p /var/gopher
  1329. #+END_SRC
  1330. 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.
  1331. #+BEGIN_SRC: bash
  1332. emacs /etc/init.d/gopher
  1333. #+END_SRC
  1334. Enter the following:
  1335. #+BEGIN_SRC: bash
  1336. #! /bin/sh
  1337. ### BEGIN INIT INFO
  1338. # Provides: gopher
  1339. # Required-Start: $remote_fs $syslog
  1340. # Required-Stop: $remote_fs $syslog
  1341. # Default-Start: 2 3 4 5
  1342. # Default-Stop: 0 1 6
  1343. # Short-Description: Gopher daemon
  1344. # Description: Gopher daemon
  1345. ### END INIT INFO
  1346. # Do NOT "set -e"
  1347. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  1348. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  1349. DESC="Gopher daemon"
  1350. NAME=geomyidae
  1351. DAEMON=/usr/bin/$NAME
  1352. DAEMON_ARGS="-l /var/log/geomyidae.log -b /var/gopher -p 70"
  1353. PIDFILE=/var/run/$NAME.pid
  1354. SCRIPTNAME=/etc/init.d/$NAME
  1355. # Exit if the package is not installed
  1356. [ -x "$DAEMON" ] || exit 0
  1357. # Read configuration variable file if it is present
  1358. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  1359. # Load the VERBOSE setting and other rcS variables
  1360. . /lib/init/vars.sh
  1361. # Define LSB log_* functions.
  1362. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  1363. # and status_of_proc is working.
  1364. . /lib/lsb/init-functions
  1365. #
  1366. # Function that starts the daemon/service
  1367. #
  1368. do_start()
  1369. {
  1370. # Return
  1371. # 0 if daemon has been started
  1372. # 1 if daemon was already running
  1373. # 2 if daemon could not be started
  1374. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  1375. || return 1
  1376. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  1377. $DAEMON_ARGS \
  1378. || return 2
  1379. # Add code here, if necessary, that waits for the process to be ready
  1380. # to handle requests from services started subsequently which depend
  1381. # on this one. As a last resort, sleep for some time.
  1382. }
  1383. #
  1384. # Function that stops the daemon/service
  1385. #
  1386. do_stop()
  1387. {
  1388. # Return
  1389. # 0 if daemon has been stopped
  1390. # 1 if daemon was already stopped
  1391. # 2 if daemon could not be stopped
  1392. # other if a failure occurred
  1393. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  1394. RETVAL="$?"
  1395. [ "$RETVAL" = 2 ] && return 2
  1396. # Wait for children to finish too if this is a daemon that forks
  1397. # and if the daemon is only ever run from this initscript.
  1398. # If the above conditions are not satisfied then add some other code
  1399. # that waits for the process to drop all resources that could be
  1400. # needed by services started subsequently. A last resort is to
  1401. # sleep for some time.
  1402. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  1403. [ "$?" = 2 ] && return 2
  1404. # Many daemons don't delete their pidfiles when they exit.
  1405. rm -f $PIDFILE
  1406. return "$RETVAL"
  1407. }
  1408. #
  1409. # Function that sends a SIGHUP to the daemon/service
  1410. #
  1411. do_reload() {
  1412. #
  1413. # If the daemon can reload its configuration without
  1414. # restarting (for example, when it is sent a SIGHUP),
  1415. # then implement that here.
  1416. #
  1417. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  1418. return 0
  1419. }
  1420. case "$1" in
  1421. start)
  1422. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  1423. do_start
  1424. case "$?" in
  1425. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  1426. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  1427. esac
  1428. ;;
  1429. stop)
  1430. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  1431. do_stop
  1432. case "$?" in
  1433. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  1434. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  1435. esac
  1436. ;;
  1437. status)
  1438. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  1439. ;;
  1440. #reload|force-reload)
  1441. #
  1442. # If do_reload() is not implemented then leave this commented out
  1443. # and leave 'force-reload' as an alias for 'restart'.
  1444. #
  1445. #log_daemon_msg "Reloading $DESC" "$NAME"
  1446. #do_reload
  1447. #log_end_msg $?
  1448. #;;
  1449. restart|force-reload)
  1450. #
  1451. # If the "reload" option is implemented then remove the
  1452. # 'force-reload' alias
  1453. #
  1454. log_daemon_msg "Restarting $DESC" "$NAME"
  1455. do_stop
  1456. case "$?" in
  1457. 0|1)
  1458. do_start
  1459. case "$?" in
  1460. 0) log_end_msg 0 ;;
  1461. 1) log_end_msg 1 ;; # Old process is still running
  1462. *) log_end_msg 1 ;; # Failed to start
  1463. esac
  1464. ;;
  1465. *)
  1466. # Failed to stop
  1467. log_end_msg 1
  1468. ;;
  1469. esac
  1470. ;;
  1471. *)
  1472. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  1473. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  1474. exit 3
  1475. ;;
  1476. esac
  1477. :
  1478. #+END_SRC
  1479. Save and exit. Then start the gopher service.
  1480. #+BEGIN_SRC: bash
  1481. chmod +x /etc/init.d/gopher
  1482. update-rc.d gopher defaults
  1483. service gopher start
  1484. #+END_SRC
  1485. 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:
  1486. #+BEGIN_SRC: bash
  1487. gopher://mydomainname.com
  1488. #+END_SRC
  1489. There is a browser addon for Gopher called "overbite". Installing that should enable you to view your site.
  1490. ** Install a Wiki
  1491. Dokuwiki is based upon flat files, and so is easy to move from one server to another without a lot of database complications.
  1492. Download the wiki.
  1493. #+BEGIN_SRC: bash
  1494. wget http://freedombone.uk.to/dokuwiki.tgz
  1495. #+END_SRC
  1496. Verify it.
  1497. #+BEGIN_SRC: bash
  1498. md5sum dokuwiki.tgz
  1499. 9f35055848429659fd63cda1cfea5a48 dokuwiki.tgz
  1500. #+END_SRC
  1501. Then extract and install it.
  1502. #+BEGIN_SRC: bash
  1503. export HOSTNAME=mywikidomainname.com
  1504. tar -xzvf dokuwiki.tgz
  1505. mv /var/www/$HOSTNAME/htdocs /var/www/$HOSTNAME/htdocs_old
  1506. mv dokuwiki /var/www/$HOSTNAME/htdocs
  1507. #+END_SRC
  1508. Edit the Apache configuration for your wiki site.
  1509. #+BEGIN_SRC: bash
  1510. emacs /etc/apache2/sites-available/$HOSTNAME
  1511. #+END_SRC
  1512. The settings should look something like the following.
  1513. #+BEGIN_SRC: bash
  1514. <VirtualHost *:80>
  1515. ServerAdmin myusername@mywikidomainname.com
  1516. ServerName mydomainname.com
  1517. DocumentRoot /var/www/mywikidomainname.com/htdocs
  1518. <Directory /var/www/mywikidomainname.com/htdocs>
  1519. order deny,allow
  1520. allow from all
  1521. </Directory>
  1522. <LocationMatch "/(data|conf|bin|inc)/">
  1523. order allow,deny
  1524. deny from all
  1525. satisfy all
  1526. </LocationMatch>
  1527. <Directory />
  1528. Options FollowSymLinks
  1529. AllowOverride All
  1530. </Directory>
  1531. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1532. <Directory "/usr/lib/cgi-bin">
  1533. AllowOverride All
  1534. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1535. Order allow,deny
  1536. Allow from all
  1537. </Directory>
  1538. ErrorLog ${APACHE_LOG_DIR}/error.log
  1539. # Possible values include: debug, info, notice, warn, error, crit,
  1540. # alert, emerg.
  1541. LogLevel warn
  1542. CustomLog ${APACHE_LOG_DIR}/access.log combined
  1543. </VirtualHost>
  1544. <IfModule mod_ssl.c>
  1545. <VirtualHost *:443>
  1546. ServerAdmin myusername@mywikidomainname.com
  1547. ServerName mywikidomainname.com
  1548. DocumentRoot /var/www/mywikidomainname.com/htdocs
  1549. <Directory /var/www/mywikidomainname.com/htdocs>
  1550. order deny,allow
  1551. allow from all
  1552. </Directory>
  1553. <LocationMatch "/(data|conf|bin|inc)/">
  1554. order allow,deny
  1555. deny from all
  1556. satisfy all
  1557. </LocationMatch>
  1558. <Directory />
  1559. Options FollowSymLinks
  1560. AllowOverride All
  1561. </Directory>
  1562. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1563. <Directory "/usr/lib/cgi-bin">
  1564. AllowOverride All
  1565. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1566. Order allow,deny
  1567. Allow from all
  1568. </Directory>
  1569. ErrorLog ${APACHE_LOG_DIR}/error.log
  1570. # Possible values include: debug, info, notice, warn, error, crit,
  1571. # alert, emerg.
  1572. LogLevel warn
  1573. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  1574. # SSL Engine Switch:
  1575. # Enable/Disable SSL for this virtual host.
  1576. SSLEngine on
  1577. # A self-signed certificate
  1578. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  1579. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  1580. # SSL Engine Options:
  1581. # Set various options for the SSL engine.
  1582. # o FakeBasicAuth:
  1583. # Translate the client X.509 into a Basic Authorisation. This means that
  1584. # the standard Auth/DBMAuth methods can be used for access control. The
  1585. # user name is the `one line' version of the client's X.509 certificate.
  1586. # Note that no password is obtained from the user. Every entry in the user
  1587. # file needs this password: `xxj31ZMTZzkVA'.
  1588. # o ExportCertData:
  1589. # This exports two additional environment variables: SSL_CLIENT_CERT and
  1590. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  1591. # server (always existing) and the client (only existing when client
  1592. # authentication is used). This can be used to import the certificates
  1593. # into CGI scripts.
  1594. # o StdEnvVars:
  1595. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  1596. # Per default this exportation is switched off for performance reasons,
  1597. # because the extraction step is an expensive operation and is usually
  1598. # useless for serving static content. So one usually enables the
  1599. # exportation for CGI and SSI requests only.
  1600. # o StrictRequire:
  1601. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  1602. # under a "Satisfy any" situation, i.e. when it applies access is denied
  1603. # and no other module can change it.
  1604. # o OptRenegotiate:
  1605. # This enables optimized SSL connection renegotiation handling when SSL
  1606. # directives are used in per-directory context.
  1607. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  1608. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  1609. SSLOptions +StdEnvVars
  1610. </FilesMatch>
  1611. <Directory /usr/lib/cgi-bin>
  1612. SSLOptions +StdEnvVars
  1613. </Directory>
  1614. # SSL Protocol Adjustments:
  1615. # The safe and default but still SSL/TLS standard compliant shutdown
  1616. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  1617. # the close notify alert from client. When you need a different shutdown
  1618. # approach you can use one of the following variables:
  1619. # o ssl-unclean-shutdown:
  1620. # This forces an unclean shutdown when the connection is closed, i.e. no
  1621. # SSL close notify alert is send or allowed to received. This violates
  1622. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  1623. # this when you receive I/O errors because of the standard approach where
  1624. # mod_ssl sends the close notify alert.
  1625. # o ssl-accurate-shutdown:
  1626. # This forces an accurate shutdown when the connection is closed, i.e. a
  1627. # SSL close notify alert is send and mod_ssl waits for the close notify
  1628. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  1629. # practice often causes hanging connections with brain-dead browsers. Use
  1630. # this only for browsers where you know that their SSL implementation
  1631. # works correctly.
  1632. # Notice: Most problems of broken clients are also related to the HTTP
  1633. # keep-alive facility, so you usually additionally want to disable
  1634. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  1635. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  1636. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  1637. # "force-response-1.0" for this.
  1638. BrowserMatch "MSIE [2-6]" \
  1639. nokeepalive ssl-unclean-shutdown \
  1640. downgrade-1.0 force-response-1.0
  1641. # MSIE 7 and newer should be able to use keepalive
  1642. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  1643. </VirtualHost>
  1644. </IfModule>
  1645. #+END_SRC
  1646. Enable your site with:
  1647. #+BEGIN_SRC: bash
  1648. a2ensite
  1649. #+END_SRC
  1650. then select the domain name and reload.
  1651. #+BEGIN_SRC: bash
  1652. service apache2 reload
  1653. #+END_SRC
  1654. and alter permissions:
  1655. #+BEGIN_SRC: bash
  1656. chmod -R 755 /var/www/$HOSTNAME/htdocs
  1657. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs
  1658. #+END_SRC
  1659. Open a browser and visit http://$HOSTNAME/install.php, then fill out the details. Once everything has been accepted without errors:
  1660. #+BEGIN_SRC: bash
  1661. rm /var/www/$HOSTNAME/htdocs/install.php
  1662. #+END_SRC
  1663. ** Install Owncloud
  1664. 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.
  1665. #+BEGIN_SRC: bash
  1666. emacs /etc/php5/apache2filter/php.ini
  1667. #+END_SRC
  1668. Set the following:
  1669. #+BEGIN_SRC: bash
  1670. post_max_size = 32M
  1671. upload_max_filesize = 32M
  1672. #+END_SRC
  1673. Restart apache.
  1674. #+BEGIN_SRC: bash
  1675. service apache2 restart
  1676. #+END_SRC
  1677. Install some dependencies:
  1678. #+BEGIN_SRC: bash
  1679. apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
  1680. apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
  1681. #+END_SRC
  1682. Download owncloud.
  1683. #+BEGIN_SRC: bash
  1684. cd /tmp
  1685. wget http://freedombone.uk.to/owncloud.tar.bz2
  1686. #+END_SRC
  1687. Verify the download:
  1688. #+BEGIN_SRC: bash
  1689. md5 owncloud.tar.bz2
  1690. f43eabb746b5e339ee70d0a6aaf4a49c
  1691. #+END_SRC
  1692. Extract the archive. This may take a couple of minutes, so don't be alarmed that the system has crashed.
  1693. #+BEGIN_SRC: bash
  1694. export HOSTNAME=myownclouddomainname.com
  1695. tar -xjf owncloud.tar.bz2
  1696. #+END_SRC
  1697. Move the extracted files to your site.
  1698. #+BEGIN_SRC: bash
  1699. cp -r owncloud /var/www/$HOSTNAME
  1700. rm -rf /var/www/$HOSTNAME/htdocs
  1701. mv /var/www/$HOSTNAME/owncloud /var/www/$HOSTNAME/htdocs
  1702. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/
  1703. chmod 775 /var/www/$HOSTNAME/htdocs
  1704. chmod 664 /var/www/$HOSTNAME/htdocs/*
  1705. chmod g+s /var/www/$HOSTNAME/htdocs
  1706. #+END_SRC
  1707. With a web browser visit your domain and enter an administrator username and password.
  1708. ** Install Gitlab
  1709. ** Install Tripwire
  1710. 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.
  1711. #+BEGIN_SRC: bash
  1712. apt-get install tripwire
  1713. export HOSTNAME=mydomainname.com
  1714. cd /etc/tripwire
  1715. cp arm-local.key $HOSTNAME-local.key
  1716. cp site.key $HOSTNAME-site.key
  1717. tripwire --init
  1718. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  1719. tripwire --check --interactive
  1720. #+END_SRC
  1721. you will be asked for two passphrases ("site" and "local"). Make a note of these.
  1722. If you subsequently install any more packages or make configuration changes then update the policy again with:
  1723. #+BEGIN_SRC: bash
  1724. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  1725. #+END_SRC
  1726. Also, to look for any rootkits.
  1727. #+BEGIN_SRC: bash
  1728. apt-get install rkhunter
  1729. #+END_SRC
  1730. * Router/Firewall ports
  1731. The following ports on your internet router/firewall should be forwarded to the BBB.
  1732. | Protocol | Port/s |
  1733. |----------+------------|
  1734. | Gopher | 70 |
  1735. | HTTP | 80 |
  1736. | HTTPS | 443 |
  1737. | IMAP | 143 |
  1738. | IRC | 6665..6669 |
  1739. | SIP | 5060..5061 |
  1740. | SMTP | 25 |
  1741. | SMTPS | 465 |
  1742. | SSH | 22 |
  1743. * Hints and Tips
  1744. ** Messaging security
  1745. 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.
  1746. ** Restrictive/hostile user environments
  1747. 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:
  1748. http://www.coralbits.com/oterm/
  1749. https://github.com/davidmoreno/onion
  1750. ** Moving Domains
  1751. 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:
  1752. #+BEGIN_SRC: bash
  1753. find /var/www/mynewdomain/htdocs -type f -exec sed -i 's@myolddomain@mynewdomain@g' {} \;
  1754. #+END_SRC
  1755. ** MySql foo
  1756. *** Backup all databases
  1757. To back up all mysql databases:
  1758. #+BEGIN_SRC: bash
  1759. mysqldump -u root -p --all-databases --events > /var/backups/databasebackup.sql
  1760. #+END_SRC
  1761. *** Restoring a particular mysql database
  1762. To restore yesterday's friendica backup:
  1763. #+BEGIN_SRC: bash
  1764. mysql -D friendica -o < /var/backups/friendica_daily.sql
  1765. #+END_SRC
  1766. To restore yesterday's mediawiki backup:
  1767. #+BEGIN_SRC: bash
  1768. mysql -D wikidb -o < /var/backups/wikidb_daily.sql
  1769. #+END_SRC
  1770. *** Removing mysql server
  1771. If you manage to screw up sql server completely then it can be fully deleted with:
  1772. #+BEGIN_SRC: bash
  1773. ps aux | grep mysql
  1774. #+END_SRC
  1775. and use /kill -9 <pid>/ to kill all mysql processes.
  1776. #+BEGIN_SRC: bash
  1777. sudo apt-get remove --purge mysql\*
  1778. apt-get clean
  1779. updatedb
  1780. #+END_SRC