beaglebone.txt 143KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556
  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, social network, irc, jabber, chat
  5. #+DESCRIPTION: Turn the Beaglebone Black into a personal communications server
  6. #+OPTIONS: ^:nil
  7. #+STYLE: <link rel="stylesheet" type="text/css" href="index.css" />
  8. #+BEGIN_CENTER
  9. *How to turn the Beaglebone Black into a FreedomBox-like personal communications server*
  10. #+END_CENTER
  11. #+CAPTION: BeagleBone Black
  12. #+ATTR_HTML: :alt BeagleBone Black image :align center
  13. [[[[./images/freedombone.jpg]]]]
  14. #+BEGIN_CENTER
  15. Copyright (C) 2014 Bob Mottram
  16. 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.
  17. 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]].
  18. #+END_CENTER
  19. * Introduction
  20. #+BEGIN_VERSE
  21. /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./
  22. -- Edward J. Snowden
  23. #+END_VERSE
  24. ** What is FreedomBone?
  25. 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.
  26. 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.
  27. ** Do I need any prior knowledge?
  28. 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.
  29. ** Why should I do this?
  30. 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).
  31. 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.
  32. 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.
  33. ** After it's installed will it need a lot of maintenance?
  34. 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.
  35. ** Is it secure?
  36. 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.
  37. 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. This project is at least as much about achieving communications independence as it is about being able to do that securely.
  38. ** Will running a server all the time affect my electricity bill?
  39. 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.
  40. ** Can I use a Raspberry Pi instead?
  41. These instructions are not highly specific to the Beaglebone Black and so will likely also work on other single board computers (SBCs) such as the Raspberry Pi. The original Raspberry Pi only had 256MB of RAM and so the performance of some services may be more limited. The Beaglebone Black was chosen mainly because of its low cost, relatively good CPU performance for the price (by the standards of 2013) and also low electricity consumption.
  42. * Inventory
  43. #+BEGIN_VERSE
  44. /You can’t help someone just by making a wish to do so, you have to take action./
  45. -- Dalai Lama
  46. #+END_VERSE
  47. These instructions assume that you have the following ingredients.
  48. ** A BeagleBone Black (BBB)
  49. 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.
  50. ** An internet connection
  51. 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.
  52. ** microSD card
  53. 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.
  54. 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.
  55. ** 5V/1A power supply
  56. 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.
  57. ** An ethernet patch cable
  58. Just an ordinary cat5 or cat6 cable that you can get from most electrical/computer stores.
  59. * Installing Debian onto the microSD card
  60. 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.
  61. Download the image.
  62. #+BEGIN_SRC: bash
  63. cd ~/
  64. wget http://freedombone.uk.to/debian-7.2-console-armhf-2013-11-15.tar.xz
  65. #+END_SRC
  66. Verify it.
  67. #+BEGIN_SRC: bash
  68. sha256sum debian-7.2-console-armhf-2013-11-15.tar.xz
  69. 262ea96d6bff530ad545e001eb2aa50b26a999c02f0c0e2e5f8536edf21c973a debian-7.2-console-armhf-2013-11-15.tar.xz
  70. #+END_SRC
  71. Uncompress it.
  72. #+BEGIN_SRC: bash
  73. tar xJf debian-7.2-console-armhf-2013-11-15.tar.xz
  74. cd debian-7.2-console-armhf-2013-11-15
  75. #+END_SRC
  76. Create the disk image, where sdX is the name of the flash drive (probably it will be sdb or sdc).
  77. #+BEGIN_SRC: bash
  78. sudo apt-get install u-boot-tools
  79. sudo ./setup_sdcard.sh --mmc /dev/sdX --uboot bone --swap-file 1024
  80. #+END_SRC
  81. Once completed then safely remove the microSD card via your file manager (usually right click and "safely remove" or "eject").
  82. * Setup
  83. #+BEGIN_VERSE
  84. /Build the tools for a future you would want to live in/
  85. -- Kurt Opsahl
  86. #+END_VERSE
  87. ** Things to be aware of
  88. *** A note on ssh
  89. 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:
  90. #+BEGIN_SRC: bash
  91. ssh-keygen -R <IP address>
  92. #+END_SRC
  93. *** Passwords
  94. 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.
  95. *** HTTPS
  96. Throughout these instructions self signed SSL certificates are used to implement access to web pages via HTTPS. The whole HTTPS security model upon which much of the internet currently rests seems broken in that it usually depends upon "trusted certificate authorities" who are not really trusted, except perhaps by the maintainers of certain web browser software. So all that HTTPS really guarantees is that you have an encrypted connection, but an encrypted connection /to who/ can be subject to doubt. As was seen in 2013 with the [[https://www.schneier.com/essay-455.html][information coming from Edward Snowden]], and also the [[http://en.wikipedia.org/wiki/Lavabit][Lavabit email service]], it's possible for companies/organisations to be compromised or bribed and SSL private keys for all users can be demanded using gagging orders or secret laws without any individual user ever being able to know that their communications is no longer secure..
  97. Not knowing who you're really connecting to is especially true for self-signed certificates, so it is in principle possible that when logging into a site with a username and password a system such as [[http://arstechnica.com/tech-policy/2013/11/uk-spies-continue-quantum-insert-attack-via-linkedin-slashdot-pages/][Quantum Insert]], or a compromised [[http://en.wikipedia.org/wiki/Domain_Name_System][DNS service]], could be used to direct the user to a fake copy of the login screen for the purposes of obtaining their login details. While this doesn't seem to be a major problem at the time of writing it's something to keep in mind. So if you can't log in or if you log in and what you see doesn't look like your site then it's possible that such a compromise could have taken place. Using a password manager with different login details for each site is one way to ensure that if one system is compromised then the attacker can't necessarily get access to all your other stuff.
  98. ** Initial
  99. Plug the microSD card into the BBB and Connect the USB cable to your laptop/desktop, then login via ssh.
  100. #+BEGIN_SRC: bash
  101. ssh debian@192.168.7.2
  102. #+END_SRC
  103. The default password is /temppwd/
  104. Then log in as root:
  105. #+BEGIN_SRC: bash
  106. su
  107. #+END_SRC
  108. The default password is /root/
  109. The first thing to do is to change the passwords from their defaults.
  110. #+BEGIN_SRC: bash
  111. passwd
  112. #+END_SRC
  113. 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.
  114. #+BEGIN_SRC: bash
  115. nano /etc/network/interfaces
  116. #+END_SRC
  117. The resulting interfaces file should look like this:
  118. #+BEGIN_SRC: bash
  119. # This file describes the network interfaces available on your system
  120. # and how to activate them. For more information, see interfaces(5).
  121. # The loopback network interface
  122. auto lo
  123. iface lo inet loopback
  124. # The primary network interface
  125. allow-hotplug eth0
  126. iface eth0 inet static
  127. address 192.168.1.60
  128. netmask 255.255.255.0
  129. gateway 192.168.1.254
  130. dns-nameservers 213.73.91.35 85.214.20.141
  131. # Example to keep MAC address between reboots
  132. #hwaddress ether DA:AD:CE:EF:CA:FE
  133. # WiFi Example
  134. #auto wlan0
  135. #iface wlan0 inet dhcp
  136. # wpa-ssid "essid"
  137. # wpa-psk "password"
  138. # Ethernet/RNDIS gadget (g_ether)
  139. # ... or on host side, usbnet and random hwaddr
  140. # Note on some boards, usb0 is automaticly setup with an init script
  141. # in that case, to completely disable remove file [run_boot-scripts] from the boot partition
  142. #iface usb0 inet static
  143. # address 192.168.7.2
  144. # netmask 255.255.255.0
  145. # network 192.168.7.0
  146. # gateway 192.168.7.1
  147. #+END_SRC
  148. CTRL-O followed by ENTER to save, then CTRL-X to exit.
  149. 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.
  150. "gateway 192.168.1.254" should be the IP address of the router.
  151. Note that setting the DNS servers with dns-nameservers is important because some home routers do not allow you to change the DNS settings.
  152. Edit resolv.conf.
  153. #+BEGIN_SRC: bash
  154. nano /etc/resolv.conf
  155. #+END_SRC
  156. It should look something like the following:
  157. #+BEGIN_SRC: bash
  158. domain localdomain
  159. search localdomain
  160. nameserver 213.73.91.35
  161. nameserver 85.214.20.141
  162. #+END_SRC
  163. CTRL-O followed by ENTER to save, then CTRL-X to exit.
  164. 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.
  165. 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".
  166. ** Add a user
  167. Ssh back in to the BBB and login as root. In this example the BBB's IP address is 192.168.1.60.
  168. #+BEGIN_SRC: bash
  169. ssh-keygen -f "/home/myusername/.ssh/known_hosts" -R 192.168.1.60
  170. ssh debian@192.168.1.60
  171. su
  172. #+END_SRC
  173. Then make a new user. It's a bad idea to add users to the sudo group, because that then means that an attacker potentially only needs to know one password in order to get administrator access to the system. With no sudoers an attacker needs to know, or be able to obtain, two separate passwords to be able to really compromise the system.
  174. #+BEGIN_SRC: bash
  175. adduser myusername
  176. #+END_SRC
  177. 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.
  178. Remove the default debian user.
  179. #+BEGIN_SRC: bash
  180. userdel -r debian
  181. #+END_SRC
  182. ** Text editor
  183. For an editor which is less erratic than vi when used within a remote console such as Terminator.
  184. #+BEGIN_SRC: bash
  185. apt-get update
  186. apt-get install emacs
  187. #+END_SRC
  188. Some basic Emacs keys which will be useful to new users are:
  189. | Load a file | CTRL-x CTRL-f |
  190. | Save | CTRL-x CTRL-s |
  191. | Exit | CTRL-x CTRL-c |
  192. ** Create a swap file
  193. Without a swap file the system may occasionally run out of memory and crash, since the Beaglebone only has 512MB of RAM. The following commands will create a 1GB swap file:
  194. #+BEGIN_SRC: bash
  195. mkdir -p /var/cache/swap/
  196. dd if=/dev/zero of=/var/cache/swap/swapfile bs=1M count=1024
  197. chmod 600 /var/cache/swap/swapfile
  198. mkswap /var/cache/swap/swapfile
  199. swapon /var/cache/swap/swapfile
  200. #+END_SRC
  201. To tell the OS to load this swapfile on each start up.
  202. #+BEGIN_SRC: bash
  203. emacs /etc/fstab
  204. #+END_SRC
  205. Append the following line:
  206. #+BEGIN_SRC: bash
  207. /var/cache/swap/swapfile none swap sw 0 0
  208. #+END_SRC
  209. Then save and exit.
  210. To verify that the swapfile is accessilble type /top/ and look for the line which begins with "KiB Swap". Probably there will be zero bytes used, but this might be non-zero when the system is under some load (for example getting a lot of web views or being crawled by a search engine). CTRL-C exits from the /top/ command.
  211. ** Enable backports
  212. To enable some newer packages add backports to the repositories.
  213. #+BEGIN_SRC: bash
  214. echo "deb http://ftp.us.debian.org/debian wheezy-backports main" >> /etc/apt/sources.list
  215. apt-get update
  216. apt-get dist-upgrade
  217. #+END_SRC
  218. ** Random number generation
  219. #+BEGIN_VERSE
  220. /Near as I can tell, the answer on what has been requested is everything: deliberate weakenings of encryption algorithms, deliberate weakenings of random number generations, copies of master keys, encryption of the session key with an NSA-specific key … everything./
  221. -- Bruce Schneier, on the 2013 leaked NSA documents
  222. #+END_VERSE
  223. The security of encryption depends upon the randomness of the random source used on your system. If it isn't very random then it may be far more vulnerable to cryptanalysis, and it's known that in the past some dubious agencies have encouraged the use of flawed random number generators to assist with their prurient activities. Randomness - typically referred to as /entropy/ - is often gathered from factors such as the timing of key presses or mouse movements, but since the BBB won't have such devices plugged into it this reduces the amount of entropy available.
  224. To improve entropy generation there are two options. One is to install a kernel module which enables the hardware crypto available on the BBB, but that's a bit complicated and might have some stability implications. The other option is to install [[http://www.issihosts.com/haveged/][havegd]]. While not as good as a true hardware random number generator, havegd is better than the default pseudo-random number generation within the Linux kernel. To install it:
  225. #+BEGIN_SRC: bash
  226. apt-get install haveged
  227. #+END_SRC
  228. At the time of writing there is also some hardware called [[http://beagleboard.org/project/CryptoCape/][cryptocape]] being developed, with the intention of adding extra random number generation capabilities to the BBB.
  229. ** Alter ssh configuration
  230. Altering the ssh configuration will make it a little more secure than the standard Debian settings.
  231. #+BEGIN_SRC: bash
  232. emacs /etc/ssh/sshd_config
  233. #+END_SRC
  234. Check the following values:
  235. #+BEGIN_SRC: bash
  236. PermitRootLogin no
  237. X11Forwarding no
  238. ServerKeyBits 4096
  239. Protocol 2
  240. PermitEmptyPasswords no
  241. StrictModes yes
  242. #+END_SRC
  243. Append the following:
  244. #+BEGIN_SRC: bash
  245. Ciphers aes256-ctr,aes192-ctr,aes128-ctr
  246. MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
  247. KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
  248. #+END_SRC
  249. CTRL-X CTRL-S to save, then CTRL-X CTRL-C to exit.
  250. #+BEGIN_SRC: bash
  251. service ssh restart
  252. #+END_SRC
  253. To test the new settings log out by typing "exit" a couple of times, then log back in again with:
  254. #+BEGIN_SRC: bash
  255. ssh -vvv myusername@192.168.1.60
  256. #+END_SRC
  257. and check that some number of bits are set within a 4096 bit sized key:
  258. #+BEGIN_SRC: bash
  259. debug2: bits set: */4096
  260. #+END_SRC
  261. ** Getting onto the web
  262. 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.
  263. Select "/dynamic DNS/" then click "/quick cron example/"
  264. An example would look like:
  265. #+BEGIN_SRC: bash
  266. 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 &
  267. #+END_SRC
  268. Edit */etc/crontab* and append that to the end of the file.
  269. 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.
  270. The freeDNS subdomain which you just created will hereafter just be refered to as "/your domain name/".
  271. ** Set the host name
  272. #+BEGIN_SRC: bash
  273. emacs /etc/hostname
  274. #+END_SRC
  275. CTRL-x CTRL-s to save, then CTRL-x CTRL-c to exit.
  276. Also issue the command, replacing /mydomainname.com/ with your domain name.
  277. #+BEGIN_SRC: bash
  278. hostname mydomainname.com
  279. #+END_SRC
  280. You may also need to assign the same hostname separately via your router's web interface.
  281. #+BEGIN_SRC: bash
  282. emacs /etc/hosts
  283. #+END_SRC
  284. Append the following, replacing /mydomainname.com/ with your domain name.
  285. #+BEGIN_SRC: bash
  286. 127.0.1.1 mydomainname.com
  287. #+END_SRC
  288. If you then run the command:
  289. #+BEGIN_SRC: bash
  290. hostname -f
  291. #+END_SRC
  292. it should return your domain name.
  293. ** Install NTP
  294. To synchronise time.
  295. #+BEGIN_SRC: bash
  296. apt-get install ntp
  297. #+END_SRC
  298. ** Install fail2ban
  299. #+BEGIN_SRC: bash
  300. apt-get install fail2ban
  301. #+END_SRC
  302. ** Set up a firewall
  303. #+BEGIN_VERSE
  304. /The documents, from a PowerPoint presentation prepared for a 2012 NSA conference called SIGDEV, show that the unit known as the Joint Threat Research Intelligence Group, or JTRIG, boasted of using the DDOS attack – which it dubbed Rolling Thunder/
  305. -- NBC News article: /War on Anonymous: British Spies Attacked Hackers, Snowden Docs Show/
  306. #+END_VERSE
  307. A basic firewall limits the maximum rate at which connections can be made and closes any unused ports, and this helps to defend against various kinds of DDOS attack.
  308. #+BEGIN_SRC: bash
  309. apt-get install portsentry
  310. emacs /etc/portsentry/portsentry.conf
  311. #+END_SRC
  312. Uncomment the entry for *iptables support for Linux*
  313. Set the following properties:
  314. #+BEGIN_SRC: bash
  315. TCP_PORTS="1,7,9,11,15,79,109,110,111,119,138,139,512,513,514,515,540,635,1080,1524,2000,2001,4000,4001,5742,6000,6001,6667,12345,12346,20034,27665,30303,32771,32772,32773,32774,31337,40421,40425,49724,54320"
  316. UDP_PORTS="1,7,9,66,67,68,69,111,137,138,161,162,474,513,517,518,635,640,641,666,700,2049,31335,27444,34555,32770,32771,32772,32773,32774,31337,54321"
  317. ADVANCED_EXCLUDE_TCP="113,139,70,80,443,143,6670,993,5060,5061,25,465,22,5222,5223,5269,5280,5281,8444"
  318. ADVANCED_EXCLUDE_UDP="520,138,137,67,70,80,443,143,6670,993, 5060,5061,25,465,22,5222,5223,5269,5280,5281,8444"
  319. SCAN_TRIGGER="2"
  320. BLOCK_UDP="2"
  321. BLOCK_TCP="2"
  322. #+END_SRC
  323. Save and exit.
  324. #+BEGIN_SRC: bash
  325. service portsentry restart
  326. emacs /tmp/firewall.sh
  327. #+END_SRC
  328. Enter the following:
  329. #+BEGIN_SRC: bash
  330. #!/bin/bash
  331. # Enable syn cookies
  332. echo 1 > /proc/sys/net/ipv4/tcp_syncookies
  333. # Other settings
  334. echo 1 > /proc/sys/net/ipv4/tcp_keepalive_probes
  335. echo 2 > /proc/sys/net/ipv4/tcp_synack_retries
  336. echo 1 > /proc/sys/net/ipv4/tcp_syn_retries
  337. # First of all delete any existing rules.
  338. # This means you're back to a known state:
  339. iptables -P INPUT ACCEPT
  340. iptables -F
  341. iptables -X
  342. # Drop access to unused ports
  343. iptables -A INPUT -p tcp --destination-port 1 -j DROP
  344. iptables -A INPUT -p tcp --destination-port 7 -j DROP
  345. iptables -A INPUT -p tcp --destination-port 109:111 -j DROP
  346. iptables -A INPUT -p tcp --destination-port 995 -j DROP
  347. iptables -A INPUT -p tcp --destination-port 139 -j DROP
  348. iptables -A INPUT -p tcp --destination-port 6000:6001 -j DROP
  349. iptables -A INPUT -p tcp --destination-port 9 -j DROP
  350. iptables -A INPUT -p tcp --destination-port 79 -j DROP
  351. iptables -A INPUT -p tcp --destination-port 515 -j DROP
  352. iptables -A INPUT -p tcp --destination-port 4001 -j DROP
  353. iptables -A INPUT -p tcp --destination-port 1524 -j DROP
  354. iptables -A INPUT -p tcp --destination-port 1080 -j DROP
  355. iptables -A INPUT -p tcp --destination-port 512:514 -j DROP
  356. iptables -A INPUT -p tcp --destination-port 31337 -j DROP
  357. iptables -A INPUT -p tcp --destination-port 2000:2001 -j DROP
  358. iptables -A INPUT -p tcp --destination-port 12345 -j DROP
  359. iptables -A INPUT -p tcp --destination-port 32771:32774 -j DROP
  360. iptables -A INPUT -p tcp --destination-port 4000 -j DROP
  361. iptables -A INPUT -p tcp --destination-port 119 -j DROP
  362. iptables -A INPUT -p tcp --destination-port 137 -j DROP
  363. iptables -A INPUT -p udp --destination-port 1 -j DROP
  364. iptables -A INPUT -p udp --destination-port 7 -j DROP
  365. iptables -A INPUT -p udp --destination-port 109:111 -j DROP
  366. iptables -A INPUT -p udp --destination-port 995 -j DROP
  367. iptables -A INPUT -p udp --destination-port 139 -j DROP
  368. iptables -A INPUT -p udp --destination-port 6000:6001 -j DROP
  369. iptables -A INPUT -p udp --destination-port 9 -j DROP
  370. iptables -A INPUT -p udp --destination-port 79 -j DROP
  371. iptables -A INPUT -p udp --destination-port 515 -j DROP
  372. iptables -A INPUT -p udp --destination-port 4001 -j DROP
  373. iptables -A INPUT -p udp --destination-port 1524 -j DROP
  374. iptables -A INPUT -p udp --destination-port 1080 -j DROP
  375. iptables -A INPUT -p udp --destination-port 512:514 -j DROP
  376. iptables -A INPUT -p udp --destination-port 31337 -j DROP
  377. iptables -A INPUT -p udp --destination-port 2000:2001 -j DROP
  378. iptables -A INPUT -p udp --destination-port 12345 -j DROP
  379. iptables -A INPUT -p udp --destination-port 32771:32774 -j DROP
  380. iptables -A INPUT -p udp --destination-port 4000 -j DROP
  381. iptables -A INPUT -p udp --destination-port 119 -j DROP
  382. iptables -A INPUT -p udp --destination-port 137 -j DROP
  383. # Make sure NEW incoming tcp connections are SYN packets
  384. iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
  385. # Drop packets with incoming fragments
  386. iptables -A INPUT -f -j DROP
  387. # Incoming malformed XMAS packets drop them
  388. iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
  389. iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP
  390. iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
  391. # Incoming malformed NULL packets:
  392. iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
  393. # Drop UDP to used ports
  394. iptables -A INPUT -p udp --match multiport --dports 70,80,443,143,6670,993,5060,5061,25 -j DROP
  395. iptables -A INPUT -p udp --match multiport --dports 465,22,5222,5223,5269,5280,5281,8444 -j DROP
  396. # Limit ssh logins
  397. iptables -A INPUT -p tcp --dport 22 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  398. # Limit web connections
  399. iptables -A INPUT -p tcp --dport 80 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  400. iptables -A INPUT -p tcp --dport 443 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  401. # Limit number of XMPP connections
  402. iptables -A INPUT -p tcp --match multiport --dports 5222:5223,5269,5280:5281 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  403. # Limit IRC connections
  404. iptables -A INPUT -p tcp --dport 6666:6670 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  405. # Limit gopher connections
  406. iptables -A INPUT -p tcp --dport 70 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  407. # Limit IMAP connections
  408. iptables -A INPUT -p tcp --dport 143 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  409. iptables -A INPUT -p tcp --dport 993 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  410. # Limit SIP connections
  411. iptables -A INPUT -p tcp --dport 5060:5061 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  412. # Limit SMTP/SMTPS connections
  413. iptables -A INPUT -p tcp --dport 25 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  414. iptables -A INPUT -p tcp --dport 465 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  415. # Limit Bitmessage connections
  416. iptables -A INPUT -p tcp --dport 8444 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  417. # Limit the number of incoming tcp connections
  418. # Interface 0 incoming syn-flood protection
  419. iptables -N syn_flood
  420. iptables -A INPUT -p tcp --syn -j syn_flood
  421. iptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
  422. iptables -A syn_flood -j DROP
  423. # Limiting the incoming icmp ping request:
  424. iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j ACCEPT
  425. iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j LOG --log-prefix PING-DROP:
  426. iptables -A INPUT -p icmp -j DROP
  427. iptables -A OUTPUT -p icmp -j ACCEPT
  428. # Save the settings
  429. iptables-save > /etc/firewall.conf
  430. echo '#!/bin/sh' > /etc/network/if-up.d/iptables
  431. echo 'iptables-restore < /etc/firewall.conf' >> /etc/network/if-up.d/iptables
  432. chmod +x /etc/network/if-up.d/iptables
  433. #+END_SRC
  434. Save and exit
  435. #+BEGIN_SRC: bash
  436. chmod +x /tmp/firewall.sh
  437. . /tmp/firewall.sh
  438. rm /tmp/firewall.sh
  439. #+END_SRC
  440. Also disable ping. This may be inconvenient to some extent, but it seems common for malicious systems, including but not limited to the [[http://www.nbcnews.com/news/investigations/snowden-docs-british-spies-used-sex-dirty-tricks-n23091][JTRIG "EFFECTS" team]], to try to disable the machine by flooding it with pings. These days there seems to be not much difference between "cybercrime" and nefarious state-sponsored internet activities.
  441. #+BEGIN_SRC: bash
  442. emacs /etc/sysctl.conf
  443. #+END_SRC
  444. Uncomment or change the following:
  445. #+BEGIN_SRC: bash
  446. net.ipv4.conf.all.accept_redirects = 0
  447. net.ipv6.conf.all.accept_redirects = 0
  448. net.ipv4.conf.all.send_redirects = 0
  449. net.ipv4.conf.all.accept_source_route = 0
  450. net.ipv6.conf.all.accept_source_route = 0
  451. net.ipv4.conf.default.rp_filter=1
  452. net.ipv4.conf.all.rp_filter=1
  453. #+END_SRC
  454. And append the following:
  455. #+BEGIN_SRC: bash
  456. # ignore pings
  457. net.ipv4.icmp_echo_ignore_all = 1
  458. #+END_SRC
  459. Save and exit. It may be a good idea to reboot at this point and then log back into the BBB using ssh. You can do a safe reboot of the system by typing:
  460. #+BEGIN_SRC: bash
  461. reboot
  462. #+END_SRC
  463. ** Install Email
  464. #+BEGIN_VERSE
  465. /If you knew what I know about email, you might not use it/
  466. -- Ladar Levison
  467. #+END_VERSE
  468. 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.
  469. Exim4 seems much easier to install and configure than Postfix.
  470. #+BEGIN_SRC: bash
  471. aptitude install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
  472. #+END_SRC
  473. You will be prompted to remove postfix. Say yes and yes again.
  474. #+BEGIN_SRC: bash
  475. dpkg-reconfigure exim4-config
  476. #+END_SRC
  477. Settings as follows:
  478. #+BEGIN_SRC: bash
  479. internet site
  480. System mail name: mydomainname.com
  481. IP addresses to listen on: blank
  482. Destinations: mydomainname.com
  483. Domains to relay mail: blank
  484. Smarthost Relay: 192.168.1.0/60 (the range of addresses on your LAN)
  485. Dial on demand = no
  486. Maildir format in home directory
  487. Split configuration = no
  488. Root and postmaster: root email
  489. #+END_SRC
  490. To test the installation:
  491. #+BEGIN_SRC: bash
  492. telnet 192.168.1.60 25
  493. ehlo xxx
  494. quit
  495. #+END_SRC
  496. #+BEGIN_SRC: bash
  497. emacs /etc/default/saslauthd
  498. #+END_SRC
  499. set START=yes then save and exit.
  500. #+BEGIN_SRC: bash
  501. /etc/init.d/saslauthd start
  502. emacs exim-gencert
  503. #+END_SRC
  504. #+BEGIN_SRC: bash
  505. #!/bin/sh -e
  506. if [ -n "$EX4DEBUG" ]; then
  507. echo "now debugging $0 $@"
  508. set -x
  509. fi
  510. DIR=/etc/exim4
  511. CERT=$DIR/exim.crt
  512. KEY=$DIR/exim.key
  513. # This exim binary was built with GnuTLS which does not support dhparams
  514. # from a file. See /usr/share/doc/exim4-base/README.Debian.gz
  515. #DH=$DIR/exim.dhparam
  516. if ! which openssl > /dev/null ;then
  517. echo "$0: openssl is not installed, exiting" 1>&2
  518. exit 1
  519. fi
  520. # valid for ten years
  521. DAYS=3650
  522. if [ "$1" != "--force" ] && [ -f $CERT ] && [ -f $KEY ]; then
  523. echo "[*] $CERT and $KEY exists!"
  524. echo " Use \"$0 --force\" to force generation!"
  525. exit 0
  526. fi
  527. if [ "$1" = "--force" ]; then
  528. shift
  529. fi
  530. #SSLEAY=/tmp/exim.ssleay.$$.cnf
  531. SSLEAY="$(tempfile -m600 -pexi)"
  532. cat > $SSLEAY <<EOM
  533. RANDFILE = $HOME/.rnd
  534. [ req ]
  535. default_bits = 4096
  536. default_keyfile = exim.key
  537. distinguished_name = req_distinguished_name
  538. [ req_distinguished_name ]
  539. countryName = Country Code (2 letters)
  540. countryName_default = GB
  541. countryName_min = 2
  542. countryName_max = 2
  543. stateOrProvinceName = State or Province Name (full name)
  544. localityName = Locality Name (eg, city)
  545. organizationName = Organization Name (eg, company; recommended)
  546. organizationName_max = 64
  547. organizationalUnitName = Organizational Unit Name (eg, section)
  548. organizationalUnitName_max = 64
  549. commonName = Server name (eg. ssl.domain.tld; required!!!)
  550. commonName_max = 64
  551. emailAddress = Email Address
  552. emailAddress_max = 40
  553. EOM
  554. echo "[*] Creating a self signed SSL certificate for Exim!"
  555. echo " This may be sufficient to establish encrypted connections but for"
  556. echo " secure identification you need to buy a real certificate!"
  557. echo " "
  558. echo " Please enter the hostname of your MTA at the Common Name (CN) prompt!"
  559. echo " "
  560. openssl req -config $SSLEAY -x509 -sha256 -newkey rsa:4096 -keyout $KEY -out $CERT -days $DAYS -nodes
  561. #see README.Debian.gz*# openssl dhparam -check -text -5 512 -out $DH
  562. rm -f $SSLEAY
  563. chown root:Debian-exim $KEY $CERT $DH
  564. chmod 640 $KEY $CERT $DH
  565. echo "[*] Done generating self signed certificates for exim!"
  566. echo " Refer to the documentation and example configuration files"
  567. echo " over at /usr/share/doc/exim4-base/ for an idea on how to enable TLS"
  568. echo " support in your mail transfer agent."
  569. #+END_SRC
  570. Save and exit
  571. #+BEGIN_SRC: bash
  572. chmod +x exim-gencert
  573. ./exim-gencert
  574. #+END_SRC
  575. 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.
  576. #+BEGIN_SRC: bash
  577. emacs /etc/exim4/exim4.conf.template
  578. #+END_SRC
  579. Append the following:
  580. #+BEGIN_SRC: bash
  581. login_saslauthd_server:
  582. driver = plaintext
  583. public_name = LOGIN
  584. server_prompts = "Username:: : Password::"
  585. # don't send system passwords over unencrypted connections
  586. server_condition = ${if saslauthd{{$auth1}{$auth2}}{1}{0}}
  587. server_set_id = $auth1
  588. .ifndef AUTH_SERVER_ALLOW_NOTLS_PASSWORDS
  589. server_advertise_condition = ${if eq{$tls_cipher}{}{}{*}}
  590. .endif
  591. #+END_SRC
  592. Search for the line *.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME* and above it insert the line:
  593. #+BEGIN_SRC: bash
  594. MAIN_HARDCODE_PRIMARY_HOSTNAME = mydomainname.com
  595. #+END_SRC
  596. Save and exit.
  597. #+BEGIN_SRC: bash
  598. emacs /etc/exim4/exim4.conf.template
  599. #+END_SRC
  600. Add the line:
  601. #+BEGIN_SRC: bash
  602. MAIN_TLS_ENABLE = true
  603. #+END_SRC
  604. Save and exit.
  605. #+BEGIN_SRC: bash
  606. emacs /etc/default/exim4
  607. change SMTPLISTENEROPTIONS to:
  608. SMTPLISTENEROPTIONS='-oX 465:25 -oP /var/run/exim4/exim.pid'
  609. #+END_SRC
  610. save and exit
  611. #+BEGIN_SRC: bash
  612. emacs /etc/exim4/exim4.conf.template
  613. under the section "main/03_exim4-config_tlsoptions"
  614. Add the following:
  615. tls_on_connect_ports=465
  616. #+END_SRC
  617. save and exit
  618. #+BEGIN_SRC: bash
  619. adduser myusername sasl
  620. addgroup Debian-exim sasl
  621. /etc/init.d/exim4 restart
  622. mkdir -m 700 /etc/skel/Maildir
  623. mkdir -m 700 /etc/skel/Maildir/sent
  624. mkdir -m 700 /etc/skel/Maildir/sent/tmp
  625. mkdir -m 700 /etc/skel/Maildir/sent/cur
  626. mkdir -m 700 /etc/skel/Maildir/sent/new
  627. #+END_SRC
  628. If you're starting from scratch and don't already have a /Maildir/ directory in your home directory, then create one as follows:
  629. #+BEGIN_SRC: bash
  630. export MYUSERNAME=myusername
  631. mkdir -m 700 /home/$MYUSERNAME/Maildir
  632. mkdir -m 700 /home/$MYUSERNAME/Maildir/cur
  633. mkdir -m 700 /home/$MYUSERNAME/Maildir/tmp
  634. mkdir -m 700 /home/$MYUSERNAME/Maildir/new
  635. mkdir -m 700 /home/$MYUSERNAME/Maildir/sent
  636. mkdir -m 700 /home/$MYUSERNAME/Maildir/sent/cur
  637. mkdir -m 700 /home/$MYUSERNAME/Maildir/sent/tmp
  638. mkdir -m 700 /home/$MYUSERNAME/Maildir/sent/new
  639. chown -R $MYUSERNAME:$MYUSERNAME /home/$MYUSERNAME/Maildir
  640. #+END_SRC
  641. ** Spam filtering
  642. #+BEGIN_SRC: bash
  643. apt-get install spamassassin exim4-daemon-heavy
  644. emacs /etc/default/spamassassin
  645. #+END_SRC
  646. Set ENABLED=1 then save and exit.
  647. #+BEGIN_SRC: bash
  648. emacs /etc/exim4/exim4.conf.template
  649. #+END_SRC
  650. uncomment or change according to your configuration
  651. #+BEGIN_SRC: bash
  652. # For spam scanning, there is a similar option that defines the interface to
  653. # SpamAssassin. You do not need to set this if you are using the default, which
  654. # is shown in this commented example. As for virus scanning, you must also
  655. # modify the acl_check_data access control list to enable spam scanning.
  656. spamd_address = 127.0.0.1 783
  657. #+END_SRC
  658. add spam header in the /acl_check_data/ section:
  659. #+BEGIN_SRC: bash
  660. ### acl/40_exim4-config_check_data
  661. #################################
  662. # This ACL is used after the contents of a message have been received. This
  663. # is the ACL in which you can test a message's headers or body, and in
  664. # particular, this is where you can invoke external virus or spam scanners.
  665. acl_check_data:
  666. ...
  667. ...
  668. ...
  669. # See the exim docs and the exim wiki for more suitable examples.
  670. #
  671. # warn
  672. # spam = Debian-exim:true
  673. # add_header = X-Spam_score: $spam_score\n\
  674. # X-Spam_score_int: $spam_score_int\n\
  675. # X-Spam_bar: $spam_bar\n\
  676. # X-Spam_report: $spam_report
  677. # put headers in all messages (no matter if spam or not)
  678. warn spam = nobody:true
  679. add_header = X-Spam-Score: $spam_score ($spam_bar)
  680. add_header = X-Spam-Report: $spam_report
  681. # add second subject line with *SPAM* marker when message
  682. # is over threshold
  683. warn spam = nobody
  684. add_header = Subject: ***SPAM (score:$spam_score)*** $h_Subject:
  685. #+END_SRC
  686. Save and exit.
  687. Then restart
  688. #+BEGIN_SRC: bash
  689. exit
  690. emacs ~/.procmailrc
  691. #+END_SRC
  692. The text should look like the following.
  693. #+BEGIN_SRC: sh
  694. MAILDIR=$HOME/Maildir
  695. DEFAULT=$MAILDIR/
  696. LOGFILE=$HOME/log/procmail.log
  697. LOGABSTRACT=all
  698. # get spamassassin to check emails
  699. :0fw: .spamassassin.lock
  700. * < 256000
  701. | spamc
  702. # strong spam are discarded
  703. :0
  704. * ^X-Spam-Level: \*\*\*\*\*\*
  705. /dev/null
  706. # weak spam are kept just in case - clear this out every now and then
  707. :0
  708. * ^X-Spam-Level: \*\*\*\*\*
  709. .0-spam/
  710. # otherwise, marginal spam goes here for revision
  711. :0
  712. * ^X-Spam-Level: \*\*
  713. .spam/
  714. #+END_SRC
  715. Save and exit.
  716. #+BEGIN_SRC: bash
  717. su
  718. emacs /usr/bin/filterspam
  719. #+END_SRC
  720. Add the following contents:
  721. #+BEGIN_SRC: bash
  722. #!/bin/bash
  723. USERNAME=$1
  724. MAILDIR=/home/$USERNAME/Maildir/.learn-spam
  725. if [ ! -d "$MAILDIR" ]; then
  726. exit
  727. fi
  728. for f in `ls $MAILDIR/cur`
  729. do
  730. spamc -L spam < "$MAILDIR/cur/$f" > /dev/null
  731. rm "$MAILDIR/cur/$f"
  732. done
  733. for f in `ls $MAILDIR/new`
  734. do
  735. spamc -L spam < "$MAILDIR/new/$f" > /dev/null
  736. rm "$MAILDIR/new/$f"
  737. done
  738. #+END_SRC
  739. Save and exit.
  740. #+BEGIN_SRC: bash
  741. emacs /usr/bin/filterham
  742. #+END_SRC
  743. Add the following contents:
  744. #+BEGIN_SRC: bash
  745. #!/bin/bash
  746. USERNAME=$1
  747. MAILDIR=/home/$USERNAME/Maildir/.learn-ham
  748. if [ ! -d "$MAILDIR" ]; then
  749. exit
  750. fi
  751. for f in `ls $MAILDIR/cur`
  752. do
  753. spamc -L ham < "$MAILDIR/cur/$f" > /dev/null
  754. rm "$MAILDIR/cur/$f"
  755. done
  756. for f in `ls $MAILDIR/new`
  757. do
  758. spamc -L ham < "$MAILDIR/new/$f" > /dev/null
  759. rm "$MAILDIR/new/$f"
  760. done
  761. #+END_SRC
  762. Save and exit.
  763. #+BEGIN_SRC: bash
  764. emacs /etc/crontab
  765. #+END_SRC
  766. Append the following, replacing *myusername* with your username.
  767. #+BEGIN_SRC: bash
  768. */3 * * * * root /usr/bin/filterspam myusername
  769. */3 * * * * root /usr/bin/filterham myusername
  770. #+END_SRC
  771. Save and exit.
  772. #+BEGIN_SRC: bash
  773. chmod 655 /usr/bin/filterspam /usr/bin/filterham
  774. service spamassassin restart
  775. service exim4 restart
  776. service cron restart
  777. #+END_SRC
  778. ** Install Dovecot
  779. Install the required packages.
  780. #+BEGIN_SRC: bash
  781. aptitude -y install dovecot-common dovecot-pop3d dovecot-imapd
  782. #+END_SRC
  783. Edit the configuration file.
  784. #+BEGIN_SRC: bash
  785. emacs /etc/dovecot/dovecot.conf
  786. #+END_SRC
  787. Line 26: change:
  788. #+BEGIN_SRC: bash
  789. listen = *
  790. #+END_SRC
  791. Save and exit.
  792. #+BEGIN_SRC: bash
  793. emacs /etc/dovecot/conf.d/10-auth.conf
  794. #+END_SRC
  795. Line 9: uncomment and change (allow plain text auth)
  796. #+BEGIN_SRC: bash
  797. disable_plaintext_auth = no
  798. #+END_SRC
  799. Line 99: add:
  800. #+BEGIN_SRC: bash
  801. auth_mechanisms = plain login
  802. #+END_SRC
  803. Save and exit.
  804. #+BEGIN_SRC: bash
  805. emacs /etc/dovecot/conf.d/10-mail.conf
  806. #+END_SRC
  807. Line 30: uncomment and add:
  808. #+BEGIN_SRC: bash
  809. mail_location = maildir:~/Maildir
  810. #+END_SRC
  811. Save and exit, then start the dovecot service.
  812. #+BEGIN_SRC: bash
  813. service dovecot restart
  814. #+END_SRC
  815. ** Create Email folders and rules
  816. A common situation with email is that you may be subscribed to various mailing lists and want incoming email from those to be automatically grouped into a separate folder for each list.
  817. We can make a script to make adding mailing list rules easy:
  818. #+BEGIN_SRC: bash
  819. emacs /usr/bin/mailinglistrule
  820. #+END_SRC
  821. Add the following:
  822. #+BEGIN_SRC: bash
  823. #!/bin/bash
  824. MYUSERNAME=$1
  825. MAILINGLIST=$2
  826. SUBJECTTAG=$3
  827. MUTTRC=/home/$MYUSERNAME/.muttrc
  828. PM=/home/$MYUSERNAME/.procmailrc
  829. LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST
  830. if [ ! -d "$LISTDIR" ]; then
  831. mkdir -m 700 $LISTDIR
  832. mkdir -m 700 $LISTDIR/tmp
  833. mkdir -m 700 $LISTDIR/new
  834. mkdir -m 700 $LISTDIR/cur
  835. fi
  836. chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
  837. echo "" >> $PM
  838. echo ":0" >> $PM
  839. echo " * ^Subject:.*()\[$SUBJECTTAG\]" >> $PM
  840. echo "$LISTDIR/new" >> $PM
  841. chown $MYUSERNAME:$MYUSERNAME $PM
  842. if [ ! -f "$MUTTRC" ]; then
  843. cp /etc/Muttrc $MUTTRC
  844. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  845. fi
  846. #+END_SRC
  847. Save and exit, then make the script executable.
  848. #+BEGIN_SRC: bash
  849. chmod +x /usr/bin/mailinglistrule
  850. #+END_SRC
  851. Now we can add a new mailing list rule with the following, where /myusername/ is your username, /mailinglistname/ is the name of the mailing list (with no spaces) and /subjecttag/ is the tag which usually appears within square brackets in the subject line of emails from the list.
  852. #+BEGIN_SRC: bash
  853. mailinglistrule myusername mailinglistname subjecttag
  854. #+END_SRC
  855. Repeat this command for as many mailing lists as you need. Then edit your local Mutt configuration.
  856. #+BEGIN_SRC: bash
  857. emacs /home/myusername/.muttrc
  858. #+END_SRC
  859. Search for the *mailboxes* variable and add entries for the mailing lists you just created. For example:
  860. #+BEGIN_SRC: bash
  861. mailboxes = =sent =mailinglistname
  862. #+END_SRC
  863. Then save and exit.
  864. ** Setting up a web site
  865. #+BEGIN_VERSE
  866. /It's important to have the geek community as a whole think about its responsibility and what it can do. We need various alternative voices pushing back on conventional government sometimes./
  867. -- Tim Berners-Lee
  868. #+END_VERSE
  869. Edit the apache configuration so that it doesn't run out of memory if there are a lot of connections.
  870. #+BEGIN_SRC: bash
  871. su
  872. emacs /etc/apache2/apache2.conf
  873. #+END_SRC
  874. Search for MaxClients and replace the value with 10 then save and exit.
  875. In the examples below replace mydomainname.com with your own domain.
  876. #+BEGIN_SRC: bash
  877. export HOSTNAME=mydomainname.com
  878. mkdir /var/www/$HOSTNAME
  879. mkdir /var/www/$HOSTNAME/htdocs
  880. emacs /etc/apache2/sites-available/$HOSTNAME
  881. #+END_SRC
  882. The Apache configuration for the site should look something like the following. Replace /mydonainname.com/ with the site domain name.
  883. #+BEGIN_SRC: bash
  884. <VirtualHost *:80>
  885. ServerAdmin myusername@mydomainname.com
  886. ServerName mydomainname.com
  887. DocumentRoot /var/www/mydomainname.com/htdocs
  888. <Directory />
  889. Options FollowSymLinks
  890. AllowOverride All
  891. </Directory>
  892. <Directory /var/www/mydomainname.com/htdocs/>
  893. Options All
  894. AllowOverride All
  895. Order allow,deny
  896. allow from all
  897. </Directory>
  898. # Don't serve .php~ or .php# files created by emacs
  899. <Files ~ "(^#.*#|~|\.sw[op])$">
  900. Order allow,deny
  901. Deny from all
  902. </Files>
  903. <IfModule headers_module>
  904. Header set X-Content-Type-Options nosniff
  905. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  906. Header set Pragma no-cache
  907. </IfModule>
  908. <Files .htaccess>
  909. deny from all
  910. </Files>
  911. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  912. <Directory "/usr/lib/cgi-bin">
  913. AllowOverride All
  914. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  915. Order allow,deny
  916. Allow from all
  917. </Directory>
  918. ErrorLog ${APACHE_LOG_DIR}/error.log
  919. # Possible values include: debug, info, notice, warn, error, crit,
  920. # alert, emerg.
  921. LogLevel error
  922. CustomLog ${APACHE_LOG_DIR}/access.log combined
  923. </VirtualHost>
  924. <IfModule mod_ssl.c>
  925. <VirtualHost *:443>
  926. ServerAdmin myusername@mydomainname.com
  927. ServerName mydomainname.com
  928. DocumentRoot /var/www/mydomainname.com/htdocs
  929. <Directory />
  930. Options FollowSymLinks
  931. AllowOverride All
  932. </Directory>
  933. <Directory /var/www/mydomainname.com/htdocs/>
  934. Options All
  935. AllowOverride All
  936. Order allow,deny
  937. allow from all
  938. </Directory>
  939. # Don't serve .php~ or .php# files created by emacs
  940. <Files ~ "(^#.*#|~|\.sw[op])$">
  941. Order allow,deny
  942. Deny from all
  943. </Files>
  944. <IfModule headers_module>
  945. Header set X-Content-Type-Options nosniff
  946. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  947. Header set Pragma no-cache
  948. </IfModule>
  949. <Files .htaccess>
  950. deny from all
  951. </Files>
  952. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  953. <Directory "/usr/lib/cgi-bin">
  954. AllowOverride All
  955. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  956. Order allow,deny
  957. Allow from all
  958. </Directory>
  959. ErrorLog ${APACHE_LOG_DIR}/error.log
  960. # Possible values include: debug, info, notice, warn, error, crit,
  961. # alert, emerg.
  962. LogLevel error
  963. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  964. # SSL Engine Switch:
  965. # Enable/Disable SSL for this virtual host.
  966. SSLEngine on
  967. # A self-signed certificate
  968. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  969. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  970. # Options based on bettercrypto.org
  971. SSLProtocol All -SSLv2 -SSLv3
  972. SSLHonorCipherOrder On
  973. SSLCompression off
  974. 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
  975. # Add six earth month HSTS header for all users ...
  976. Header add Strict-Transport-Security "max-age=15768000"
  977. # If you want to protect all subdomains , use the following header
  978. # ALL subdomains HAVE TO support https if you use this !
  979. # Strict-Transport-Security: max-age=15768000 ; includeSubDomains
  980. # SSL Engine Options:
  981. # Set various options for the SSL engine.
  982. # o FakeBasicAuth:
  983. # Translate the client X.509 into a Basic Authorisation. This means that
  984. # the standard Auth/DBMAuth methods can be used for access control. The
  985. # user name is the `one line' version of the client's X.509 certificate.
  986. # Note that no password is obtained from the user. Every entry in the user
  987. # file needs this password: `xxj31ZMTZzkVA'.
  988. # o ExportCertData:
  989. # This exports two additional environment variables: SSL_CLIENT_CERT and
  990. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  991. # server (always existing) and the client (only existing when client
  992. # authentication is used). This can be used to import the certificates
  993. # into CGI scripts.
  994. # o StdEnvVars:
  995. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  996. # Per default this exportation is switched off for performance reasons,
  997. # because the extraction step is an expensive operation and is usually
  998. # useless for serving static content. So one usually enables the
  999. # exportation for CGI and SSI requests only.
  1000. # o StrictRequire:
  1001. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  1002. # under a "Satisfy any" situation, i.e. when it applies access is denied
  1003. # and no other module can change it.
  1004. # o OptRenegotiate:
  1005. # This enables optimized SSL connection renegotiation handling when SSL
  1006. # directives are used in per-directory context.
  1007. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  1008. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  1009. SSLOptions +StdEnvVars
  1010. </FilesMatch>
  1011. <Directory /usr/lib/cgi-bin>
  1012. SSLOptions +StdEnvVars
  1013. </Directory>
  1014. # SSL Protocol Adjustments:
  1015. # The safe and default but still SSL/TLS standard compliant shutdown
  1016. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  1017. # the close notify alert from client. When you need a different shutdown
  1018. # approach you can use one of the following variables:
  1019. # o ssl-unclean-shutdown:
  1020. # This forces an unclean shutdown when the connection is closed, i.e. no
  1021. # SSL close notify alert is send or allowed to received. This violates
  1022. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  1023. # this when you receive I/O errors because of the standard approach where
  1024. # mod_ssl sends the close notify alert.
  1025. # o ssl-accurate-shutdown:
  1026. # This forces an accurate shutdown when the connection is closed, i.e. a
  1027. # SSL close notify alert is send and mod_ssl waits for the close notify
  1028. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  1029. # practice often causes hanging connections with brain-dead browsers. Use
  1030. # this only for browsers where you know that their SSL implementation
  1031. # works correctly.
  1032. # Notice: Most problems of broken clients are also related to the HTTP
  1033. # keep-alive facility, so you usually additionally want to disable
  1034. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  1035. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  1036. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  1037. # "force-response-1.0" for this.
  1038. BrowserMatch "MSIE [2-6]" \
  1039. nokeepalive ssl-unclean-shutdown \
  1040. downgrade-1.0 force-response-1.0
  1041. # MSIE 7 and newer should be able to use keepalive
  1042. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  1043. </VirtualHost>
  1044. </IfModule>
  1045. #+END_SRC
  1046. Then to enable the site:
  1047. #+BEGIN_SRC: bash
  1048. a2ensite
  1049. a2dissite default
  1050. a2dissite default-ssl
  1051. a2enmod rewrite
  1052. a2enmod headers
  1053. #+END_SRC
  1054. Ensure that "NameVirtualHost *:443" is added to /etc/apache2/ports.conf. It should look something like the following:
  1055. #+BEGIN_SRC: bash
  1056. NameVirtualHost *:80
  1057. Listen 80
  1058. <IfModule mod_ssl.c>
  1059. NameVirtualHost *:443
  1060. Listen 443
  1061. </IfModule>
  1062. <IfModule mod_gnutls.c>
  1063. NameVirtualHost *:443
  1064. Listen 443
  1065. </IfModule>
  1066. #+END_SRC
  1067. Create a self-signed certificate. The passphrase isn't important and will be removed, so make it easy (such as "password").
  1068. #+BEGIN_SRC: bash
  1069. emacs makecert
  1070. #+END_SRC
  1071. Enter the following:
  1072. #+BEGIN_SRC: bash
  1073. #!/bin/bash
  1074. HOSTNAME=$1
  1075. openssl genrsa -des3 -out $HOSTNAME.key 1024
  1076. openssl req -new -x509 -nodes -sha1 -days 3650 -key $HOSTNAME.key -out $HOSTNAME.crt
  1077. openssl rsa -in $HOSTNAME.key -out $HOSTNAME.new.key
  1078. cp $HOSTNAME.new.key $HOSTNAME.key
  1079. rm $HOSTNAME.new.key
  1080. cp $HOSTNAME.key /etc/ssl/private
  1081. chmod 400 /etc/ssl/private/$HOSTNAME.key
  1082. cp $HOSTNAME.crt /etc/ssl/certs
  1083. shred -zu $HOSTNAME.key $HOSTNAME.crt
  1084. a2enmod ssl
  1085. service apache2 restart
  1086. #+END_SRC
  1087. Save and exit.
  1088. #+BEGIN_SRC: bash
  1089. chmod +x makecert
  1090. ./makecert mydomainname.com
  1091. #+END_SRC
  1092. 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.
  1093. 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.
  1094. ** Accessing your Email
  1095. *** Mutt email client
  1096. #+BEGIN_VERSE
  1097. /I dreamt last night that I was living in a surveillance state. I woke up and… I’m still in a surveillance state./
  1098. -- Conrad Kramer
  1099. #+END_VERSE
  1100. #+BEGIN_SRC: bash
  1101. apt-get install mutt-patched lynx abook
  1102. exit
  1103. mkdir ~/.mutt
  1104. echo "text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^ //’; copiousoutput; needsterminal; nametemplate=%s.html" > ~/.mutt/mailcap
  1105. #+END_SRC
  1106. Save and exit.
  1107. #+BEGIN_SRC: bash
  1108. su
  1109. emacs /etc/Muttrc
  1110. #+END_SRC
  1111. Append the following:
  1112. #+BEGIN_SRC: bash
  1113. set mbox_type=Maildir
  1114. set folder="~/Maildir"
  1115. set mask="!^\\.[^.]"
  1116. set mbox="~/Maildir"
  1117. set record="+.Sent"
  1118. set postponed="+.Drafts"
  1119. set spoolfile="~/Maildir"
  1120. auto_view text/x-vcard text/html text/enriched
  1121. set editor="emacsclient %s"
  1122. set header_cache="+.cache"
  1123. macro index S "<tag-prefix><save-message>=.learn-spam<enter>" "move to learn-spam"
  1124. macro pager S "<save-message>=.learn-spam<enter>" "move to learn-spam"
  1125. macro index H "<tag-prefix><copy-message>=.learn-ham<enter>" "copy to learn-ham"
  1126. macro pager H "<copy-message>=.learn-ham<enter>" "copy to learn-ham"
  1127. # set up the sidebar
  1128. set sidebar_width=12
  1129. set sidebar_visible=yes
  1130. set sidebar_delim='|'
  1131. set sidebar_sort=yes
  1132. set rfc2047_parameters
  1133. # Show inbox and sent items
  1134. mailboxes = =sent
  1135. # Alter these colours as needed for maximum bling
  1136. color sidebar_new yellow default
  1137. color normal white default
  1138. color hdrdefault brightcyan default
  1139. color signature green default
  1140. color attachment brightyellow default
  1141. color quoted green default
  1142. color quoted1 white default
  1143. color tilde blue default
  1144. # ctrl-n, ctrl-p to select next, prev folder
  1145. # ctrl-o to open selected folder
  1146. bind index \Cp sidebar-prev
  1147. bind index \Cn sidebar-next
  1148. bind index \Co sidebar-open
  1149. bind pager \Cp sidebar-prev
  1150. bind pager \Cn sidebar-next
  1151. bind pager \Co sidebar-open
  1152. # ctrl-b toggles sidebar visibility
  1153. macro index \Cb '<enter-command>toggle sidebar_visible<enter><refresh>' "toggle sidebar"
  1154. macro pager \Cb '<enter-command>toggle sidebar_visible<enter><redraw-screen>' "toggle sidebar"
  1155. # esc-m Mark new messages as read
  1156. macro index <esc>m "T~N<enter>;WNT~O<enter>;WO\CT~T<enter>" "mark all messages read"
  1157. #+END_SRC
  1158. Save and exit.
  1159. #+BEGIN_SRC: bash
  1160. emacs /etc/mail/spamassassin/local.cf
  1161. #+END_SRC
  1162. Uncomment *use_bayes*, *bayes_auto_learn*
  1163. Save and exit, then run:
  1164. #+BEGIN_SRC: bash
  1165. service spamassassin restart
  1166. #+END_SRC
  1167. Now to add an address book:
  1168. #+BEGIN_SRC: bash
  1169. emacs ~/.muttrc
  1170. #+END_SRC
  1171. Append the following:
  1172. #+BEGIN_SRC: bash
  1173. set alias_file=~/.mutt-alias
  1174. source ~/.mutt-alias
  1175. set query_command= "abook --mutt-query '%s'"
  1176. macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
  1177. #+END_SRC
  1178. Then save and exit.
  1179. #+BEGIN_SRC: bash
  1180. touch ~/.mutt-alias
  1181. #+END_SRC
  1182. 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.
  1183. 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.
  1184. Some useful keys to know are:
  1185. | ESC / | Search for text within message contents |
  1186. | "/" | Search for text within headers |
  1187. | * | Move to the last message |
  1188. | TAB | Move to the next unread message |
  1189. | d | Delete a message |
  1190. | u | Undelete a mail which is pending deletion |
  1191. | $ | Delete all messages selected and check for new messages |
  1192. | a | Add to the address book |
  1193. | m | Send a new mail |
  1194. | ESC-m | Mark all messages as having been read |
  1195. | S | Mark a message as spam |
  1196. | H | Mark a message as ham |
  1197. | CTRL-b | Toggle side bar on/off |
  1198. | CTRL-n | Next mailbox (on side bar) |
  1199. | CTRL-p | Previous mailbox (on side bar) |
  1200. | CTRL-o | Open mailbox (on side bar) |
  1201. *** K9 Android client
  1202. #+BEGIN_VERSE
  1203. /The surveillance state is robust. It is robust politically, legally, and technically./
  1204. -- Bruce Schneier
  1205. #+END_VERSE
  1206. **** Incoming server settings
  1207. * Select settings/account settings
  1208. * Select Fetching mail/incoming server
  1209. * Enter your username and password
  1210. * IMAP server should be your domain name
  1211. * Security: SSL/TLS (always)
  1212. * Authentication: Plain
  1213. * Port: 993
  1214. **** Outgoing (SMTP) server settings
  1215. * Select settings/account settings
  1216. * Select Sending mail/outgoing server
  1217. * Set SMTP server to your domain name
  1218. * Set Security to SSL/TLS (always)
  1219. * Set port to 465
  1220. * Set authentication to PLAIN
  1221. * Enter your username and password
  1222. * Accept the SSL certificate
  1223. *** Webmail
  1224. #+BEGIN_VERSE
  1225. /Most of the information extracted is "content", such as recordings of phone calls or the substance of email messages./
  1226. -- From a 2013 Guardian article on GCHQ/NSA bulk internet data interception.
  1227. #+END_VERSE
  1228. For maximum speed and efficiency the recommended email client is Mutt, accessed via ssh, but non-technical people who aren't using an Android app are unlikely to want to use email in that manner. So it's a good idea to also have a webmail system installed, both for accessibility and as a fallback should ssh not be available due to port blocking.
  1229. Install dependencies.
  1230. #+BEGIN_SRC: bash
  1231. apt-get install libapache2-mod-authz-unixgroup
  1232. #+END_SRC
  1233. Create a mysql database, specifying a password which should be a long random string generated with a password manager such as KeepassX.
  1234. #+BEGIN_SRC: bash
  1235. mysql -u root -p
  1236. create database roundcubemail;
  1237. CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'roundcubepassword';
  1238. GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
  1239. quit
  1240. #+END_SRC
  1241. Download roundcube.
  1242. #+BEGIN_SRC: bash
  1243. cd /tmp
  1244. wget http://freedombone.uk.to/roundcubemail.tar.gz
  1245. #+END_SRC
  1246. Verify it.
  1247. #+BEGIN_SRC: bash
  1248. sha256sum roundcubemail.tar.gz
  1249. e8a311b22a8e1f70abb72ed9551cc9233cf6c5221f1eebf1ae64974117e3148b roundcubemail.tar.gz
  1250. #+END_SRC
  1251. Extract the files.
  1252. #+BEGIN_SRC: bash
  1253. tar -xzvf roundcubemail.tar.gz
  1254. export HOSTNAME=mydomainname.com
  1255. cp -r roundcubemail-* /var/www/$HOSTNAME/htdocs/mail
  1256. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/temp
  1257. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/logs
  1258. rm /var/www/$HOSTNAME/htdocs/mail/.htaccess
  1259. #+END_SRC
  1260. Edit your web site configuration.
  1261. #+BEGIN_SRC: bash
  1262. emacs /etc/apache2/sites-available/$HOSTNAME
  1263. #+END_SRC
  1264. Within the 80 VirtualHost section add the following:
  1265. #+BEGIN_SRC: bash
  1266. <Directory /var/www/mydomainname.com/htdocs/mail>
  1267. deny from all
  1268. </Directory>
  1269. #+END_SRC
  1270. Within the 443 VirtualHost section add the following:
  1271. #+BEGIN_SRC: bash
  1272. <Directory /var/www/mydomainname.com/htdocs/mail>
  1273. Options Indexes FollowSymLinks MultiViews
  1274. AllowOverride All
  1275. Order allow,deny
  1276. allow from all
  1277. </Directory>
  1278. #+END_SRC
  1279. Save and exit, then restart Apache.
  1280. #+BEGIN_SRC: bash
  1281. service apache2 restart
  1282. #+END_SRC
  1283. Now with a browser visit https://mydomainname.com/mail/installer. Scroll down and click "next". Give your webmail site a product name.
  1284. The *spellcheck_engine* option being limited to Google is slightly concerning in terms of privacy and security, but seems not to be implemented.
  1285. Change the *database password* to the password you gave when creating the MySql database above.
  1286. Set *smtp_port* to 465.
  1287. Click *create config*
  1288. Click download to download the file.
  1289. In a terminal on your local machine (not logged into the BBB):
  1290. #+BEGIN_SRC: bash
  1291. cd ~/Downloads
  1292. scp config.inc.php myusername@mydomainname.com:/home/myusername
  1293. #+END_SRC
  1294. Then in a terminal ssh'd into the BBB:
  1295. #+BEGIN_SRC: bash
  1296. mv /home/myusername/config.inc.php /var/www/$HOSTNAME/htdocs/mail/config
  1297. chmod 755 /var/www/$HOSTNAME/htdocs/mail/config/config.inc.php
  1298. #+END_SRC
  1299. Click *continue*.
  1300. Click *initialize database*.
  1301. Under *Test SMTP config* you can use a [[mailinator.com]] address to check that mail can be sent.
  1302. Now we can delete the installer.
  1303. #+BEGIN_SRC: bash
  1304. rm -rf /var/www/$HOSTNAME/htdocs/mail/installer
  1305. #+END_SRC
  1306. Now with a browser navigate to https://mydomainname.com/mail and log in.
  1307. TODO: connect Sent and Draft folders.
  1308. *** Thunderbird
  1309. #+BEGIN_VERSE
  1310. /Towards the end of 2012, we heard from the National Technical Assistance Centre (NTAC), a division of GCHQ and a liaison with the Home Office, [that] they wanted the keys to decrypt the customer data./
  1311. -- Brian Spector, on the shutting down of the PrivateSky encrypted email service
  1312. #+END_VERSE
  1313. Another common way in which you may want to access email is via Thunderbird. This may be especially useful if you're trying to convert former Windows users who may previously have been using some version of Outlook.
  1314. The following instructions should be carried out on the client machines (laptop, etc), not on the BBB itself.
  1315. **** Initial setup
  1316. Install *Thunderbird* and *Enigmail*. How you do this just depends upon your distro and software manager or "app store".
  1317. Open Thinderbird
  1318. Select "*Skip this and use existing email*"
  1319. Enter your name, email address (myusername@mydomainname.com) and the password for your user (the one from [[Add a user]]).
  1320. You'll get a message saying "/Thunderbird failed to find the settings/"
  1321. The settings should be as follows, substituting /mydomainname.com/ for your domain name and /myusername/ for the username given previously in [[Add a user]].
  1322. * Incoming: IMAP, mydomainname.com, 993, SSL/TLS, Normal Password
  1323. * Outgoing: SMTP, mydomainname.com, 465, SSL/TLS, Normal Password
  1324. * Username: myusername
  1325. Click *Done*.
  1326. Click *Get Certificate* and make sure "*permanently store this exception*" is selected", then click *Store Security Exception*.
  1327. From OpenPGP setup select "*Yes, I would like the wizard to get me started*". If the wizard doesn't start automatically then "setup wizard" can be selected from OpenPGP on the menu bar.
  1328. Select "*Yes, I want to sign all of my email*"
  1329. Select "*No, I will create per-recipient rules*"
  1330. Select "*yes*" to change default settings.
  1331. **** If you have existing GPG key
  1332. Export your GPG public and private keys.
  1333. #+BEGIN_SRC: bash
  1334. gpg --output ~/public_key.txt --armor --export KEY_ID
  1335. gpg --output ~/private_key.txt --armor --export-secret-key KEY_ID
  1336. #+END_SRC
  1337. Select "*I have existing public and private keys*".
  1338. Select your public and private GPG exported key files.
  1339. Select the account which you want to use and click *Next*, *Next* and *Finish*.
  1340. Remove your exported key files.
  1341. #+BEGIN_SRC: bash
  1342. shred -zu ~/public_key.txt
  1343. shred -zu ~/private_key.txt
  1344. #+END_SRC
  1345. **** If you don't have any existing GPG or PGP key
  1346. Select "*I want to create a new key pair*"
  1347. Enter a passphrase and click *Next* a couple of times.
  1348. Click *Generate Certificate* to generate a revocation certificate.
  1349. Enter the passphrase which you gave previously.
  1350. Click *Finish*
  1351. From the menu select *OpenPGP* and then *Key Management*. Make sure that *Display all keys* is selected and then select your key. Select *Keyserver* on the menu and then *Upload Public Keys*. This will upload your public key to a key server so that others can find it.
  1352. Select *File* from the menu then *Export keys to file*. Click on *Export Secret keys* and select a location to save them to. It's a good idea to save them to a USB stick which can then be removed from the computer and carried around on a keyring together with your physical keys. If you need to set up GPG or Thunderbird/Enigmail on others then this file will be used to import your keys.
  1353. **** Using for the first time
  1354. Click on the Thunderbird menu, which looks like three horizontal bars on the right hand side.
  1355. Hover over *preferences* and then *Account settings*.
  1356. Select *Synchronization & Storage*.
  1357. Make sure that *Keep messages for this account on this computer* is unticked, then click *Ok*.
  1358. Click on *Inbox*. Depending upon how much email you have it may take a while to import the subject lines.
  1359. Note that when sending an email for the first time you will also need to accept the SSL certificate.
  1360. Get into the habit of using email encryption and encourage others to do so. Remember that you may not think that your emails are very interesting but the Surveillance State is highly interested in them and will be actively trying to data mine your private life looking for "suspicious" patterns, regardless of whether you are guilty of any crime or not.
  1361. ** Install a Blog
  1362. #+BEGIN_VERSE
  1363. /When society gives censors wide and vague powers they never confine themselves to deserving targets. They are not snipers, but machine-gunners. Allow them to fire at will, and they will hit anything that moves./
  1364. -- Nick Cohen
  1365. #+END_VERSE
  1366. 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.
  1367. 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.
  1368. Download flatpress.
  1369. #+BEGIN_SRC: bash
  1370. cd /tmp
  1371. wget http://freedombone.uk.to/flatpress.tar.gz
  1372. #+END_SRC
  1373. Verify the download:
  1374. #+BEGIN_SRC: bash
  1375. sha256sum flatpress.tar.gz
  1376. 6312a49aab5aabd6371518dcaf081f489dff04d001bc34b4fe3f2a81170bbd4e flatpress.tar.gz
  1377. #+END_SRC
  1378. Extract and install it.
  1379. #+BEGIN_SRC: bash
  1380. tar -xzvf flatpress.tar.gz
  1381. cd flatpress-*
  1382. cp -r * /var/www/$HOSTNAME/htdocs
  1383. rm -rf flatpress-*
  1384. rm -f flatpress.tar.gz
  1385. #+END_SRC
  1386. 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
  1387. ** Install an IRC server
  1388. #+BEGIN_VERSE
  1389. /Give me the liberty to know, to utter, and to argue freely according to conscience, above all liberties./
  1390. -- John Milton
  1391. #+END_VERSE
  1392. *** Base install
  1393. IRC is not an especially secure system. For instance, even with the best encryption it's easily possible to imagine IRC-specific cribs which could be used by cryptanalytic systems. However, we'll try to implement it in a manner which will at least give the surveillance aparatus something to ponder over.
  1394. First install some dependencies.
  1395. #+BEGIN_SRC: bash
  1396. apt-get update
  1397. apt-get install build-essential openssl libssl-dev
  1398. #+END_SRC
  1399. Then get the source code for ircd-hybrid.
  1400. #+BEGIN_SRC: bash
  1401. cd /tmp
  1402. mkdir hybrid
  1403. cd hybrid
  1404. apt-get source ircd-hybrid
  1405. #+END_SRC
  1406. Modify the source code to include SSL security.
  1407. #+BEGIN_SRC: bash
  1408. emacs ircd-hybrid-*/debian/rules
  1409. #+END_SRC
  1410. Beneath MAXCLIENTS add the line:
  1411. #+BEGIN_SRC: bash
  1412. USE_OPENSSL = 1
  1413. #+END_SRC
  1414. Then save and exit. Now we can build the debian package for ircd-hybrid and install it.
  1415. #+BEGIN_SRC: bash
  1416. cd ircd-hybrid-*
  1417. dpkg-buildpackage -rfakeroot -uc -b
  1418. cd ..
  1419. dpkg -i ircd-hybrid_*.deb
  1420. #+END_SRC
  1421. Customise the configuration to your system, giving it a name and description. In this example 192.168.1.60 is the static IP address on the BBB on the local network, so change that if necessary.
  1422. #+BEGIN_SRC: bash
  1423. emacs /etc/ircd-hybrid/ircd.conf
  1424. #+END_SRC
  1425. Set *name* to the name of your server, and set a description.
  1426. Set a *network_name* and *network_desc*. The network name should not contain any spaces.
  1427. Set max_clients to 20, or however many you expect that you'll typically need.
  1428. Within the admin section set your *name* and *email*.
  1429. Within the *listen* section set host to your fixed IP address (in the earlier
  1430. sections it was 192.168.1.60).
  1431. Within the *auth* section set user = "*@192.168.1.60" - or whatever the fixed IP address of the BBB is on your network.
  1432. Uncomment the first *connect* section and set the *name* to your domain name, the *host* to 192.168.1.60 and the send/accept passwords to a password which you use to log into the IRC server. Also set the *port* to 6670.
  1433. Save and exit, then restart the IRC server. Open port 6670 on your internet router and forward it to the BBB.
  1434. Ensure that the configuration is only readable by the root user.
  1435. #+BEGIN_SRC: bash
  1436. chmod 600 /etc/ircd-hybrid/ircd.conf
  1437. #+END_SRC
  1438. *** Channel management
  1439. To to install channel management tools.
  1440. #+BEGIN_SRC: bash
  1441. cd /tmp
  1442. wget http://freedombone.uk.to/hybserv_1.9.4-1_armhf.deb
  1443. #+END_SRC
  1444. Verify it.
  1445. #+BEGIN_SRC: bash
  1446. sha256sum hybserv_1.9.4-1_armhf.deb
  1447. 41bf4eb6e24c87610a80bc14db1103a57484835510eea7e4ba9709c523318615 hybserv_1.9.4-1_armhf.deb
  1448. #+END_SRC
  1449. Install it.
  1450. #+BEGIN_SRC: bash
  1451. dpkg -i hybserv_1.9.4-1_armhf.deb
  1452. #+END_SRC
  1453. Make a md5 version of the password for the IRC server operator.
  1454. #+BEGIN_SRC: bash
  1455. /usr/bin/mkpasswd <myoperatorpassword>
  1456. #+END_SRC
  1457. Edit the ircd-hybrid configuration.
  1458. #+BEGIN_SRC: bash
  1459. emacs /etc/ircd-hybrid/ircd.conf
  1460. #+END_SRC
  1461. Enter the md5 password which you previously created within the /operator/ section. Also change /user/ to:
  1462. #+BEGIN_SRC: bash
  1463. user = "*@*";
  1464. #+END_SRC
  1465. Then save and exit.
  1466. #+BEGIN_SRC: bash
  1467. emacs /etc/hybserv/hybserv.conf
  1468. #+END_SRC
  1469. Change #MD5 PASSWORD HERE# to the md5 operator password created earlier, mydomainname.com to your domain name and mysendacceptpassword to the send/accept password specified within /ircd.conf/.
  1470. #+BEGIN_SRC: bash
  1471. A:mynickname <myemailaddress>
  1472. N:irc.mydomainname.com:Hybrid services
  1473. O:*@*:#MD5 PASSWORD HERE#:root:segj (comment out other Q: lines)
  1474. S:mysendacceptpassword:192.168.1.60:6670 (remove the other two services)
  1475. #+END_SRC
  1476. Also remove the line *#NOT-EDITED#*, then save and exit.
  1477. Now we need to restart the ircd and hybrid server to make things work:
  1478. #+BEGIN_SRC: bash
  1479. service ircd-hybrid restart
  1480. service hybserv start
  1481. #+END_SRC
  1482. *** Usage
  1483. On another computer (not the BBB).
  1484. #+BEGIN_SRC: bash
  1485. sudo apt-get install irssi
  1486. irssi
  1487. #+END_SRC
  1488. Connect to the IRC and identify yourself as an operator. Here /mynetwork/ should be the same as *network_name* specified earlier within /ircd.conf/.
  1489. #+BEGIN_SRC: bash
  1490. /server add -auto -network mynetwork -ssl mydonainname.com 6670 mysendacceptpassword
  1491. /connect mydomainname.com
  1492. /channel add -auto #mychannel mynetwork channelpassword
  1493. /network add -nick mynick mychannel
  1494. /join #mychannel
  1495. /msg -servername chanserv REGISTER #mychannel channelpassword
  1496. /msg -servername chanserv set #mychannel mlock +k channelpassword
  1497. #+END_SRC
  1498. If you edit the irssi config file:
  1499. #+BEGIN_SRC: bash
  1500. emacs ~/.irssi/config
  1501. #+END_SRC
  1502. It should look something like this:
  1503. #+BEGIN_SRC: bash
  1504. {
  1505. address = "mydomainname.com";
  1506. chatnet = "mynetwork";
  1507. port = "6670";
  1508. password = "mysendacceptpassword";
  1509. use_ssl = "yes";
  1510. ssl_verify = "no";
  1511. autoconnect = "yes";
  1512. },
  1513. #+END_SRC
  1514. If you're not using a self-signed certificate (self-signed is the default) then you can set *ssl_verify* to "yes".
  1515. ** Install a Jabber/XMPP server
  1516. #+BEGIN_VERSE
  1517. /Well heck, it isn’t that hard to write an instant messaging system./
  1518. --Jeremie Miller
  1519. #+END_VERSE
  1520. *** The Server
  1521. Generate a SSL certificate.
  1522. #+BEGIN_SRC: bash
  1523. openssl ecparam -out /etc/ssl/private/xmpp.pem -name prime256v1
  1524. openssl genpkey -paramfile /etc/ssl/private/xmpp.pem -out /etc/ssl/private/xmpp.key
  1525. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  1526. #+END_SRC
  1527. The above uses a Diffie-Hellman elliptic curve (ECDH P-256) algorithm. It is apparent that amongst crypographers there are differences of opinion about the security of elliptic curves, so if you prefer there is also a more traditional RSA way to generate an SSL certificate:
  1528. #+BEGIN_SRC: bash
  1529. openssl genrsa -out /etc/ssl/private/xmpp.key 4096
  1530. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  1531. #+END_SRC
  1532. Change permissions.
  1533. #+BEGIN_SRC: bash
  1534. chmod 600 /etc/ssl/private/xmpp.key
  1535. chmod 600 /etc/ssl/certs/xmpp.crt
  1536. chown prosody:prosody /etc/ssl/private/xmpp.key
  1537. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  1538. #+END_SRC
  1539. Install Prosody.
  1540. #+BEGIN_SRC: bash
  1541. apt-get install prosody
  1542. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  1543. emacs /etc/prosody/conf.avail/xmpp.cfg.lua
  1544. #+END_SRC
  1545. Change the *VirtualHost* name to your domain name and remove the line below it.
  1546. Set the ssl section to:
  1547. #+BEGIN_SRC: bash
  1548. ssl = {
  1549. key = "/etc/ssl/private/xmpp.key";
  1550. certificate = "/etc/ssl/certs/xmpp.crt";
  1551. }
  1552. #+END_SRC
  1553. And also append the following:
  1554. #+BEGIN_SRC: bash
  1555. modules_enabled = {
  1556. "bosh"; -- Enable mod_bosh
  1557. "tls"; -- Enable mod_tls
  1558. }
  1559. c2s_require_encryption = true
  1560. s2s_require_encryption = true
  1561. #+END_SRC
  1562. Save and exit. Create a symbolic link.
  1563. #+BEGIN_SRC: bash
  1564. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  1565. #+END_SRC
  1566. Add a user. You will be prompted to specify a password. You can repeat the process for as many users as needed. This will also be your Jabber ID (JID).
  1567. #+BEGIN_SRC: bash
  1568. prosodyctl adduser myusername@mydomainname.com
  1569. #+END_SRC
  1570. Restart the server
  1571. #+BEGIN_SRC: bash
  1572. service prosody restart
  1573. #+END_SRC
  1574. On your internet router/firewall open ports 5222, 5223, 5269, 5280 and 5281 and forward them to the BBB.
  1575. It's possible to test that your XMPP server is working at https://xmpp.net. It may take several minutes and you'll get a low score because of the self-signed certificate, but it will at least verify that your server is capable of communicating.
  1576. *** Managing users
  1577. To add a user:
  1578. #+BEGIN_SRC: bash
  1579. prosodyctl adduser myusername@mydomainname.com
  1580. #+END_SRC
  1581. To change a user password:
  1582. #+BEGIN_SRC: bash
  1583. prosodyctl passwd myusername@mydomainname.com
  1584. #+END_SRC
  1585. To remove a user:
  1586. #+BEGIN_SRC: bash
  1587. prosodyctl deluser myusername@mydomainname.com
  1588. #+END_SRC
  1589. Report the status of the XMPP server:
  1590. #+BEGIN_SRC: bash
  1591. prosodyctl status
  1592. #+END_SRC
  1593. *** Using with Jitsi
  1594. Jitsi is the recommended communications client for desktop or laptop systems, since it includes the /off the record/ (OTR) feature which provides some additional security beyond the usual SSL certificates.
  1595. Jitsi can be downloaded from https://jitsi.org/
  1596. On your desktop/laptop open Jitsi and select *Options* from the *Tools* menu.
  1597. Click *Add* to add a new user, then enter the Jabber ID which you previously specified with /prosodyctl/ when setting up the XMPP server. Close and then you should notice that your status is "Online" (or if not then you should be able to set it to online).
  1598. From the *File* menu you can add contacts, then select the chat icon to begin a chat. Click on the lock icon on the right hand side and this will initiate an authentication procedure in which you can specify a question and answer to verify the identity of the person you're communicating with. Once authentication is complete then you'll be chating using OTR, which provides an additional layer of security.
  1599. When opening Jitsi initially you will get a certificate warning for your domain name (assuming that you're using a self-signed certificate). If this happens then select *View Certificate* and enable the checkbox to trust the certificate, then select *Continue Anyway*. Once you've done this then the certificate warning will not appear again unless you reinstall Jitsi or use a different computer.
  1600. You can also [[https://www.youtube.com/watch?v=vgx7VSrDGjk][see this video]] as an example of using OTR.
  1601. *** Using with Ubuntu
  1602. The default XMPP client in Ubuntu is Empathy. Using Empathy isn't as secure as using Jitsi, since it doesn't include the /off the record/ feature, but since it's the default it's what many users will have easy access to.
  1603. Open *System Settings* and select *Online Accounts*, *Add account* and then *Jabber*.
  1604. Enter your username (myusername@mydomainname.com) and password.
  1605. Click on *Advanced* and make sure that *Encryption required* and *Ignore SSL certificate errors* are checked. Ignoring the certificate errors will allow you to use the self-signed certificate created earlier. Then click *Done* and set your Jabber account and Empathy to *On*.
  1606. *** Using with Android
  1607. There are a few XMPP clients available on Android. Ideally choose ones which support off-the-record messaging. Here are some examples.
  1608. **** Xabber
  1609. Install [[https://f-droid.org/][F-Droid]]
  1610. Search for and install Xabber.
  1611. Add an account and enter your Jabber/XMPP ID and password.
  1612. From the menu select *Settings* then *Security* then *OTR mode*. Set the mode to *Required*.
  1613. Make sure that *Check server certificate* is not checked.
  1614. Go back to the initial screen and then using the menu you can add contacts and begin chatting. Both parties will need to go through the off-the-record question and answer verification before the chat can begin, but that only needs to be done once for each person you're chatting with.
  1615. **** Gibberbot
  1616. Install [[https://f-droid.org/][F-Droid]]
  1617. Search for and install Gibberbot, otherwise known as ChatSecure.
  1618. From the menu open *Accounts*
  1619. Select *Add account*
  1620. Change the server port from 0 to 5222
  1621. Done
  1622. Accept unknown certificate? Select *Always*
  1623. Go back to the initial screen and then using the menu you can add contacts and begin chatting.
  1624. ** Social Networking
  1625. #+BEGIN_VERSE
  1626. /Facebook is not your friend, it is a surveillance engine./
  1627. -- Richard Stallman, Free Software Foundation
  1628. #+END_VERSE
  1629. *** Friendica
  1630. **** Installation
  1631. See [[Setting up a web site]] for details of how to update the Apache configuration for your Friendica site. You should have a separate domain name specifically to run Friendica on. It can't be installed in a subdirectory on a domain used for something else.
  1632. Edit your Apache configuration and disable the port 80 (HTTP) version of the site. We only want to log into Friendica via HTTPS, so to prevent anyone from accidentally logging in insecurely:
  1633. #+BEGIN_SRC: bash
  1634. emacs /etc/apache2/sites-available/mydomainname.com
  1635. #+END_SRC
  1636. Within the section which begins with *<VirtualHost *:80>* change the following:
  1637. #+BEGIN_SRC: bash
  1638. <Directory /var/www/mydomainname.com/htdocs/>
  1639. deny from all
  1640. </Directory>
  1641. #+END_SRC
  1642. Save and exit, then restart the apache server.
  1643. #+BEGIN_SRC: bash
  1644. service apache2 restart
  1645. #+END_SRC
  1646. Now install some dependencies.
  1647. #+BEGIN_SRC: bash
  1648. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  1649. #+END_SRC
  1650. Enter an admin password for MySQL.
  1651. Create a mysql database.
  1652. #+BEGIN_SRC: bash
  1653. mysql -u root -p
  1654. create database friendica;
  1655. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'password';
  1656. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  1657. quit
  1658. #+END_SRC
  1659. You may need to fix Git SSL problems.
  1660. #+BEGIN_SRC: bash
  1661. git config --global http.sslVerify true
  1662. apt-get install ca-certificates
  1663. cd ~/
  1664. emacs .gitconfig
  1665. #+END_SRC
  1666. The .gitconfig file should look something like this:
  1667. #+BEGIN_SRC: bash
  1668. [http]
  1669. sslVerify = true
  1670. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  1671. [user]
  1672. email = myusername@mydomainname.com
  1673. name = yourname
  1674. #+END_SRC
  1675. Get the source code.
  1676. #+BEGIN_SRC: bash
  1677. export HOSTNAME=mydomainname.com
  1678. cd /var/www/$HOSTNAME
  1679. mv htdocs htdocs_old
  1680. git clone https://github.com/friendica/friendica.git htdocs
  1681. chmod -R 755 htdocs
  1682. chown -R www-data:www-data htdocs
  1683. chown -R www-data:www-data htdocs/view/smarty3
  1684. git clone https://github.com/friendica/friendica-addons.git htdocs/addon
  1685. #+END_SRC
  1686. 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.
  1687. Install the poller.
  1688. #+BEGIN_SRC: bash
  1689. emacs /etc/crontab
  1690. #+END_SRC
  1691. and append the following, changing mydomainname.com to whatever your domain is.
  1692. #+BEGIN_SRC: bash
  1693. */10 * * * * root cd /var/www/mydomainname.com/htdocs; /usr/bin/php include/poller.php
  1694. #+END_SRC
  1695. Save and exit, then restart cron.
  1696. #+BEGIN_SRC: bash
  1697. service cron restart
  1698. #+END_SRC
  1699. You can improve the speed of Friendica database searches by adding the following indexes:
  1700. #+BEGIN_SRC: bash
  1701. mysql -u root -p
  1702. use friendica;
  1703. CREATE INDEX `uri_received` ON item(`uri`, `received`);
  1704. CREATE INDEX `received_uri` ON item(`received`, `uri`);
  1705. CREATE INDEX `contact-id_created` ON item(`contact-id`, created);
  1706. CREATE INDEX `uid_network_received` ON item(`uid`, `network`, `received`);
  1707. CREATE INDEX `uid_parent` ON item(`uid`, `parent`);
  1708. CREATE INDEX `uid_received` ON item(`uid`, `received`);
  1709. CREATE INDEX `uid_network_commented` ON item(`uid`, `network`, `commented`);
  1710. CREATE INDEX `uid_title` ON item(uid, `title`);
  1711. CREATE INDEX `created_contact-id` ON item(`created`, `contact-id`);
  1712. quit
  1713. #+END_SRC
  1714. Make sure that Friendica doesn't use too much memory.
  1715. #+BEGIN_SRC: bash
  1716. emacs /var/www/$HOSTNAME/htdocs/.htaccess
  1717. #+END_SRC
  1718. Append the following:
  1719. #+BEGIN_SRC: bash
  1720. php_value memory_limit 32M
  1721. #+END_SRC
  1722. The save ane exit.
  1723. **** Backups
  1724. 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.
  1725. #+BEGIN_SRC: bash
  1726. emacs /etc/cron.daily/friendicabackup
  1727. #+END_SRC
  1728. Enter the following
  1729. #+BEGIN_SRC: bash
  1730. #!/bin/sh
  1731. MYSQL_PASSWORD=<mysql root password>
  1732. umask 0077
  1733. # Backup the database
  1734. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_daily.sql
  1735. # Make the backup readable only by root
  1736. chmod 600 /var/backups/friendica_daily.sql
  1737. #+END_SRC
  1738. Save and exit.
  1739. #+BEGIN_SRC: bash
  1740. chmod 600 /etc/cron.daily/friendicabackup
  1741. chmod +x /etc/cron.daily/friendicabackup
  1742. emacs /etc/cron.weekly/friendicabackup
  1743. #+END_SRC
  1744. Enter the following
  1745. #+BEGIN_SRC: bash
  1746. #!/bin/sh
  1747. MYSQL_PASSWORD=<mysql root password>
  1748. umask 0077
  1749. # Backup the database
  1750. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_weekly.sql
  1751. # Make the backup readable only by root
  1752. chmod 600 /var/backups/friendica_weekly.sql
  1753. #+END_SRC
  1754. Save and exit.
  1755. #+BEGIN_SRC: bash
  1756. chmod 600 /etc/cron.weekly/friendicabackup
  1757. chmod +x /etc/cron.weekly/friendicabackup
  1758. #+END_SRC
  1759. **** Recommended configuration
  1760. ***** Admin
  1761. 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.
  1762. 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.
  1763. Under the *themes* section select a few themes, including mobile themes which are suitable for phones or tablets.
  1764. 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.
  1765. 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]].
  1766. ***** Settings
  1767. Each user has their own customisable settings, typically available either via an icon or by an entry on a drop down menu.
  1768. Under *additional features* enable "/richtext editor/", "/post preview/", "/group filter/", "/network filter/", "/edit sent posts/" and "/dislike posts/".
  1769. Under *display settings* select your desktop and mobile themes.
  1770. 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.
  1771. **** To access from an Android device
  1772. ***** App
  1773. 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.
  1774. 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.
  1775. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  1776. ***** Mobile Theme
  1777. 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.
  1778. *** Movim
  1779. #+BEGIN_VERSE
  1780. /The way we communicate with others and with ourselves ultimately determines the quality of our lives/
  1781. -- Anthony Robbins
  1782. #+END_VERSE
  1783. Movim is another social networking system based around the XMPP protocol.
  1784. You will need to have previously [[Install a Jabber/XMPP server][installed the Jabber/XMPP server]].
  1785. Edit your Apache configuration and disable the port 80 (HTTP) version of the site. We only want to log into Movim via HTTPS, so to prevent anyone from accidentally logging in insecurely:
  1786. #+BEGIN_SRC: bash
  1787. emacs /etc/apache2/sites-available/mydomainname.com
  1788. #+END_SRC
  1789. Within the section which begins with *<VirtualHost *:80>* add the following:
  1790. #+BEGIN_SRC: bash
  1791. <Directory /var/www/mydomainname.com/htdocs/movim>
  1792. deny from all
  1793. </Directory>
  1794. #+END_SRC
  1795. Within the section which begins with *<VirtualHost *:443>* add the following:
  1796. #+BEGIN_SRC: bash
  1797. <Directory /var/www/mydomainname.com/htdocs/movim>
  1798. Options Indexes FollowSymLinks MultiViews
  1799. AllowOverride All
  1800. Order allow,deny
  1801. allow from all
  1802. </Directory>
  1803. #+END_SRC
  1804. Save and exit, then restart the apache server.
  1805. #+BEGIN_SRC: bash
  1806. service apache2 restart
  1807. #+END_SRC
  1808. Download the source.
  1809. #+BEGIN_SRC: bash
  1810. cd /tmp
  1811. wget http://freedombone.uk.to/movim.tar.gz
  1812. #+END_SRC
  1813. Verify it.
  1814. #+BEGIN_SRC: bash
  1815. sha256sum movim.tar.gz
  1816. 2740ddbedf6cefcc2934759374376643b6cdea4fb7f944ec25098a6868cb499e movim.tar.gz
  1817. #+END_SRC
  1818. Install it.
  1819. #+BEGIN_SRC: bash
  1820. tar -xzvf movim.tar.gz
  1821. export HOSTNAME=mydomainname.com
  1822. cp -r movim-* /var/www/$HOSTNAME/htdocs/movim
  1823. chmod 755 /var/www/$HOSTNAME/htdocs/movim
  1824. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/movim
  1825. #+END_SRC
  1826. Install some MySql prerequisites.
  1827. #+BEGIN_SRC: bash
  1828. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  1829. #+END_SRC
  1830. If necessary, enter an admin password for MySQL.
  1831. Create a mysql database.
  1832. #+BEGIN_SRC: bash
  1833. mysql -u root -p
  1834. create database movim;
  1835. CREATE USER 'movimadmin'@'localhost' IDENTIFIED BY 'movimadminpassword';
  1836. GRANT ALL PRIVILEGES ON movim.* TO 'movimadmin'@'localhost';
  1837. quit
  1838. #+END_SRC
  1839. With a web browser navigate to:
  1840. https://mydomainname.com/movim/admin
  1841. Enter /admin/ as the username and /password/ as the password.
  1842. Click on /General Settings/ and alter the administrator username to /movimadmin/ and password to some long random string (using a password manager such as KeepassX).
  1843. Change the /Environment/ from /Development/ to /Production/.
  1844. The /BOSH URL/ should be http://localhost:5280/http-bind (TODO: should this be https://localhost:5281/http-bind and if so do certificate warnings need to be disabled?)
  1845. Click /Submit/ followed by /Resend/.
  1846. Click on /Database Settings/ and alter the MySql movim database username to /movimadmin/ and password to the password you specified in the previous step.
  1847. Click /Submit/ followed by /Resend/. If you get a lot of orange warnings about database fields being created then hit /Submit/ again until you see "Movim database is up to date".
  1848. If everything on all three tabs looks green then you are ready to go. Click on the Movim logo at the top left and then log in with your Jabber ID (JID).
  1849. *** Red Matrix
  1850. **** Introduction
  1851. Red Matrix is the current version of the Friendica social networking system. It's more general than Friendica in that it's designed as a generic communication system based around a protocol called "zot". At the time of writing in early 2014 Red Matrix remains at an alpha stage of development and so it's not advised that you install it unless you're willing to put up with bugs and frustrations. In the large majority of cases it's better to stick with Friendica for now.
  1852. **** Prerequisites
  1853. The main problem with Red Matrix is that in order to install it you will need to have purchased a domain name (i.e. not a FreeDNS subdomain) and a SSL certificate for it.
  1854. You could join some other Red Matrix server, but this suffers from "/The Levison Problem/" in which some goons show up with a gagging order demanding coppies of the SSL private key. In that scenario unless the owner of the server is exceptionally brave users may never be informed that the site has been compromised or that there is interception hardware attached to the server. Joining another server defeats the object of being digitally self-sufficient and raises legal question marks about the ownership of data which you might upload to a server which doesn't belong to you.
  1855. **** Installation
  1856. See [[Setting up a web site]] for details of how to update the Apache configuration for your Red Matrix site. You should have a separate domain name specifically to run Red Matrix on. It can't be installed in a subdirectory on a domain used for something else.
  1857. Edit your Apache configuration and disable the port 80 (HTTP) version of the site. We only want to log into Red Matrix via HTTPS, so to prevent anyone from accidentally logging in insecurely:
  1858. #+BEGIN_SRC: bash
  1859. emacs /etc/apache2/sites-available/mydomainname.com
  1860. #+END_SRC
  1861. Within the section which begins with *<VirtualHost *:80>* change the following:
  1862. #+BEGIN_SRC: bash
  1863. <Directory /var/www/mydomainname.com/htdocs/>
  1864. deny from all
  1865. </Directory>
  1866. #+END_SRC
  1867. Save and exit, then restart the apache server.
  1868. #+BEGIN_SRC: bash
  1869. service apache2 restart
  1870. #+END_SRC
  1871. Now install some dependencies.
  1872. #+BEGIN_SRC: bash
  1873. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  1874. #+END_SRC
  1875. Enter an admin password for MySQL.
  1876. Create a mysql database.
  1877. #+BEGIN_SRC: bash
  1878. mysql -u root -p
  1879. create database redmatrix;
  1880. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'password';
  1881. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  1882. quit
  1883. #+END_SRC
  1884. You may need to fix Git SSL problems.
  1885. #+BEGIN_SRC: bash
  1886. git config --global http.sslVerify true
  1887. apt-get install ca-certificates
  1888. cd ~/
  1889. emacs .gitconfig
  1890. #+END_SRC
  1891. The .gitconfig file should look something like this:
  1892. #+BEGIN_SRC: bash
  1893. [http]
  1894. sslVerify = true
  1895. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  1896. [user]
  1897. email = myusername@mydomainname.com
  1898. name = yourname
  1899. #+END_SRC
  1900. Get the source code.
  1901. #+BEGIN_SRC: bash
  1902. export HOSTNAME=mydomainname.com
  1903. cd /var/www/$HOSTNAME
  1904. mv htdocs htdocs_old
  1905. git clone https://github.com/friendica/red.git htdocs
  1906. chmod -R 755 htdocs
  1907. chown -R www-data:www-data htdocs
  1908. mkdir htdocs/view/tpl/smarty3
  1909. chmod 777 htdocs/view/tpl
  1910. chmod 777 htdocs/view/tpl/smarty3
  1911. git clone https://github.com/friendica/red-addons.git htdocs/addon
  1912. #+END_SRC
  1913. Now visit the URL of your site and you should be taken through the rest of the installation procedure. Note that this may take a few minutes so don't be concerned if it looks as if it has crashed - just leave it running. 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.
  1914. Install the poller.
  1915. #+BEGIN_SRC
  1916. emacs /etc/crontab
  1917. #+END_SRC
  1918. and append the following, changing mydomainname.com to whatever your domain is.
  1919. #+BEGIN_SRC
  1920. */10 * * * * root cd /var/www/mydomainname.com/htdocs; /usr/bin/php include/poller.php
  1921. #+END_SRC
  1922. Save and exit, then restart cron.
  1923. #+BEGIN_SRC: bash
  1924. service cron restart
  1925. #+END_SRC
  1926. **** Backups
  1927. 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.
  1928. #+BEGIN_SRC: bash
  1929. emacs /etc/cron.daily/redmatrixbackup
  1930. #+END_SRC
  1931. Enter the following
  1932. #+BEGIN_SRC: bash
  1933. #!/bin/sh
  1934. MYSQL_PASSWORD=<mysql root password>
  1935. umask 0077
  1936. # Backup the database
  1937. mysqldump --password=$MYSQL_PASSWORD redmatrix > /var/backups/redmatrix_daily.sql
  1938. # Make the backup readable only by root
  1939. chmod 600 /var/backups/redmatrix_daily.sql
  1940. #+END_SRC
  1941. Save and exit.
  1942. #+BEGIN_SRC: bash
  1943. chmod 600 /etc/cron.daily/redmatrixbackup
  1944. chmod +x /etc/cron.daily/redmatrixbackup
  1945. emacs /etc/cron.weekly/redmatrixbackup
  1946. #+END_SRC
  1947. Enter the following
  1948. #+BEGIN_SRC: bash
  1949. #!/bin/sh
  1950. MYSQL_PASSWORD=<mysql root password>
  1951. umask 0077
  1952. # Backup the database
  1953. mysqldump --password=$MYSQL_PASSWORD redmatrix > /var/backups/redmatrix_weekly.sql
  1954. # Make the backup readable only by root
  1955. chmod 600 /var/backups/redmatrix_weekly.sql
  1956. #+END_SRC
  1957. Save and exit.
  1958. #+BEGIN_SRC: bash
  1959. chmod 600 /etc/cron.weekly/redmatrixbackup
  1960. chmod +x /etc/cron.weekly/redmatrixbackup
  1961. #+END_SRC
  1962. **** To access from an Android device
  1963. ***** App
  1964. 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.
  1965. 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.
  1966. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  1967. ** Install Gopher
  1968. 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.
  1969. To set up a gopher server:
  1970. #+BEGIN_SRC: bash
  1971. apt-get install build-essential
  1972. cd /tmp
  1973. wget http://freedombone.uk.to/geomyidae-current.tgz
  1974. #+END_SRC
  1975. Verify the download:
  1976. #+BEGIN_SRC: bash
  1977. sha256sum geomyidae-current.tgz
  1978. 162f55ab059ab0a9be8e840497795293bbd51c34b1f4564dcdf3f0ddd5c0db31 geomyidae-current.tgz
  1979. #+END_SRC
  1980. Then extract and install it.
  1981. #+BEGIN_SRC: bash
  1982. tar -xzvf geomyidae-current.tgz
  1983. cd geomyidae-*
  1984. make
  1985. make install
  1986. mkdir -p /var/gopher
  1987. #+END_SRC
  1988. 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.
  1989. #+BEGIN_SRC: bash
  1990. emacs /etc/init.d/gopher
  1991. #+END_SRC
  1992. Enter the following:
  1993. #+BEGIN_SRC: bash
  1994. #! /bin/sh
  1995. ### BEGIN INIT INFO
  1996. # Provides: gopher
  1997. # Required-Start: $remote_fs $syslog
  1998. # Required-Stop: $remote_fs $syslog
  1999. # Default-Start: 2 3 4 5
  2000. # Default-Stop: 0 1 6
  2001. # Short-Description: Gopher daemon
  2002. # Description: Gopher daemon
  2003. ### END INIT INFO
  2004. # Do NOT "set -e"
  2005. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  2006. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  2007. DESC="Gopher daemon"
  2008. NAME=geomyidae
  2009. DAEMON=/usr/bin/$NAME
  2010. DAEMON_ARGS="-l /var/log/geomyidae.log -b /var/gopher -p 70"
  2011. PIDFILE=/var/run/$NAME.pid
  2012. SCRIPTNAME=/etc/init.d/$NAME
  2013. # Exit if the package is not installed
  2014. [ -x "$DAEMON" ] || exit 0
  2015. # Read configuration variable file if it is present
  2016. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  2017. # Load the VERBOSE setting and other rcS variables
  2018. . /lib/init/vars.sh
  2019. # Define LSB log_* functions.
  2020. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  2021. # and status_of_proc is working.
  2022. . /lib/lsb/init-functions
  2023. #
  2024. # Function that starts the daemon/service
  2025. #
  2026. do_start()
  2027. {
  2028. # Return
  2029. # 0 if daemon has been started
  2030. # 1 if daemon was already running
  2031. # 2 if daemon could not be started
  2032. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  2033. || return 1
  2034. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  2035. $DAEMON_ARGS \
  2036. || return 2
  2037. # Add code here, if necessary, that waits for the process to be ready
  2038. # to handle requests from services started subsequently which depend
  2039. # on this one. As a last resort, sleep for some time.
  2040. }
  2041. #
  2042. # Function that stops the daemon/service
  2043. #
  2044. do_stop()
  2045. {
  2046. # Return
  2047. # 0 if daemon has been stopped
  2048. # 1 if daemon was already stopped
  2049. # 2 if daemon could not be stopped
  2050. # other if a failure occurred
  2051. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  2052. RETVAL="$?"
  2053. [ "$RETVAL" = 2 ] && return 2
  2054. # Wait for children to finish too if this is a daemon that forks
  2055. # and if the daemon is only ever run from this initscript.
  2056. # If the above conditions are not satisfied then add some other code
  2057. # that waits for the process to drop all resources that could be
  2058. # needed by services started subsequently. A last resort is to
  2059. # sleep for some time.
  2060. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  2061. [ "$?" = 2 ] && return 2
  2062. # Many daemons don't delete their pidfiles when they exit.
  2063. rm -f $PIDFILE
  2064. return "$RETVAL"
  2065. }
  2066. #
  2067. # Function that sends a SIGHUP to the daemon/service
  2068. #
  2069. do_reload() {
  2070. #
  2071. # If the daemon can reload its configuration without
  2072. # restarting (for example, when it is sent a SIGHUP),
  2073. # then implement that here.
  2074. #
  2075. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  2076. return 0
  2077. }
  2078. case "$1" in
  2079. start)
  2080. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  2081. do_start
  2082. case "$?" in
  2083. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  2084. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  2085. esac
  2086. ;;
  2087. stop)
  2088. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  2089. do_stop
  2090. case "$?" in
  2091. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  2092. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  2093. esac
  2094. ;;
  2095. status)
  2096. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  2097. ;;
  2098. #reload|force-reload)
  2099. #
  2100. # If do_reload() is not implemented then leave this commented out
  2101. # and leave 'force-reload' as an alias for 'restart'.
  2102. #
  2103. #log_daemon_msg "Reloading $DESC" "$NAME"
  2104. #do_reload
  2105. #log_end_msg $?
  2106. #;;
  2107. restart|force-reload)
  2108. #
  2109. # If the "reload" option is implemented then remove the
  2110. # 'force-reload' alias
  2111. #
  2112. log_daemon_msg "Restarting $DESC" "$NAME"
  2113. do_stop
  2114. case "$?" in
  2115. 0|1)
  2116. do_start
  2117. case "$?" in
  2118. 0) log_end_msg 0 ;;
  2119. 1) log_end_msg 1 ;; # Old process is still running
  2120. *) log_end_msg 1 ;; # Failed to start
  2121. esac
  2122. ;;
  2123. *)
  2124. # Failed to stop
  2125. log_end_msg 1
  2126. ;;
  2127. esac
  2128. ;;
  2129. *)
  2130. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  2131. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  2132. exit 3
  2133. ;;
  2134. esac
  2135. :
  2136. #+END_SRC
  2137. Save and exit. Then start the gopher service.
  2138. #+BEGIN_SRC: bash
  2139. chmod +x /etc/init.d/gopher
  2140. update-rc.d gopher defaults
  2141. service gopher start
  2142. #+END_SRC
  2143. 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:
  2144. #+BEGIN_SRC: bash
  2145. gopher://mydomainname.com
  2146. #+END_SRC
  2147. There is a browser addon for Gopher called "overbite". Installing that should enable you to view your site.
  2148. ** Install Owncloud
  2149. #+BEGIN_VERSE
  2150. /It's not water vapour/
  2151. -- Larry Ellison
  2152. #+END_VERSE
  2153. Owncloud will allow you to upload and download files, share photos, collaboratively edit documents, have a calendar and more. You should be warned that Owncloud runs quite slowly via an ordinary web browser, but it can be a convenient way to access and share your data from any location in a reasonably secure manner.
  2154. *** Server Installation
  2155. Install some dependencies:
  2156. #+BEGIN_SRC: bash
  2157. apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
  2158. apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
  2159. #+END_SRC
  2160. It's very important that /mod_php5/ and not /mod_php5filter/ be installed. If you have /mod_php5filter/ installed then Owncloud will always fail to install.
  2161. #+BEGIN_SRC: bash
  2162. a2dismod php5filter
  2163. apt-get install libapache2-mod-php5
  2164. #+END_SRC
  2165. Ensure that the size of files which may be uploaded or downloaded is large enough.
  2166. #+BEGIN_SRC: bash
  2167. emacs /etc/php5/apache2/php.ini
  2168. #+END_SRC
  2169. Set the following:
  2170. #+BEGIN_SRC: bash
  2171. upload_max_filesize = 512M
  2172. post_max_size = 512M
  2173. #+END_SRC
  2174. Save and exit, then edit your Apache configuration.
  2175. #+BEGIN_SRC: bash
  2176. export HOSTNAME=mydomainname.com
  2177. emacs /etc/apache2/sites-available/$HOSTNAME
  2178. #+END_SRC
  2179. And add the following, to the 443 VirtualHost section. Really we only will want to be using Owncloud with HTTPS to ensure some level of security and avoidance of dragnet surveillance.
  2180. #+BEGIN_SRC: bash
  2181. <Directory /var/www/mydomainname.com/htdocs/owncloud>
  2182. Options Indexes FollowSymLinks MultiViews
  2183. AllowOverride All
  2184. Order allow,deny
  2185. allow from all
  2186. </Directory>
  2187. #+END_SRC
  2188. To ensure that nobody logs in insecurely add the following to the 80 VirtualHost section.
  2189. #+BEGIN_SRC: bash
  2190. <Directory /var/www/mydomainname.com/htdocs/owncloud>
  2191. deny from all
  2192. </Directory>
  2193. #+END_SRC
  2194. Save and exit, then restart apache.
  2195. #+BEGIN_SRC: bash
  2196. service apache2 restart
  2197. #+END_SRC
  2198. Download owncloud.
  2199. #+BEGIN_SRC: bash
  2200. cd /tmp
  2201. wget http://freedombone.uk.to/owncloud.tar.bz2
  2202. #+END_SRC
  2203. Verify the download:
  2204. #+BEGIN_SRC: bash
  2205. sha256sum owncloud.tar.bz2
  2206. 92b53fdfa7c4165b83dd2f8447f63928454a5815d08ff2d6165dd1a8969ecbe1 owncloud.tar.bz2
  2207. #+END_SRC
  2208. Extract the archive. This may take a couple of minutes, so don't be alarmed that the system has crashed.
  2209. #+BEGIN_SRC: bash
  2210. export HOSTNAME=mydomainname.com
  2211. tar -xjf owncloud.tar.bz2
  2212. #+END_SRC
  2213. Move the extracted files to your site and set file permissions.
  2214. #+BEGIN_SRC: bash
  2215. cp -r owncloud /var/www/$HOSTNAME/htdocs
  2216. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/apps
  2217. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/config
  2218. chown www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud
  2219. #+END_SRC
  2220. Edit the htaccess file for Owncloud.
  2221. #+BEGIN_SRC: bash
  2222. emacs /var/www/$HOSTNAME/htdocs/owncloud/.htaccess
  2223. #+END_SRC
  2224. Set the following.
  2225. #+BEGIN_SRC: bash
  2226. php_value upload_max_filesize 512M
  2227. php_value post_max_size 512M
  2228. php_value memory_limit 32M
  2229. #+END_SRC
  2230. Save and exit.
  2231. With a web browser visit your domain (mydomainname.com/owncloud) and enter an administrator username and password.
  2232. *** Owncloud on Android
  2233. First install [[https://f-droid.org/][F-Droid]] and then search for the current Owncloud app. Once it's installed you'll then be able to log into the BBB with the URL https://mydomainname.com/opencloud, supplying your username and password.
  2234. ** Install a Wiki
  2235. #+BEGIN_VERSE
  2236. /I believe that technology can liberate, but you need to be a master rather than a user. You need to pull technology apart and master it rather than letting it control you./
  2237. -- Tom Barbalet
  2238. #+END_VERSE
  2239. Dokuwiki is based upon flat files, and so is easy to move from one server to another without a lot of database complications.
  2240. Download the wiki.
  2241. #+BEGIN_SRC: bash
  2242. cd /tmp
  2243. wget http://freedombone.uk.to/dokuwiki.tgz
  2244. #+END_SRC
  2245. Verify it.
  2246. #+BEGIN_SRC: bash
  2247. sha256sum dokuwiki.tgz
  2248. 6b126f90979463d9ddaa74acc6f96aa230cfdc789946f241c3646086d9574be8 dokuwiki.tgz
  2249. #+END_SRC
  2250. Then extract and install it.
  2251. #+BEGIN_SRC: bash
  2252. export HOSTNAME=mywikidomainname.com
  2253. tar -xzvf dokuwiki.tgz
  2254. mv /var/www/$HOSTNAME/htdocs /var/www/$HOSTNAME/htdocs_old
  2255. mv dokuwiki /var/www/$HOSTNAME/htdocs
  2256. #+END_SRC
  2257. Edit the Apache configuration for your wiki site.
  2258. #+BEGIN_SRC: bash
  2259. emacs /etc/apache2/sites-available/$HOSTNAME
  2260. #+END_SRC
  2261. The settings should look something like the following. Replace /mywikidomainname.com/ with your wiki domain name.
  2262. #+BEGIN_SRC: bash
  2263. <VirtualHost *:80>
  2264. ServerAdmin myusername@mywikidomainname.com
  2265. ServerName mydomainname.com
  2266. DocumentRoot /var/www/mywikidomainname.com/htdocs
  2267. <Directory /var/www/mywikidomainname.com/htdocs>
  2268. order deny,allow
  2269. allow from all
  2270. </Directory>
  2271. <LocationMatch "/(data|conf|bin|inc)/">
  2272. order allow,deny
  2273. deny from all
  2274. satisfy all
  2275. </LocationMatch>
  2276. <Directory />
  2277. Options FollowSymLinks
  2278. AllowOverride All
  2279. </Directory>
  2280. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  2281. <Directory "/usr/lib/cgi-bin">
  2282. AllowOverride All
  2283. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  2284. Order allow,deny
  2285. Allow from all
  2286. </Directory>
  2287. ErrorLog ${APACHE_LOG_DIR}/error.log
  2288. # Possible values include: debug, info, notice, warn, error, crit,
  2289. # alert, emerg.
  2290. LogLevel error
  2291. CustomLog ${APACHE_LOG_DIR}/access.log combined
  2292. </VirtualHost>
  2293. <IfModule mod_ssl.c>
  2294. <VirtualHost *:443>
  2295. ServerAdmin myusername@mywikidomainname.com
  2296. ServerName mywikidomainname.com
  2297. DocumentRoot /var/www/mywikidomainname.com/htdocs
  2298. <Directory /var/www/mywikidomainname.com/htdocs>
  2299. order deny,allow
  2300. allow from all
  2301. </Directory>
  2302. <LocationMatch "/(data|conf|bin|inc)/">
  2303. order allow,deny
  2304. deny from all
  2305. satisfy all
  2306. </LocationMatch>
  2307. <Directory />
  2308. Options FollowSymLinks
  2309. AllowOverride All
  2310. </Directory>
  2311. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  2312. <Directory "/usr/lib/cgi-bin">
  2313. AllowOverride All
  2314. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  2315. Order allow,deny
  2316. Allow from all
  2317. </Directory>
  2318. ErrorLog ${APACHE_LOG_DIR}/error.log
  2319. # Possible values include: debug, info, notice, warn, error, crit,
  2320. # alert, emerg.
  2321. LogLevel error
  2322. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  2323. # SSL Engine Switch:
  2324. # Enable/Disable SSL for this virtual host.
  2325. SSLEngine on
  2326. # A self-signed certificate
  2327. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  2328. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  2329. # Options based on bettercrypto.org
  2330. SSLProtocol All -SSLv2 -SSLv3
  2331. SSLHonorCipherOrder On
  2332. SSLCompression off
  2333. 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
  2334. # SSL Engine Options:
  2335. # Set various options for the SSL engine.
  2336. # o FakeBasicAuth:
  2337. # Translate the client X.509 into a Basic Authorisation. This means that
  2338. # the standard Auth/DBMAuth methods can be used for access control. The
  2339. # user name is the `one line' version of the client's X.509 certificate.
  2340. # Note that no password is obtained from the user. Every entry in the user
  2341. # file needs this password: `xxj31ZMTZzkVA'.
  2342. # o ExportCertData:
  2343. # This exports two additional environment variables: SSL_CLIENT_CERT and
  2344. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  2345. # server (always existing) and the client (only existing when client
  2346. # authentication is used). This can be used to import the certificates
  2347. # into CGI scripts.
  2348. # o StdEnvVars:
  2349. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  2350. # Per default this exportation is switched off for performance reasons,
  2351. # because the extraction step is an expensive operation and is usually
  2352. # useless for serving static content. So one usually enables the
  2353. # exportation for CGI and SSI requests only.
  2354. # o StrictRequire:
  2355. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  2356. # under a "Satisfy any" situation, i.e. when it applies access is denied
  2357. # and no other module can change it.
  2358. # o OptRenegotiate:
  2359. # This enables optimized SSL connection renegotiation handling when SSL
  2360. # directives are used in per-directory context.
  2361. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  2362. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  2363. SSLOptions +StdEnvVars
  2364. </FilesMatch>
  2365. <Directory /usr/lib/cgi-bin>
  2366. SSLOptions +StdEnvVars
  2367. </Directory>
  2368. # SSL Protocol Adjustments:
  2369. # The safe and default but still SSL/TLS standard compliant shutdown
  2370. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  2371. # the close notify alert from client. When you need a different shutdown
  2372. # approach you can use one of the following variables:
  2373. # o ssl-unclean-shutdown:
  2374. # This forces an unclean shutdown when the connection is closed, i.e. no
  2375. # SSL close notify alert is send or allowed to received. This violates
  2376. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  2377. # this when you receive I/O errors because of the standard approach where
  2378. # mod_ssl sends the close notify alert.
  2379. # o ssl-accurate-shutdown:
  2380. # This forces an accurate shutdown when the connection is closed, i.e. a
  2381. # SSL close notify alert is send and mod_ssl waits for the close notify
  2382. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  2383. # practice often causes hanging connections with brain-dead browsers. Use
  2384. # this only for browsers where you know that their SSL implementation
  2385. # works correctly.
  2386. # Notice: Most problems of broken clients are also related to the HTTP
  2387. # keep-alive facility, so you usually additionally want to disable
  2388. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  2389. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  2390. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  2391. # "force-response-1.0" for this.
  2392. BrowserMatch "MSIE [2-6]" \
  2393. nokeepalive ssl-unclean-shutdown \
  2394. downgrade-1.0 force-response-1.0
  2395. # MSIE 7 and newer should be able to use keepalive
  2396. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  2397. </VirtualHost>
  2398. </IfModule>
  2399. #+END_SRC
  2400. Enable your site with:
  2401. #+BEGIN_SRC: bash
  2402. a2ensite
  2403. #+END_SRC
  2404. then select the domain name and reload.
  2405. #+BEGIN_SRC: bash
  2406. service apache2 reload
  2407. #+END_SRC
  2408. and alter permissions:
  2409. #+BEGIN_SRC: bash
  2410. chmod -R 755 /var/www/$HOSTNAME/htdocs
  2411. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs
  2412. #+END_SRC
  2413. Open a browser and visit http://$HOSTNAME/install.php, then fill out the details. Once everything has been accepted without errors:
  2414. #+BEGIN_SRC: bash
  2415. rm /var/www/$HOSTNAME/htdocs/install.php
  2416. #+END_SRC
  2417. Add a few extra mime types:
  2418. #+BEGIN_SRC: bash
  2419. emacs /var/www/$HOSTNAME/htdocs/conf/mime.conf
  2420. #+END_SRC
  2421. Append the following:
  2422. #+BEGIN_SRC: bash
  2423. ogv video/ogg
  2424. mp4 video/mp4
  2425. webm video/webm
  2426. #+END_SRC
  2427. Save and exit.
  2428. If you need to be able to upload large files to the wiki then edit */etc/php5/apache2/php.ini* and set *upload_max_filesize* accordingly. If the directory */etc/php5/apache2* doesn't exist then you will need to install the package *libapache2-mod-php5*.
  2429. Now you can visit your wiki and begin editing.
  2430. ** Install Bitmessage
  2431. #+BEGIN_VERSE
  2432. /Love your neighbour. Fight the future. If you are reading this you ARE the resistance./
  2433. -- BitChirp
  2434. #+END_VERSE
  2435. *** A new kind of Email
  2436. [[https://bitmessage.org][Bitmessage]] is a new type of messaging system intended to fulfill the same role as email, but without the security problems. In particular, Bitmessage attempts to not just encrypt the content but also the metadata. It's message broadcasting system makes it exceedingly difficult for an attacker to know which computer a message is destined for. The only way you know whether a message has been sent to you is whether you are able to decrypt it from the passing stream of messages.
  2437. Although similar to Bitcoin in some regards, such as "/proof of work/", Bitmessage has no block chain and messages are only buffered for approximately three days after which they are deleted from any given node.
  2438. Installing Bitmessage as a daemon will increase the size of the network, and therefore the level of security for all users.
  2439. *** The Daemon
  2440. Install from the current source code.
  2441. #+BEGIN_SRC: bash
  2442. apt-get install python screen
  2443. cd /tmp
  2444. git clone https://github.com/Bitmessage/PyBitmessage.git
  2445. cd PyBitmessage
  2446. make install
  2447. #+END_SRC
  2448. Now create the daemon.
  2449. #+BEGIN_SRC: bash
  2450. emacs /etc/init.d/pybitmessage
  2451. #+END_SRC
  2452. Add the following text:
  2453. #+BEGIN_SRC: bash
  2454. #!/bin/bash
  2455. # /etc/init.d/bitmessage
  2456. ### BEGIN INIT INFO
  2457. # Provides: pybitmessage
  2458. # Required-Start: $remote_fs $syslog
  2459. # Required-Stop: $remote_fs $syslog
  2460. # Default-Start: 2 3 4 5
  2461. # Default-Stop: 0 1 6
  2462. # Short-Description: starts bitmessage as a background daemon, suitable for servers
  2463. # Description: This file should be used to construct scripts to be
  2464. # placed in /etc/init.d.
  2465. ### END INIT INFO
  2466. # Author: Super-Nathan <BM-Gu2k3Wy2hpTMYBxSoM2937SPcuU6xzEj>
  2467. #Settings
  2468. SERVICE='pybitmessage'
  2469. LOGFILE='/dev/null' # this disables logging
  2470. # LOGFILE='/var/log/bitmessage.log' # comment out the above line and un-comment this line to save a log
  2471. COMMAND="python bitmessagemain.py > $LOGFILE"
  2472. USERNAME='bitmsg'
  2473. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  2474. HISTORY=1024
  2475. PBM_LOCATION="/usr/local/share/pybitmessage"
  2476. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  2477. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin:/usr/local/share/pybitmessage'
  2478. bm_start() {
  2479. echo "Starting $SERVICE..."
  2480. cd ${PBM_LOCATION}
  2481. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  2482. }
  2483. bm_stop() {
  2484. echo "Stopping $SERVICE"
  2485. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  2486. }
  2487. #Start-Stop here
  2488. case "$1" in
  2489. start)
  2490. bm_start
  2491. ;;
  2492. stop)
  2493. bm_stop
  2494. ;;
  2495. restart)
  2496. bm_stop
  2497. sleep 60s
  2498. bm_start
  2499. ;;
  2500. *)
  2501. echo "Usage: $0 {start|stop|restart}"
  2502. exit 1
  2503. ;;
  2504. esac
  2505. exit 0
  2506. #+END_SRC
  2507. Save and exit.
  2508. Add a user which will be specifically for Bitmessage. Since bitmessage is still a relatively young and experimental project, this adds further compartmentalisation such that if there are any bugs within PyBitmessage then an attacker can't neccessarily gain control of root or any other user account. Here we create a user called /bitmsg/ and give it a long random password.
  2509. #+BEGIN_SRC: bash
  2510. adduser bitmsg
  2511. #+END_SRC
  2512. Create a /keys.dat/ file which is used to configure Bitmessage.
  2513. #+BEGIN_SRC: bash
  2514. mkdir /home/bitmsg/.config
  2515. mkdir /home/bitmsg/.config/PyBitmessage
  2516. emacs /home/bitmsg/.config/PyBitmessage/keys.dat
  2517. #+END_SRC
  2518. Add the following:
  2519. #+BEGIN_SRC: bash
  2520. [bitmessagesettings]
  2521. settingsversion = 7
  2522. port = 8444
  2523. timeformat = %%a, %%d %%b %%Y %%I:%%M %%p
  2524. blackwhitelist = black
  2525. startonlogon = false
  2526. minimizetotray = false
  2527. showtraynotifications = false
  2528. startintray = false
  2529. socksproxytype = none
  2530. sockshostname = localhost
  2531. socksport = 9050
  2532. socksauthentication = false
  2533. sockslisten = false
  2534. socksusername =
  2535. sockspassword =
  2536. keysencrypted = false
  2537. messagesencrypted = false
  2538. defaultnoncetrialsperbyte = 640
  2539. defaultpayloadlengthextrabytes = 14000
  2540. minimizeonclose = false
  2541. maxacceptablenoncetrialsperbyte = 0
  2542. maxacceptablepayloadlengthextrabytes = 0
  2543. userlocale = system
  2544. namecoinrpctype = namecoind
  2545. namecoinrpchost = localhost
  2546. namecoinrpcuser =
  2547. namecoinrpcpassword =
  2548. namecoinrpcport = 8336
  2549. sendoutgoingconnections = True
  2550. daemon = true
  2551. #+END_SRC
  2552. Save and exit. Then enable the daemon and run it.
  2553. #+BEGIN_SRC: bash
  2554. rm -f /tmp/-usr-local-share-pybitmessage-*.lock
  2555. chown -R bitmsg:bitmsg /home/bitmsg
  2556. chmod +x /etc/init.d/pybitmessage
  2557. update-rc.d pybitmessage defaults
  2558. service pybitmessage start
  2559. #+END_SRC
  2560. Now open port 8444 on your internet router or firewall and direct it to the BBB.
  2561. *** Using Bitmessage
  2562. Although in principle it would be possible to send Bitmessages directly from the BBB, in practice the /proof of work/ requirement would mean that it would take an infeasibly long time to send messages, and the computational workload would likely greatly impair the performance of other services also running on the system. So to send and receive Bitmessages it's better to just install the client on a laptop or desktop machine.
  2563. The easiest way to install the client is either to download it from [[https://bitmessage.org][bitmessage.org]] or to get the latest build from Github as follows:
  2564. #+BEGIN_SRC: bash
  2565. cd /tmp
  2566. git clone https://github.com/Bitmessage/PyBitmessage.git
  2567. cd PyBitmessage
  2568. make install
  2569. pybitmessage
  2570. #+END_SRC
  2571. *** Connect to Email
  2572. TODO: how to connect Bitmessage to an email client.
  2573. #+BEGIN_SRC: bash
  2574. cd /tmp
  2575. wget http://freedombone.uk.to/notbit.tar.gz
  2576. #+END_SRC
  2577. Verify it.
  2578. #+BEGIN_SRC: bash
  2579. sha256sum notbit.tar.gz
  2580. 972fdc9cbb8034141282337dcd5e557bce57969ff6bd1d607da89bd93cc7bb68
  2581. #+END_SRC
  2582. Extract and install it.
  2583. #+BEGIN_SRC: bash
  2584. tar -xzvf notbit.tar.gz
  2585. cd notbit
  2586. apt-get install dh-autoreconf
  2587. ./autogen.sh --prefix=/home/myusername
  2588. make
  2589. make install
  2590. #+END_SRC
  2591. ** Overcome restrictive environments
  2592. #+BEGIN_VERSE
  2593. /Censorship reflects a society's lack of confidence in itself. It is a hallmark of an authoritarian regime./
  2594. -- Potter Stewart
  2595. #+END_VERSE
  2596. In some environments, such as behind corporate firewalls or under regimes hostile towards the idea of open access to knowledge and information you may find that you're not able to use tools such as /ssh/ to get access to the BBB. In the worst case all ports other than 80 and 443 may be blocked.
  2597. In that scenario you can use a tool called [[http://code.google.com/p/shellinabox/][shellinabox]] to log into your BBB via your web site rather than via a terminal. This means that you can administrate your system from any device which has a web browser and keyboard.
  2598. #+BEGIN_SRC: bash
  2599. apt-get install shellinabox libapache2-mod-proxy-html
  2600. #+END_SRC
  2601. Update your Apache configuration.
  2602. #+BEGIN_SRC: bash
  2603. export HOSTNAME=mydomainname.com
  2604. emacs /etc/apache2/sites-available/$HOSTNAME
  2605. #+END_SRC
  2606. Within the section which begins with *<VirtualHost *:443>* add the following, replacing /mydomainname.com/ with your domain name and /myusername/ with your username.
  2607. #+BEGIN_SRC: bash
  2608. <Location /shell>
  2609. ProxyPass http://localhost:4200/
  2610. Order allow,deny
  2611. Allow from all
  2612. AuthName "Authentication for shellinabox"
  2613. AuthUserFile /home/mydomainname.com/public_html/.htpasswd
  2614. AuthGroupFile /home/mydomainname.com/public_html/.htgroup
  2615. AuthType Basic
  2616. Require group shellinabox
  2617. Require user myusername
  2618. </Location>
  2619. #+END_SRC
  2620. Save and exit, then create a login password. It's recommended that the password be a long random string and that you then access it using a password manager such as KeepassX.
  2621. #+BEGIN_SRC: bash
  2622. mkdir /home/$HOSTNAME
  2623. mkdir /home/$HOSTNAME/public_html
  2624. htpasswd -c /home/$HOSTNAME/public_html/.htpasswd myusername
  2625. #+END_SRC
  2626. Create a user group.
  2627. #+BEGIN_SRC: bash
  2628. emacs /home/$HOSTNAME/public_html/.htgroup
  2629. #+END_SRC
  2630. Add the following:
  2631. #+BEGIN_SRC: bash
  2632. shellinabox: myusername
  2633. #+END_SRC
  2634. Save and exit, then restart Apache.
  2635. #+BEGIN_SRC: bash
  2636. a2enmod proxy_http
  2637. service apache2 restart
  2638. #+END_SRC
  2639. Now with a web browser navigate to https://mydomainname.com/shell and log in.
  2640. If you're in a very locked down environment where access to web sites is severely restricted then as a last resort you may be able to use a command line browser, such as [[https://en.wikipedia.org/wiki/Lynx_%28web_browser%29][lynx]] from within /shellinabox/.
  2641. ** Set up a mailing list
  2642. #+BEGIN_VERSE
  2643. /All over the world there are many people who are united in creating software, content, and culture that is freely available for others to share, enjoy and enrich their lives. Together we believe that freedom is good. We believe it helps people do good things, make better choices, and lead safer and more secure lives. Together we are a community united by this belief./
  2644. -- Jono Bacon
  2645. #+END_VERSE
  2646. *** With Email
  2647. Email mailing lists are old skool but still remain as a common and easy way of communicating on the internet. If you're running a public organisation such as an open source project or community group then you may want to set one up.
  2648. **** Installation
  2649. #+BEGIN_SRC: bash
  2650. export HOSTNAME=mydomainname.com
  2651. apt-get install mailman
  2652. newlist mailman
  2653. #+END_SRC
  2654. Enter an email address for the list administrator and a password.
  2655. #+BEGIN_SRC: bash
  2656. emacs /etc/mailman/mm_cfg.py
  2657. #+END_SRC
  2658. Set *MTA=None* and change *http:* to *https:*, then save and exit.
  2659. Add some settings.
  2660. #+BEGIN_SRC: bash
  2661. emacs /etc/exim4/conf.d/main/04_mailman_options
  2662. #+END_SRC
  2663. Add the following, replacing /mydomainname.com/ with your domain name.
  2664. #+BEGIN_SRC: bash
  2665. # Mailman macro definitions
  2666. # Home dir for the Mailman installation
  2667. MM_HOME=/var/lib/mailman
  2668. # User and group for Mailman
  2669. MM_UID=list
  2670. MM_GID=list
  2671. #
  2672. # Domains that your lists are in - colon separated list
  2673. # you may wish to add these into local_domains as well
  2674. domainlist mm_domains=mydomainname.com
  2675. # The path of the Mailman mail wrapper script
  2676. MM_WRAP=MM_HOME/mail/mailman
  2677. #
  2678. # The path of the list config file (used as a required file when
  2679. # verifying list addresses)
  2680. MM_LISTCHK=MM_HOME/lists/${lc::$local_part}/config.pck
  2681. #+END_SRC
  2682. Save and exit.
  2683. #+BEGIN_SRC: bash
  2684. emacs /etc/exim4/conf.d/main/000_localmacros
  2685. #+END_SRC
  2686. Append the following:
  2687. #+BEGIN_SRC: bash
  2688. SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe
  2689. SYSTEM_ALIASES_USER = list
  2690. SYSTEM_ALIASES_GROUP = list
  2691. #+END_SRC
  2692. Save and exit.
  2693. #+BEGIN_SRC: bash
  2694. emacs /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
  2695. #+END_SRC
  2696. Append the following, before the final /accept/:
  2697. #+BEGIN_SRC: bash
  2698. # Do callback verification unless Mailman incoming bounce
  2699. deny !local_parts = *-bounces : *-bounces+*
  2700. !verify = sender/callout=30s,defer_ok
  2701. #+END_SRC
  2702. Save and exit.
  2703. #+BEGIN_SRC: bash
  2704. emacs
  2705. /etc/exim4/conf.d/router/450_mailman_aliases
  2706. #+END_SRC
  2707. Add the following:
  2708. #+BEGIN_SRC: bash
  2709. mailman_router:
  2710. driver = accept
  2711. domains = +mm_domains
  2712. require_files = MM_LISTCHK
  2713. local_part_suffix_optional
  2714. local_part_suffix = -admin : \
  2715. -bounces : -bounces+* : \
  2716. -confirm : -confirm+* : \
  2717. -join : -leave : \
  2718. -owner : -request : \
  2719. -subscribe : -unsubscribe
  2720. transport = mailman_transport
  2721. #+END_SRC
  2722. Save and exit.
  2723. #+BEGIN_SRC: bash
  2724. emacs /etc/exim4/conf.d/transport/40_mailman_pipe
  2725. #+END_SRC
  2726. Add the following:
  2727. #+BEGIN_SRC: bash
  2728. mailman_transport:
  2729. driver = pipe
  2730. command = MM_WRAP \
  2731. '${if def:local_part_suffix \
  2732. {${sg{$local_part_suffix}{-(\\w+)(\\+.*)?}{\$1}}} \
  2733. {post}}' \
  2734. $local_part
  2735. current_directory = MM_HOME
  2736. home_directory = MM_HOME
  2737. user = MM_UID
  2738. group = MM_GID
  2739. #+END_SRC
  2740. Save and exit.
  2741. #+BEGIN_SRC: bash
  2742. chown root:list /var/lib/mailman/mail/mailman
  2743. update-exim4.conf.template -r
  2744. update-exim4.conf
  2745. service exim4 restart
  2746. emacs /etc/apache2/conf.d/mailman
  2747. #+END_SRC
  2748. Add the following:
  2749. #+BEGIN_SRC: bash
  2750. Alias /pipermail /var/lib/mailman/archives/public
  2751. Alias /images/mailman /usr/share/images/mailman
  2752. <directory /var/lib/mailman/archives/public>
  2753. DirectoryIndex index.html
  2754. </directory>
  2755. #+END_SRC
  2756. Save and exit.
  2757. #+BEGIN_SRC: bash
  2758. emacs /etc/apache2/sites-available/$HOSTNAME
  2759. #+END_SRC
  2760. Add the following to the 443 section.
  2761. #+BEGIN_SRC: bash
  2762. <Location /mailman>
  2763. Options Indexes FollowSymLinks MultiViews
  2764. Order allow,deny
  2765. Allow from all
  2766. RedirectMatch ^/$ /cgi-bin/mailman/listinfo
  2767. </Location>
  2768. #+END_SRC
  2769. Save and exit.
  2770. #+BEGIN_SRC: bash
  2771. service apache2 restart
  2772. #+END_SRC
  2773. Now add your mailing list. The list name should not include any spaces.
  2774. #+BEGIN_SRC: bash
  2775. newlist mymailinglistname
  2776. #+END_SRC
  2777. With a browser visit https://$HOSTNAME/cgi-bin/mailman/admin/mymailinglistname to configure the mailing list.
  2778. Under *General Options* add an email address for a moderator (could be the same as the administrator) and click *Submit your changes*.
  2779. Under *Privacy Options* set steps required for subscription to *Confirm and approve* and click *Submit your changes*.
  2780. Also change these settings for the account within https://$HOSTNAME/cgi-bin/mailman/admin/mailman
  2781. #+BEGIN_SRC: bash
  2782. emacs /etc/aliases
  2783. #+END_SRC
  2784. Append the following, replacing /mymailinglistname/ with your mailing list name:
  2785. #+BEGIN_SRC: bash
  2786. mymailinglistname: "|/var/lib/mailman/mail/mailman post mymailinglistname"
  2787. mymailinglistname-admin: "|/var/lib/mailman/mail/mailman admin mymailinglistname"
  2788. mymailinglistname-bounces: "|/var/lib/mailman/mail/mailman bounces mymailinglistname"
  2789. mymailinglistname-confirm: "|/var/lib/mailman/mail/mailman confirm mymailinglistname"
  2790. mymailinglistname-join: "|/var/lib/mailman/mail/mailman join mymailinglistname"
  2791. mymailinglistname-leave: "|/var/lib/mailman/mail/mailman leave mymailinglistname"
  2792. mymailinglistname-owner: "|/var/lib/mailman/mail/mailman owner mymailinglistname"
  2793. mymailinglistname-request: "|/var/lib/mailman/mail/mailman request mymailinglistname"
  2794. mymailinglistname-subscribe: "|/var/lib/mailman/mail/mailman subscribe mymailinglistname"
  2795. mymailinglistname-unsubscribe: "|/var/lib/mailman/mail/mailman unsubscribe mymailinglistname"
  2796. #+END_SRC
  2797. Save and exit. Then to test that the mailing list works:
  2798. #+BEGIN_SRC: bash
  2799. exim -d+route -bt mymailinglistname@$HOSTNAME
  2800. #+END_SRC
  2801. If everything is working then this shouldn't show any problems.
  2802. **** Using the mailing list
  2803. Direct subscribers towards:
  2804. #+BEGIN_SRC: bash
  2805. https://mydomainname.com/cgi-bin/mailman/listinfo/mymailinglistname
  2806. #+END_SRC
  2807. To administrate the list visit:
  2808. #+BEGIN_SRC: bash
  2809. https://mydomainname.com/cgi-bin/mailman/admin/mymailinglistname
  2810. #+END_SRC
  2811. To add another mailing list:
  2812. #+BEGIN_SRC: bash
  2813. newlist mymailinglistname
  2814. #+END_SRC
  2815. To delete a mailing list:
  2816. #+BEGIN_SRC: bash
  2817. rmlist -a mymailinglistname
  2818. #+END_SRC
  2819. *** With Bitmessage
  2820. On your local machine (not the BBB) you can make a private mailing list which is difficult to censor and where there is no single point of failure. This type of mailing list is known as a "chan".
  2821. On a Debian based system:
  2822. #+BEGIN_SRC: bash
  2823. sudo apt-get install makepasswd
  2824. #+END_SRC
  2825. or on an RPM based system:
  2826. #+BEGIN_SRC: bash
  2827. sudo yum install makepasswd
  2828. #+END_SRC
  2829. Create a name for your mailing list. This will be a random string.
  2830. #+BEGIN_SRC: bash
  2831. makepasswd -c 40
  2832. #+END_SRC
  2833. Keep a note of this.
  2834. Run the Bitmessage client and on the menu select *File/Join-Create Chan/Create new chan*
  2835. Enter the random string which you created as the name of the mailing list. Also take a note of the BM address which is created.
  2836. You can hand out the random string used to generate the mailing list and its corresponding BM address to fellow members, either within a bitmessage or on paper or via [[https://en.wikipedia.org/wiki/Sneakernet][sneakernet]] or in a GPG/PGP encrypted email or via an XMPP+OTR or Friendica private message. Once others have those two pieces of data then they will be able to join.
  2837. To make the list easier to identify, rather than just appearing as a random string, then under the *Your Identities* tab right click on it and select *Set Avatar* and assign a suitable icon.
  2838. The disadvantage of this type of mailing list is that it's not possible for any one participant to act as a list moderator, or in other words each participant must do their own moderation. That's ok if the size of the group is small, but if it's larger then anyone spamming or trolling the list can make things miserable for the others.
  2839. ** Install Tripwire
  2840. #+BEGIN_VERSE
  2841. /...by the time you get done with all of that, we have a freedom box/
  2842. -- Eben Moglen
  2843. #+END_VERSE
  2844. 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.
  2845. #+BEGIN_SRC: bash
  2846. apt-get install tripwire
  2847. export HOSTNAME=mydomainname.com
  2848. cd /etc/tripwire
  2849. cp arm-local.key $HOSTNAME-local.key
  2850. cp site.key $HOSTNAME-site.key
  2851. tripwire --init
  2852. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  2853. tripwire --check --interactive
  2854. #+END_SRC
  2855. you will be asked for two passphrases ("site" and "local"). Make a note of these.
  2856. Turn off reporting of changes to system logs.
  2857. #+BEGIN_SRC: bash
  2858. emacs /etc/tripwire/twcfg.txt
  2859. #+END_SRC
  2860. Set *SYSLOGREPORTING* to false, then save and exit.
  2861. If you subsequently install any more packages or make configuration changes then update the policy again with:
  2862. #+BEGIN_SRC: bash
  2863. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  2864. #+END_SRC
  2865. Also, to look for any rootkits.
  2866. #+BEGIN_SRC: bash
  2867. apt-get install rkhunter
  2868. #+END_SRC
  2869. * Router/Firewall ports
  2870. The following ports on your internet router/firewall should be forwarded to the BBB.
  2871. | Protocol | Port/s |
  2872. |---------------+------------|
  2873. | Gopher | 70 |
  2874. | HTTP | 80 |
  2875. | HTTPS | 443 |
  2876. | IMAP | 143 |
  2877. | IRC SSL | 6670 |
  2878. | SIP | 5060..5061 |
  2879. | SMTP | 25 |
  2880. | SMTPS | 465 |
  2881. | SSH | 22 |
  2882. | XMPP | 5222..5223 |
  2883. | XMPP (server) | 5269 |
  2884. | XMPP (BOSH) | 5280..5281 |
  2885. | Bitmessage | 8444 |
  2886. * Hints and Tips
  2887. ** Messaging security
  2888. 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.
  2889. ** Moving Domains
  2890. 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:
  2891. #+BEGIN_SRC: bash
  2892. find /var/www/mynewdomain/htdocs -type f -exec sed -i 's@myolddomain@mynewdomain@g' {} \;
  2893. #+END_SRC
  2894. ** MySql foo
  2895. *** Backup all databases
  2896. To back up all mysql databases:
  2897. #+BEGIN_SRC: bash
  2898. mysqldump -u root -p --all-databases --events > /var/backups/databasebackup.sql
  2899. #+END_SRC
  2900. *** Restoring a particular mysql database
  2901. To restore yesterday's friendica backup:
  2902. #+BEGIN_SRC: bash
  2903. mysql -D friendica -o < /var/backups/friendica_daily.sql
  2904. #+END_SRC
  2905. To restore yesterday's mediawiki backup:
  2906. #+BEGIN_SRC: bash
  2907. mysql -D wikidb -o < /var/backups/wikidb_daily.sql
  2908. #+END_SRC
  2909. *** Removing mysql server
  2910. If you manage to screw up sql server completely then it can be fully deleted with:
  2911. #+BEGIN_SRC: bash
  2912. ps aux | grep mysql
  2913. #+END_SRC
  2914. and use /kill -9 <pid>/ to kill all mysql processes.
  2915. #+BEGIN_SRC: bash
  2916. apt-get remove --purge mysql\*
  2917. apt-get clean
  2918. updatedb
  2919. #+END_SRC
  2920. * Deprecated
  2921. The following items have been deprecated until such time as a successful installation is achieved.
  2922. ** Collaborative Document Editing
  2923. #+BEGIN_VERSE
  2924. /Openness and participation are antidotes to surveillance and control./
  2925. -- Howard Rheingold
  2926. #+END_VERSE
  2927. #+BEGIN_SRC: bash
  2928. apt-get install nodejs-legacy
  2929. curl https://npmjs.org/install.sh | sh
  2930. #+END_SRC
  2931. Create an etherpad database.
  2932. #+BEGIN_SRC: bash
  2933. mysql -p
  2934. CREATE DATABASE etherpad CHARACTER SET utf8 COLLATE utf8_general_ci;
  2935. GRANT ALL PRIVILEGES ON etherpad.* TO etherpad@localhost IDENTIFIED BY '__yourPasswd__';
  2936. FLUSH PRIVILEGES;
  2937. exit
  2938. #+END_SRC
  2939. Download etherpad.
  2940. #+BEGIN_SRC: bash
  2941. export HOSTNAME=mydomainname.com
  2942. cd /var/www/$HOSTNAME/htdocs
  2943. git clone git://github.com/ether/etherpad-lite.git etherpad
  2944. #+END_SRC
  2945. Edit the configuration file
  2946. #+BEGIN_SRC: bash
  2947. cd /var/www/$HOSTNAME/htdocs/etherpad
  2948. cp settings.json.template settings.json
  2949. emacs /var/www/$HOSTNAME/htdocs/etherpad/settings.json
  2950. #+END_SRC
  2951. Change the following settings. /rAnD0m5tRIng/ should be altered to a random string 10 characters in length.
  2952. #+BEGIN_SRC: bash
  2953. //IP and port which etherpad should bind at
  2954. "ip": "127.0.0.1",
  2955. // set a session key
  2956. "sessionKey" : "rAnD0m5tRIng",
  2957. //configure the connection settings
  2958. "dbType" : "mysql",
  2959. "dbSettings" : {
  2960. "user" : "etherpad",
  2961. "host" : "localhost",
  2962. "password": "__yourPassword__",
  2963. "database": "etherpad"
  2964. },
  2965. // add admin user
  2966. "users": {
  2967. "admin": {
  2968. "password": "__yourAdminPassword__",
  2969. "is_admin": true
  2970. }
  2971. },
  2972. #+END_SRC
  2973. Save and exit, then create a system user.
  2974. #+BEGIN_SRC: bash
  2975. adduser --system --home=/var/www/$HOSTNAME/htdocs/etherpad/ --group etherpad
  2976. chown -R etherpad: /var/www/$HOSTNAME/htdocs/etherpad/
  2977. #+END_SRC
  2978. Create an init script using your favorite editor.
  2979. #+BEGIN_SRC: bash
  2980. emacs /etc/init.d/etherpad
  2981. #+END_SRC
  2982. Add the following, replacing /mydomainname.com/ with your domain name:
  2983. #+BEGIN_SRC: bash
  2984. #!/bin/sh
  2985. ### BEGIN INIT INFO
  2986. # Provides: etherpad-lite
  2987. # Required-Start: $local_fs $remote_fs $network $syslog
  2988. # Required-Stop: $local_fs $remote_fs $network $syslog
  2989. # Default-Start: 2 3 4 5
  2990. # Default-Stop: 0 1 6
  2991. # Short-Description: starts etherpad lite
  2992. # Description: starts etherpad lite using start-stop-daemon
  2993. ### END INIT INFO
  2994. PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin"
  2995. LOGFILE="/var/www/mydomainname.com/htdocs/etherpad/etherpad-lite.log"
  2996. EPLITE_DIR="/var/www/mydomainname.com/htdocs/etherpad"
  2997. EPLITE_BIN="bin/safeRun.sh"
  2998. USER="etherpad"
  2999. GROUP="etherpad"
  3000. DESC="Etherpad Lite"
  3001. NAME="etherpad-lite"
  3002. set -e
  3003. . /lib/lsb/init-functions
  3004. start() {
  3005. echo "Starting $DESC... "
  3006. start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --exec $EPLITE_DIR/$EPLITE_BIN -- $LOGFILE || true
  3007. echo "done"
  3008. }
  3009. #We need this function to ensure the whole process tree will be killed
  3010. killtree() {
  3011. local _pid=$1
  3012. local _sig=${2-TERM}
  3013. for _child in $(ps -o pid --no-headers --ppid ${_pid}); do
  3014. killtree ${_child} ${_sig}
  3015. done
  3016. kill -${_sig} ${_pid}
  3017. }
  3018. stop() {
  3019. echo "Stopping $DESC... "
  3020. while test -d /proc/$(cat /var/run/$NAME.pid); do
  3021. killtree $(cat /var/run/$NAME.pid) 15
  3022. sleep 0.5
  3023. done
  3024. rm /var/run/$NAME.pid
  3025. echo "done"
  3026. }
  3027. status() {
  3028. status_of_proc -p /var/run/$NAME.pid "" "etherpad-lite" && exit 0 || exit $?
  3029. }
  3030. case "$1" in
  3031. start)
  3032. start
  3033. ;;
  3034. stop)
  3035. stop
  3036. ;;
  3037. restart)
  3038. stop
  3039. start
  3040. ;;
  3041. status)
  3042. status
  3043. ;;
  3044. *)
  3045. echo "Usage: $NAME {start|stop|restart|status}" >&2
  3046. exit 1
  3047. ;;
  3048. esac
  3049. exit 0
  3050. #+END_SRC
  3051. Save and exit, then enable the daemon.
  3052. #+BEGIN_SRC: bash
  3053. chmod +x /etc/init.d/etherpad
  3054. update-rc.d etherpad defaults
  3055. service etherpad start
  3056. #+END_SRC
  3057. Update your Apache configuration.
  3058. #+BEGIN_SRC: bash
  3059. emacs /etc/apache2/sites-available/$HOSTNAME
  3060. #+END_SRC
  3061. Within the section which begins with *<VirtualHost *:443>* add the following:
  3062. #+BEGIN_SRC: bash
  3063. <Location /etherpad>
  3064. ProxyPass http://localhost:9001/
  3065. ProxyPassReverse http://localhost:9001/
  3066. Order allow,deny
  3067. allow from all
  3068. AuthName "Welcome to Etherpad"
  3069. AuthUserFile /home/mydomainname.com/public_html/.htpasswd
  3070. AuthGroupFile /home/mydomainname.com/public_html/.htgroup
  3071. AuthType Basic
  3072. Require group etherpad
  3073. </Location>
  3074. #+END_SRC
  3075. Save and exit, then restart Apache.
  3076. #+BEGIN_SRC: bash
  3077. apt-get install libapache2-mod-proxy-html
  3078. a2enmod proxy proxy_http headers deflate
  3079. service apache2 restart
  3080. #+END_SRC
  3081. Create some passwords for users.
  3082. #+BEGIN_SRC: bash
  3083. mkdir /home/$HOSTNAME
  3084. mkdir /home/$HOSTNAME/public_html
  3085. htpasswd -c /home/$HOSTNAME/public_html/.htpasswd myusername
  3086. #+END_SRC
  3087. Create a user group.
  3088. #+BEGIN_SRC: bash
  3089. emacs /home/$HOSTNAME/public_html/.htgroup
  3090. #+END_SRC
  3091. Add the following:
  3092. #+BEGIN_SRC: bash
  3093. etherpad: myusername
  3094. #+END_SRC
  3095. Save and exit.
  3096. ** Install a VoIP server
  3097. #+BEGIN_VERSE
  3098. /Our core principles, whether in software or sovereignty, have always been about freedom and dignity, for all people, on an equal basis/
  3099. -- David Sugar, GNU Telephony
  3100. #+END_VERSE
  3101. *** The server
  3102. 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.
  3103. Edit your package sources:
  3104. #+BEGIN_SRC: bash
  3105. emacs /etc/apt/sources.list
  3106. #+END_SRC
  3107. Append the following line:
  3108. #+BEGIN_SRC: bash
  3109. deb http://dev.gnutelephony.org/archive/ wheezy/
  3110. #+END_SRC
  3111. Save and exit.
  3112. 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
  3113. #+BEGIN_SRC: bash
  3114. apt-get install gnutelephony-keyring
  3115. #+END_SRC
  3116. After that it will be happy to accept it as a signed repository. The verification keys can also be directly fetched with
  3117. #+BEGIN_SRC: bash
  3118. cd /tmp
  3119. wget http://dev.gnutelephony.org/archive/wheezy/public.key
  3120. #+END_SRC
  3121. and manually added instead with
  3122. #+BEGIN_SRC: bash
  3123. apt-key add public.key
  3124. #+END_SRC
  3125. To make sure you have all dependencies, do
  3126. #+BEGIN_SRC: bash
  3127. apt-get update;apt-get dist-upgrade
  3128. #+END_SRC
  3129. Before we install anything, let's inspect what is available to us by using
  3130. #+BEGIN_SRC: bash
  3131. dpkg -l sipwitch
  3132. #+END_SRC
  3133. To see the main application. The columns will indicate if the package is installed, which version and a description of the package. Then do
  3134. #+BEGIN_SRC: bash
  3135. dpkg -l sipwitch-*
  3136. #+END_SRC
  3137. 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.
  3138. To install only the main application, do
  3139. #+BEGIN_SRC: bash
  3140. apt-get install sipwitch
  3141. #+END_SRC
  3142. and to install all supporting plugins:
  3143. #+BEGIN_SRC: bash
  3144. apt-get install sipwitch-plugin-scripting sipwitch-plugin-subscriber sipwitch-plugin-forward sipwitch-plugin-zeroconf
  3145. #+END_SRC
  3146. Add your user into the sipwitch group
  3147. #+BEGIN_SRC: bash
  3148. groupadd sipwitch
  3149. groupadd sipusers
  3150. usermod -aG sipwitch myusername
  3151. usermod -aG sipusers myusername
  3152. #+END_SRC
  3153. Then edit the configuration
  3154. #+BEGIN_SRC: bash
  3155. emacs /etc/sipwitch.conf
  3156. #+END_SRC
  3157. Change the *mapped* value from 200 to 20, since we don't want to be serving huge numbers of calls.
  3158. 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.
  3159. Do not set the *realm* value, as doing so seems to prevent the server from working.
  3160. Save and exit.
  3161. Create a digest string for your username:
  3162. #+BEGIN_SRC: bash
  3163. sipwitch digest myusername
  3164. #+END_SRC
  3165. Make a note of the resulting string because you're going to use it in the users file you'll now create.
  3166. #+BEGIN_SRC: bash
  3167. export HOSTNAME=mydomainname.com
  3168. touch /etc/sipwitch.d/$HOSTNAME.xml
  3169. chmod 600 /etc/sipwitch.d/$HOSTNAME.xml
  3170. emacs /etc/sipwitch.d/$HOSTNAME.xml
  3171. #+END_SRC
  3172. It should look something like the following:
  3173. #+BEGIN_SRC: bash
  3174. <provision>
  3175. <user id="myusername">
  3176. <digest>yourdigeststring</digest>
  3177. <extension>201</extension>
  3178. <display>Your full name</display>
  3179. </user>
  3180. </provision>
  3181. #+END_SRC
  3182. Save and exit. Now edit the configuration.
  3183. #+BEGIN_SRC: bash
  3184. emacs /etc/default/sipwitch
  3185. #+END_SRC
  3186. Change "desktop" to "server", then save and exit.
  3187. Update the IP settings:
  3188. #+BEGIN_SRC: bash
  3189. iptables -A INPUT -p tcp --dport 5060 -j ACCEPT
  3190. iptables -A INPUT -p udp --dport 5060 -j ACCEPT
  3191. iptables -A INPUT -p tcp --dport 5061 -j ACCEPT
  3192. iptables -A INPUT -p udp --dport 5061 -j ACCEPT
  3193. iptables-save
  3194. #+END_SRC
  3195. Test that it's working:
  3196. #+BEGIN_SRC: bash
  3197. pkill -9 sipw
  3198. sipw -x9 -f
  3199. #+END_SRC
  3200. 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.
  3201. #+BEGIN_SRC: bash
  3202. service sipwitch start
  3203. #+END_SRC
  3204. *** Clients
  3205. **** Jitsi
  3206. Download the latst version from https://jitsi.org/index.php/Main/Download
  3207. TODO
  3208. **** Twinkle client
  3209. The client should have a user profile as following:
  3210. The "user name" is the xxx id used in the <user id="xxx"> entry of /etc/sipwitch.conf
  3211. The "domain" is the yyy domain in the main config <stack><domain>yyy entry of /etc/sipwitch.conf
  3212. The SIP Authentication should have:
  3213. realm = realm as set in <registry><realm> of /etc/sipwitch.conf
  3214. authentication name = <user id="xx"> entry, same as "User Name" field.
  3215. password = value of <secret>zzz in <user> entry of /etc/sipwitch.conf
  3216. Under security tab, set "Enable ZRTP/SRTP encryption"
  3217. **** Android
  3218. TODO
  3219. CSipSimple?
  3220. ** Install Mediagoblin
  3221. #+BEGIN_SRC: bash
  3222. apt-get install git-core python python-dev python-lxml python-imaging python-virtualenv apache2-suexec libapache2-mod-fcgid
  3223. #+END_SRC
  3224. #+BEGIN_SRC: bash
  3225. adduser --system mediagoblin
  3226. addgroup mediagoblin
  3227. adduser mediagoblin mediagoblin
  3228. export HOSTNAME=mydomainname.com
  3229. cd /var/www/$HOSTNAME/htdocs
  3230. git clone git://gitorious.org/mediagoblin/mediagoblin.git mediagoblin
  3231. chown -hR mediagoblin:mediagoblin /var/www/$HOSTNAME/htdocs/mediagoblin
  3232. cd /var/www/$HOSTNAME/htdocs/mediagoblin
  3233. git submodule init && git submodule update
  3234. cp mediagoblin.ini mediagoblin_local.ini
  3235. emacs mediagoblin.ini
  3236. #+END_SRC
  3237. Set email_sender_address to the address you wish to be used as the sender for system-generated emails
  3238. Edit direct_remote_path, base_dir, and base_url if your mediagoblin directory is not the root directory of your vhost.
  3239. Save and exit.
  3240. #+BEGIN_SRC: bash
  3241. a2enmod suexec
  3242. a2enmod fcgid
  3243. emacs /etc/apache2/sites-available/$HOSTNAME
  3244. #+END_SRC
  3245. Add the following to the 80 virtual host, replacing mydomainname.com with your domain name.
  3246. #+BEGIN_SRC: bash
  3247. <Directory /var/www/mydomainname.com/htdocs/mediagoblin>
  3248. deny from all
  3249. </Directory>
  3250. #+END_SRC
  3251. Add the following to the 443 virtual host.
  3252. #+BEGIN_SRC: bash
  3253. # Serve static and media files via alias
  3254. Alias /mgoblin_static/ /var/www/mydomainname.com/htdocs/mediagoblin/mediagoblin/static/
  3255. Alias /mgoblin_media/ /var/www/mydomainname.com/htdocs/mediagoblin/user_dev/media/public/
  3256. # Rewrite all URLs to fcgi, except for static and media urls
  3257. RewriteEngine On
  3258. RewriteRule ^(mgoblin_static|mgoblin_media)($|/) - [L]
  3259. RewriteCond %{REQUEST_FILENAME} !-f
  3260. RewriteRule ^/(.*)$ /mg.fcgi/$1 [QSA,L]
  3261. # Allow access to static and media directories
  3262. <Directory /var/www/mydomainname.com/htdocs/mediagoblin/mediagoblin/static>
  3263. Order allow,deny
  3264. Allow from all
  3265. </Directory>
  3266. <Directory /var/www/mydomainname.com/htdocs/mediagoblin/mediagoblin/user_dev/media/public>
  3267. Order allow,deny
  3268. Allow from all
  3269. </Directory>
  3270. # Connect to fcgi server
  3271. FastCGIExternalServer /var/www/mg.fcgi -host 127.0.0.1:26543
  3272. #+END_SRC
  3273. Save and exit
  3274. #+BEGIN_SRC: bash
  3275. cd /var/www/$HOSTNAME/htdocs/mediagoblin
  3276. ./lazyserver.sh --server-name=fcgi fcgi_host=127.0.0.1 fcgi_port=26543
  3277. #+END_SRC
  3278. https://github.com/joar/mediagoblin-init-scripts
  3279. ** Kune
  3280. Kune is a collaboration tool aimed at not just socialising but also getting stuff done within a community. It's based upon Apache Wave (formerly Google Wave).
  3281. #+BEGIN_SRC: bash
  3282. apt-get install openjdk-6-jdk openjdk-7-jre mysql-server adduser dbconfig-common libjmagick6-jni
  3283. #+END_SRC
  3284. Add the Kune repository:
  3285. #+BEGIN_SRC: bash
  3286. emacs /etc/apt/sources.list
  3287. #+END_SRC
  3288. Append the following:
  3289. #+BEGIN_SRC: bash
  3290. deb ftp://ftp.kune.ourproject.org/pub/kune/debian/ stable/
  3291. #+END_SRC
  3292. Save and exit, then install the Kune package.
  3293. #+BEGIN_SRC: bash
  3294. gpg --keyserver pgp.mit.edu --recv-keys 9E358A05
  3295. gpg --armor --export 9E358A05 | apt-key add -
  3296. apt-get update
  3297. apt-get install kune
  3298. #+END_SRC
  3299. You will be asked for the MySql root password and another password to be used with the Kune database.
  3300. Allow the system to start automatically at boot.
  3301. #+BEGIN_SRC: bash
  3302. emacs /etc/default/kune
  3303. #+END_SRC
  3304. Set /START=yes/, then save and exit.
  3305. #+BEGIN_SRC: bash
  3306. service kune start
  3307. #+END_SRC
  3308. Now configure Apache.
  3309. #+BEGIN_SRC: bash
  3310. a2enmod expires
  3311. a2enmod proxy
  3312. a2enmod proxy_connect
  3313. a2enmod proxy_http
  3314. #+END_SRC
  3315. Upgrade the database.
  3316. #+BEGIN_SRC: bash
  3317. mysql -p kune_prod < /usr/share/dbconfig-common/data/kune/upgrade/mysql/0.1.0+b5
  3318. mysql -p kune_prod < /usr/share/dbconfig-common/data/kune/upgrade/mysql/0.1.0+b6
  3319. mysql -p kune_prod < /usr/share/dbconfig-common/data/kune/upgrade/mysql/0.2.0+b12
  3320. mysql -p kune_prod < /usr/share/dbconfig-common/data/kune/upgrade/mysql/0.2.0+b23
  3321. mysql -p kune_prod < /usr/share/dbconfig-common/data/kune/upgrade/mysql/0.2.0+b25
  3322. #+END_SRC
  3323. Edit the Apache configuration.
  3324. #+BEGIN_SRC: bash
  3325. emacs /etc/apache2/sites-available/$HOSTNAME
  3326. #+END_SRC
  3327. <VirtualHost *:80>
  3328. ServerName YOURSERVERNAME
  3329. ProxyRequests Off
  3330. <Proxy *>
  3331. Order deny,allow
  3332. Allow from all
  3333. </Proxy>
  3334. <Files *.cache.*>
  3335. ExpiresActive On
  3336. ExpiresDefault "modification plus 2 years"
  3337. </Files>
  3338. <Files *.nocache.*>
  3339. ExpiresActive Off
  3340. </Files>
  3341. ProxyPass /kune/ http://localhost:8888/
  3342. ProxyPassReverse /kune/ http://localhost:8888/
  3343. <Location /var/www/mydomainname.com/htdocs/kune/>
  3344. Order allow,deny
  3345. Allow from all
  3346. </Location>
  3347. </VirtualHost>
  3348. Within a browser open https://mydomainname.com:8888
  3349. See documentation in /usr/share/doc/kune/INSTALL.gz
  3350. * Related projects
  3351. * [[https://freedomboxfoundation.org/][Freedombox]]
  3352. * [[https://arkos.io/][ArkOS]]