beaglebone.txt 143KB

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