beaglebone.txt 243KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515
  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
  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. [[./images/freedombone_small.jpg]]
  12. #+BEGIN_CENTER
  13. Copyright (C) 2014 Bob Mottram
  14. Permission is granted to copy, distribute and/or modify this document under the terms of the [[https://gnu.org/licenses/fdl.html][GNU Free Documentation License]], Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
  15. Source for this web site in [[https://en.wikipedia.org/wiki/Org-mode][Emacs org-mode]] format is available [[/beaglebone.txt][here]]. Comments or patches may be submitted via [[https://github.com/bashrc/freedombone][Github]].
  16. #+END_CENTER
  17. * Introduction
  18. #+BEGIN_VERSE
  19. /The battle for liberty is never won, and is never lost. The battle for liberty always continues. It is never too late, and it is never soon enough, to defend freedom. No matter how enslaved we are, we always have hope. No matter how free we are we are never safe. Nothing ever limits the government, except the people. Any generation which fails to defend freedom will lose it, and the next generation will have to shed blood to gain it back./
  20. -- John Perna
  21. #+END_VERSE
  22. ** What is FreedomBone?
  23. Today many of us rely upon "free" services in the cloud, such as Gmail, Facebook, Google+ and so on. It might appear that these services are indispensible infrastructure of the modern internet, but actually they're not strictly needed and the amount of value which they deliver to the average internet user is very marginal. It is possible to be a citizen of the internet and yet not use those things - to disintermediate the most well known companies and cut out their prurient or merely cringeworthy business models.
  24. FreedomBone is a personal home communications server based upon the BeagleBone Black hardware. It's small and cheap and will allow you to use email, have your own web site and do social networking in a federated way without needing to rely upon any intermediary companies other than your ISP.
  25. ** Do I need any prior knowledge?
  26. In these instructions only a minimal level of familiarity with Linux is assumed. It's assumed that you know the basics of the /nano/ and /emacs/ editors, but it would be simple to also use other editors if you prefer.
  27. ** Why should I do this?
  28. You should consider doing this if you are a freedom-oriented sort of person and you want to maintain sovereignty over your information. Laws in many places in the world consider you to have relinquished any property rights over data which you put onto a server not owned by youself (i.e. owned by a third party, such as Google or Facebook).
  29. If you don't like the idea of having all your communications intercepted and investigated by the Surveillance State then you should consider running a FreedomBone. If your profession involves maintaining confidentiality as an essential feature, such as legal or medical services, counselling, teaching or any sort of activism then you should consider running a FreedomBone. Especially if your activities include [[https://firstlook.org/theintercept/article/2014/03/20/inside-nsa-secret-efforts-hunt-hack-system-administrators/][systems administration]] or [[http://www.spiegel.de/international/germany/gchq-and-nsa-targeted-private-german-companies-a-961444.html][software engineering for any communications-related systems]] then it is highly likely that you have already been targeted and "tasked" by the surveillance apparatus.
  30. As Eben Moglen noted in his now famous [[https://www.youtube.com/watch?v=QOEMv0S8AcA]["Freedom in The Cloud"]] talk the simple fact of you keeping your own internet logs (found in the /var/log directory) puts a certain amount of power in your hands and takes it away from parties who would otherwise sell that information without your knowledge or permission to advertisers or other shady outfits who may not have your best interests at heart.
  31. ** After it's installed will it need a lot of maintenance?
  32. So long as the hardware is ok the amount of maintenance needed should be very small. Unlike on Windows based systems you don't need to defragment drives or mess about with anti-virus programs. I ran a similar Sheevaplug system between 2010 and 2013 with only occasional software updates or reboots, and uptime was probably 99% or better.
  33. ** Is it secure?
  34. Nothing is totally secure or infallible. You could have the most secure technology and yet still use easy to guess passwords. In general any software described as "uncrackable" or "guaranteed secure" is likely to be bogus and should be treated with suspicion. No matter what the hype may claim, all software has bugs so it's really a question of whether your communications are more secure or less secure. Using something like Freedombone will be likely to increase your degree of communications security to a level which is above average.
  35. 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.
  36. 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 any kind of impenetrable information fortress.
  37. This project is not only about security. It's also about having independence and at least in the realm of information being able to have more control over your own life, without having gatekeepers, censors or companies in the middle. That's the way that the internet was designed to be in the first place.
  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 or Cubieboard 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 [[https://en.wikipedia.org/wiki/Raspberry_pi][Raspberry Pi]] or [[https://en.wikipedia.org/wiki/Cubieboard][Cubieboard]]. 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. The Cubieboard is also another good alternative, with the A20 version having similar specifications but twice as much RAM as the BeagleBone Black.
  42. ** Why should I trust the packages or source code downloaded from this site?
  43. If you're particularly security conscious then you shouldn't. Binary or source packages have only been included here for convenience and to avoid confusion. "/Go and find a Debian installation for the BeagleBone Black somewhere on the web/" is too vague an instruction for my liking, and I've attempted to keep things as concise and unambiguous as possible - particularly with an average or new Linux user in mind.
  44. However, for maximum security for those software systems which are not already packaged within the Debian repositories then seek out the original sources and verify the hashes independently.
  45. It's worth adopting an attitude of "/trust but verify/". Don't let fear of mass surveillance and [[https://www.techdirt.com/articles/20140207/08354426130/gchq-has-entire-program-dirty-tricks-including-honeypots-using-journalists-deleting-online-accounts.shtml]["dirty tricks"]] paralyse you into trusting nothing and consequently doing nothing. Doing nothing means that the surveillance apparatus has succeeded in keeping you under observation at all times.
  46. ** Do I need to have a static IP address?
  47. This is often a question which people ask about running a server from home. The answer is that you don't need a static IP address. In the vast majority of cases you will have a dynamic IP address issued by your ISP, which may change from time to time. How then does the DNS system know how to resolve your domain name correctly? To do this you need to use a dynamic IP address system, such as [[http://freedns.afraid.org/][freeDNS]]. The details of that are explained [[Getting onto the web][here]]. Other services are available, but they're not usually /free as in beer/. In this guide a static IP address of 192.168.1.60 is only used within your /local network/ (i.e. not the big bad internet of public IP addresses), so that your internet router can be set up to send incoming traffic to the right computer.
  48. * Inventory
  49. #+BEGIN_VERSE
  50. /You can’t help someone just by making a wish to do so, you have to take action./
  51. -- Dalai Lama
  52. #+END_VERSE
  53. These instructions assume that you have the following ingredients.
  54. ** A BeagleBone Black (BBB)
  55. 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.
  56. ** An internet connection
  57. 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.
  58. ** microSD card
  59. 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.
  60. 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.
  61. ** 5V/2A power supply
  62. 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. One way to test whether the board has enough power is to try compiling a Linux kernel on it, but any CPU and disk intensive program will also suffice as a test.
  63. [[http://beagleboard.org/Support/FAQ][beagleboard.org]] gives the following advice on power supplies:
  64. #+BEGIN_VERSE
  65. /Power over USB is sufficient as long as the software and system running perform some management to keep it under the USB current limit threshold. For simplicity and maximum capability, powering over the 5V barrel connector is typically recommended./
  66. /The power adapter is required to provide 5V over a 5.5mm outer diameter and 2.1mm inner diameter barrel connector (a barrel connector length of 9.5mm is more than sufficient). The recommended supply current is at least 1.2A (or 6W), but at least 2A (or 10W) is recommended if you are going to connect up anything over the USB./
  67. #+END_VERSE
  68. The plug should be /centre positive/, meaning that the centre/tip is positive and the outer part is negative.
  69. ** An ethernet patch cable
  70. Just an ordinary cat5 or cat6 cable that you can get from most electrical/computer stores.
  71. * Installing Debian onto the microSD card
  72. ** Beaglebone Black
  73. 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.
  74. Download the image.
  75. #+BEGIN_SRC: bash
  76. cd ~/
  77. wget http://freedombone.uk.to/debian-7.2-console-armhf-2013-11-15.tar.xz
  78. #+END_SRC
  79. Verify it.
  80. #+BEGIN_SRC: bash
  81. sha256sum debian-7.2-console-armhf-2013-11-15.tar.xz
  82. 262ea96d6bff530ad545e001eb2aa50b26a999c02f0c0e2e5f8536edf21c973a debian-7.2-console-armhf-2013-11-15.tar.xz
  83. #+END_SRC
  84. Uncompress it.
  85. #+BEGIN_SRC: bash
  86. tar xJf debian-7.2-console-armhf-2013-11-15.tar.xz
  87. cd debian-7.2-console-armhf-2013-11-15
  88. #+END_SRC
  89. Create the disk image, where sdX is the name of the flash drive (probably it will be sdb or sdc). An easy way to find out the device name of the flash drive is to enter the command:
  90. #+BEGIN_SRC: bash
  91. ls /dev/sd*
  92. #+END_SRC
  93. then plug in the flash drive and type the same command again. You'll be able to see the difference. Once you know the device name then you can proceed to install the image onto the flash drive.
  94. #+BEGIN_SRC: bash
  95. sudo apt-get install u-boot-tools dosfstools git-core kpartx wget parted
  96. sudo ./setup_sdcard.sh --mmc /dev/sdX --uboot bone --swap-file 1024
  97. #+END_SRC
  98. Once completed then safely remove the microSD card via your file manager (usually right click and "safely remove" or "eject").
  99. ** Cubieboard
  100. 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.
  101. Download the Cubieboard image from http://cubian.org/downloads/
  102. #+BEGIN_SRC: bash
  103. sudo apt-get install p7zip-full
  104. 7z x CUBIAN_IMAGE.7z
  105. #+END_SRC
  106. Create the disk image, where sdX is the name of the flash drive (probably it will be sdb or sdc). An easy way to find out the device name of the flash drive is to enter the command:
  107. #+BEGIN_SRC: bash
  108. ls /dev/sd*
  109. #+END_SRC
  110. then plug in the flash drive and type the same command again. You'll be able to see the difference. Once you know the device name then you can proceed to install the image onto the flash drive.
  111. #+BEGIN_SRC: bash
  112. sudo dd if=EXTRACTED_CUBIAN_IMAGE of=/dev/sdX bs=4096; sync
  113. #+END_SRC
  114. * Setup
  115. #+BEGIN_VERSE
  116. /Build the tools for a future you would want to live in/
  117. -- Kurt Opsahl
  118. #+END_VERSE
  119. ** Things to be aware of
  120. *** A note on ssh
  121. 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:
  122. #+BEGIN_SRC: bash
  123. ssh-keygen -R <IP address>
  124. #+END_SRC
  125. *** Passwords
  126. 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.
  127. *** HTTPS
  128. 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..
  129. 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.
  130. ** Initial
  131. Eject the microSD card from your computer and plug it into the BBB, then connect the USB cable between the two. You may need to wait for a couple of minutes for the BBB to boot from the card, then you can then open a terminal and login via ssh.
  132. Note that if you're using a Cubieboard then the ssh login is different (see https://github.com/cubieplayer/Cubian/wiki/Get-started-with-Cubian) and it may be easier to directly edit the following files with the microSD card plugged into your laptop.
  133. #+BEGIN_SRC: bash
  134. ssh debian@192.168.7.2
  135. #+END_SRC
  136. The default password is /temppwd/
  137. Then log in as root:
  138. #+BEGIN_SRC: bash
  139. su
  140. #+END_SRC
  141. The default password is /root/
  142. The first thing to do is to change the passwords from their defaults.
  143. #+BEGIN_SRC: bash
  144. passwd
  145. #+END_SRC
  146. 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.
  147. #+BEGIN_SRC: bash
  148. nano /etc/network/interfaces
  149. #+END_SRC
  150. The resulting interfaces file should look like this:
  151. #+BEGIN_SRC: bash
  152. # This file describes the network interfaces available on your system
  153. # and how to activate them. For more information, see interfaces(5).
  154. # The loopback network interface
  155. auto lo
  156. iface lo inet loopback
  157. # The primary network interface
  158. allow-hotplug eth0
  159. iface eth0 inet static
  160. address 192.168.1.60
  161. netmask 255.255.255.0
  162. gateway 192.168.1.254
  163. dns-nameservers 213.73.91.35 85.214.20.141
  164. # Example to keep MAC address between reboots
  165. #hwaddress ether DA:AD:CE:EF:CA:FE
  166. # WiFi Example
  167. #auto wlan0
  168. #iface wlan0 inet dhcp
  169. # wpa-ssid "essid"
  170. # wpa-psk "password"
  171. # Ethernet/RNDIS gadget (g_ether)
  172. # ... or on host side, usbnet and random hwaddr
  173. # Note on some boards, usb0 is automaticly setup with an init script
  174. # in that case, to completely disable remove file [run_boot-scripts] from the boot partition
  175. #iface usb0 inet static
  176. # address 192.168.7.2
  177. # netmask 255.255.255.0
  178. # network 192.168.7.0
  179. # gateway 192.168.7.1
  180. #+END_SRC
  181. CTRL-o followed by ENTER to save, then CTRL-x to exit.
  182. 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.
  183. "gateway 192.168.1.254" should be the IP address of the router.
  184. Note that setting the DNS servers with dns-nameservers is important because some home routers do not allow you to change the DNS settings.
  185. Edit resolv.conf.
  186. #+BEGIN_SRC: bash
  187. nano /etc/resolv.conf
  188. #+END_SRC
  189. It should look something like the following:
  190. #+BEGIN_SRC: bash
  191. domain localdomain
  192. search localdomain
  193. nameserver 213.73.91.35
  194. nameserver 85.214.20.141
  195. #+END_SRC
  196. It's not a good idea to use the DNS servers provided by default by your ISP, since those are almost certainly subject to censorship and monitoring. Other possible IP addresses are:
  197. | DNS IP | Organisation | Location |
  198. |-----------------+--------------------------------+-------------|
  199. | 85.214.73.63 | Digitalcourage | Germany |
  200. | 87.118.100.175 | German Privacy Foundation e.V. | Germany |
  201. | 94.75.228.29 | German Privacy Foundation e.V. | Germany |
  202. | 85.25.251.254 | German Privacy Foundation e.V. | Germany |
  203. | 2.141.58.13 | German Privacy Foundation e.V. | Germany |
  204. | 213.73.91.35 | Chaos Computer Club Berlin | Germany |
  205. | 212.82.225.7 | ClaraNet | Germany |
  206. | 212.82.226.212 | ClaraNet | Germany |
  207. | 58.6.115.42 | OpenNIC | Australia |
  208. | 58.6.115.43 | OpenNIC | Australia |
  209. | 119.31.230.42 | OpenNIC | Australia |
  210. | 200.252.98.162 | OpenNIC | Brazil |
  211. | 217.79.186.148 | OpenNIC | Germany |
  212. | 81.89.98.6 | OpenNIC | Germany |
  213. | 78.159.101.37 | OpenNIC | Germany |
  214. | 203.167.220.153 | OpenNIC | New Zealand |
  215. | 82.229.244.191 | OpenNIC | France |
  216. | 82.229.244.191 | OpenNIC | Czechnya |
  217. | 216.87.84.211 | OpenNIC | USA |
  218. | 66.244.95.20 | OpenNIC | USA |
  219. | 207.192.69.155 | OpenNIC | USA |
  220. | 72.14.189.120 | OpenNIC | USA |
  221. | 194.145.226.26 | PowerNS | Germany |
  222. | 77.220.232.44 | PowerNS | Germany |
  223. | 78.46.89.147 | ValiDOM | Germany |
  224. | 88.198.75.145 | ValiDOM | Germany |
  225. | 85.25.149.144 | Freie Unzensierte Nameserver | Germany |
  226. | 87.106.37.196 | Freie Unzensierte Nameserver | Germany |
  227. | 209.59.210.167 | Christoph Hochstätter | USA |
  228. | 85.214.117.11 | Christoph Hochstätter | Germany |
  229. | 83.243.5.253 | private | Germany |
  230. | 88.198.130.211 | private | Germany |
  231. | 85.10.211.244 | private | Germany |
  232. CTRL-o followed by ENTER to save, then CTRL-x to exit.
  233. 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.
  234. 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".
  235. If you're using a Cubieboard:
  236. #+BEGIN_SRC: bash
  237. nano /etc/apt/sources.list
  238. #+END_SRC
  239. Delete the existing sources and replace them with the sources [[Example software sources][listed here]], then save and exit. If you use the default Cubian software sources then dependency problems will occur later on.
  240. ** Add a user
  241. Ssh back in to the BBB and login as root. In this example the BBB's IP address is 192.168.1.60.
  242. #+BEGIN_SRC: bash
  243. ssh-keygen -f "/home/myusername/.ssh/known_hosts" -R 192.168.1.60
  244. ssh debian@192.168.1.60
  245. su
  246. #+END_SRC
  247. 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.
  248. #+BEGIN_SRC: bash
  249. adduser myusername
  250. #+END_SRC
  251. 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.
  252. Remove the default debian user.
  253. #+BEGIN_SRC: bash
  254. userdel -r debian
  255. #+END_SRC
  256. ** Text editor
  257. For an editor which is less erratic than vi when used within a remote console such as Terminator.
  258. #+BEGIN_SRC: bash
  259. apt-get update
  260. apt-get install emacs
  261. update-alternatives --set editor /usr/bin/emacs23
  262. #+END_SRC
  263. Some basic Emacs keys which will be useful to new users are:
  264. | Load a file | CTRL-x CTRL-f |
  265. | Save | CTRL-x CTRL-s |
  266. | Exit | CTRL-x CTRL-c |
  267. ** Enable backports
  268. To enable some newer packages add backports to the repositories.
  269. #+BEGIN_SRC: bash
  270. echo "deb http://ftp.us.debian.org/debian wheezy-backports main" >> /etc/apt/sources.list
  271. apt-get update
  272. apt-get dist-upgrade
  273. apt-get install ca-certificates
  274. #+END_SRC
  275. ** Configure your location/language
  276. #+BEGIN_SRC: bash
  277. dpkg-reconfigure locales
  278. apt-get install keyboard-configuration
  279. reboot
  280. #+END_SRC
  281. After reboot is complete ssh back in as the root user, then to verify the change.
  282. #+BEGIN_SRC: bash
  283. locale -a
  284. #+END_SRC
  285. Set your time zone with:
  286. #+BEGIN_SRC: bash
  287. tzselect
  288. #+END_SRC
  289. For example, for British time:
  290. #+BEGIN_SRC: bash
  291. export TZ='Europe/London'
  292. echo "export TZ='Europe/London'" >> ~/.bashrc
  293. echo "export TZ='Europe/London'" >> /home/myusername/.bashrc
  294. #+END_SRC
  295. ** Upgrade the kernel
  296. Using a more recent kernel should improve stability of the system and also allow it to make use of hardware random number generation, which improves the overall security. Please note that this kernel is specific to the BBB, so if you're using a Raspberry Pi, Cubieboard or other SBC then look elsewhere on the web for information about upgrading the kernel.
  297. #+BEGIN_SRC: bash
  298. cd /tmp
  299. wget http://freedombone.uk.to/kernel-3.14.tar.gz
  300. #+END_SRC
  301. Verify it.
  302. #+BEGIN_SRC: bash
  303. sha256sum kernel-3.14.tar.gz
  304. c489a451b2ab0442ff9105c72307061cfe6858350dacceb29e094b9a20c18739
  305. #+END_SRC
  306. Then extract and install it.
  307. #+BEGIN_SRC: bash
  308. mkdir kernel-3.14
  309. cd kernel-3.14
  310. tar -xzvf ../kernel-3.14.tar.gz
  311. sh install-me.sh
  312. #+END_SRC
  313. If you get a certificate error then edit *install-me.sh* and change the /https/ to /http/, save and try again. Once the installation has completed then you can reboot by typing:
  314. #+BEGIN_SRC: bash
  315. reboot
  316. #+END_SRC
  317. After the system has rebooted you can ssh back unto it and log in as the root user. You can check that the kernel version has changed with the command:
  318. #+BEGIN_SRC: bash
  319. uname -mrs
  320. #+END_SRC
  321. Now enable zram.
  322. #+BEGIN_SRC: bash
  323. editor /etc/modprobe.d/zram.conf
  324. #+END_SRC
  325. Add the following:
  326. #+BEGIN_SRC: bash
  327. options zram num_devices=1
  328. #+END_SRC
  329. Save and exit, then create an initialisation script.
  330. #+BEGIN_SRC: bash
  331. editor /etc/init.d/zram
  332. #+END_SRC
  333. Add the following:
  334. #+BEGIN_SRC: bash
  335. #!/bin/bash
  336. ### BEGIN INIT INFO
  337. # Provides: zram
  338. # Required-Start:
  339. # Required-Stop:
  340. # Default-Start: 2 3 4 5
  341. # Default-Stop: 0 1 6
  342. # Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)
  343. # Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram
  344. ### END INIT INFO
  345. start() {
  346. # get the number of CPUs
  347. num_cpus=$(grep -c processor /proc/cpuinfo)
  348. # if something goes wrong, assume we have 1
  349. [ "$num_cpus" != 0 ] || num_cpus=1
  350. # set decremented number of CPUs
  351. decr_num_cpus=$((num_cpus - 1))
  352. # get the amount of memory in the machine
  353. mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
  354. mem_total=$((mem_total_kb * 1024))
  355. # load dependency modules
  356. modprobe zram num_devices=$num_cpus
  357. # initialize the devices
  358. for i in $(seq 0 $decr_num_cpus); do
  359. echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize
  360. done
  361. # Creating swap filesystems
  362. for i in $(seq 0 $decr_num_cpus); do
  363. mkswap /dev/zram$i
  364. done
  365. # Switch the swaps on
  366. for i in $(seq 0 $decr_num_cpus); do
  367. swapon -p 100 /dev/zram$i
  368. done
  369. }
  370. stop() {
  371. # get the number of CPUs
  372. num_cpus=$(grep -c processor /proc/cpuinfo)
  373. # set decremented number of CPUs
  374. decr_num_cpus=$((num_cpus - 1))
  375. # Switching off swap
  376. for i in $(seq 0 $decr_num_cpus); do
  377. if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
  378. swapoff /dev/zram$i
  379. sleep 1
  380. fi
  381. done
  382. sleep 1
  383. rmmod zram
  384. }
  385. case "$1" in
  386. start)
  387. start
  388. ;;
  389. stop)
  390. stop
  391. ;;
  392. restart)
  393. stop
  394. sleep 3
  395. start
  396. ;;
  397. *)
  398. echo "Usage: $0 {start|stop|restart}"
  399. RETVAL=1
  400. esac
  401. exit $RETVAL
  402. #+END_SRC
  403. Save and exit, then reboot again.
  404. #+BEGIN_SRC: bash
  405. chmod +x /etc/init.d/zram
  406. update-rc.d zram defaults
  407. service zram start
  408. reboot
  409. #+END_SRC
  410. After the system has rebooted ssh back into it and become the root user, then to check that the changes were successful:
  411. #+BEGIN_SRC: bash
  412. dmesg | grep zram
  413. #+END_SRC
  414. Should show something like:
  415. #+BEGIN_SRC: bash
  416. [ 507.322337] zram: Created 1 device(s) ...
  417. [ 507.651151] Adding 505468k swap on /dev/zram0. Priority:100 extents:1 across:505468k SS
  418. #+END_SRC
  419. ** Random number generation
  420. #+BEGIN_VERSE
  421. /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./
  422. -- Bruce Schneier, on the 2013 leaked NSA documents
  423. #+END_VERSE
  424. 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.
  425. *** On the Beaglebone Black
  426. Computers can't really generate truly random numbers by themselves, since they're deterministic and so operate in a highly predictable manner. Fortunately, the BBB has an onboard hardware random number generator, which is a physical process which behaves randomly and which can then be read into the computer and stored for later use in encryption algorithms.
  427. Information on exactly how the hardware random number generator on the Beaglebone AM335x CPU works [[http://e2e.ti.com/support/arm/sitara_arm/f/791/t/292794.aspx][seems hard to come by]], but we can later use some software to verify that it does indeed produce random numbers and hasn't been deliberately weakened.
  428. If you are using a Beaglebone and have updated the kernel then install:
  429. #+BEGIN_SRC: bash
  430. apt-get install rng-tools
  431. editor /etc/default/rng-tools
  432. #+END_SRC
  433. Uncomment *HRNGDEVICE=/dev/hwrng*, save and exit then restart the daemon.
  434. #+BEGIN_SRC: bash
  435. service rng-tools restart
  436. #+END_SRC
  437. Your BBB will now use hardware to generate random numbers.
  438. *** On other Single Board Computers
  439. If you are not using a Beaglebone (a Cubieboard for example), or if you didn't update the kernel, then you can still improve the random number generation by installing:
  440. #+BEGIN_SRC: bash
  441. apt-get install haveged
  442. #+END_SRC
  443. *** Verifying random number quality
  444. #+BEGIN_VERSE
  445. /Living in a surveillance state is exactly like being guilty until proven guilty./
  446. -- Mohammad Tarakiyee
  447. #+END_VERSE
  448. You can check how much randomness (entropy) is available with:
  449. #+BEGIN_SRC: bash
  450. cat /proc/sys/kernel/random/entropy_avail
  451. #+END_SRC
  452. Ideally it should be in the range 1000-4096. If it is persistently below 500 then there may be a problem with your system which could make it less secure.
  453. To verify that random number generation is good on the BBB run:
  454. #+BEGIN_SRC: bash
  455. cat /dev/hwrng | rngtest -c 1000
  456. #+END_SRC
  457. You should see something like this, with zero or a small number of failures:
  458. #+BEGIN_SRC: bash
  459. rngtest: starting FIPS tests...
  460. rngtest: bits received from input: 20000032
  461. rngtest: FIPS 140-2 successes: 1000
  462. rngtest: FIPS 140-2 failures: 0
  463. rngtest: FIPS 140-2(2001-10-10) Monobit: 0
  464. rngtest: FIPS 140-2(2001-10-10) Poker: 0
  465. rngtest: FIPS 140-2(2001-10-10) Runs: 0
  466. rngtest: FIPS 140-2(2001-10-10) Long run: 0
  467. rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
  468. rngtest: input channel speed: (min=3.104; avg=26.015; max=18.626)Gibits/s
  469. rngtest: FIPS tests speed: (min=160.281; avg=165.696; max=168.792)Mibits/s
  470. rngtest: Program run time: 115987 microseconds
  471. #+END_SRC
  472. *** Cryptotronix Hashlet
  473. #+BEGIN_VERSE
  474. /One must acknowledge with cryptography no amount of violence will ever solve a math problem./
  475. -- Jacob Appelbaum
  476. #+END_VERSE
  477. An optional extra is the [[http://cryptotronix.com/products/hashlet/][Cryptotronix Hashlet]] which also has hardware random number generation capability via the [[./Atmel-8740-CryptoAuth-ATSHA204-Datasheet.pdf][Atmel ATSHA204]] chip.
  478. Install the hashlet [[./images/hashlet_installed.jpg][like this]] on the BBB, then install some dependencies.
  479. #+BEGIN_SRC: bash
  480. apt-get install git build-essential libgcrypt11-dev texinfo
  481. #+END_SRC
  482. Download the source code.
  483. #+BEGIN_SRC: bash
  484. cd /tmp
  485. git clone https://github.com/bashrc/hashlet.git
  486. #+END_SRC
  487. Now install the driver.
  488. #+BEGIN_SRC: bash
  489. cd hashlet
  490. chmod o+rw /dev/i2c*
  491. ./autogen.sh
  492. make check
  493. make install
  494. #+END_SRC
  495. To check the initial state of the device:
  496. #+BEGIN_SRC: bash
  497. hashlet --bus=/dev/i2c-2 state
  498. #+END_SRC
  499. It should return the message "/Factory/". This is intended to provide an indication that the hardware hasn't been tampered with by [[https://en.wikipedia.org/wiki/Tailored_Access_Operations][TAO]] or other shady outfits in transit. If /i2c-2/ fails then try /i2c-1/ or /i2c-0/.
  500. #+BEGIN_SRC: bash
  501. hashlet --bus=/dev/i2c-2 personalize
  502. #+END_SRC
  503. Nothing should be returned by this command, but a file called ~/.hashlet will be generated which is the private key of the device. This personalization process is a one-time operation which physically alters the hardware, so it would not be trivial to reset the device back to "Factory" again. To make sure it's only accessible by the root user:
  504. #+BEGIN_SRC: bash
  505. chmod 400 ~/.hashlet
  506. #+END_SRC
  507. Now create a daemon which will create a random number generator device */dev/hashletrng*.
  508. #+BEGIN_SRC: bash
  509. editor /usr/bin/hashletd
  510. #+END_SRC
  511. #+BEGIN_SRC: bash
  512. #!/bin/sh
  513. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  514. I2CBUS=2
  515. BYTES=32
  516. DEVICE=/dev/hashletrng
  517. # create a device
  518. if [ ! -e ${DEVICE} ]; then
  519. chmod o+rw /dev/i2c*
  520. mknod ${DEVICE} p
  521. fi
  522. while :
  523. do
  524. hashlet --bus=/dev/i2c-${I2CBUS} --Bytes ${BYTES} random-bytes > ${DEVICE}
  525. done
  526. #+END_SRC
  527. Save and exit. Now create an init script to run it.
  528. #+BEGIN_SRC: bash
  529. editor /etc/init.d/hashlet
  530. #+END_SRC
  531. Add the following:
  532. #+BEGIN_SRC: bash
  533. #!/bin/bash
  534. # /etc/init.d/hashlet
  535. ### BEGIN INIT INFO
  536. # Provides: hashlet
  537. # Required-Start: $remote_fs $syslog
  538. # Required-Stop: $remote_fs $syslog
  539. # Default-Start: 2 3 4 5
  540. # Default-Stop: 0 1 6
  541. # Short-Description: hashlet
  542. # Description: Creates a random number generator device
  543. ### END INIT INFO
  544. # Author: Bob Mottram <bob@robotics.uk.to>
  545. #Settings
  546. SERVICE='hashlet'
  547. LOGFILE='/dev/null'
  548. COMMAND="/usr/bin/hashletd"
  549. USERNAME='root'
  550. NICELEVEL=19
  551. HISTORY=1024
  552. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  553. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  554. hashlet_start() {
  555. echo "Starting $SERVICE..."
  556. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  557. }
  558. hashlet_stop() {
  559. echo "Stopping $SERVICE"
  560. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  561. }
  562. #Start-Stop here
  563. case "$1" in
  564. start)
  565. hashlet_start
  566. ;;
  567. stop)
  568. hashlet_stop
  569. ;;
  570. restart)
  571. hashlet_stop
  572. sleep 10s
  573. hashlet_start
  574. ;;
  575. *)
  576. echo "Usage: $0 {start|stop|restart}"
  577. exit 1
  578. ;;
  579. esac
  580. exit 0
  581. #+END_SRC
  582. Save and exit, then start the daemon.
  583. #+BEGIN_SRC: bash
  584. chmod +x /usr/bin/hashletd
  585. chmod +x /etc/init.d/hashlet
  586. update-rc.d hashlet defaults
  587. service hashlet start
  588. #+END_SRC
  589. Then to obtain some random bytes:
  590. #+BEGIN_SRC: bash
  591. cat /dev/hashletrng
  592. #+END_SRC
  593. The rate of entropy generation by the Hashlet seems very slow compared to */dev/hwrng*, and this is most likely because of the I2C interface. So it's probably a good idea to keep hwrng as the main random source and only use the Hashlet's random number generator for any ancillary stuff.
  594. ** Alter ssh configuration
  595. #+BEGIN_VERSE
  596. /The privacy rights of US persons in international communications are significantly diminished, if not completely eliminated, when those communications have been transmitted to or obtained from non-US persons located outside the United States./
  597. -- US Department Of Justice
  598. #+END_VERSE
  599. Altering the ssh configuration will make it a little more secure than the standard Debian settings.
  600. #+BEGIN_SRC: bash
  601. editor /etc/ssh/sshd_config
  602. #+END_SRC
  603. Check the following values:
  604. #+BEGIN_SRC: bash
  605. PermitRootLogin no
  606. X11Forwarding no
  607. ServerKeyBits 4096
  608. Protocol 2
  609. PermitEmptyPasswords no
  610. StrictModes yes
  611. TCPKeepAlive no
  612. #+END_SRC
  613. Append the following:
  614. #+BEGIN_SRC: bash
  615. ClientAliveInterval 60
  616. ClientAliveCountMax 3
  617. Ciphers aes256-ctr,aes192-ctr,aes128-ctr
  618. MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
  619. KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
  620. #+END_SRC
  621. CTRL-x CTRL-s to save, then CTRL-x CTRL-c to exit. Now clear out any pre-existing host keys and reconfigure the ssh server.
  622. #+BEGIN_SRC: bash
  623. rm /etc/ssh/ssh_host_*
  624. dpkg-reconfigure openssh-server
  625. service ssh restart
  626. #+END_SRC
  627. To test the new settings log out by typing "exit" a couple of times, then log back in again with:
  628. #+BEGIN_SRC: bash
  629. ssh -vvv myusername@192.168.1.60
  630. #+END_SRC
  631. and check that some number of bits are set within a 4096 bit sized key:
  632. #+BEGIN_SRC: bash
  633. debug2: bits set: */4096
  634. #+END_SRC
  635. ** Getting onto the web
  636. 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.
  637. Select "/dynamic DNS/" then click "/quick cron example/"
  638. An example would look like:
  639. #+BEGIN_SRC: bash
  640. 4,14,24,34,44,54 * * * * root sleep 29 ; /usr/bin/timeout 200 wget -O - https://free\ dns.afraid.org/dynamic/update.php?ABCKDNRCLFHENSLKNFEGSBFLFF== >> /dev/null 2>&1 &
  641. #+END_SRC
  642. It's important to make sure that you change the *http* to *https*, since this will help to prevent a potential attacker from hijacking your site and redirecting it to a fake version for the purposes of obtaining your login details.
  643. Edit */etc/crontab* and append that to the top of the file, underneath the heading line which looks like this:
  644. #+BEGIN_SRC: bash
  645. # m h dom mon dow user command
  646. #+END_SRC
  647. In general the most frequently run crontab entries should be at the top. Then save and exit.
  648. 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.
  649. The freeDNS subdomain which you just created will hereafter just be refered to as "/your domain name/".
  650. If you have multiple freedns subdomains then you may want to rationalise that a little within */etc/crontab*. Rather than listing them all individually create a script:
  651. #+BEGIN_SRC: bash
  652. editor /usr/bin/dynamicdns
  653. #+END_SRC
  654. Add however many freedns subdomains you have.
  655. #+BEGIN_SRC: bash
  656. #!/bin/bash
  657. # subdomain name 1
  658. wget -O - https://freedns.afraid.org/dynamic/update.php?<subdomain code 1>== >> /dev/null 2>&1
  659. # subdomain name 2
  660. wget -O - https://freedns.afraid.org/dynamic/update.php?<subdomain code 2>== >> /dev/null 2>&1
  661. ...
  662. #+END_SRC
  663. Save and exit, then make the script runnable and only readable by the root user.
  664. #+BEGIN_SRC: bash
  665. chmod 600 /usr/bin/dynamicdns
  666. chmod +x /usr/bin/dynamicdns
  667. #+END_SRC
  668. Then within */etc/crontab*
  669. #+BEGIN_SRC: bash
  670. editor /etc/crontab
  671. #+END_SRC
  672. You can replace the multiple freedns entries with a single line:
  673. #+BEGIN_SRC: bash
  674. */10 * * * * root /usr/bin/timeout 200 /usr/bin/dynamicdns
  675. #+END_SRC
  676. Then save and exit and restart the cron daemon.
  677. #+BEGIN_SRC: bash
  678. service cron restart
  679. #+END_SRC
  680. If you want to know what a typical /crontab/ file might look like then see the [[Example crontab file]]
  681. ** Set the host name
  682. #+BEGIN_SRC: bash
  683. editor /etc/hostname
  684. #+END_SRC
  685. CTRL-x CTRL-s to save, then CTRL-x CTRL-c to exit.
  686. Also issue the command, replacing /mydomainname.com/ with your domain name.
  687. #+BEGIN_SRC: bash
  688. hostname mydomainname.com
  689. #+END_SRC
  690. You may also need to assign the same hostname separately via your router's web interface.
  691. #+BEGIN_SRC: bash
  692. editor /etc/hosts
  693. #+END_SRC
  694. Append the following, replacing /mydomainname.com/ with your domain name.
  695. #+BEGIN_SRC: bash
  696. 127.0.1.1 mydomainname.com
  697. #+END_SRC
  698. If you then run the command:
  699. #+BEGIN_SRC: bash
  700. hostname -f
  701. #+END_SRC
  702. it should return your domain name.
  703. ** Install time synchronisation
  704. #+BEGIN_VERSE
  705. /You may delay, but time will not./
  706. -- Benjamin Franklin
  707. #+END_VERSE
  708. It's convenient to have the clock on your server automatically synchronised with other servers on the internet so that you don't need to set the clock manually. The usual way of doing this is via [[https://en.wikipedia.org/wiki/Network_Time_Protocol][NTP]], but that method uses unencrypted signals which could potentially be interfered with in order to mess up your system. /tlsdate/ provides a slightly more secure way of setting the date and time over a SSL/TLS connection to a known good time source.
  709. First install some prerequisites.
  710. #+BEGIN_SRC: bash
  711. apt-get install build-essential automake git pkg-config autoconf libtool libssl-dev
  712. apt-get remove ntpdate
  713. #+END_SRC
  714. Now download and install tlsdate.
  715. #+BEGIN_SRC: bash
  716. mkdir ~/build
  717. cd ~/build
  718. git clone https://github.com/ioerror/tlsdate.git
  719. cd ~/build/tlsdate
  720. ./autogen.sh
  721. ./configure
  722. make
  723. make install
  724. #+END_SRC
  725. If you get errors during the /configure/ stage then you may need to reboot so that some of the installed dependencies take effect.
  726. #+BEGIN_SRC: bash
  727. editor /etc/crontab
  728. #+END_SRC
  729. Add the following near the top of the list of tasks.
  730. #+BEGIN_SRC: bash
  731. */15 * * * * root /usr/bin/timeout 20 tlsdate -l -t -H www.ptb.de -p 443 >> /var/log/tlsdate.log
  732. #+END_SRC
  733. Save and exit.
  734. #+BEGIN_SRC: bash
  735. service cron restart
  736. #+END_SRC
  737. This obtains the date and time from www.ptb.de every 15 minutes. Obviously if you wish to use a different source for the date and time then the cron entry can be edited accordingly.
  738. To ensure that the system always gets the correct time on initial bootup create an init script.
  739. #+BEGIN_SRC: bash
  740. editor /etc/init.d/tlsdate
  741. #+END_SRC
  742. Add the following:
  743. #+BEGIN_SRC: bash
  744. #!/bin/bash
  745. # /etc/init.d/tlsdate
  746. ### BEGIN INIT INFO
  747. # Provides: tlsdate
  748. # Required-Start: $remote_fs $syslog
  749. # Required-Stop: $remote_fs $syslog
  750. # Default-Start: 2 3 4 5
  751. # Default-Stop: 0 1 6
  752. # Short-Description: Initially calls tlsdate with the timewarp option
  753. # Description: Initially calls tlsdate with the timewarp option
  754. ### END INIT INFO
  755. # Author: Bob Mottram <bob@robotics.uk.to>
  756. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  757. LOGFILE="/var/log/tlsdate.log"
  758. TLSDATECOMMAND="tlsdate --timewarp -l -H www.ptb.de -p 443 >> $LOGFILE"
  759. #Start-Stop here
  760. case "$1" in
  761. start)
  762. echo "tlsdate started"
  763. $TLSDATECOMMAND
  764. ;;
  765. stop)
  766. echo "tlsdate stopped"
  767. ;;
  768. restart)
  769. echo "tlsdate restarted"
  770. $TLSDATECOMMAND
  771. ;;
  772. *)
  773. echo "Usage: $0 {start|stop|restart}"
  774. exit 1
  775. ;;
  776. esac
  777. exit 0
  778. #+END_SRC
  779. Save and exit, then start the daemon.
  780. #+BEGIN_SRC: bash
  781. chmod +x /etc/init.d/tlsdate
  782. update-rc.d tlsdate defaults
  783. service tlsdate start
  784. #+END_SRC
  785. ** Install fail2ban
  786. #+BEGIN_SRC: bash
  787. apt-get install fail2ban
  788. #+END_SRC
  789. ** Set up a firewall
  790. #+BEGIN_VERSE
  791. /The NSA also attacks network devices directly: routers, switches, firewalls, etc. Most of these devices have surveillance capabilities already built in; the trick is to surreptitiously turn them on. This is an especially fruitful avenue of attack; routers are updated less frequently, tend not to have security software installed on them, and are generally ignored as a vulnerability./
  792. -- Bruce Schneier
  793. #+END_VERSE
  794. 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. Your internet router may contain a firewall, but chances are that it also contains proprietary software which can be remotely changed/updated by the ISP. Unless you're running free software, such as [[https://en.wikipedia.org/wiki/OpenWrt][OpenWrt]], on your internet router then it's reasonable to assume that the device is hostile and could be conducting surveillance, trying to do [[https://en.wikipedia.org/wiki/Man-in-the-middle_attack]["man in the middle"]] attacks or be pushing "implants" onto the computers and mobile devices on your local network. That means that your server needs its own firewall.
  795. #+BEGIN_SRC: bash
  796. apt-get install portsentry
  797. editor /etc/portsentry/portsentry.conf
  798. #+END_SRC
  799. Uncomment the entry for *iptables support for Linux*
  800. Set the following properties:
  801. #+BEGIN_SRC: bash
  802. TCP_PORTS="1,7,9,11,15,79,109,110,111,119,138,139,512,513,514,515,540,635,1080,1524,2000,2001,3000,4000,4001,5742,6000,6001,6667,12345,12346,20034,27665,30303,32771,32772,32773,32774,31337,40421,40425,49724,54320"
  803. UDP_PORTS="1,7,9,66,67,68,69,111,137,138,161,162,474,513,517,518,635,640,641,666,700,2049,3000,31335,27444,34555,32770,32771,32772,32773,32774,31337,54321"
  804. ADVANCED_EXCLUDE_TCP="113,139,70,80,443,587,143,6697,993,5060,5061,25,465,22,5222,5223,5269,5280,5281,8432,8433,8444"
  805. ADVANCED_EXCLUDE_UDP="520,138,137,67,70,80,443,143,6697,993, 5060,5061,25,465,22,5222,5223,5269,5280,5281,8444"
  806. SCAN_TRIGGER="2"
  807. BLOCK_UDP="2"
  808. BLOCK_TCP="2"
  809. #+END_SRC
  810. Save and exit.
  811. #+BEGIN_SRC: bash
  812. service portsentry restart
  813. editor /tmp/firewall.sh
  814. #+END_SRC
  815. Enter the following:
  816. #+BEGIN_SRC: bash
  817. #!/bin/bash
  818. # First of all delete any existing rules.
  819. # This means you're back to a known state:
  820. iptables -P INPUT ACCEPT
  821. ip6tables -P INPUT ACCEPT
  822. iptables -F
  823. ip6tables -F
  824. iptables -X
  825. ip6tables -X
  826. # Drop any IPv6 traffic
  827. ip6tables -A INPUT -p icmp -j DROP
  828. ip6tables -A INPUT -p tcp -j DROP
  829. ip6tables -A INPUT -p udp -j DROP
  830. # Drop access to unused ports
  831. iptables -A INPUT -p tcp --destination-port 1 -j DROP
  832. iptables -A INPUT -p tcp --destination-port 7 -j DROP
  833. iptables -A INPUT -p tcp --destination-port 109:111 -j DROP
  834. iptables -A INPUT -p tcp --destination-port 995 -j DROP
  835. iptables -A INPUT -p tcp --destination-port 139 -j DROP
  836. iptables -A INPUT -p tcp --destination-port 6000:6001 -j DROP
  837. iptables -A INPUT -p tcp --destination-port 9 -j DROP
  838. iptables -A INPUT -p tcp --destination-port 79 -j DROP
  839. iptables -A INPUT -p tcp --destination-port 515 -j DROP
  840. iptables -A INPUT -p tcp --destination-port 4001 -j DROP
  841. iptables -A INPUT -p tcp --destination-port 1524 -j DROP
  842. iptables -A INPUT -p tcp --destination-port 1080 -j DROP
  843. iptables -A INPUT -p tcp --destination-port 512:514 -j DROP
  844. iptables -A INPUT -p tcp --destination-port 31337 -j DROP
  845. iptables -A INPUT -p tcp --destination-port 2000:2001 -j DROP
  846. iptables -A INPUT -p tcp --destination-port 12345 -j DROP
  847. iptables -A INPUT -p tcp --destination-port 32771:32774 -j DROP
  848. iptables -A INPUT -p tcp --destination-port 6665:6669 -j DROP
  849. iptables -A INPUT -p tcp --destination-port 4000 -j DROP
  850. iptables -A INPUT -p tcp --destination-port 119 -j DROP
  851. iptables -A INPUT -p tcp --destination-port 137 -j DROP
  852. iptables -A INPUT -p tcp --destination-port 3306 -j DROP
  853. iptables -A INPUT -p tcp --destination-port 4242 -j DROP
  854. iptables -A INPUT -p tcp --destination-port 9050 -j DROP
  855. iptables -A INPUT -p tcp --destination-port 3000 -j DROP
  856. iptables -A INPUT -p udp --destination-port 1 -j DROP
  857. iptables -A INPUT -p udp --destination-port 7 -j DROP
  858. iptables -A INPUT -p udp --destination-port 109:111 -j DROP
  859. iptables -A INPUT -p udp --destination-port 995 -j DROP
  860. iptables -A INPUT -p udp --destination-port 139 -j DROP
  861. iptables -A INPUT -p udp --destination-port 6000:6001 -j DROP
  862. iptables -A INPUT -p udp --destination-port 9 -j DROP
  863. iptables -A INPUT -p udp --destination-port 79 -j DROP
  864. iptables -A INPUT -p udp --destination-port 515 -j DROP
  865. iptables -A INPUT -p udp --destination-port 4001 -j DROP
  866. iptables -A INPUT -p udp --destination-port 1524 -j DROP
  867. iptables -A INPUT -p udp --destination-port 1080 -j DROP
  868. iptables -A INPUT -p udp --destination-port 512:514 -j DROP
  869. iptables -A INPUT -p udp --destination-port 31337 -j DROP
  870. iptables -A INPUT -p udp --destination-port 2000:2001 -j DROP
  871. iptables -A INPUT -p udp --destination-port 12345 -j DROP
  872. iptables -A INPUT -p udp --destination-port 32771:32774 -j DROP
  873. iptables -A INPUT -p udp --destination-port 6665:6669 -j DROP
  874. iptables -A INPUT -p udp --destination-port 4000 -j DROP
  875. iptables -A INPUT -p udp --destination-port 119 -j DROP
  876. iptables -A INPUT -p udp --destination-port 137 -j DROP
  877. iptables -A INPUT -p udp --destination-port 8432 -j DROP
  878. iptables -A INPUT -p udp --destination-port 8433 -j DROP
  879. iptables -A INPUT -p udp --destination-port 3306 -j DROP
  880. iptables -A INPUT -p udp --destination-port 4242 -j DROP
  881. iptables -A INPUT -p udp --destination-port 9050 -j DROP
  882. iptables -A INPUT -p udp --destination-port 3000 -j DROP
  883. # Make sure NEW incoming tcp connections are SYN packets
  884. iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
  885. # Drop packets with incoming fragments
  886. iptables -A INPUT -f -j DROP
  887. # Incoming malformed XMAS packets drop them
  888. iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
  889. iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP
  890. iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
  891. # Incoming malformed NULL packets:
  892. iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
  893. # Drop UDP to used ports
  894. iptables -A INPUT -p udp --match multiport --dports 70,80,443,143,6697,993,5060,5061,25 -j DROP
  895. iptables -A INPUT -p udp --match multiport --dports 465,587,22,5222,5223,5269,5280,5281,8444 -j DROP
  896. # Limit ssh logins
  897. iptables -A INPUT -p tcp --dport 22 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  898. # Limit web connections
  899. iptables -A INPUT -p tcp --dport 80 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  900. iptables -A INPUT -p tcp --dport 443 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  901. # Limit number of XMPP connections
  902. iptables -A INPUT -p tcp --match multiport --dports 5222:5223,5269,5280:5281 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  903. # Limit IRC connections
  904. iptables -A INPUT -p tcp --dport 6697 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  905. # Limit gopher connections
  906. iptables -A INPUT -p tcp --dport 70 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  907. # Limit IMAP connections
  908. iptables -A INPUT -p tcp --dport 143 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  909. iptables -A INPUT -p tcp --dport 993 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  910. # Limit SIP connections
  911. iptables -A INPUT -p tcp --dport 5060:5061 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  912. # Limit SMTP/SMTPS connections
  913. iptables -A INPUT -p tcp --dport 25 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  914. iptables -A INPUT -p tcp --dport 465 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  915. iptables -A INPUT -p tcp --dport 587 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  916. # Limit Bitmessage connections
  917. iptables -A INPUT -p tcp --dport 8444 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  918. # Limit Convergence notary
  919. iptables -A INPUT -p tcp --dport 8432:8433 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  920. # Limit the number of incoming tcp connections
  921. # Interface 0 incoming syn-flood protection
  922. iptables -N syn_flood
  923. iptables -A INPUT -p tcp --syn -j syn_flood
  924. iptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
  925. iptables -A syn_flood -j DROP
  926. # Limiting the incoming icmp ping request:
  927. #iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j ACCEPT
  928. #iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j LOG --log-prefix PING-DROP:
  929. iptables -A INPUT -p icmp -j DROP
  930. #iptables -A OUTPUT -p icmp -j ACCEPT
  931. # Block malware servers (See Der Spiegel Snowden files)
  932. iptables -A INPUT -s 146.185.26.163 -j DROP
  933. iptables -A INPUT -s 37.130.229.100 -j DROP
  934. iptables -A INPUT -s 85.237.211.198 -j DROP
  935. iptables -A INPUT -s 85.237.212.52 -j DROP
  936. iptables -A INPUT -s 85.237.211.177 -j DROP
  937. iptables -A INPUT -s 212.118.232.184 -j DROP
  938. iptables -A INPUT -s 212.118.232.50 -j DROP
  939. iptables -A INPUT -s 176.249.28.104 -j DROP
  940. iptables -A INPUT -s 212.118.232.140 -j DROP
  941. iptables -A INPUT -s 37.130.229.101 -j DROP
  942. iptables -A INPUT -s 31.6.17.94 -j DROP
  943. iptables -A INPUT -s 84.45.121.218 -j DROP
  944. iptables -A INPUT -s 80.84.63.242 -j DROP
  945. iptables -A INPUT -s 37.220.10.28 -j DROP
  946. iptables -A INPUT -s 94.229.78.58 -j DROP
  947. iptables -A OUTPUT -s 146.185.26.163 -j DROP
  948. iptables -A OUTPUT -s 37.130.229.100 -j DROP
  949. iptables -A OUTPUT -s 85.237.211.198 -j DROP
  950. iptables -A OUTPUT -s 85.237.212.52 -j DROP
  951. iptables -A OUTPUT -s 85.237.211.177 -j DROP
  952. iptables -A OUTPUT -s 212.118.232.184 -j DROP
  953. iptables -A OUTPUT -s 212.118.232.50 -j DROP
  954. iptables -A OUTPUT -s 176.249.28.104 -j DROP
  955. iptables -A OUTPUT -s 212.118.232.140 -j DROP
  956. iptables -A OUTPUT -s 37.130.229.101 -j DROP
  957. iptables -A OUTPUT -s 31.6.17.94 -j DROP
  958. iptables -A OUTPUT -s 84.45.121.218 -j DROP
  959. iptables -A OUTPUT -s 80.84.63.242 -j DROP
  960. iptables -A OUTPUT -s 37.220.10.28 -j DROP
  961. iptables -A OUTPUT -s 94.229.78.58 -j DROP
  962. # Save the settings
  963. iptables-save > /etc/firewall.conf
  964. ip6tables-save > /etc/firewall6.conf
  965. printf '#!/bin/sh\n' > /etc/network/if-up.d/iptables
  966. printf 'iptables-restore < /etc/firewall.conf\n' >> /etc/network/if-up.d/iptables
  967. printf 'ip6tables-restore < /etc/firewall6.conf\n' >> /etc/network/if-up.d/iptables
  968. chmod +x /etc/network/if-up.d/iptables
  969. #+END_SRC
  970. Save and exit.
  971. Note that this will disable IP version 6. At the time of writing it is expected that the average internet user is running on IP version 4.
  972. #+BEGIN_SRC: bash
  973. chmod +x /tmp/firewall.sh
  974. . /tmp/firewall.sh
  975. rm /tmp/firewall.sh
  976. #+END_SRC
  977. 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.
  978. #+BEGIN_SRC: bash
  979. editor /etc/sysctl.conf
  980. #+END_SRC
  981. Uncomment or change the following:
  982. #+BEGIN_SRC: bash
  983. net.ipv4.tcp_syncookies = 1
  984. net.ipv4.conf.all.accept_redirects = 0
  985. net.ipv6.conf.all.accept_redirects = 0
  986. net.ipv4.conf.all.send_redirects = 0
  987. net.ipv4.conf.all.accept_source_route = 0
  988. net.ipv6.conf.all.accept_source_route = 0
  989. net.ipv4.conf.default.rp_filter=1
  990. net.ipv4.conf.all.rp_filter=1
  991. net.ipv4.ip_forward=0
  992. net.ipv6.conf.all.forwarding=0
  993. #+END_SRC
  994. And append the following:
  995. #+BEGIN_SRC: bash
  996. # ignore pings
  997. net.ipv4.icmp_echo_ignore_all = 1
  998. net.ipv6.icmp_echo_ignore_all = 1
  999. # disable ipv6
  1000. net.ipv6.conf.all.disable_ipv6 = 1
  1001. net.ipv4.tcp_synack_retries = 2
  1002. net.ipv4.tcp_syn_retries = 1
  1003. # keepalive
  1004. net.ipv4.tcp_keepalive_probes = 9
  1005. net.ipv4.tcp_keepalive_intvl = 75
  1006. net.ipv4.tcp_keepalive_time = 7200
  1007. #+END_SRC
  1008. 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:
  1009. #+BEGIN_SRC: bash
  1010. reboot
  1011. #+END_SRC
  1012. After reboot and logging back in to the root account via /ssh/ you can verify that the firewall rules were restored correctly with:
  1013. #+BEGIN_SRC: bash
  1014. iptables -L
  1015. #+END_SRC
  1016. and
  1017. #+BEGIN_SRC: bash
  1018. ip6tables -L
  1019. #+END_SRC
  1020. ** Install Email
  1021. #+BEGIN_VERSE
  1022. /The government argued that, since the "inspection" of the data was to be carried out by a machine, they were exempt from the normal search-and-seizure protections of the Fourth Amendment...The prosecution also argued that my users had no expectation of privacy, even though the service I provided - encryption - is designed for users' privacy/
  1023. -- Ladar Levison
  1024. #+END_VERSE
  1025. 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.
  1026. Exim4 seems much easier to install and configure than Postfix.
  1027. #+BEGIN_SRC: bash
  1028. service postfix stop
  1029. apt-get remove postfix
  1030. aptitude install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
  1031. #+END_SRC
  1032. You will be prompted to remove postfix. Say yes and yes again.
  1033. #+BEGIN_SRC: bash
  1034. dpkg-reconfigure exim4-config
  1035. #+END_SRC
  1036. Settings as follows:
  1037. #+BEGIN_SRC: bash
  1038. internet site
  1039. System mail name: mydomainname.com
  1040. IP addresses to listen on: blank
  1041. Destinations: mydomainname.com (and any other domains that you own)
  1042. Domains to relay mail: blank
  1043. Smarthost Relay: 192.168.1.0/24 (the range of addresses on your LAN)
  1044. Dial on demand = no
  1045. Maildir format in home directory
  1046. Split configuration = no
  1047. Root and postmaster: root email
  1048. #+END_SRC
  1049. To test the installation:
  1050. #+BEGIN_SRC: bash
  1051. telnet 192.168.1.60 25
  1052. ehlo xxx
  1053. quit
  1054. #+END_SRC
  1055. #+BEGIN_SRC: bash
  1056. editor /etc/default/saslauthd
  1057. #+END_SRC
  1058. set START=yes then save and exit.
  1059. #+BEGIN_SRC: bash
  1060. /etc/init.d/saslauthd start
  1061. editor /usr/bin/exim-gencert
  1062. #+END_SRC
  1063. #+BEGIN_SRC: bash
  1064. #!/bin/sh -e
  1065. if [ -n "$EX4DEBUG" ]; then
  1066. echo "now debugging $0 $@"
  1067. set -x
  1068. fi
  1069. DIR=/etc/exim4
  1070. CERT=$DIR/exim.crt
  1071. KEY=$DIR/exim.key
  1072. # This exim binary was built with GnuTLS which does not support dhparams
  1073. # from a file. See /usr/share/doc/exim4-base/README.Debian.gz
  1074. #DH=$DIR/exim.dhparam
  1075. if ! which openssl > /dev/null ;then
  1076. echo "$0: openssl is not installed, exiting" 1>&2
  1077. exit 1
  1078. fi
  1079. # valid for ten years
  1080. DAYS=3650
  1081. if [ "$1" != "--force" ] && [ -f $CERT ] && [ -f $KEY ]; then
  1082. echo "[*] $CERT and $KEY exists!"
  1083. echo " Use \"$0 --force\" to force generation!"
  1084. exit 0
  1085. fi
  1086. if [ "$1" = "--force" ]; then
  1087. shift
  1088. fi
  1089. #SSLEAY=/tmp/exim.ssleay.$$.cnf
  1090. SSLEAY="$(tempfile -m600 -pexi)"
  1091. cat > $SSLEAY <<EOM
  1092. RANDFILE = $HOME/.rnd
  1093. [ req ]
  1094. default_bits = 4096
  1095. default_keyfile = exim.key
  1096. distinguished_name = req_distinguished_name
  1097. [ req_distinguished_name ]
  1098. countryName = Country Code (2 letters)
  1099. countryName_default = GB
  1100. countryName_min = 2
  1101. countryName_max = 2
  1102. stateOrProvinceName = State or Province Name (full name)
  1103. localityName = Locality Name (eg, city)
  1104. organizationName = Organization Name (eg, company; recommended)
  1105. organizationName_max = 64
  1106. organizationalUnitName = Organizational Unit Name (eg, section)
  1107. organizationalUnitName_max = 64
  1108. commonName = Server name (eg. ssl.domain.tld; required!!!)
  1109. commonName_max = 64
  1110. emailAddress = Email Address
  1111. emailAddress_max = 40
  1112. EOM
  1113. echo "[*] Creating a self signed SSL certificate for Exim!"
  1114. echo " This may be sufficient to establish encrypted connections but for"
  1115. echo " secure identification you need to buy a real certificate!"
  1116. echo " "
  1117. echo " Please enter the hostname of your MTA at the Common Name (CN) prompt!"
  1118. echo " "
  1119. openssl req -config $SSLEAY -x509 -sha256 -newkey rsa:4096 -keyout $KEY -out $CERT -days $DAYS -nodes
  1120. #see README.Debian.gz*# openssl dhparam -check -text -5 512 -out $DH
  1121. rm -f $SSLEAY
  1122. chown root:Debian-exim $KEY $CERT $DH
  1123. chmod 640 $KEY $CERT $DH
  1124. echo "[*] Done generating self signed certificates for exim!"
  1125. echo " Refer to the documentation and example configuration files"
  1126. echo " over at /usr/share/doc/exim4-base/ for an idea on how to enable TLS"
  1127. echo " support in your mail transfer agent."
  1128. #+END_SRC
  1129. Save and exit
  1130. #+BEGIN_SRC: bash
  1131. chmod +x /usr/bin/exim-gencert
  1132. exim-gencert --force
  1133. #+END_SRC
  1134. 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.
  1135. #+BEGIN_SRC: bash
  1136. editor /etc/exim4/exim4.conf.template
  1137. #+END_SRC
  1138. Uncomment the section which begins with *login_saslauthd_server*
  1139. Search for the line *.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME* and above it insert the line:
  1140. #+BEGIN_SRC: bash
  1141. MAIN_HARDCODE_PRIMARY_HOSTNAME = mydomainname.com
  1142. #+END_SRC
  1143. Add the line:
  1144. #+BEGIN_SRC: bash
  1145. MAIN_TLS_ENABLE = true
  1146. #+END_SRC
  1147. Save and exit.
  1148. #+BEGIN_SRC: bash
  1149. editor /etc/default/exim4
  1150. change SMTPLISTENEROPTIONS to:
  1151. SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'
  1152. #+END_SRC
  1153. save and exit
  1154. #+BEGIN_SRC: bash
  1155. editor /etc/exim4/exim4.conf.template
  1156. under the section "main/03_exim4-config_tlsoptions"
  1157. Add the following:
  1158. tls_on_connect_ports=465
  1159. #+END_SRC
  1160. save and exit
  1161. #+BEGIN_SRC: bash
  1162. adduser myusername sasl
  1163. addgroup Debian-exim sasl
  1164. /etc/init.d/exim4 restart
  1165. mkdir -m 700 /etc/skel/Maildir
  1166. mkdir -m 700 /etc/skel/Maildir/Sent
  1167. mkdir -m 700 /etc/skel/Maildir/Sent/tmp
  1168. mkdir -m 700 /etc/skel/Maildir/Sent/cur
  1169. mkdir -m 700 /etc/skel/Maildir/Sent/new
  1170. mkdir -m 700 /etc/skel/Maildir/.learn-spam
  1171. mkdir -m 700 /etc/skel/Maildir/.learn-spam/cur
  1172. mkdir -m 700 /etc/skel/Maildir/.learn-spam/new
  1173. mkdir -m 700 /etc/skel/Maildir/.learn-spam/tmp
  1174. mkdir -m 700 /etc/skel/Maildir/.learn-ham
  1175. mkdir -m 700 /etc/skel/Maildir/.learn-ham/cur
  1176. mkdir -m 700 /etc/skel/Maildir/.learn-ham/new
  1177. mkdir -m 700 /etc/skel/Maildir/.learn-ham/tmp
  1178. ln -s /etc/skel/Maildir/.learn-spam /etc/skel/Maildir/spam
  1179. ln -s /etc/skel/Maildir/.learn-ham /etc/skel/Maildir/ham
  1180. #+END_SRC
  1181. If you're starting from scratch and don't already have a /Maildir/ directory in your home directory, then create one as follows:
  1182. #+BEGIN_SRC: bash
  1183. export MYUSERNAME=myusername
  1184. mkdir -m 700 /home/$MYUSERNAME/Maildir
  1185. mkdir -m 700 /home/$MYUSERNAME/Maildir/cur
  1186. mkdir -m 700 /home/$MYUSERNAME/Maildir/tmp
  1187. mkdir -m 700 /home/$MYUSERNAME/Maildir/new
  1188. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent
  1189. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/cur
  1190. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/tmp
  1191. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/new
  1192. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam
  1193. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/cur
  1194. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/new
  1195. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/tmp
  1196. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham
  1197. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/cur
  1198. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/new
  1199. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/tmp
  1200. ln -s /home/$MYUSERNAME/Maildir/.learn-spam /home/$MYUSERNAME/Maildir/spam
  1201. ln -s /home/$MYUSERNAME/Maildir/.learn-ham /home/$MYUSERNAME/Maildir/ham
  1202. chown -R $MYUSERNAME:$MYUSERNAME /home/$MYUSERNAME/Maildir
  1203. #+END_SRC
  1204. ** Spam filtering
  1205. #+BEGIN_SRC: bash
  1206. aptitude install spamassassin exim4-daemon-heavy
  1207. #+END_SRC
  1208. If you encounter any problems with dependencies then select 'n' and then 'y' to whatever the suggestion for removals is. Repeat the aptitude install process until you don't get any more dependency errors.
  1209. #+BEGIN_SRC: bash
  1210. editor /etc/default/spamassassin
  1211. #+END_SRC
  1212. Set ENABLED=1 then save and exit.
  1213. #+BEGIN_SRC: bash
  1214. editor /etc/exim4/exim4.conf.template
  1215. #+END_SRC
  1216. uncomment or change according to your configuration
  1217. #+BEGIN_SRC: bash
  1218. # For spam scanning, there is a similar option that defines the interface to
  1219. # SpamAssassin. You do not need to set this if you are using the default, which
  1220. # is shown in this commented example. As for virus scanning, you must also
  1221. # modify the acl_check_data access control list to enable spam scanning.
  1222. spamd_address = 127.0.0.1 783
  1223. #+END_SRC
  1224. add spam header in the /acl_check_data/ section:
  1225. #+BEGIN_SRC: bash
  1226. ### acl/40_exim4-config_check_data
  1227. #################################
  1228. # This ACL is used after the contents of a message have been received. This
  1229. # is the ACL in which you can test a message's headers or body, and in
  1230. # particular, this is where you can invoke external virus or spam scanners.
  1231. acl_check_data:
  1232. ...
  1233. ...
  1234. ...
  1235. # See the exim docs and the exim wiki for more suitable examples.
  1236. #
  1237. # warn
  1238. # spam = Debian-exim:true
  1239. # add_header = X-Spam_score: $spam_score\n\
  1240. # X-Spam_score_int: $spam_score_int\n\
  1241. # X-Spam_bar: $spam_bar\n\
  1242. # X-Spam_report: $spam_report
  1243. # put headers in all messages (no matter if spam or not)
  1244. warn spam = nobody:true
  1245. add_header = X-Spam-Score: $spam_score ($spam_bar)
  1246. add_header = X-Spam-Report: $spam_report
  1247. # add second subject line with *SPAM* marker when message
  1248. # is over threshold
  1249. warn spam = nobody
  1250. add_header = Subject: ***SPAM (score:$spam_score)*** $h_Subject:
  1251. #+END_SRC
  1252. Save and exit.
  1253. Then restart
  1254. #+BEGIN_SRC: bash
  1255. exit
  1256. editor ~/.procmailrc
  1257. #+END_SRC
  1258. The text should look like the following.
  1259. #+BEGIN_SRC: sh
  1260. MAILDIR=$HOME/Maildir
  1261. DEFAULT=$MAILDIR/
  1262. LOGFILE=$HOME/log/procmail.log
  1263. LOGABSTRACT=all
  1264. # get spamassassin to check emails
  1265. :0fw: .spamassassin.lock
  1266. * < 256000
  1267. | spamc
  1268. # strong spam are discarded
  1269. :0
  1270. * ^X-Spam-Level: \*\*\*\*\*\*
  1271. /dev/null
  1272. # weak spam are kept just in case - clear this out every now and then
  1273. :0
  1274. * ^X-Spam-Level: \*\*\*\*\*
  1275. .0-spam/
  1276. # otherwise, marginal spam goes here for revision
  1277. :0
  1278. * ^X-Spam-Level: \*\*
  1279. .spam/
  1280. #+END_SRC
  1281. Save and exit.
  1282. #+BEGIN_SRC: bash
  1283. su
  1284. editor /usr/bin/filterspam
  1285. #+END_SRC
  1286. Add the following contents:
  1287. #+BEGIN_SRC: bash
  1288. #!/bin/bash
  1289. USERNAME=$1
  1290. MAILDIR=/home/$USERNAME/Maildir/.learn-spam
  1291. if [ ! -d "$MAILDIR" ]; then
  1292. exit
  1293. fi
  1294. for f in `ls $MAILDIR/cur`
  1295. do
  1296. spamc -L spam < "$MAILDIR/cur/$f" > /dev/null
  1297. rm "$MAILDIR/cur/$f"
  1298. done
  1299. for f in `ls $MAILDIR/new`
  1300. do
  1301. spamc -L spam < "$MAILDIR/new/$f" > /dev/null
  1302. rm "$MAILDIR/new/$f"
  1303. done
  1304. #+END_SRC
  1305. Save and exit.
  1306. #+BEGIN_SRC: bash
  1307. editor /usr/bin/filterham
  1308. #+END_SRC
  1309. Add the following contents:
  1310. #+BEGIN_SRC: bash
  1311. #!/bin/bash
  1312. USERNAME=$1
  1313. MAILDIR=/home/$USERNAME/Maildir/.learn-ham
  1314. if [ ! -d "$MAILDIR" ]; then
  1315. exit
  1316. fi
  1317. for f in `ls $MAILDIR/cur`
  1318. do
  1319. spamc -L ham < "$MAILDIR/cur/$f" > /dev/null
  1320. rm "$MAILDIR/cur/$f"
  1321. done
  1322. for f in `ls $MAILDIR/new`
  1323. do
  1324. spamc -L ham < "$MAILDIR/new/$f" > /dev/null
  1325. rm "$MAILDIR/new/$f"
  1326. done
  1327. #+END_SRC
  1328. Save and exit.
  1329. #+BEGIN_SRC: bash
  1330. editor /etc/crontab
  1331. #+END_SRC
  1332. Append the following, replacing *myusername* with your username.
  1333. #+BEGIN_SRC: bash
  1334. */3 * * * * root /usr/bin/timeout 120 /usr/bin/filterspam myusername
  1335. */3 * * * * root /usr/bin/timeout 120 /usr/bin/filterham myusername
  1336. #+END_SRC
  1337. Save and exit.
  1338. #+BEGIN_SRC: bash
  1339. chmod 655 /usr/bin/filterspam /usr/bin/filterham
  1340. service spamassassin restart
  1341. service exim4 restart
  1342. service cron restart
  1343. #+END_SRC
  1344. ** Install Dovecot
  1345. #+BEGIN_VERSE
  1346. /I dreamt last night that I was living in a surveillance state. I woke up and… I’m still in a surveillance state./
  1347. -- Conrad Kramer
  1348. #+END_VERSE
  1349. Install the required packages.
  1350. #+BEGIN_SRC: bash
  1351. aptitude -y install dovecot-common dovecot-imapd
  1352. #+END_SRC
  1353. Edit the configuration file.
  1354. #+BEGIN_SRC: bash
  1355. editor /etc/dovecot/dovecot.conf
  1356. #+END_SRC
  1357. Line 26: change:
  1358. #+BEGIN_SRC: bash
  1359. listen = *
  1360. #+END_SRC
  1361. Save and exit.
  1362. #+BEGIN_SRC: bash
  1363. editor /etc/dovecot/conf.d/10-auth.conf
  1364. #+END_SRC
  1365. Line 9: uncomment and change (allow plain text auth)
  1366. #+BEGIN_SRC: bash
  1367. disable_plaintext_auth = no
  1368. #+END_SRC
  1369. Line 99: add:
  1370. #+BEGIN_SRC: bash
  1371. auth_mechanisms = plain login
  1372. #+END_SRC
  1373. Save and exit.
  1374. #+BEGIN_SRC: bash
  1375. editor /etc/dovecot/conf.d/10-mail.conf
  1376. #+END_SRC
  1377. Line 30: uncomment and add:
  1378. #+BEGIN_SRC: bash
  1379. mail_location = maildir:~/Maildir:LAYOUT=fs
  1380. #+END_SRC
  1381. Save and exit.
  1382. #+BEGIN_SRC: bash
  1383. editor /etc/dovecot/conf.d/10-ssl.conf
  1384. #+END_SRC
  1385. Append the following:
  1386. #+BEGIN_SRC: bash
  1387. ssl_cipher_list = '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:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA'
  1388. #+END_SRC
  1389. Save and exit, then start the dovecot service.
  1390. #+BEGIN_SRC: bash
  1391. service dovecot restart
  1392. #+END_SRC
  1393. ** Create a GPG key
  1394. #+BEGIN_VERSE
  1395. /If privacy is outlawed, only outlaws will have privacy./
  1396. -- Philip Zimmermann
  1397. #+END_VERSE
  1398. *** Initial installation
  1399. Assuming that you are logged in as root, first ensure that GPG is installed and then exit to your user account.
  1400. #+BEGIN_SRC: bash
  1401. apt-get install gnupg
  1402. exit
  1403. #+END_SRC
  1404. Now we will add some settings:
  1405. #+BEGIN_SRC: bash
  1406. mkdir ~/.gnupg
  1407. editor ~/.gnupg/gpg.conf
  1408. #+END_SRC
  1409. The configuration should look like the following. Of particular importance are the default preferences at the end.
  1410. #+BEGIN_SRC: bash
  1411. # Options for GnuPG
  1412. # Copyright 1998, 1999, 2000, 2001, 2002, 2003,
  1413. # 2010 Free Software Foundation, Inc.
  1414. #
  1415. # This file is free software; as a special exception the author gives
  1416. # unlimited permission to copy and/or distribute it, with or without
  1417. # modifications, as long as this notice is preserved.
  1418. #
  1419. # This file is distributed in the hope that it will be useful, but
  1420. # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
  1421. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  1422. #
  1423. # Unless you specify which option file to use (with the command line
  1424. # option "--options filename"), GnuPG uses the file ~/.gnupg/gpg.conf
  1425. # by default.
  1426. #
  1427. # An options file can contain any long options which are available in
  1428. # GnuPG. If the first non white space character of a line is a '#',
  1429. # this line is ignored. Empty lines are also ignored.
  1430. #
  1431. # See the man page for a list of options.
  1432. # Uncomment the following option to get rid of the copyright notice
  1433. #no-greeting
  1434. # If you have more than 1 secret key in your keyring, you may want to
  1435. # uncomment the following option and set your preferred keyid.
  1436. #default-key 621CC013
  1437. # If you do not pass a recipient to gpg, it will ask for one. Using
  1438. # this option you can encrypt to a default key. Key validation will
  1439. # not be done in this case. The second form uses the default key as
  1440. # default recipient.
  1441. #default-recipient some-user-id
  1442. #default-recipient-self
  1443. # Use --encrypt-to to add the specified key as a recipient to all
  1444. # messages. This is useful, for example, when sending mail through a
  1445. # mail client that does not automatically encrypt mail to your key.
  1446. # In the example, this option allows you to read your local copy of
  1447. # encrypted mail that you've sent to others.
  1448. #encrypt-to some-key-id
  1449. # By default GnuPG creates version 4 signatures for data files as
  1450. # specified by OpenPGP. Some earlier (PGP 6, PGP 7) versions of PGP
  1451. # require the older version 3 signatures. Setting this option forces
  1452. # GnuPG to create version 3 signatures.
  1453. #force-v3-sigs
  1454. # Because some mailers change lines starting with "From " to ">From "
  1455. # it is good to handle such lines in a special way when creating
  1456. # cleartext signatures; all other PGP versions do it this way too.
  1457. #no-escape-from-lines
  1458. # If you do not use the Latin-1 (ISO-8859-1) charset, you should tell
  1459. # GnuPG which is the native character set. Please check the man page
  1460. # for supported character sets. This character set is only used for
  1461. # metadata and not for the actual message which does not undergo any
  1462. # translation. Note that future version of GnuPG will change to UTF-8
  1463. # as default character set. In most cases this option is not required
  1464. # as GnuPG is able to figure out the correct charset at runtime.
  1465. #charset utf-8
  1466. # Group names may be defined like this:
  1467. # group mynames = paige 0x12345678 joe patti
  1468. #
  1469. # Any time "mynames" is a recipient (-r or --recipient), it will be
  1470. # expanded to the names "paige", "joe", and "patti", and the key ID
  1471. # "0x12345678". Note there is only one level of expansion - you
  1472. # cannot make an group that points to another group. Note also that
  1473. # if there are spaces in the recipient name, this will appear as two
  1474. # recipients. In these cases it is better to use the key ID.
  1475. #group mynames = paige 0x12345678 joe patti
  1476. # Lock the file only once for the lifetime of a process. If you do
  1477. # not define this, the lock will be obtained and released every time
  1478. # it is needed, which is usually preferable.
  1479. #lock-once
  1480. # GnuPG can send and receive keys to and from a keyserver. These
  1481. # servers can be HKP, email, or LDAP (if GnuPG is built with LDAP
  1482. # support).
  1483. #
  1484. # Example HKP keyserver:
  1485. # hkp://keys.gnupg.net
  1486. # hkp://subkeys.pgp.net
  1487. #
  1488. # Example email keyserver:
  1489. # mailto:pgp-public-keys@keys.pgp.net
  1490. #
  1491. # Example LDAP keyservers:
  1492. # ldap://keyserver.pgp.com
  1493. #
  1494. # Regular URL syntax applies, and you can set an alternate port
  1495. # through the usual method:
  1496. # hkp://keyserver.example.net:22742
  1497. #
  1498. # Most users just set the name and type of their preferred keyserver.
  1499. # Note that most servers (with the notable exception of
  1500. # ldap://keyserver.pgp.com) synchronize changes with each other. Note
  1501. # also that a single server name may actually point to multiple
  1502. # servers via DNS round-robin. hkp://keys.gnupg.net is an example of
  1503. # such a "server", which spreads the load over a number of physical
  1504. # servers. To see the IP address of the server actually used, you may use
  1505. # the "--keyserver-options debug".
  1506. keyserver hkp://keys.gnupg.net
  1507. #keyserver mailto:pgp-public-keys@keys.nl.pgp.net
  1508. #keyserver ldap://keyserver.pgp.com
  1509. # Common options for keyserver functions:
  1510. #
  1511. # include-disabled : when searching, include keys marked as "disabled"
  1512. # on the keyserver (not all keyservers support this).
  1513. #
  1514. # no-include-revoked : when searching, do not include keys marked as
  1515. # "revoked" on the keyserver.
  1516. #
  1517. # verbose : show more information as the keys are fetched.
  1518. # Can be used more than once to increase the amount
  1519. # of information shown.
  1520. #
  1521. # use-temp-files : use temporary files instead of a pipe to talk to the
  1522. # keyserver. Some platforms (Win32 for one) always
  1523. # have this on.
  1524. #
  1525. # keep-temp-files : do not delete temporary files after using them
  1526. # (really only useful for debugging)
  1527. #
  1528. # http-proxy="proxy" : set the proxy to use for HTTP and HKP keyservers.
  1529. # This overrides the "http_proxy" environment variable,
  1530. # if any.
  1531. #
  1532. # auto-key-retrieve : automatically fetch keys as needed from the keyserver
  1533. # when verifying signatures or when importing keys that
  1534. # have been revoked by a revocation key that is not
  1535. # present on the keyring.
  1536. #
  1537. # no-include-attributes : do not include attribute IDs (aka "photo IDs")
  1538. # when sending keys to the keyserver.
  1539. keyserver-options auto-key-retrieve
  1540. # Display photo user IDs in key listings
  1541. # list-options show-photos
  1542. # Display photo user IDs when a signature from a key with a photo is
  1543. # verified
  1544. # verify-options show-photos
  1545. # Use this program to display photo user IDs
  1546. #
  1547. # %i is expanded to a temporary file that contains the photo.
  1548. # %I is the same as %i, but the file isn't deleted afterwards by GnuPG.
  1549. # %k is expanded to the key ID of the key.
  1550. # %K is expanded to the long OpenPGP key ID of the key.
  1551. # %t is expanded to the extension of the image (e.g. "jpg").
  1552. # %T is expanded to the MIME type of the image (e.g. "image/jpeg").
  1553. # %f is expanded to the fingerprint of the key.
  1554. # %% is %, of course.
  1555. #
  1556. # If %i or %I are not present, then the photo is supplied to the
  1557. # viewer on standard input. If your platform supports it, standard
  1558. # input is the best way to do this as it avoids the time and effort in
  1559. # generating and then cleaning up a secure temp file.
  1560. #
  1561. # If no photo-viewer is provided, GnuPG will look for xloadimage, eog,
  1562. # or display (ImageMagick). On Mac OS X and Windows, the default is
  1563. # to use your regular JPEG image viewer.
  1564. #
  1565. # Some other viewers:
  1566. # photo-viewer "qiv %i"
  1567. # photo-viewer "ee %i"
  1568. #
  1569. # This one saves a copy of the photo ID in your home directory:
  1570. # photo-viewer "cat > ~/photoid-for-key-%k.%t"
  1571. #
  1572. # Use your MIME handler to view photos:
  1573. # photo-viewer "metamail -q -d -b -c %T -s 'KeyID 0x%k' -f GnuPG"
  1574. # Passphrase agent
  1575. #
  1576. # We support the old experimental passphrase agent protocol as well as
  1577. # the new Assuan based one (currently available in the "newpg" package
  1578. # at ftp.gnupg.org/gcrypt/alpha/aegypten/). To make use of the agent,
  1579. # you have to run an agent as daemon and use the option
  1580. #
  1581. # use-agent
  1582. #
  1583. # which tries to use the agent but will fallback to the regular mode
  1584. # if there is a problem connecting to the agent. The normal way to
  1585. # locate the agent is by looking at the environment variable
  1586. # GPG_AGENT_INFO which should have been set during gpg-agent startup.
  1587. # In certain situations the use of this variable is not possible, thus
  1588. # the option
  1589. #
  1590. # --gpg-agent-info=<path>:<pid>:1
  1591. #
  1592. # may be used to override it.
  1593. # Automatic key location
  1594. #
  1595. # GnuPG can automatically locate and retrieve keys as needed using the
  1596. # auto-key-locate option. This happens when encrypting to an email
  1597. # address (in the "user@example.com" form), and there are no
  1598. # user@example.com keys on the local keyring. This option takes the
  1599. # following arguments, in the order they are to be tried:
  1600. #
  1601. # cert = locate a key using DNS CERT, as specified in RFC-4398.
  1602. # GnuPG can handle both the PGP (key) and IPGP (URL + fingerprint)
  1603. # CERT methods.
  1604. #
  1605. # pka = locate a key using DNS PKA.
  1606. #
  1607. # ldap = locate a key using the PGP Universal method of checking
  1608. # "ldap://keys.(thedomain)". For example, encrypting to
  1609. # user@example.com will check ldap://keys.example.com.
  1610. #
  1611. # keyserver = locate a key using whatever keyserver is defined using
  1612. # the keyserver option.
  1613. #
  1614. # You may also list arbitrary keyservers here by URL.
  1615. #
  1616. # Try CERT, then PKA, then LDAP, then hkp://subkeys.net:
  1617. #auto-key-locate cert pka ldap hkp://subkeys.pgp.net
  1618. # default preferences
  1619. personal-digest-preferences SHA256
  1620. cert-digest-algo SHA256
  1621. default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
  1622. #+END_SRC
  1623. Save and exit.
  1624. *** If you have an existing key
  1625. #+BEGIN_SRC: bash
  1626. gpg --import ~/public_key.txt
  1627. gpg --allow-secret-key-import --import ~/private_key.txt
  1628. shred -zu ~/private_key.txt
  1629. #+END_SRC
  1630. Now check the digest preferences, replacing /keyID/ with your GPG key ID. This applies especially if you have a key which was generated some time ago.
  1631. #+BEGIN_SRC: bash
  1632. export MYGPGKEYID=keyID
  1633. gpg --edit-key $MYGPGKEYID
  1634. setpref SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
  1635. save
  1636. gpg --send-keys $MYGPGKEYID
  1637. #+END_SRC
  1638. *** To create a new key
  1639. Generate a key with the following command:
  1640. #+BEGIN_SRC: bash
  1641. gpg --gen-key
  1642. #+END_SRC
  1643. You can find your GPG key ID by entering:
  1644. #+BEGIN_SRC: bash
  1645. gpg --list-keys
  1646. #+END_SRC
  1647. The key ID is the second part of the string of numbers and letters. So for example in:
  1648. #+BEGIN_SRC: bash
  1649. pub 4096R/EA982E38 2012-05-20
  1650. #+END_SRC
  1651. the key ID is EA982E38. Now send your public key to a server so that others can find it.
  1652. #+BEGIN_SRC: bash
  1653. gpg --send-keys $MYGPGKEYID
  1654. #+END_SRC
  1655. *** root settings
  1656. If you later create an encrypted mailing list then the root user will also need to have good GPG settings so that it can generate key pairs for the list. The easiest way to ensure this is to do the following, replacing /myusername/ with your username:
  1657. #+BEGIN_SRC: bash
  1658. su
  1659. cp -r /home/myusername/.gnupg ~/
  1660. chown -R root:root ~/.gnupg
  1661. #+END_SRC
  1662. ** Protect processes
  1663. Because the BBB has limited RAM some processes may occasionally be automatically killed if physical memory availability is getting too low. The way in which processes are chosen to be sacrificed is not particularly intelligent, and so can result in vital systems being stopped. To try to prevent that from ever happening the following script can be used, which should ensure that at a minimum ssh, email and mysql keep running.
  1664. #+BEGIN_SRC: bash
  1665. editor /usr/bin/protectprocesses
  1666. #+END_SRC
  1667. Add the following:
  1668. #+BEGIN_SRC: bash
  1669. #!/bin/bash
  1670. declare -a protect=('/usr/sbin/sshd' '/usr/sbin/mysqld --basedir=/usr' '/bin/sh /usr/bin/mysqld_safe' '/usr/sbin/exim4')
  1671. for p in "${protect[@]}"
  1672. do
  1673. OOM_PROC_ID=$(ps aux | grep '$p' | grep -v grep | head -n 1 | awk -F ' ' '{print $2}')
  1674. if [ ! -z "$OOM_PROC_ID" ]; then
  1675. echo -1000 >/proc/$OOM_PROC_ID/oom_score_adj
  1676. echo -17 >/proc/$OOM_PROC_ID/oom_adj
  1677. fi
  1678. done
  1679. #+END_SRC
  1680. Save and exit, then edit the cron jobs:
  1681. #+BEGIN_SRC: bash
  1682. editor /etc/crontab
  1683. #+END_SRC
  1684. And add the line:
  1685. #+BEGIN_SRC: bash
  1686. */1 * * * * root /usr/bin/timeout 30 /usr/bin/protectprocesses
  1687. #+END_SRC
  1688. Then save and exit and restart cron.
  1689. #+BEGIN_SRC: bash
  1690. chmod +x /usr/bin/protectprocesses
  1691. service cron restart
  1692. #+END_SRC
  1693. Here cron is used so that if we stop one of the relevant processes and then restart it then its oom priority will be reassigned again
  1694. .
  1695. ** Setting up a web site
  1696. #+BEGIN_VERSE
  1697. /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./
  1698. -- Tim Berners-Lee
  1699. #+END_VERSE
  1700. Edit the apache configuration so that it doesn't run out of memory if there are a lot of connections.
  1701. #+BEGIN_SRC: bash
  1702. su
  1703. editor /etc/apache2/apache2.conf
  1704. #+END_SRC
  1705. Search for MaxClients and replace the value with 6. As an example the settings should look something like this:
  1706. #+BEGIN_SRC: bash
  1707. Timeout 30
  1708. KeepAlive On
  1709. MaxKeepAliveRequests 5
  1710. KeepAliveTimeout 10
  1711. <IfModule mpm_prefork_module>
  1712. StartServers 1
  1713. MinSpareServers 1
  1714. MaxSpareServers 3
  1715. MaxClients 10
  1716. MaxRequestsPerChild 3000
  1717. </IfModule>
  1718. <IfModule mpm_worker_module>
  1719. StartServers 1
  1720. MinSpareThreads 5
  1721. MaxSpareThreads 15
  1722. ThreadLimit 25
  1723. ThreadsPerChild 5
  1724. MaxClients 25
  1725. MaxRequestsPerChild 200
  1726. </IfModule>
  1727. <IfModule mpm_event_module>
  1728. StartServers 1
  1729. MinSpareThreads 5
  1730. MaxSpareThreads 15
  1731. ThreadLimit 25
  1732. ThreadsPerChild 5
  1733. MaxClients 25
  1734. MaxRequestsPerChild 200
  1735. </IfModule>
  1736. #+END_SRC
  1737. Also append the following:
  1738. #+BEGIN_SRC: bash
  1739. ServerSignature Off
  1740. ServerTokens Prod
  1741. #+END_SRC
  1742. Then save and exit. Install some extra security.
  1743. #+BEGIN_SRC: bash
  1744. apt-get install libapache2-modsecurity
  1745. apt-get install libapache2-mod-evasive
  1746. #+END_SRC
  1747. In the examples below replace /mydomainname.com/ with your own domain name.
  1748. #+BEGIN_SRC: bash
  1749. export HOSTNAME=mydomainname.com
  1750. mkdir /var/www/$HOSTNAME
  1751. mkdir /var/www/$HOSTNAME/htdocs
  1752. editor /etc/apache2/sites-available/$HOSTNAME
  1753. #+END_SRC
  1754. The Apache configuration for the site should look something like the following. Replace /mydonainname.com/ with the site domain name.
  1755. #+BEGIN_SRC: bash
  1756. <VirtualHost *:80>
  1757. ServerAdmin myusername@mydomainname.com
  1758. ServerName mydomainname.com
  1759. DocumentRoot /var/www/mydomainname.com/htdocs
  1760. <Directory />
  1761. Options FollowSymLinks
  1762. AllowOverride All
  1763. </Directory>
  1764. <Directory /var/www/mydomainname.com/htdocs/>
  1765. Options All
  1766. AllowOverride All
  1767. Order allow,deny
  1768. allow from all
  1769. LimitRequestBody 512000
  1770. </Directory>
  1771. # Don't serve .php~ or .php# files created by emacs
  1772. <Files ~ "(^#.*#|~|\.sw[op])$">
  1773. Order allow,deny
  1774. Deny from all
  1775. </Files>
  1776. <IfModule headers_module>
  1777. Header set X-Content-Type-Options nosniff
  1778. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  1779. Header set Pragma no-cache
  1780. </IfModule>
  1781. <Files .htaccess>
  1782. deny from all
  1783. </Files>
  1784. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1785. <Directory "/usr/lib/cgi-bin">
  1786. AllowOverride All
  1787. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1788. Order allow,deny
  1789. Allow from all
  1790. LimitRequestBody 512000
  1791. </Directory>
  1792. ErrorLog ${APACHE_LOG_DIR}/error.log
  1793. # Possible values include: debug, info, notice, warn, error, crit,
  1794. # alert, emerg.
  1795. LogLevel error
  1796. CustomLog ${APACHE_LOG_DIR}/access.log combined
  1797. </VirtualHost>
  1798. <IfModule mod_ssl.c>
  1799. <VirtualHost *:443>
  1800. ServerAdmin myusername@mydomainname.com
  1801. ServerName mydomainname.com
  1802. DocumentRoot /var/www/mydomainname.com/htdocs
  1803. <Directory />
  1804. Options FollowSymLinks
  1805. AllowOverride All
  1806. </Directory>
  1807. <Directory /var/www/mydomainname.com/htdocs/>
  1808. Options All
  1809. AllowOverride All
  1810. Order allow,deny
  1811. allow from all
  1812. LimitRequestBody 512000
  1813. </Directory>
  1814. # Don't serve .php~ or .php# files created by emacs
  1815. <Files ~ "(^#.*#|~|\.sw[op])$">
  1816. Order allow,deny
  1817. Deny from all
  1818. </Files>
  1819. <IfModule headers_module>
  1820. Header set X-Content-Type-Options nosniff
  1821. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  1822. Header set Pragma no-cache
  1823. </IfModule>
  1824. <Files .htaccess>
  1825. deny from all
  1826. </Files>
  1827. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1828. <Directory "/usr/lib/cgi-bin">
  1829. AllowOverride All
  1830. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1831. Order allow,deny
  1832. Allow from all
  1833. LimitRequestBody 512000
  1834. </Directory>
  1835. ErrorLog ${APACHE_LOG_DIR}/error.log
  1836. # Possible values include: debug, info, notice, warn, error, crit,
  1837. # alert, emerg.
  1838. LogLevel error
  1839. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  1840. # SSL Engine Switch:
  1841. # Enable/Disable SSL for this virtual host.
  1842. SSLEngine on
  1843. # A self-signed certificate
  1844. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  1845. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  1846. # Options based on bettercrypto.org
  1847. SSLProtocol All -SSLv2 -SSLv3
  1848. SSLHonorCipherOrder On
  1849. SSLCompression off
  1850. 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
  1851. # Add six earth month HSTS header for all users ...
  1852. Header add Strict-Transport-Security "max-age=15768000"
  1853. # If you want to protect all subdomains , use the following header
  1854. # ALL subdomains HAVE TO support https if you use this !
  1855. # Strict-Transport-Security: max-age=15768000 ; includeSubDomains
  1856. # SSL Engine Options:
  1857. # Set various options for the SSL engine.
  1858. # o FakeBasicAuth:
  1859. # Translate the client X.509 into a Basic Authorisation. This means that
  1860. # the standard Auth/DBMAuth methods can be used for access control. The
  1861. # user name is the `one line' version of the client's X.509 certificate.
  1862. # Note that no password is obtained from the user. Every entry in the user
  1863. # file needs this password: `xxj31ZMTZzkVA'.
  1864. # o ExportCertData:
  1865. # This exports two additional environment variables: SSL_CLIENT_CERT and
  1866. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  1867. # server (always existing) and the client (only existing when client
  1868. # authentication is used). This can be used to import the certificates
  1869. # into CGI scripts.
  1870. # o StdEnvVars:
  1871. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  1872. # Per default this exportation is switched off for performance reasons,
  1873. # because the extraction step is an expensive operation and is usually
  1874. # useless for serving static content. So one usually enables the
  1875. # exportation for CGI and SSI requests only.
  1876. # o StrictRequire:
  1877. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  1878. # under a "Satisfy any" situation, i.e. when it applies access is denied
  1879. # and no other module can change it.
  1880. # o OptRenegotiate:
  1881. # This enables optimized SSL connection renegotiation handling when SSL
  1882. # directives are used in per-directory context.
  1883. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  1884. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  1885. SSLOptions +StdEnvVars
  1886. </FilesMatch>
  1887. <Directory /usr/lib/cgi-bin>
  1888. SSLOptions +StdEnvVars
  1889. </Directory>
  1890. # SSL Protocol Adjustments:
  1891. # The safe and default but still SSL/TLS standard compliant shutdown
  1892. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  1893. # the close notify alert from client. When you need a different shutdown
  1894. # approach you can use one of the following variables:
  1895. # o ssl-unclean-shutdown:
  1896. # This forces an unclean shutdown when the connection is closed, i.e. no
  1897. # SSL close notify alert is send or allowed to received. This violates
  1898. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  1899. # this when you receive I/O errors because of the standard approach where
  1900. # mod_ssl sends the close notify alert.
  1901. # o ssl-accurate-shutdown:
  1902. # This forces an accurate shutdown when the connection is closed, i.e. a
  1903. # SSL close notify alert is send and mod_ssl waits for the close notify
  1904. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  1905. # practice often causes hanging connections with brain-dead browsers. Use
  1906. # this only for browsers where you know that their SSL implementation
  1907. # works correctly.
  1908. # Notice: Most problems of broken clients are also related to the HTTP
  1909. # keep-alive facility, so you usually additionally want to disable
  1910. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  1911. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  1912. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  1913. # "force-response-1.0" for this.
  1914. BrowserMatch "MSIE [2-6]" \
  1915. nokeepalive ssl-unclean-shutdown \
  1916. downgrade-1.0 force-response-1.0
  1917. # MSIE 7 and newer should be able to use keepalive
  1918. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  1919. </VirtualHost>
  1920. </IfModule>
  1921. #+END_SRC
  1922. Then to enable the site:
  1923. #+BEGIN_SRC: bash
  1924. a2ensite
  1925. a2dissite default
  1926. a2dissite default-ssl
  1927. a2enmod rewrite
  1928. a2enmod headers
  1929. #+END_SRC
  1930. Ensure that "NameVirtualHost *:443" is added to /etc/apache2/ports.conf. It should look something like the following:
  1931. #+BEGIN_SRC: bash
  1932. NameVirtualHost *:80
  1933. Listen 80
  1934. <IfModule mod_ssl.c>
  1935. NameVirtualHost *:443
  1936. Listen 443
  1937. </IfModule>
  1938. <IfModule mod_gnutls.c>
  1939. NameVirtualHost *:443
  1940. Listen 443
  1941. </IfModule>
  1942. #+END_SRC
  1943. Create a self-signed certificate. The passphrase isn't important and will be removed, so make it easy (such as "password").
  1944. #+BEGIN_SRC: bash
  1945. editor /usr/bin/makecert
  1946. #+END_SRC
  1947. Enter the following:
  1948. #+BEGIN_SRC: bash
  1949. #!/bin/bash
  1950. HOSTNAME=$1
  1951. openssl genrsa -des3 -out $HOSTNAME.key 1024
  1952. openssl req -new -x509 -nodes -sha1 -days 3650 -key $HOSTNAME.key -out $HOSTNAME.crt
  1953. openssl rsa -in $HOSTNAME.key -out $HOSTNAME.new.key
  1954. cp $HOSTNAME.new.key $HOSTNAME.key
  1955. rm $HOSTNAME.new.key
  1956. cp $HOSTNAME.key /etc/ssl/private
  1957. chmod 400 /etc/ssl/private/$HOSTNAME.key
  1958. cp $HOSTNAME.crt /etc/ssl/certs
  1959. shred -zu $HOSTNAME.key $HOSTNAME.crt
  1960. a2enmod ssl
  1961. service apache2 restart
  1962. #+END_SRC
  1963. Save and exit.
  1964. #+BEGIN_SRC: bash
  1965. chmod +x /usr/bin/makecert
  1966. makecert mydomainname.com
  1967. #+END_SRC
  1968. Enter some trivial password for the key file, such as "password". The password will be removed as part of the /makecert/ script which you just created. 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.
  1969. 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.
  1970. Also limit the amount of memory which any php scripts can use.
  1971. #+BEGIN_SRC: bash
  1972. editor /etc/php5/apache2/php.ini
  1973. #+END_SRC
  1974. Set the following:
  1975. #+BEGIN_SRC: bash
  1976. memory_limit = 32M
  1977. #+END_SRC
  1978. Save and exit. Also edit */etc/php5/cli/php.ini* and set /memory_limit/ to the same value. This should prevent any rogue scripts from crashing the system.
  1979. ** Accessing your Email
  1980. #+BEGIN_VERSE
  1981. /The emails showed that Google...was among several other military/defense contractors vying for a piece of DAC’s $10.9-million surveillance contracting action./
  1982. -- Article on the "Google-Military-Surveillance Complex" by Yasha Levine
  1983. #+END_VERSE
  1984. *** Mutt email client
  1985. #+BEGIN_SRC: bash
  1986. apt-get install mutt-patched lynx abook
  1987. exit
  1988. mkdir ~/.mutt
  1989. echo "text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^ //’; copiousoutput; needsterminal; nametemplate=%s.html" > ~/.mutt/mailcap
  1990. su
  1991. editor /etc/Muttrc
  1992. #+END_SRC
  1993. Append the following:
  1994. #+BEGIN_SRC: bash
  1995. set mbox_type=Maildir
  1996. set folder="~/Maildir"
  1997. set mask="!^\\.[^.]"
  1998. set mbox="~/Maildir"
  1999. set record="+Sent"
  2000. set postponed="+Drafts"
  2001. set trash="+Trash"
  2002. set spoolfile="~/Maildir"
  2003. auto_view text/x-vcard text/html text/enriched
  2004. set editor="emacs"
  2005. set header_cache="+.cache"
  2006. macro index S "<tag-prefix><save-message>=.learn-spam<enter>" "move to learn-spam"
  2007. macro pager S "<save-message>=.learn-spam<enter>" "move to learn-spam"
  2008. macro index H "<tag-prefix><copy-message>=.learn-ham<enter>" "copy to learn-ham"
  2009. macro pager H "<copy-message>=.learn-ham<enter>" "copy to learn-ham"
  2010. # set up the sidebar
  2011. set sidebar_width=12
  2012. set sidebar_visible=yes
  2013. set sidebar_delim='|'
  2014. set sidebar_sort=yes
  2015. set rfc2047_parameters
  2016. # Show inbox and sent items
  2017. mailboxes = =Sent
  2018. # Alter these colours as needed for maximum bling
  2019. color sidebar_new yellow default
  2020. color normal white default
  2021. color hdrdefault brightcyan default
  2022. color signature green default
  2023. color attachment brightyellow default
  2024. color quoted green default
  2025. color quoted1 white default
  2026. color tilde blue default
  2027. # ctrl-n, ctrl-p to select next, prev folder
  2028. # ctrl-o to open selected folder
  2029. bind index \Cp sidebar-prev
  2030. bind index \Cn sidebar-next
  2031. bind index \Co sidebar-open
  2032. bind pager \Cp sidebar-prev
  2033. bind pager \Cn sidebar-next
  2034. bind pager \Co sidebar-open
  2035. # ctrl-b toggles sidebar visibility
  2036. macro index,pager \Cb '<enter-command>toggle sidebar_visible<enter><redraw-screen>' "toggle sidebar"
  2037. # esc-m Mark new messages as read
  2038. macro index <esc>m "T~N<enter>;WNT~O<enter>;WO\CT~T<enter>" "mark all messages read"
  2039. # Collapsing threads
  2040. macro index [ "<collapse-thread>" "collapse/uncollapse thread"
  2041. macro index ] "<collapse-all>" "collapse/uncollapse all threads"
  2042. # threads containing new messages
  2043. uncolor index "~(~N)"
  2044. color index brightblue default "~(~N)"
  2045. # new messages themselves
  2046. uncolor index "~N"
  2047. color index brightyellow default "~N"
  2048. # GPG/PGP integration
  2049. # this set the number of seconds to keep in memory the passphrase used to encrypt/sign
  2050. set pgp_timeout=60
  2051. # automatically sign and encrypt with PGP/MIME
  2052. set pgp_autosign # autosign all outgoing mails
  2053. set pgp_replyencrypt # autocrypt replies to crypted
  2054. set pgp_replysign # autosign replies to signed
  2055. set pgp_auto_decode=yes # decode attachments
  2056. unset smime_is_default
  2057. set alias_file=~/.mutt-alias
  2058. source ~/.mutt-alias
  2059. set query_command= "abook --mutt-query '%s'"
  2060. macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
  2061. #+END_SRC
  2062. Save and exit.
  2063. #+BEGIN_SRC: bash
  2064. editor /etc/mail/spamassassin/local.cf
  2065. #+END_SRC
  2066. Uncomment *use_bayes*, *bayes_auto_learn*
  2067. Save and exit, then run:
  2068. #+BEGIN_SRC: bash
  2069. service spamassassin restart
  2070. exit
  2071. cp /etc/Muttrc ~/.muttrc
  2072. touch ~/.mutt-alias
  2073. #+END_SRC
  2074. 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.
  2075. 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.
  2076. Some useful keys to know are:
  2077. | ESC / | Search for text within message contents |
  2078. | "/" | Search for text within headers |
  2079. | * | Move to the last message |
  2080. | TAB | Move to the next unread message |
  2081. | d | Delete a message |
  2082. | u | Undelete a mail which is pending deletion |
  2083. | $ | Delete all messages selected and check for new messages |
  2084. | a | Add to the address book |
  2085. | m | Send a new mail |
  2086. | ESC-m | Mark all messages as having been read |
  2087. | S | Mark a message as spam |
  2088. | H | Mark a message as ham |
  2089. | CTRL-b | Toggle side bar on/off |
  2090. | CTRL-n | Next mailbox (on side bar) |
  2091. | CTRL-p | Previous mailbox (on side bar) |
  2092. | CTRL-o | Open mailbox (on side bar) |
  2093. | ] | Expand or collapse all threads |
  2094. | [ | Expand of collapse the current thread |
  2095. | CTRL-k | Import a PGP/GPG public key |
  2096. One of the most common things which you might wish to do is to send an email. To do this first press /m/ to create a new message. Enter the address to send to and the subject, then after a few seconds the Emacs editor will appear with a blank document. Type your email then press /CTRL-x CTRL-s/ to save it and /CTRL-x CTRL-c/ to exit. You will then see a summary of the email to be sent out. Press /y/ to send it and then enter your GPG key passphrase (the one you gave when creating a PGP/GPG key). The purpose of that is to add a signature which is a strong proof that the email was written by you and not by someone else.
  2097. *** K9 Android client
  2098. #+BEGIN_VERSE
  2099. /The surveillance state is robust. It is robust politically, legally, and technically./
  2100. -- Bruce Schneier
  2101. #+END_VERSE
  2102. **** Incoming server settings
  2103. * Select settings/account settings
  2104. * Select Fetching mail/incoming server
  2105. * Enter your username and password
  2106. * IMAP server should be your domain name
  2107. * Security: SSL/TLS (always)
  2108. * Authentication: Plain
  2109. * Port: 993
  2110. **** Outgoing (SMTP) server settings
  2111. * Select settings/account settings
  2112. * Select Sending mail/outgoing server
  2113. * Set SMTP server to your domain name
  2114. * Set Security to SSL/TLS (always)
  2115. * Set port to 465
  2116. * Set authentication to PLAIN
  2117. * Enter your username and password
  2118. * Accept the SSL certificate
  2119. **** Folders
  2120. To view any new folders which you may have created using the /mailinglistrule/ script from your inbox press the *K9 icon* at the top left to access folders, then press the *menu button* and select *refresh folder list*.
  2121. If your folder still doesn't show up then press the *menu button*, select *show folders* and select *all folders*.
  2122. *** Webmail
  2123. #+BEGIN_VERSE
  2124. /Most of the information extracted is "content", such as recordings of phone calls or the substance of email messages./
  2125. -- From a 2013 Guardian article on GCHQ/NSA bulk internet data interception.
  2126. #+END_VERSE
  2127. 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.
  2128. If you're not already logged in as root:
  2129. #+BEGIN_SRC: bash
  2130. su
  2131. #+END_SRC
  2132. Install dependencies.
  2133. #+BEGIN_SRC: bash
  2134. apt-get install mysql-server libapache2-mod-authz-unixgroup
  2135. #+END_SRC
  2136. Create a mysql database, specifying a password which should be a long random string generated with a password manager such as KeepassX.
  2137. #+BEGIN_SRC: bash
  2138. mysql -u root -p
  2139. create database roundcubemail;
  2140. CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'roundcubepassword';
  2141. GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
  2142. quit
  2143. #+END_SRC
  2144. Download roundcube.
  2145. #+BEGIN_SRC: bash
  2146. cd /tmp
  2147. wget http://freedombone.uk.to/roundcubemail.tar.gz
  2148. #+END_SRC
  2149. Verify it.
  2150. #+BEGIN_SRC: bash
  2151. sha256sum roundcubemail.tar.gz
  2152. e8a311b22a8e1f70abb72ed9551cc9233cf6c5221f1eebf1ae64974117e3148b roundcubemail.tar.gz
  2153. #+END_SRC
  2154. Extract the files.
  2155. #+BEGIN_SRC: bash
  2156. tar -xzvf roundcubemail.tar.gz
  2157. export HOSTNAME=mydomainname.com
  2158. cp -r roundcubemail-* /var/www/$HOSTNAME/htdocs/mail
  2159. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/temp
  2160. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/logs
  2161. rm /var/www/$HOSTNAME/htdocs/mail/.htaccess
  2162. #+END_SRC
  2163. Edit your web site configuration.
  2164. #+BEGIN_SRC: bash
  2165. editor /etc/apache2/sites-available/$HOSTNAME
  2166. #+END_SRC
  2167. Within the 80 VirtualHost section add the following:
  2168. #+BEGIN_SRC: bash
  2169. <Directory /var/www/mydomainname.com/htdocs/mail>
  2170. deny from all
  2171. </Directory>
  2172. #+END_SRC
  2173. Within the 443 VirtualHost section add the following:
  2174. #+BEGIN_SRC: bash
  2175. <Directory /var/www/mydomainname.com/htdocs/mail>
  2176. Options Indexes FollowSymLinks MultiViews
  2177. AllowOverride All
  2178. Order allow,deny
  2179. allow from all
  2180. </Directory>
  2181. #+END_SRC
  2182. Save and exit, then restart Apache.
  2183. #+BEGIN_SRC: bash
  2184. service apache2 restart
  2185. #+END_SRC
  2186. Now with a browser visit https://mydomainname.com/mail/installer. Scroll down and click "next". Give your webmail site a product name.
  2187. The *spellcheck_engine* option being limited to Google is slightly concerning in terms of privacy and security, but seems not to be implemented.
  2188. Change the *database password* to the password you gave when creating the MySql database above.
  2189. Set *smtp_port* to 465.
  2190. Click *create config*
  2191. Click download to download the file.
  2192. The config file which you downloaded should contain the following:
  2193. #+BEGIN_SRC: bash
  2194. $config['default_host'] = 'localhost';
  2195. $config['smtp_port'] = 465;
  2196. $config['username_domain'] = '';
  2197. #+END_SRC
  2198. In a terminal on your local machine (not logged into the BBB):
  2199. #+BEGIN_SRC: bash
  2200. cd ~/Downloads
  2201. scp config.inc.php myusername@mydomainname.com:/home/myusername
  2202. #+END_SRC
  2203. Then in a terminal ssh'd into the BBB:
  2204. #+BEGIN_SRC: bash
  2205. mv /home/myusername/config.inc.php /var/www/$HOSTNAME/htdocs/mail/config
  2206. chmod 755 /var/www/$HOSTNAME/htdocs/mail/config/config.inc.php
  2207. #+END_SRC
  2208. Click *continue*.
  2209. Click *initialize database*.
  2210. Under *Test SMTP config* you can use a [[mailinator.com]] address to check that mail can be sent.
  2211. Now we can delete the installer.
  2212. #+BEGIN_SRC: bash
  2213. rm -rf /var/www/$HOSTNAME/htdocs/mail/installer
  2214. #+END_SRC
  2215. Now with a browser navigate to https://mydomainname.com/mail and log in.
  2216. You'll notice that you may not be able to see any mailing list folders which you may have created earlier using the /mailinglistrule/ script. To make folders visible click on the cog-like settings icon at the bottom left of the screen then select *manage folders*. You will then be able to select which folders you wish to become visible. Make sure that the *Sent*, *spam* and *ham* folders are selected.
  2217. Click on the *Mail* icon to go back to your main mail screen then click on the *Settings* icon at the top right of the screen and select *special folders*. Set *Junk* to *spam* then click the save button. Also select *identities* and make sure that your email address is correct.
  2218. *** Thunderbird
  2219. #+BEGIN_VERSE
  2220. /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./
  2221. -- Brian Spector, on the shutting down of the PrivateSky encrypted email service
  2222. #+END_VERSE
  2223. 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.
  2224. The following instructions should be carried out on the client machines (laptop, etc), not on the BBB itself.
  2225. **** Initial setup
  2226. Install *Thunderbird* and *Enigmail*. How you do this just depends upon your distro and software manager or "app store".
  2227. Open Thinderbird
  2228. Select "*Skip this and use existing email*"
  2229. Enter your name, email address (myusername@mydomainname.com) and the password for your user (the one from [[Add a user]]).
  2230. You'll get a message saying "/Thunderbird failed to find the settings/"
  2231. The settings should be as follows, substituting /mydomainname.com/ for your domain name and /myusername/ for the username given previously in [[Add a user]].
  2232. * Incoming: IMAP, mydomainname.com, 993, SSL/TLS, Normal Password
  2233. * Outgoing: SMTP, mydomainname.com, 465, SSL/TLS, Normal Password
  2234. * Username: myusername
  2235. Click *Done*.
  2236. Click *Get Certificate* and make sure "*permanently store this exception*" is selected", then click *Store Security Exception*.
  2237. 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.
  2238. Select "*Yes, I want to sign all of my email*"
  2239. Select "*No, I will create per-recipient rules*"
  2240. Select "*yes*" to change default settings.
  2241. **** If you have existing GPG key
  2242. Export your GPG public and private keys.
  2243. #+BEGIN_SRC: bash
  2244. gpg --output ~/public_key.txt --armor --export KEY_ID
  2245. gpg --output ~/private_key.txt --armor --export-secret-key KEY_ID
  2246. #+END_SRC
  2247. Select "*I have existing public and private keys*".
  2248. Select your public and private GPG exported key files.
  2249. Select the account which you want to use and click *Next*, *Next* and *Finish*.
  2250. Remove your exported key files.
  2251. #+BEGIN_SRC: bash
  2252. shred -zu ~/public_key.txt
  2253. shred -zu ~/private_key.txt
  2254. #+END_SRC
  2255. **** If you don't have any existing GPG or PGP key
  2256. Select "*I want to create a new key pair*"
  2257. Enter a passphrase and click *Next* a couple of times.
  2258. Click *Generate Certificate* to generate a revocation certificate.
  2259. Enter the passphrase which you gave previously.
  2260. Click *Finish*
  2261. 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.
  2262. 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.
  2263. **** Using for the first time
  2264. Click on the Thunderbird menu, which looks like three horizontal bars on the right hand side.
  2265. Hover over *preferences* and then *Account settings*.
  2266. Select *OpenPGP Security* and make sure that *use PGP/MIME by default* is ticked. This will enable you to sign/encrypt attachments, HTML bodies and UTF-8 without any problems.
  2267. Select *Synchronization & Storage*.
  2268. Make sure that *Keep messages for this account on this computer* is unticked, then click *Ok*.
  2269. Click on *Inbox*. Depending upon how much email you have it may take a while to import the subject lines.
  2270. Note that when sending an email for the first time you will also need to accept the SSL certificate.
  2271. 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.
  2272. **** Making folders visible
  2273. By default you won't be able to see any folders which you may have created earlier using the /mailinglistrule/ script. To make folders visible select:
  2274. *Menu*, hover over *Preferences*, select *Account Settings*, select *Server Settings* then click on the *Advanced* button.
  2275. Make sure that "*show only subscribed folders*" is not checked. Then click the *ok* buttons. Folders will be re-scanned, which may take some time depending upon how much email you have, but your folders will then appear.
  2276. ** Create Email folders and rules
  2277. #+BEGIN_VERSE
  2278. /Yes, the NSA set fire to the Internet but it’s the business models of Google, Facebook, etc, that provide the firewood. Trusting the companies supplying the firewood to be your fire fighters is naïve at best./
  2279. -- Aral Balkan
  2280. #+END_VERSE
  2281. *** Rules for mailing lists
  2282. 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.
  2283. We can make a script to make adding mailing list rules easy:
  2284. #+BEGIN_SRC: bash
  2285. editor /usr/bin/mailinglistrule
  2286. #+END_SRC
  2287. Add the following:
  2288. #+BEGIN_SRC: bash
  2289. #!/bin/bash
  2290. MYUSERNAME=$1
  2291. MAILINGLIST=$2
  2292. SUBJECTTAG=$3
  2293. MUTTRC=/home/$MYUSERNAME/.muttrc
  2294. PM=/home/$MYUSERNAME/.procmailrc
  2295. LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST
  2296. if [ ! -d "$LISTDIR" ]; then
  2297. mkdir -m 700 $LISTDIR
  2298. mkdir -m 700 $LISTDIR/tmp
  2299. mkdir -m 700 $LISTDIR/new
  2300. mkdir -m 700 $LISTDIR/cur
  2301. fi
  2302. chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
  2303. echo "" >> $PM
  2304. echo ":0" >> $PM
  2305. echo " * ^Subject:.*()\[$SUBJECTTAG\]" >> $PM
  2306. echo "$LISTDIR/new" >> $PM
  2307. chown $MYUSERNAME:$MYUSERNAME $PM
  2308. if [ ! -f "$MUTTRC" ]; then
  2309. cp /etc/Muttrc $MUTTRC
  2310. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  2311. fi
  2312. PROCMAILLOG=/home/$MYUSERNAME/log
  2313. if [ ! -d $PROCMAILLOG ]; then
  2314. mkdir $PROCMAILLOG
  2315. chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
  2316. fi
  2317. #+END_SRC
  2318. Save and exit, then make the script executable.
  2319. #+BEGIN_SRC: bash
  2320. chmod +x /usr/bin/mailinglistrule
  2321. #+END_SRC
  2322. 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.
  2323. #+BEGIN_SRC: bash
  2324. mailinglistrule [myusername] [mailinglistname] [subjecttag]
  2325. #+END_SRC
  2326. Repeat this command for as many mailing lists as you need. Then edit your local Mutt configuration.
  2327. #+BEGIN_SRC: bash
  2328. editor /home/myusername/.muttrc
  2329. #+END_SRC
  2330. Search for the *mailboxes* variable and add entries for the mailing lists you just created. For example:
  2331. #+BEGIN_SRC: bash
  2332. mailboxes = =Sent =mailinglistname
  2333. #+END_SRC
  2334. Then save and exit.
  2335. *** Rules for specific email addresses
  2336. You can also make a script which will allow you to move mail from specific email addresses to a folder.
  2337. #+BEGIN_SRC: bash
  2338. editor /usr/bin/emailrule
  2339. #+END_SRC
  2340. Add the following:
  2341. #+BEGIN_SRC: bash
  2342. #!/bin/bash
  2343. MYUSERNAME=$1
  2344. EMAILADDRESS=$2
  2345. MAILINGLIST=$3
  2346. MUTTRC=/home/$MYUSERNAME/.muttrc
  2347. PM=/home/$MYUSERNAME/.procmailrc
  2348. LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST
  2349. if [ ! -d "$LISTDIR" ]; then
  2350. mkdir -m 700 $LISTDIR
  2351. mkdir -m 700 $LISTDIR/tmp
  2352. mkdir -m 700 $LISTDIR/new
  2353. mkdir -m 700 $LISTDIR/cur
  2354. fi
  2355. chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
  2356. echo "" >> $PM
  2357. echo ":0" >> $PM
  2358. echo " * ^From: $EMAILADDRESS" >> $PM
  2359. echo "$LISTDIR/new" >> $PM
  2360. chown $MYUSERNAME:$MYUSERNAME $PM
  2361. if [ ! -f "$MUTTRC" ]; then
  2362. cp /etc/Muttrc $MUTTRC
  2363. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  2364. fi
  2365. PROCMAILLOG=/home/$MYUSERNAME/log
  2366. if [ ! -d $PROCMAILLOG ]; then
  2367. mkdir $PROCMAILLOG
  2368. chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
  2369. fi
  2370. #+END_SRC
  2371. Save and exit, then make the script executable.
  2372. #+BEGIN_SRC: bash
  2373. chmod +x /usr/bin/emailrule
  2374. #+END_SRC
  2375. Then to add a particular email address to a folder run the command:
  2376. #+BEGIN_SRC: bash
  2377. emailrule [myusername] [emailaddress] [foldername]
  2378. #+END_SRC
  2379. If you want any mail from the given email address to be deleted then set the /foldername/ to /Trash/.
  2380. To ensure that the folder appears within Mutt.
  2381. #+BEGIN_SRC: bash
  2382. editor /home/myusername/.muttrc
  2383. #+END_SRC
  2384. Search for the *mailboxes* variable and add entries for the mailing lists you just created. For example:
  2385. #+BEGIN_SRC: bash
  2386. mailboxes = =Sent =foldername
  2387. #+END_SRC
  2388. Then save and exit.
  2389. ** Install a Blog
  2390. #+BEGIN_VERSE
  2391. /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./
  2392. -- Nick Cohen
  2393. #+END_VERSE
  2394. 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.
  2395. 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.
  2396. Download flatpress.
  2397. #+BEGIN_SRC: bash
  2398. cd /tmp
  2399. wget http://freedombone.uk.to/flatpress.tar.gz
  2400. #+END_SRC
  2401. Verify the download:
  2402. #+BEGIN_SRC: bash
  2403. sha256sum flatpress.tar.gz
  2404. 6312a49aab5aabd6371518dcaf081f489dff04d001bc34b4fe3f2a81170bbd4e flatpress.tar.gz
  2405. #+END_SRC
  2406. Extract and install it.
  2407. #+BEGIN_SRC: bash
  2408. tar -xzvf flatpress.tar.gz
  2409. cd flatpress-*
  2410. cp -r * /var/www/$HOSTNAME/htdocs
  2411. chmod -R 755 /var/www/$HOSTNAME/htdocs/fp-content
  2412. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/fp-content
  2413. cd ..
  2414. rm -rf flatpress-*
  2415. rm -f flatpress.tar.gz
  2416. #+END_SRC
  2417. 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
  2418. ** Install an IRC server
  2419. #+BEGIN_VERSE
  2420. /Give me the liberty to know, to utter, and to argue freely according to conscience, above all liberties./
  2421. -- John Milton
  2422. #+END_VERSE
  2423. *** Base install
  2424. 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.
  2425. First install some dependencies.
  2426. #+BEGIN_SRC: bash
  2427. apt-get update
  2428. apt-get install build-essential openssl libssl-dev debhelper dpatch docbook-to-man flex bison libpcre3-dev screen
  2429. #+END_SRC
  2430. Then get the source code for ircd-hybrid.
  2431. #+BEGIN_SRC: bash
  2432. cd /tmp
  2433. wget http://freedombone.uk.to/ircd-hybrid-8.1.17.tgz
  2434. #+END_SRC
  2435. verify it.
  2436. #+BEGIN_SRC: bash
  2437. sha256sum ircd-hybrid-8.1.17.tgz
  2438. 440c9d86ba6bc930efef9cdaaec547b425c35cad3f08bed8df69e55788c1268a
  2439. #+END_SRC
  2440. Install it.
  2441. #+BEGIN_SRC: bash
  2442. tar -xzvf ircd-hybrid-8.1.17.tgz
  2443. cd ircd-hybrid-*
  2444. ./configure --prefix=/usr/local/ircd --enable-openssl
  2445. make
  2446. make install
  2447. #+END_SRC
  2448. 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.
  2449. #+BEGIN_SRC: bash
  2450. chown -R irc:irc /usr/local/ircd
  2451. cp /usr/local/ircd/etc/reference.conf /usr/local/ircd/etc/ircd.conf
  2452. editor /usr/local/ircd/etc/ircd.conf
  2453. #+END_SRC
  2454. Set *name* to the domain name of your server, and set a description.
  2455. Set a *network_name* and *network_desc*. The network name should not contain any spaces.
  2456. Set max_clients to 20, or however many you expect that you'll typically need.
  2457. Within the admin section set your *name* and *email*.
  2458. Within the *listen* section set host to your fixed IP address (in the earlier
  2459. sections it was 192.168.1.60).
  2460. Within the *auth* section set user = "*@192.168.1.60" - or whatever the fixed IP address of the BBB is on your network - and password to the desired password for the IRC server. If you don't wish to use a password then remove need_password from the flags.
  2461. Within the *connect* section set *host* and *vhost* to your fixed IP address (in the earlier
  2462. sections it was 192.168.1.60) and *name* to your domain name. Also set the *send/accept passwords* to your IRC login password.
  2463. Within the *operator* section change *name* to the username/nick which you will user to irc@192.168.1.60
  2464. Change *ssl_connection_required* to *yes*.
  2465. Save and exit, then restart the IRC server. Open port 6697 on your internet router and forward it to the BBB. Note that although ports 6665 to 6669 are active within the configuration file in practice we will only use the encrypted port.
  2466. Ensure that the configuration is only readable by the root user.
  2467. #+BEGIN_SRC: bash
  2468. chmod 600 /usr/local/ircd/etc/ircd.conf
  2469. #+END_SRC
  2470. Now create an init script.
  2471. #+BEGIN_SRC: bash
  2472. adduser --disabled-login irc
  2473. editor /usr/bin/runircd
  2474. #+END_SRC
  2475. Add the following:
  2476. #+BEGIN_SRC: bash
  2477. #!/bin/sh
  2478. USERNAME=irc
  2479. COMMAND="cd /usr/local/ircd; ircd > /usr/local/ircd/ircd.log"
  2480. su -l $USERNAME -c '$COMMAND'
  2481. #+END_SRC
  2482. Save and exit.
  2483. #+BEGIN_SRC: bash
  2484. chmod +x /usr/bin/runircd
  2485. editor /etc/init.d/ircd-hybrid
  2486. #+END_SRC
  2487. Add the following:
  2488. #+BEGIN_SRC: bash
  2489. #!/bin/bash
  2490. # /etc/init.d/ircd-hybrid
  2491. ### BEGIN INIT INFO
  2492. # Provides: ircd-hybrid
  2493. # Required-Start: $remote_fs $syslog
  2494. # Required-Stop: $remote_fs $syslog
  2495. # Default-Start: 2 3 4 5
  2496. # Default-Stop: 0 1 6
  2497. # Short-Description: starts irc server
  2498. # Description: starts irc server
  2499. ### END INIT INFO
  2500. # Author: Bob Mottram <bob@robotics.uk.to>
  2501. #Settings
  2502. SERVICE='ircd-hybrid'
  2503. COMMAND="runircd"
  2504. USER='irc'
  2505. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  2506. HISTORY=1024
  2507. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  2508. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin'
  2509. irc_start() {
  2510. echo "Starting $SERVICE..."
  2511. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USER
  2512. }
  2513. irc_stop() {
  2514. echo "Stopping $SERVICE"
  2515. pkill ${COMMAND}
  2516. }
  2517. #Start-Stop here
  2518. case "$1" in
  2519. start)
  2520. irc_start
  2521. ;;
  2522. stop)
  2523. irc_stop
  2524. ;;
  2525. restart)
  2526. irc_stop
  2527. sleep 10s
  2528. irc_start
  2529. ;;
  2530. *)
  2531. echo "Usage: $0 {start|stop|restart}"
  2532. exit 1
  2533. ;;
  2534. esac
  2535. exit 0
  2536. #+END_SRC
  2537. Save and exit, then start the daemon.
  2538. #+BEGIN_SRC: bash
  2539. chmod +x /etc/init.d/ircd-hybrid
  2540. update-rc.d ircd-hybrid defaults
  2541. service ircd-hybrid start
  2542. #+END_SRC
  2543. *** Channel management
  2544. To to install channel management tools.
  2545. #+BEGIN_SRC: bash
  2546. cd /tmp
  2547. wget http://freedombone.uk.to/hybserv_1.9.4-1_armhf.deb
  2548. #+END_SRC
  2549. Verify it.
  2550. #+BEGIN_SRC: bash
  2551. sha256sum hybserv_1.9.4-1_armhf.deb
  2552. 41bf4eb6e24c87610a80bc14db1103a57484835510eea7e4ba9709c523318615 hybserv_1.9.4-1_armhf.deb
  2553. #+END_SRC
  2554. Install it.
  2555. #+BEGIN_SRC: bash
  2556. dpkg -i hybserv_1.9.4-1_armhf.deb
  2557. #+END_SRC
  2558. Make a md5 version of the password for the IRC server operator.
  2559. #+BEGIN_SRC: bash
  2560. /usr/bin/mkpasswd <myoperatorpassword>
  2561. #+END_SRC
  2562. Edit the ircd-hybrid configuration.
  2563. #+BEGIN_SRC: bash
  2564. editor /etc/ircd-hybrid/ircd.conf
  2565. #+END_SRC
  2566. Enter the md5 password which you previously created within the /operator/ section. Also change /user/ to:
  2567. #+BEGIN_SRC: bash
  2568. user = "*@*";
  2569. #+END_SRC
  2570. Then save and exit.
  2571. #+BEGIN_SRC: bash
  2572. editor /etc/hybserv/hybserv.conf
  2573. #+END_SRC
  2574. 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/.
  2575. #+BEGIN_SRC: bash
  2576. A:mynickname <myemailaddress>
  2577. N:irc.mydomainname.com:Hybrid services
  2578. O:*@*:#MD5 PASSWORD HERE#:root:segj (comment out other Q: lines)
  2579. S:mysendacceptpassword:192.168.1.60:6697 (remove the other two services)
  2580. #+END_SRC
  2581. Also remove the line *#NOT-EDITED#*, then save and exit.
  2582. Now we need to restart the ircd and hybrid server to make things work:
  2583. #+BEGIN_SRC: bash
  2584. service ircd-hybrid restart
  2585. service hybserv start
  2586. #+END_SRC
  2587. *** Usage with Irssi
  2588. On another computer (not the BBB).
  2589. #+BEGIN_SRC: bash
  2590. sudo apt-get install irssi irssi-plugin-otr irssi-plugin-xmpp
  2591. irssi
  2592. #+END_SRC
  2593. Connect to the IRC and identify yourself as an operator. Here /mynetwork/ should be the same as *network_name* specified earlier within /ircd.conf/. The network name is something equivalent to "freenode".
  2594. #+BEGIN_SRC: bash
  2595. /network add -nick mynick mynetwork
  2596. /channel add -auto #mychannel mynetwork channelpassword
  2597. /server add -auto -network mynetwork -ssl mydonainname.com 6697 mysendacceptpassword
  2598. /connect mydomainname.com
  2599. /join #mychannel
  2600. /msg -servername chanserv REGISTER #mychannel channelpassword
  2601. /msg -servername chanserv set #mychannel mlock +k channelpassword
  2602. /set paste_join_multiline OFF
  2603. #+END_SRC
  2604. If you edit the irssi config file:
  2605. #+BEGIN_SRC: bash
  2606. editor ~/.irssi/config
  2607. #+END_SRC
  2608. It should look something like this:
  2609. #+BEGIN_SRC: bash
  2610. {
  2611. address = "mydomainname.com";
  2612. chatnet = "mynetwork";
  2613. port = "6697";
  2614. password = "mysendacceptpassword";
  2615. use_ssl = "yes";
  2616. ssl_verify = "no";
  2617. autoconnect = "yes";
  2618. },
  2619. #+END_SRC
  2620. If you're not using a self-signed certificate (self-signed is the default) then you can set *ssl_verify* to "yes".
  2621. By default irssi will use UTC time. An example of setting to some other time zone is as follows:
  2622. #+BEGIN_SRC: bash
  2623. echo "load perl" >> ~/.irssi/startup
  2624. echo "script exec $ENV{'TZ'}='Europe/London';" >> ~/.irssi/startup
  2625. #+END_SRC
  2626. Also enable /Off The Record/ (OTR) messaging.
  2627. #+BEGIN_SRC: bash
  2628. echo "load otr" >> ~/.irssi/startup
  2629. #+END_SRC
  2630. By default Irssi does not look especially attractive. To improve it's looks:
  2631. #+BEGIN_SRC: bash
  2632. cd ~/.irssi
  2633. wget http://freedombone.uk.to/irssi/xchat.theme
  2634. mkdir ~/.irssi/scripts
  2635. mkdir ~/.irssi/scripts/autorun
  2636. cd ~/.irssi/scripts/autorun
  2637. wget http://freedombone.uk.to/irssi/xchatnickcolor.pl
  2638. wget http://freedombone.uk.to/irssi/adv_windowlist.pl
  2639. #+END_SRC
  2640. Verify the files:
  2641. #+BEGIN_SRC: bash
  2642. sha256sum ~/.irssi/xchat.theme
  2643. 7a84130ad55aabd0b043a03b013628438e6c7f82a58e15267633bc7eb443e60b
  2644. sha256sum ~/.irssi/scripts/autorun/xchatnickcolor.pl
  2645. 8293e867a22d42ce5a28cd755237509b6f3587fd2b21d7d20af4a832081610ca
  2646. sha256sum ~/.irssi/scripts/autorun/adv_windowlist.pl
  2647. e4dd8f6d384bf4f2d0ab5ccf06df06e4a69d2647b08d37c8fc6cfd9326688395
  2648. #+END_SRC
  2649. Then run Irssi and enter the commands:
  2650. #+BEGIN_SRC: bash
  2651. /set theme xchat
  2652. /statusbar window remove act
  2653. /set awl
  2654. /set awl_block -14
  2655. /set awl_display_key $Q%K|$N%n $H$C$S
  2656. /set awl_display_key_active $Q%K|$N%n $H%U$C%n$S
  2657. /set awl_display_nokey [$N]$H$C$S
  2658. /run autorun/adv_windowlist.pl
  2659. /set awl_viewer off
  2660. /save
  2661. #+END_SRC
  2662. *** Using irssi with Off The Record messaging (OTR)
  2663. Once you're running irssi then you can enable OTR with:
  2664. #+BEGIN_SRC: bash
  2665. /statusbar window add otr
  2666. /otr genkey mynick@network (for example mynick@irc.freenode.net)
  2667. #+END_SRC
  2668. Then to see your OTR fingerprint:
  2669. #+BEGIN_SRC: bash
  2670. /otr info
  2671. #+END_SRC
  2672. And to trust or distrust someone else's fingerprint.
  2673. #+BEGIN_SRC: bash
  2674. /otr trust [fingerprint]
  2675. /otr distrust [fingerprint]
  2676. #+END_SRC
  2677. *** Usage with XChat
  2678. Within the network list click, *Add* and enter your domain name then click *Edit*.
  2679. Select the entry within the servers box, then enter *mydomainname.com/6697* and press *Enter*.
  2680. Uncheck *use global user information*.
  2681. Enter first and second nicknames and check *auto connect to this network on startup*.
  2682. Check *use SSL* and *accept invalid SSL certificate*.
  2683. Enter some favourite channels and within *server password* enter /mysendacceptpassword/ which you defined earlier when setting up the server.
  2684. Click *close* and then *connect*.
  2685. *** Install Irssi as a daemon
  2686. It may be useful to run a persistent Irssi session on the BBB. This will enable you to log in and see any entries which occurred previously so that you don't find yourself in an argument without knowledge of what was said in the last few minutes or hours. This feature only works for a single user on the BBB - typically the administrator.
  2687. First install some prerequisites.
  2688. #+BEGIN_SRC: bash
  2689. apt-get install irssi irssi-plugin-otr irssi-plugin-xmpp screen
  2690. #+END_SRC
  2691. Create an initialisation script.
  2692. #+BEGIN_SRC: bash
  2693. editor /etc/init.d/irssid
  2694. #+END_SRC
  2695. Add the following:
  2696. #+BEGIN_SRC: bash
  2697. #!/bin/bash
  2698. ### BEGIN INIT INFO
  2699. # Provides: irssid
  2700. # Required-Start: $network
  2701. # Required-Stop: $network
  2702. # Default-Start: 2 3 4 5
  2703. # Default-Stop: 0 1 6
  2704. # Short-Description: Start irssi daemon within screen session at boot time
  2705. # Description: This init script will start an irssi session under screen using the settings provided in /etc/irssid.conf
  2706. ### END INIT INFO
  2707. # Include the LSB library functions
  2708. . /lib/lsb/init-functions
  2709. # Setup static variables
  2710. configFile='/etc/irssid.conf'
  2711. daemonExec='/usr/bin/screen'
  2712. daemonArgs='-D -m'
  2713. daemonName="$(basename "$daemonExec")"
  2714. pidFile='/var/run/irssid.pid'
  2715. #
  2716. # Checks if the environment is capable of running the script (such as
  2717. # availability of programs etc).
  2718. #
  2719. # Return: 0 if the environmnt is properly setup for execution of init script, 1
  2720. # if not all conditions have been met.
  2721. #
  2722. function checkEnvironment() {
  2723. # Verify that the necessary binaries are available for execution.
  2724. local binaries=(irssi screen)
  2725. for bin in "${binaries[@]}"; do
  2726. if ! which "$bin" > /dev/null; then
  2727. log_failure_msg "Binary '$bin' is not available. Please install \
  2728. package containing it."
  2729. exit 5
  2730. fi
  2731. done
  2732. }
  2733. #
  2734. # Checks if the configuration files are available and properly setup.
  2735. #
  2736. # Return: 0 if irssid if properly configured, 1 otherwise.
  2737. #
  2738. function checkConfig() {
  2739. # Make sure the configuration file has been created
  2740. if ! [[ -f $configFile ]]; then
  2741. log_failure_msg "Please populate the configuration file '$configFile' \
  2742. before running."
  2743. exit 6
  2744. fi
  2745. # Make sure the required options have been set
  2746. local reqOptions=(user group session)
  2747. for option in "${reqOptions[@]}"; do
  2748. if ! grep -q -e "^[[:blank:]]*$option=" "$configFile"; then
  2749. log_failure_msg "Mandatory option '$option' was not specified in \
  2750. '$configFile'"
  2751. exit 6
  2752. fi
  2753. done
  2754. }
  2755. #
  2756. # Loads the configuration file and performs any additional configuration steps.
  2757. #
  2758. function configure() {
  2759. . "$configFile"
  2760. daemonArgs="$daemonArgs -S $session irssi"
  2761. [[ -n $args ]] && daemonArgs="$daemonArgs $args"
  2762. daemonCommand="$daemonExec $daemonArgs"
  2763. }
  2764. #
  2765. # Starts the daemon.
  2766. #
  2767. # Return: LSB-compliant code.
  2768. #
  2769. function start() {
  2770. start-stop-daemon --start -v -b -x /bin/su -p /tmp/irssi.screen.session -m --chdir /home/$user -- - $user -c "screen -D -m -S irssi -- irssi" 1>>/log.irssi
  2771. }
  2772. #
  2773. # Stops the daemon.
  2774. #
  2775. # Return: LSB-compliant code.
  2776. #
  2777. function stop() {
  2778. start-stop-daemon --stop -x /bin/su -p /tmp/irssi.screen.session -q
  2779. }
  2780. checkEnvironment
  2781. checkConfig
  2782. configure
  2783. case "$1" in
  2784. start)
  2785. log_daemon_msg "Starting daemon" "irssid"
  2786. start && log_end_msg 0 || log_end_msg $?
  2787. ;;
  2788. stop)
  2789. log_daemon_msg "Stopping daemon" "irssid"
  2790. stop && log_end_msg 0 || log_end_msg $?
  2791. ;;
  2792. restart)
  2793. log_daemon_msg "Restarting daemon" "irssid"
  2794. stop
  2795. start && log_end_msg 0 || log_end_msg $?
  2796. ;;
  2797. force-reload)
  2798. log_daemon_msg "Restarting daemon" "irssid"
  2799. stop
  2800. start && log_end_msg 0 || log_end_msg $?
  2801. ;;
  2802. status)
  2803. status_of_proc -p "$pidFile" "$daemonExec" screen && exit 0 || exit $?
  2804. ;;
  2805. *)
  2806. echo "irssid (start|stop|restart|force-reload|status|help)"
  2807. ;;
  2808. esac
  2809. #+END_SRC
  2810. Save and exit.
  2811. #+BEGIN_SRC: bash
  2812. chmod +x /etc/init.d/irssid
  2813. #+END_SRC
  2814. Create a configuration file, replacing /myusername/ with your username.
  2815. #+BEGIN_SRC: bash
  2816. editor /etc/irssid.conf
  2817. #+END_SRC
  2818. #+BEGIN_SRC: bash
  2819. #
  2820. # Configuration file for irssid init script
  2821. #
  2822. # Mandatory options:
  2823. #
  2824. # user - Specify user for running irssi.
  2825. # group - Specify group for running irssi.
  2826. # session - Specify screen session name to be used for irssi.
  2827. #
  2828. # Non-mandatory options:
  2829. #
  2830. # args - Pass additional arguments to irssi.
  2831. #
  2832. user='myusername'
  2833. group='irssi'
  2834. session='irssi'
  2835. args='--config /home/myusername/.irssi/config'
  2836. #+END_SRC
  2837. Save and exit. Then add your user to the irssi group and start the daemon.
  2838. #+BEGIN_SRC: bash
  2839. groupadd irssi
  2840. usermod -aG irssi myusername
  2841. update-rc.d irssid defaults
  2842. chown -R myusername:irssi /home/myusername/.irssi
  2843. service irssid start
  2844. #+END_SRC
  2845. Create a script to make running IRC on the server easier.
  2846. #+BEGIN_SRC: bash
  2847. editor /usr/bin/irc
  2848. #+END_SRC
  2849. Add the following:
  2850. #+BEGIN_SRC: bash
  2851. #!/bin/bash
  2852. screen -r irssi
  2853. #+END_SRC
  2854. Save and exit.
  2855. #+BEGIN_SRC: bash
  2856. chmod +x /usr/bin/irc
  2857. chown myusername:myusername /usr/bin/irc
  2858. #+END_SRC
  2859. Then to subsequently access irssi log into the BBB using ssh and type:
  2860. #+BEGIN_SRC: bash
  2861. irc
  2862. #+END_SRC
  2863. To set UK time within Irssi:
  2864. #+BEGIN_SRC: bash
  2865. /script exec $ENV{'TZ'}='Europe/London';
  2866. /save
  2867. #+END_SRC
  2868. ** Install a Jabber/XMPP server
  2869. #+BEGIN_VERSE
  2870. /Well heck, it isn’t that hard to write an instant messaging system./
  2871. --Jeremie Miller
  2872. #+END_VERSE
  2873. *** The Server
  2874. Generate a SSL certificate.
  2875. #+BEGIN_SRC: bash
  2876. openssl genrsa -out /etc/ssl/private/xmpp.key 4096
  2877. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  2878. #+END_SRC
  2879. Change permissions.
  2880. #+BEGIN_SRC: bash
  2881. chmod 600 /etc/ssl/private/xmpp.key
  2882. chmod 600 /etc/ssl/certs/xmpp.crt
  2883. #+END_SRC
  2884. Install Prosody.
  2885. #+BEGIN_SRC: bash
  2886. apt-get install prosody
  2887. chown prosody:prosody /etc/ssl/private/xmpp.key
  2888. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  2889. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  2890. editor /etc/prosody/conf.avail/xmpp.cfg.lua
  2891. #+END_SRC
  2892. Change the *VirtualHost* name to your domain name and remove the line below it.
  2893. Set the ssl section to:
  2894. #+BEGIN_SRC: bash
  2895. ssl = {
  2896. key = "/etc/ssl/private/xmpp.key";
  2897. certificate = "/etc/ssl/certs/xmpp.crt";
  2898. }
  2899. #+END_SRC
  2900. And also append the following:
  2901. #+BEGIN_SRC: bash
  2902. modules_enabled = {
  2903. "bosh"; -- Enable mod_bosh
  2904. "tls"; -- Enable mod_tls
  2905. }
  2906. c2s_require_encryption = true
  2907. s2s_require_encryption = true
  2908. #+END_SRC
  2909. Save and exit. Create a symbolic link.
  2910. #+BEGIN_SRC: bash
  2911. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  2912. editor /etc/prosody/prosody.cfg.lua
  2913. #+END_SRC
  2914. Within the *ssl* section set:
  2915. #+BEGIN_SRC: bash
  2916. ssl = {
  2917. key = "/etc/ssl/private/xmpp.key";
  2918. certificate = "/etc/ssl/certs/xmpp.crt";
  2919. }
  2920. #+END_SRC
  2921. Uncomment and set the following to *true*
  2922. #+BEGIN_SRC: bash
  2923. c2s_require_encryption = true
  2924. s2s_require_encryption = true
  2925. #+END_SRC
  2926. Within the *modules_enabled* section uncomment *bosh*, then save and exit.
  2927. 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).
  2928. #+BEGIN_SRC: bash
  2929. prosodyctl adduser myusername@mydomainname.com
  2930. #+END_SRC
  2931. Restart the server
  2932. #+BEGIN_SRC: bash
  2933. service prosody restart
  2934. #+END_SRC
  2935. On your internet router/firewall open ports 5222, 5223, 5269, 5280 and 5281 and forward them to the BBB.
  2936. 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.
  2937. *** Managing users
  2938. To add a user:
  2939. #+BEGIN_SRC: bash
  2940. prosodyctl adduser myusername@mydomainname.com
  2941. #+END_SRC
  2942. To change a user password:
  2943. #+BEGIN_SRC: bash
  2944. prosodyctl passwd myusername@mydomainname.com
  2945. #+END_SRC
  2946. To remove a user:
  2947. #+BEGIN_SRC: bash
  2948. prosodyctl deluser myusername@mydomainname.com
  2949. #+END_SRC
  2950. Report the status of the XMPP server:
  2951. #+BEGIN_SRC: bash
  2952. prosodyctl status
  2953. #+END_SRC
  2954. *** Using with Jitsi
  2955. 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.
  2956. Jitsi can be downloaded from https://jitsi.org/
  2957. On your desktop/laptop open Jitsi and select *Options* from the *Tools* menu.
  2958. 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).
  2959. 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.
  2960. 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.
  2961. You can also [[https://www.youtube.com/watch?v=vgx7VSrDGjk][see this video]] as an example of using OTR.
  2962. *** Using with Ubuntu
  2963. 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.
  2964. Open *System Settings* and select *Online Accounts*, *Add account* and then *Jabber*.
  2965. Enter your username (myusername@mydomainname.com) and password.
  2966. 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*.
  2967. *** Using with Android
  2968. There are a few XMPP clients available on Android. Ideally choose ones which support off-the-record messaging. Here are some examples.
  2969. **** Xabber
  2970. Install [[https://f-droid.org/][F-Droid]]
  2971. Search for and install Xabber.
  2972. Add an account and enter your Jabber/XMPP ID and password.
  2973. From the menu select *Settings* then *Security* then *OTR mode*. Set the mode to *Required*.
  2974. Make sure that *Check server certificate* is not checked.
  2975. 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.
  2976. **** Gibberbot
  2977. Install [[https://f-droid.org/][F-Droid]]
  2978. Search for and install Gibberbot, otherwise known as ChatSecure.
  2979. From the menu open *Accounts*
  2980. Select *Add account*
  2981. Change the server port from 0 to 5222
  2982. Done
  2983. Accept unknown certificate? Select *Always*
  2984. Go back to the initial screen and then using the menu you can add contacts and begin chatting.
  2985. ** Social Networking
  2986. #+BEGIN_VERSE
  2987. /Facebook is not your friend, it is a surveillance engine./
  2988. -- Richard Stallman, Free Software Foundation
  2989. #+END_VERSE
  2990. *** Friendica
  2991. **** Installation
  2992. 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.
  2993. 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:
  2994. #+BEGIN_SRC: bash
  2995. editor /etc/apache2/sites-available/myfriendicadomainname.com
  2996. #+END_SRC
  2997. Replace the section which begins with *<VirtualHost *:80>* with the following, replacing /myusername@mydomainname.com/ with your email address and /myfriendicadomainname.com/ with your Friendica domain name:
  2998. #+BEGIN_SRC: bash
  2999. <VirtualHost *:80>
  3000. ServerAdmin myusername@mydomainname.com
  3001. ServerName myfriendicadomainname.com
  3002. RewriteEngine On
  3003. RewriteCond %{HTTPS} off
  3004. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3005. </VirtualHost>
  3006. #+END_SRC
  3007. Save and exit, then restart the apache server.
  3008. #+BEGIN_SRC: bash
  3009. service apache2 restart
  3010. #+END_SRC
  3011. Now install some dependencies.
  3012. #+BEGIN_SRC: bash
  3013. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt php5-fpm php5-cgi php-apc
  3014. #+END_SRC
  3015. Enter an admin password for MySQL.
  3016. Reduce the memory use of mysql by using the "small" configuration.
  3017. #+BEGIN_SRC: bash
  3018. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3019. #+END_SRC
  3020. Create a mysql database, replacing /myfriendicapassword/ with a password used to administer the friendica database.
  3021. #+BEGIN_SRC: bash
  3022. mysql -u root -p
  3023. create database friendica;
  3024. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'myfriendicapassword';
  3025. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  3026. quit
  3027. #+END_SRC
  3028. You may need to fix Git SSL problems.
  3029. #+BEGIN_SRC: bash
  3030. git config --global http.sslVerify true
  3031. apt-get install ca-certificates
  3032. cd ~/
  3033. editor .gitconfig
  3034. #+END_SRC
  3035. The .gitconfig file should look something like this:
  3036. #+BEGIN_SRC: bash
  3037. [user]
  3038. name = yourname
  3039. email = myusername@mydomainname.com
  3040. [http]
  3041. sslVerify = true
  3042. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  3043. #+END_SRC
  3044. Get the source code.
  3045. #+BEGIN_SRC: bash
  3046. export HOSTNAME=myfriendicadomainname.com
  3047. cd /var/www/$HOSTNAME
  3048. rm -rf htdocs
  3049. git clone https://github.com/friendica/friendica.git htdocs
  3050. chmod -R 755 htdocs
  3051. chown -R www-data:www-data htdocs
  3052. chown -R www-data:www-data htdocs/view/smarty3
  3053. git clone https://github.com/friendica/friendica-addons.git htdocs/addon
  3054. #+END_SRC
  3055. Now visit the URL of your site and you should be taken through the rest of the installation procedure.
  3056. | Database Server Name | localhost |
  3057. | Database login name | friendicaadmin |
  3058. | Database Login Password | myfriendicapassword |
  3059. | Database Name | friendica |
  3060. When installation is complete if you already have an exported account which you wish to import then visit https://myfriendicadomain.com/uimport, rather than registering a new user. If you get an error when trying to import an account then try increasing the value of LimitRequestBody within your apache configuration and restart the apache2 service.
  3061. 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.
  3062. Install the poller.
  3063. #+BEGIN_SRC: bash
  3064. editor /etc/crontab
  3065. #+END_SRC
  3066. and append the following, changing /myfriendicadomainname.com/ to whatever your Friendica domain is.
  3067. #+BEGIN_SRC: bash
  3068. */10 * * * * root cd /var/www/myfriendicadomainname.com/htdocs; /usr/bin/timeout 120 /usr/bin/php include/poller.php
  3069. #+END_SRC
  3070. Save and exit, then restart cron.
  3071. #+BEGIN_SRC: bash
  3072. service cron restart
  3073. #+END_SRC
  3074. You can improve the speed of Friendica database searches by adding the following indexes:
  3075. #+BEGIN_SRC: bash
  3076. mysql -u root -p
  3077. use friendica;
  3078. CREATE INDEX `uri_received` ON item(`uri`, `received`);
  3079. CREATE INDEX `received_uri` ON item(`received`, `uri`);
  3080. CREATE INDEX `contact-id_created` ON item(`contact-id`, created);
  3081. CREATE INDEX `uid_network_received` ON item(`uid`, `network`, `received`);
  3082. CREATE INDEX `uid_parent` ON item(`uid`, `parent`);
  3083. CREATE INDEX `uid_received` ON item(`uid`, `received`);
  3084. CREATE INDEX `uid_network_commented` ON item(`uid`, `network`, `commented`);
  3085. CREATE INDEX `uid_title` ON item(uid, `title`);
  3086. CREATE INDEX `created_contact-id` ON item(`created`, `contact-id`);
  3087. quit
  3088. #+END_SRC
  3089. Make sure that Friendica doesn't use too much memory.
  3090. #+BEGIN_SRC: bash
  3091. editor /var/www/$HOSTNAME/htdocs/.htaccess
  3092. #+END_SRC
  3093. Append the following:
  3094. #+BEGIN_SRC: bash
  3095. php_value memory_limit 32M
  3096. #+END_SRC
  3097. The save ane exit.
  3098. **** Backups
  3099. 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.
  3100. #+BEGIN_SRC: bash
  3101. editor /etc/cron.daily/backup
  3102. #+END_SRC
  3103. Enter the following
  3104. #+BEGIN_SRC: bash
  3105. #!/bin/sh
  3106. # stop the web server to avoid any changes to the databases during backup
  3107. service apache2 stop
  3108. MYSQL_PASSWORD=<mysql root password>
  3109. umask 0077
  3110. # Backup the database
  3111. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_daily.sql
  3112. # Make the backup readable only by root
  3113. chmod 600 /var/backups/friendica_daily.sql
  3114. # Backup the database
  3115. #mysqldump --password=$MYSQL_PASSWORD redmatrix > /var/backups/redmatrix_daily.sql
  3116. # Make the backup readable only by root
  3117. #chmod 600 /var/backups/redmatrix_daily.sql
  3118. # restart the web server
  3119. service apache2 start
  3120. #+END_SRC
  3121. Save and exit.
  3122. #+BEGIN_SRC: bash
  3123. chmod 600 /etc/cron.daily/backup
  3124. chmod +x /etc/cron.daily/backup
  3125. editor /etc/cron.weekly/backup
  3126. #+END_SRC
  3127. Enter the following
  3128. #+BEGIN_SRC: bash
  3129. #!/bin/sh
  3130. umask 0077
  3131. # Friendica
  3132. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_2weekly.sql
  3133. cp -f /var/backups/friendica_daily.sql /var/backups/friendica_weekly.sql
  3134. # Red Matrix
  3135. #cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_2weekly.sql
  3136. #cp -f /var/backups/redmatrix_daily.sql /var/backups/redmatrix_weekly.sql
  3137. #+END_SRC
  3138. Save and exit.
  3139. #+BEGIN_SRC: bash
  3140. chmod 600 /etc/cron.weekly/backup
  3141. chmod +x /etc/cron.weekly/backup
  3142. editor /etc/cron.monthly/backup
  3143. #+END_SRC
  3144. Enter the following
  3145. #+BEGIN_SRC: bash
  3146. #!/bin/sh
  3147. # Friendica
  3148. cp -f /var/backups/friendica_monthly.sql /var/backups/friendica_2monthly.sql
  3149. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_monthly.sql
  3150. # Red Matrix
  3151. #cp -f /var/backups/redmatrix_monthly.sql /var/backups/redmatrix_2monthly.sql
  3152. #cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_monthly.sql
  3153. #+END_SRC
  3154. Save and exit.
  3155. #+BEGIN_SRC: bash
  3156. chmod 600 /etc/cron.monthly/backup
  3157. chmod +x /etc/cron.monthly/backup
  3158. #+END_SRC
  3159. **** Recommended configuration
  3160. ***** Admin
  3161. 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.
  3162. 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.
  3163. Under the *themes* section select a few themes, including mobile themes which are suitable for phones or tablets.
  3164. 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.
  3165. If you also wish to publish your public posts to a Diaspora node then within the *site* settings select *enable Diaspora support*.
  3166. 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]].
  3167. ***** Settings
  3168. Each user has their own customisable settings, typically available either via an icon or by an entry on a drop down menu.
  3169. Under *additional features* enable "/richtext editor/", "/post preview/", "/group filter/", "/network filter/", "/edit sent posts/" and "/dislike posts/".
  3170. Under *display settings* select your desktop and mobile themes.
  3171. 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.
  3172. **** To access from an Android device
  3173. ***** App
  3174. 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.
  3175. 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.
  3176. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  3177. ***** Mobile Theme
  3178. 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.
  3179. *** Movim
  3180. #+BEGIN_VERSE
  3181. /The way we communicate with others and with ourselves ultimately determines the quality of our lives/
  3182. -- Anthony Robbins
  3183. #+END_VERSE
  3184. Movim is another social networking system based around the XMPP protocol.
  3185. You will need to have previously [[Install a Jabber/XMPP server][installed the Jabber/XMPP server]].
  3186. 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:
  3187. #+BEGIN_SRC: bash
  3188. editor /etc/apache2/sites-available/mydomainname.com
  3189. #+END_SRC
  3190. Within the section which begins with *<VirtualHost *:80>* add the following:
  3191. #+BEGIN_SRC: bash
  3192. <Directory /var/www/mydomainname.com/htdocs/movim>
  3193. deny from all
  3194. </Directory>
  3195. #+END_SRC
  3196. Within the section which begins with *<VirtualHost *:443>* add the following:
  3197. #+BEGIN_SRC: bash
  3198. <Directory /var/www/mydomainname.com/htdocs/movim>
  3199. Options Indexes FollowSymLinks MultiViews
  3200. AllowOverride All
  3201. Order allow,deny
  3202. allow from all
  3203. </Directory>
  3204. #+END_SRC
  3205. Save and exit, then restart the apache server.
  3206. #+BEGIN_SRC: bash
  3207. service apache2 restart
  3208. #+END_SRC
  3209. Download the source.
  3210. #+BEGIN_SRC: bash
  3211. cd /tmp
  3212. wget http://freedombone.uk.to/movim.tar.gz
  3213. #+END_SRC
  3214. Verify it.
  3215. #+BEGIN_SRC: bash
  3216. sha256sum movim.tar.gz
  3217. 2740ddbedf6cefcc2934759374376643b6cdea4fb7f944ec25098a6868cb499e movim.tar.gz
  3218. #+END_SRC
  3219. Install it.
  3220. #+BEGIN_SRC: bash
  3221. tar -xzvf movim.tar.gz
  3222. export HOSTNAME=mydomainname.com
  3223. cp -r movim-* /var/www/$HOSTNAME/htdocs/movim
  3224. chmod 755 /var/www/$HOSTNAME/htdocs/movim
  3225. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/movim
  3226. #+END_SRC
  3227. Install some MySql prerequisites.
  3228. #+BEGIN_SRC: bash
  3229. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  3230. #+END_SRC
  3231. If necessary, enter an admin password for MySQL.
  3232. Reduce the memory use of mysql by using the "small" configuration.
  3233. #+BEGIN_SRC: bash
  3234. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3235. #+END_SRC
  3236. Create a mysql database.
  3237. #+BEGIN_SRC: bash
  3238. mysql -u root -p
  3239. create database movim;
  3240. CREATE USER 'movimadmin'@'localhost' IDENTIFIED BY 'movimadminpassword';
  3241. GRANT ALL PRIVILEGES ON movim.* TO 'movimadmin'@'localhost';
  3242. quit
  3243. #+END_SRC
  3244. With a web browser navigate to:
  3245. https://mydomainname.com/movim/admin
  3246. Enter /admin/ as the username and /password/ as the password.
  3247. 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).
  3248. Change the /Environment/ from /Development/ to /Production/.
  3249. 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?)
  3250. Click /Submit/ followed by /Resend/.
  3251. Click on /Database Settings/ and alter the MySql movim database username to /movimadmin/ and password to the password you specified in the previous step.
  3252. 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".
  3253. 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).
  3254. *** Red Matrix
  3255. **** Introduction
  3256. 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.
  3257. **** Prerequisites
  3258. 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.
  3259. 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.
  3260. **** Installation
  3261. 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.
  3262. 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:
  3263. #+BEGIN_SRC: bash
  3264. editor /etc/apache2/sites-available/mydomainname.com
  3265. #+END_SRC
  3266. Replace the section which begins with *<VirtualHost *:80>* with the following:
  3267. #+BEGIN_SRC: bash
  3268. <VirtualHost *:80>
  3269. ServerAdmin myusername@mydomainname.com
  3270. ServerName myredmatrixdomainname.com
  3271. RewriteEngine On
  3272. RewriteCond %{HTTPS} off
  3273. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3274. </VirtualHost>
  3275. #+END_SRC
  3276. Save and exit, then restart the apache server.
  3277. #+BEGIN_SRC: bash
  3278. service apache2 restart
  3279. #+END_SRC
  3280. Now install some dependencies.
  3281. #+BEGIN_SRC: bash
  3282. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  3283. #+END_SRC
  3284. Enter an admin password for MySQL.
  3285. Reduce the memory use of mysql by using the "small" configuration.
  3286. #+BEGIN_SRC: bash
  3287. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3288. #+END_SRC
  3289. Create a mysql database.
  3290. #+BEGIN_SRC: bash
  3291. mysql -u root -p
  3292. create database redmatrix;
  3293. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'password';
  3294. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  3295. quit
  3296. #+END_SRC
  3297. You may need to fix Git SSL problems.
  3298. #+BEGIN_SRC: bash
  3299. git config --global http.sslVerify true
  3300. apt-get install ca-certificates
  3301. cd ~/
  3302. editor .gitconfig
  3303. #+END_SRC
  3304. The .gitconfig file should look something like this:
  3305. #+BEGIN_SRC: bash
  3306. [http]
  3307. sslVerify = true
  3308. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  3309. [user]
  3310. email = myusername@mydomainname.com
  3311. name = yourname
  3312. #+END_SRC
  3313. Get the source code.
  3314. #+BEGIN_SRC: bash
  3315. export HOSTNAME=mydomainname.com
  3316. mkdir /var/www/$HOSTNAME
  3317. cd /var/www/$HOSTNAME
  3318. rm -rf htdocs
  3319. git clone https://github.com/friendica/red.git htdocs
  3320. chmod -R 755 htdocs
  3321. chown -R www-data:www-data htdocs
  3322. mkdir htdocs/view/tpl/smarty3
  3323. chmod 777 htdocs/view/tpl
  3324. chmod 777 htdocs/view/tpl/smarty3
  3325. git clone https://github.com/friendica/red-addons.git htdocs/addon
  3326. #+END_SRC
  3327. 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.
  3328. Install the poller.
  3329. #+BEGIN_SRC
  3330. editor /etc/crontab
  3331. #+END_SRC
  3332. and append the following, changing mydomainname.com to whatever your domain is.
  3333. #+BEGIN_SRC
  3334. 12,22,32,42,52 * * * * root cd /var/www/apespace.org/htdocs; /usr/bin/timeout 240 /usr/bin/php include/poller.php
  3335. #+END_SRC
  3336. Save and exit, then restart cron.
  3337. #+BEGIN_SRC: bash
  3338. service cron restart
  3339. #+END_SRC
  3340. **** Backups
  3341. 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.
  3342. #+BEGIN_SRC: bash
  3343. editor /etc/cron.daily/backup
  3344. #+END_SRC
  3345. If you already have a backup script created for Friendica then just uncomment the lines for Red Matrix. The backup script should look something like the following:
  3346. #+BEGIN_SRC: bash
  3347. #!/bin/sh
  3348. # stop the web server to avoid any changes to the databases during backup
  3349. service apache2 stop
  3350. MYSQL_PASSWORD=elNYCk3hKE5jCjifUUL6ymP7
  3351. umask 0077
  3352. # Backup the database
  3353. mysqldump --password=$MYSQL_PASSWORD friendica > /var/backups/friendica_daily.sql
  3354. # Make the backup readable only by root
  3355. chmod 600 /var/backups/friendica_daily.sql
  3356. # Backup the database
  3357. mysqldump --password=$MYSQL_PASSWORD redmatrix > /var/backups/redmatrix_daily.sql
  3358. # Make the backup readable only by root
  3359. chmod 600 /var/backups/redmatrix_daily.sql
  3360. # restart the web server
  3361. service apache2 start
  3362. #+END_SRC
  3363. Save and exit.
  3364. #+BEGIN_SRC: bash
  3365. chmod 600 /etc/cron.daily/backup
  3366. chmod +x /etc/cron.daily/backup
  3367. editor /etc/cron.weekly/backup
  3368. #+END_SRC
  3369. If you already have a backup script created for Friendica then just uncomment the lines for Red Matrix. The backup script should look something like the following:
  3370. #+BEGIN_SRC: bash
  3371. #!/bin/sh
  3372. umask 0077
  3373. # Friendica
  3374. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_2weekly.sql
  3375. cp -f /var/backups/friendica_daily.sql /var/backups/friendica_weekly.sql
  3376. # Red Matrix
  3377. cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_2weekly.sql
  3378. cp -f /var/backups/redmatrix_daily.sql /var/backups/redmatrix_weekly.sql
  3379. #+END_SRC
  3380. Save and exit.
  3381. #+BEGIN_SRC: bash
  3382. chmod 600 /etc/cron.weekly/backup
  3383. chmod +x /etc/cron.weekly/backup
  3384. editor /etc/cron.monthly/backup
  3385. #+END_SRC
  3386. If you already have a backup script created for Friendica then just uncomment the lines for Red Matrix. The backup script should look something like the following:
  3387. #+BEGIN_SRC: bash
  3388. #!/bin/sh
  3389. # Friendica
  3390. cp -f /var/backups/friendica_monthly.sql /var/backups/friendica_2monthly.sql
  3391. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_monthly.sql
  3392. # Red Matrix
  3393. cp -f /var/backups/redmatrix_monthly.sql /var/backups/redmatrix_2monthly.sql
  3394. cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_monthly.sql
  3395. #+END_SRC
  3396. Save and exit.
  3397. #+BEGIN_SRC: bash
  3398. chmod 600 /etc/cron.monthly/backup
  3399. chmod +x /etc/cron.monthly/backup
  3400. #+END_SRC
  3401. **** To access from an Android device
  3402. ***** App
  3403. 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.
  3404. 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.
  3405. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  3406. *** pump.io
  3407. :PROPERTIES:
  3408. :ORDERED: t
  3409. :END:
  3410. pump.io is the successor to StatusNet (which later became [[GNU Social]]) and is a communications system which can do things other than just microblogging. It takes fewer system resources to run and so is better suited to low power servers such as the BBB, but is more complicated to install. pump.io doesn't work well with self-signed SSL certificates so this may be something which you can only use if you have your own domain and an "authority" issued certificate. Using a self-signed certificate you can only use pump.io as a /data silo/ which won't federate with other servers.
  3411. For a pump.io site you will need a separate domain/subdomain, so see [[Setting up a web site]] for details of how to create an Apache configuration for your site. If you're using freedns then you will need to create a new subdomain.
  3412. #+BEGIN_SRC: bash
  3413. apt-get update
  3414. apt-get install build-essential openssl libssl-dev redis-server imagemagick graphicsmagick git-core screen
  3415. #+END_SRC
  3416. Download nodejs
  3417. #+BEGIN_SRC: bash
  3418. cd /tmp
  3419. wget http://freedombone.uk.to/node_0.10.28-1_armhf.deb
  3420. #+END_SRC
  3421. Verify it.
  3422. #+BEGIN_SRC: bash
  3423. sha256sum node_0.10.28-1_armhf.deb
  3424. 42000a475d3397f295fe76998e79af999eebb8324ac9bb4981e931fabd9297aa
  3425. #+END_SRC
  3426. Install it.
  3427. #+BEGIN_SRC: bash
  3428. dpkg -i node_0.10.28-1_armhf.deb
  3429. #+END_SRC
  3430. Install pump.io
  3431. #+BEGIN_SRC: bash
  3432. cd /opt
  3433. git clone https://github.com/e14n/pump.io.git
  3434. cd /opt/pump.io
  3435. npm install
  3436. npm install databank-redis
  3437. echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
  3438. sysctl vm.overcommit_memory=1
  3439. #+END_SRC
  3440. Now edit the configuration file.
  3441. #+BEGIN_SRC: bash
  3442. editor /etc/pump.io.json
  3443. #+END_SRC
  3444. Add the following, replacing /mypumpiodomainname.com/ with your domain name.
  3445. #+BEGIN_SRC: bash
  3446. {
  3447. "driver": "redis",
  3448. "params": {"host":"localhost","port":6379},
  3449. "secret": "A long random string",
  3450. "noweb": false,
  3451. "site": "Name of my pump.io site",
  3452. "owner": "My name or organisation",
  3453. "ownerURL": "https://mypumpiodomainname.com/",
  3454. "port": 7270,
  3455. "urlPort": 443,
  3456. "hostname": "mypumpiodomainname.com",
  3457. "address": "localhost",
  3458. "nologger": true,
  3459. "serverUser": "pumpio",
  3460. "rejectUnauthorized": false,
  3461. "key": "/var/local/pump.io/keys/mypumpiodomainname.com.key",
  3462. "cert": "/var/local/pump.io/keys/mypumpiodomainname.com.crt",
  3463. "uploaddir": "/var/local/pump.io/uploads",
  3464. "debugClient": false,
  3465. "firehose": "ofirehose.example",
  3466. "logfile": "/var/local/pump.io/pump.log",
  3467. "disableRegistration": false
  3468. }
  3469. #+END_SRC
  3470. Save and exit.
  3471. #+BEGIN_SRC: bash
  3472. export HOSTNAME=mypumpiodomainname.com
  3473. mkdir /var/local/pump.io
  3474. mkdir /var/local/pump.io/uploads
  3475. mkdir /var/local/pump.io/keys
  3476. cp /etc/ssl/private/$HOSTNAME.key /var/local/pump.io/keys
  3477. cp /etc/ssl/certs/$HOSTNAME.crt /var/local/pump.io/keys
  3478. useradd -s /bin/bash -d /var/local/pump.io pumpio
  3479. chown -R pumpio:pumpio /var/local/pump.io
  3480. chmod 400 /var/local/pump.io/keys/*
  3481. chmod -R 777 /opt
  3482. #+END_SRC
  3483. Patch the version of Apache.
  3484. #+BEGIN_SRC: bash
  3485. mkdir /tmp/apache2
  3486. cd /tmp/apache2
  3487. apt-get build-dep apache2
  3488. apt-get install autoconf
  3489. apt-get source apache2
  3490. cd apache2-*
  3491. wget http://freedombone.uk.to/apache-2.2-wstunnel.patch
  3492. sha256sum apache-2.2-wstunnel.patch
  3493. cfc4866da2688a8eb76e0300cf16b52539ef4e525053a3851d4b6bba9a77e439
  3494. patch -p1 -i apache-2.2-wstunnel.patch
  3495. autoconf
  3496. ./configure --enable-so --enable-proxy=shared --enable-proxy-wstunnel=shared
  3497. make
  3498. make install
  3499. cp modules/proxy/.libs/mod_proxy_wstunnel.so /usr/lib/apache2/modules/
  3500. cd /etc/apache2/mods-enabled
  3501. ln -s /usr/lib/apache2/modules/mod_proxy_wstunnel.so ../mods-available/proxy_wstunnel.load
  3502. #+END_SRC
  3503. Within the section of your Apache site configuration:
  3504. #+BEGIN_SRC: bash
  3505. editor /etc/apache2/sites-available/mypumpiodomainname.com
  3506. #+END_SRC
  3507. The initial section which begins with *<VirtualHost *:80>* should be replaced by the following, replacing /mypumpiodomainname.com/ with your pump.io domain name and /myusername@mydomainname.com/ with your email address.
  3508. #+BEGIN_SRC: bash
  3509. <VirtualHost *:80>
  3510. ServerAdmin myusername@mydomainname.com
  3511. ServerName mypumpiodomainname.com
  3512. RewriteEngine On
  3513. RewriteCond %{HTTPS} off
  3514. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3515. </VirtualHost>
  3516. #+END_SRC
  3517. Add the following in the section which begins with *<VirtualHost *:443>*.
  3518. #+BEGIN_SRC: bash
  3519. ProxyVia On
  3520. ProxyPreserveHost On
  3521. ProxyRequests Off
  3522. SSLProxyEngine On
  3523. ProxyPass / https://localhost:7270/
  3524. ProxyPassReverse / https://localhost:7270/
  3525. #+END_SRC
  3526. Save and exit.
  3527. #+BEGIN_SRC: bash
  3528. a2enmod ssl
  3529. a2enmod cache
  3530. a2enmod disk_cache
  3531. a2enmod expires
  3532. a2enmod proxy
  3533. a2enmod proxy_connect
  3534. a2enmod proxy_http
  3535. apachectl configtest
  3536. service apache2 restart
  3537. npm install forever -g
  3538. #+END_SRC
  3539. Now create the daemon.
  3540. #+BEGIN_SRC: bash
  3541. editor /etc/init.d/pumpio
  3542. #+END_SRC
  3543. Add the following text:
  3544. #+BEGIN_SRC: bash
  3545. #!/bin/bash
  3546. # /etc/init.d/pumpio
  3547. ### BEGIN INIT INFO
  3548. # Provides: pump.io
  3549. # Required-Start: $remote_fs $syslog
  3550. # Required-Stop: $remote_fs $syslog
  3551. # Default-Start: 2 3 4 5
  3552. # Default-Stop: 0 1 6
  3553. # Short-Description: starts pump.io as a background daemon
  3554. # Description: Starts pump.io on boot
  3555. ### END INIT INFO
  3556. # Author: Bob Mottram <bob@robotics.uk.to>
  3557. #Settings
  3558. SERVICE='pumpio'
  3559. COMMAND="forever /opt/pump.io/bin/pump > /var/local/pump.io/daemon.log"
  3560. USERNAME='pumpio'
  3561. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system OAresources
  3562. HISTORY=1024
  3563. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  3564. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/var/local/pump.io'
  3565. pumpio_start() {
  3566. echo "Starting $SERVICE..."
  3567. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  3568. }
  3569. pumpio_stop() {
  3570. echo "Stopping $SERVICE"
  3571. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  3572. }
  3573. #Start-Stop here
  3574. case "$1" in
  3575. start)
  3576. pumpio_start
  3577. ;;
  3578. stop)
  3579. pumpio_stop
  3580. ;;
  3581. restart)
  3582. pumpio_stop
  3583. sleep 10s
  3584. pumpio_start
  3585. ;;
  3586. *)
  3587. echo "Usage: $0 {start|stop|restart}"
  3588. exit 1
  3589. ;;
  3590. esac
  3591. exit 0
  3592. #+END_SRC
  3593. Save and exit. Then enable the daemon and run it.
  3594. #+BEGIN_SRC: bash
  3595. chmod +x /etc/init.d/pumpio
  3596. update-rc.d pumpio defaults
  3597. service pumpio start
  3598. #+END_SRC
  3599. Now visit your pump.io site by navigating to:
  3600. https://mypumpiodomainname.com
  3601. and add a new user. If you wish this to be a single user node not open to the general public (including spammers and sockpuppets) then edit */etc/pump.io.json* and set *disableRegistration* to *true*. After making that change restart with the command *service pumpio restart*.
  3602. Once you've set up your user account it's recommended that you don't use the web based user interface and instead use a native client such as [[http://jancoding.wordpress.com/dianara/][Dianara]] or Pumpa. On Ubuntu you can install these via the Software Center. On mobile devices you can install AndStatus via F-Droid.
  3603. A list of pump.io sites can be found at http://pumpstatus.jpope.org. At the time of writing there isn't any public directory and so finding people to follow is really a question of navigating through lists of /following/ or /followers/ (rather like the web before search engines were invented).
  3604. Ensure that data data gets backed up with:
  3605. #+BEGIN_SRC: bash
  3606. printf "\n\n# Redis backup" >> /etc/cron.daily/backup
  3607. printf "\ntar -czvf /var/backups/redis_daily.tar.gz /var/lib/redis/dump.rdb" >> /etc/cron.daily/backup
  3608. printf "\n\n# Redis backup" >> /etc/cron.weekly/backup
  3609. printf "\ncp -f /var/backups/redis_weekly.tar.gz /var/backups/redis_weekly2.tar.gz" >> /etc/cron.weekly/backup
  3610. printf "\ncp -f /var/backups/redis_daily.tar.gz /var/backups/redis_weekly.tar.gz" >> /etc/cron.weekly/backup
  3611. printf "\n\n# Redis backup" >> /etc/cron.monthly/backup
  3612. printf "\ncp -f /var/backups/redis_monthly.tar.gz /var/backups/redis_monthly2.tar.gz" >> /etc/cron.monthly/backup
  3613. printf "\ncp -f /var/backups/redis_weekly.tar.gz /var/backups/redis_monthly.tar.gz" >> /etc/cron.monthly/backup
  3614. printf "\n\n# Pump.io backup" >> /etc/cron.daily/backup
  3615. printf "\ntar -czvf /var/backups/pumpio_daily.tar.gz /var/local/pump.io --exclude /var/local/pump.io/.forever" >> /etc/cron.daily/backup
  3616. printf "\n\n# Pump.io backup" >> /etc/cron.weekly/backup
  3617. printf "\ncp -f /var/backups/pumpio_weekly.tar.gz /var/backups/pumpio_weekly2.tar.gz" >> /etc/cron.weekly/backup
  3618. printf "\ncp -f /var/backups/pumpio_daily.tar.gz /var/backups/pumpio_weekly.tar.gz" >> /etc/cron.weekly/backup
  3619. printf "\n\n# Pump.io backup" >> /etc/cron.monthly/backup
  3620. printf "\ncp -f /var/backups/pumpio_monthly.tar.gz /var/backups/pumpio_monthly2.tar.gz" >> /etc/cron.monthly/backup
  3621. printf "\ncp -f /var/backups/pumpio_weekly.tar.gz /var/backups/pumpio_monthly.tar.gz" >> /etc/cron.monthly/backup
  3622. #+END_SRC
  3623. At the time of writing creating backups of the pump.io database is critically important, because regenerating the database or moving to a different databank type causes you to be /permanently banned/ from the pump.io network unless you change your domain name (which may not always be an available option).
  3624. ** Install Gopher
  3625. *** Server setup
  3626. 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.
  3627. To set up a gopher server:
  3628. #+BEGIN_SRC: bash
  3629. apt-get install build-essential
  3630. cd /tmp
  3631. wget http://freedombone.uk.to/geomyidae-current.tgz
  3632. #+END_SRC
  3633. Verify the download:
  3634. #+BEGIN_SRC: bash
  3635. sha256sum geomyidae-current.tgz
  3636. 162f55ab059ab0a9be8e840497795293bbd51c34b1f4564dcdf3f0ddd5c0db31 geomyidae-current.tgz
  3637. #+END_SRC
  3638. Then extract and install it.
  3639. #+BEGIN_SRC: bash
  3640. tar -xzvf geomyidae-current.tgz
  3641. cd geomyidae-*
  3642. make
  3643. make install
  3644. mkdir -p /var/gopher
  3645. #+END_SRC
  3646. 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.
  3647. #+BEGIN_SRC: bash
  3648. editor /etc/init.d/gopher
  3649. #+END_SRC
  3650. Enter the following:
  3651. #+BEGIN_SRC: bash
  3652. #! /bin/sh
  3653. ### BEGIN INIT INFO
  3654. # Provides: gopher
  3655. # Required-Start: $remote_fs $syslog
  3656. # Required-Stop: $remote_fs $syslog
  3657. # Default-Start: 2 3 4 5
  3658. # Default-Stop: 0 1 6
  3659. # Short-Description: Gopher daemon
  3660. # Description: Gopher daemon
  3661. ### END INIT INFO
  3662. # Do NOT "set -e"
  3663. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  3664. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  3665. DESC="Gopher daemon"
  3666. NAME=geomyidae
  3667. DAEMON=/usr/bin/$NAME
  3668. DAEMON_ARGS="-l /var/log/geomyidae.log -b /var/gopher -p 70"
  3669. PIDFILE=/var/run/$NAME.pid
  3670. SCRIPTNAME=/etc/init.d/$NAME
  3671. # Exit if the package is not installed
  3672. [ -x "$DAEMON" ] || exit 0
  3673. # Read configuration variable file if it is present
  3674. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  3675. # Load the VERBOSE setting and other rcS variables
  3676. . /lib/init/vars.sh
  3677. # Define LSB log_* functions.
  3678. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  3679. # and status_of_proc is working.
  3680. . /lib/lsb/init-functions
  3681. #
  3682. # Function that starts the daemon/service
  3683. #
  3684. do_start()
  3685. {
  3686. # Return
  3687. # 0 if daemon has been started
  3688. # 1 if daemon was already running
  3689. # 2 if daemon could not be started
  3690. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  3691. || return 1
  3692. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  3693. $DAEMON_ARGS \
  3694. || return 2
  3695. # Add code here, if necessary, that waits for the process to be ready
  3696. # to handle requests from services started subsequently which depend
  3697. # on this one. As a last resort, sleep for some time.
  3698. }
  3699. #
  3700. # Function that stops the daemon/service
  3701. #
  3702. do_stop()
  3703. {
  3704. # Return
  3705. # 0 if daemon has been stopped
  3706. # 1 if daemon was already stopped
  3707. # 2 if daemon could not be stopped
  3708. # other if a failure occurred
  3709. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  3710. RETVAL="$?"
  3711. [ "$RETVAL" = 2 ] && return 2
  3712. # Wait for children to finish too if this is a daemon that forks
  3713. # and if the daemon is only ever run from this initscript.
  3714. # If the above conditions are not satisfied then add some other code
  3715. # that waits for the process to drop all resources that could be
  3716. # needed by services started subsequently. A last resort is to
  3717. # sleep for some time.
  3718. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  3719. [ "$?" = 2 ] && return 2
  3720. # Many daemons don't delete their pidfiles when they exit.
  3721. rm -f $PIDFILE
  3722. return "$RETVAL"
  3723. }
  3724. #
  3725. # Function that sends a SIGHUP to the daemon/service
  3726. #
  3727. do_reload() {
  3728. #
  3729. # If the daemon can reload its configuration without
  3730. # restarting (for example, when it is sent a SIGHUP),
  3731. # then implement that here.
  3732. #
  3733. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  3734. return 0
  3735. }
  3736. case "$1" in
  3737. start)
  3738. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  3739. do_start
  3740. case "$?" in
  3741. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  3742. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  3743. esac
  3744. ;;
  3745. stop)
  3746. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  3747. do_stop
  3748. case "$?" in
  3749. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  3750. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  3751. esac
  3752. ;;
  3753. status)
  3754. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  3755. ;;
  3756. #reload|force-reload)
  3757. #
  3758. # If do_reload() is not implemented then leave this commented out
  3759. # and leave 'force-reload' as an alias for 'restart'.
  3760. #
  3761. #log_daemon_msg "Reloading $DESC" "$NAME"
  3762. #do_reload
  3763. #log_end_msg $?
  3764. #;;
  3765. restart|force-reload)
  3766. #
  3767. # If the "reload" option is implemented then remove the
  3768. # 'force-reload' alias
  3769. #
  3770. log_daemon_msg "Restarting $DESC" "$NAME"
  3771. do_stop
  3772. case "$?" in
  3773. 0|1)
  3774. do_start
  3775. case "$?" in
  3776. 0) log_end_msg 0 ;;
  3777. 1) log_end_msg 1 ;; # Old process is still running
  3778. *) log_end_msg 1 ;; # Failed to start
  3779. esac
  3780. ;;
  3781. *)
  3782. # Failed to stop
  3783. log_end_msg 1
  3784. ;;
  3785. esac
  3786. ;;
  3787. *)
  3788. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  3789. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  3790. exit 3
  3791. ;;
  3792. esac
  3793. :
  3794. #+END_SRC
  3795. Save and exit. Then start the gopher service.
  3796. #+BEGIN_SRC: bash
  3797. chmod +x /etc/init.d/gopher
  3798. update-rc.d gopher defaults
  3799. service gopher start
  3800. #+END_SRC
  3801. 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:
  3802. #+BEGIN_SRC: bash
  3803. gopher://mydomainname.com
  3804. #+END_SRC
  3805. There is a browser addon for Gopher called "overbite". Installing that should enable you to view your site.
  3806. *** A phlogging script
  3807. A phlog is the gopher equivalent of a blog on the web. You can create a script which makes phlogging easy.
  3808. #+BEGIN_SRC: bash
  3809. editor /usr/bin/mkphlog
  3810. #+END_SRC
  3811. Add the following:
  3812. #+BEGIN_SRC: bash
  3813. #!/bin/sh
  3814. # mkphlog - a utility to ease the creation of phlogs.
  3815. # Organizes phlog posts in separate directories.
  3816. # Created by octotep; anyone can distribute, modify, and
  3817. # share this file however they please.
  3818. #
  3819. # Version 0.3
  3820. #
  3821. # Modified by Bob Mottram
  3822. #
  3823. # Please note, all date strings are in the form of mm/dd/yy(yy)
  3824. # The base of the entire gopher site.
  3825. gopherRoot="/var/gopher"
  3826. # The name of the phlog directory (contained in $gopherHome)
  3827. phlogDirName="phlog"
  3828. # Default editor, unless the user has one specified in env
  3829. editor=${EDITOR:-emacs}
  3830. # Default timezone, unless the user has one specified in env
  3831. TZ=${TZ:-UTC}
  3832. # Tells the script how many lines the title of the main page spans.
  3833. # Used to insert the newest post at the top.
  3834. # Titles created by mkphlog are 3 lines.
  3835. # Isn't used if $addTitleToMain is false
  3836. titleLineCount=3
  3837. entryDate=`date +%Y-%m-%d`
  3838. # Creates the phlog directory if it dosen't already exist.
  3839. CreatePhlogDir() {
  3840. mkdir $phlogDirName
  3841. chmod 755 $phlogDirName
  3842. cd $phlogDirName
  3843. echo "Phlog directory created."
  3844. }
  3845. # Updates the main phlog listing
  3846. UpdatePhlogListing() {
  3847. # Just in case the user didn't specify a title
  3848. if [ "$postTitleAns" = "" ] ; then
  3849. echo -n "Do you want to create a blank post? (y/n) "
  3850. read blankPostAns
  3851. case $blankPostAns in
  3852. y* | Y* ) $postTitleAns="New Post" ;;
  3853. n* | N* ) echo "Goodbye, then." ; exit 1 ;;
  3854. * ) exit 1 ;;
  3855. esac
  3856. fi
  3857. cd $gopherRoot/$phlogDirName/
  3858. title2=$(echo "${postTitleAns}" | tr " " _)
  3859. postfilename="${entryDate}_${title2}.txt"
  3860. touch ${postfilename}
  3861. echo $postTitleAns >> ${postfilename}
  3862. date "+%A %b %e %l:%M:%S %Y" >> ${postfilename}
  3863. echo "------------------------------" >> ${postfilename}
  3864. echo >> ${postfilename}
  3865. }
  3866. if [ -d $gopherRoot ] ; then
  3867. cd $gopherRoot
  3868. else
  3869. echo "You don't have a gopherspace set-up. Please run the gopher server setup instructions."
  3870. exit 1
  3871. fi
  3872. if [ -d $phlogDirName ] ; then
  3873. cd $phlogDirName
  3874. else
  3875. echo -n "Do you want to create a phlog directory? (y/n) "
  3876. read phlogDirAns
  3877. case $phlogDirAns in
  3878. y* | Y* ) CreatePhlogDir ;;
  3879. n* | N* ) exit 1 ;;
  3880. * ) exit 1 ;;
  3881. esac
  3882. fi
  3883. echo -n "Would you like to create a phlog entry for today? (y/n) "
  3884. read phlogAns
  3885. case $phlogAns in
  3886. y* | Y* ) echo "Creating today's phlog entry..." ;;
  3887. n* | N* ) exit 0 ;;
  3888. * ) exit 1 ;;
  3889. esac
  3890. # Make sure there isn't a post for that day, lest we overwrite it.
  3891. if [ ! -d $entryDate ]; then
  3892. echo -n "Title: "
  3893. read postTitleAns
  3894. title2=$(echo "${postTitleAns}" | tr " " _)
  3895. postfilename="${entryDate}_${title2}.txt"
  3896. touch ${postfilename}
  3897. chmod 644 ${postfilename}
  3898. UpdatePhlogListing
  3899. echo -n "Would you like to edit the post with $editor? (y/n) "
  3900. read editorAns
  3901. case $editorAns in
  3902. y* | Y* ) $editor $gopherRoot/$phlogDirName/${postfilename} ;;
  3903. n* | N* ) exit 0 ;;
  3904. * ) exit 0 ;;
  3905. esac
  3906. rm $gopherRoot/$phlogDirName/${postfilename}~
  3907. else
  3908. echo "There is already a post for today."
  3909. echo -n "Would you like to edit the post with $editor? (y/n) "
  3910. read editorAns
  3911. case $editorAns in
  3912. y* | Y* ) $editor $gopherRoot/$phlogDirName/$entryDate*.txt ;;
  3913. n* | N* ) exit 0 ;;
  3914. * ) exit 1 ;;
  3915. esac
  3916. rm $gopherRoot/$phlogDirName/${postfilename}.txt~
  3917. fi
  3918. exit 0
  3919. #+END_SRC
  3920. Save and exit.
  3921. #+BEGIN_SRC: bash
  3922. chmod +x /usr/bin/mkphlog
  3923. #+END_SRC
  3924. Now entering the command /mkphlog/ will allow you to create a phlog entry.
  3925. ** Install Owncloud
  3926. #+BEGIN_VERSE
  3927. /It's not water vapour/
  3928. -- Larry Ellison
  3929. #+END_VERSE
  3930. 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.
  3931. *** Server Installation
  3932. Install some dependencies:
  3933. #+BEGIN_SRC: bash
  3934. apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
  3935. apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
  3936. #+END_SRC
  3937. 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.
  3938. #+BEGIN_SRC: bash
  3939. a2dismod php5filter
  3940. apt-get install libapache2-mod-php5
  3941. #+END_SRC
  3942. Ensure that the size of files which may be uploaded or downloaded is large enough.
  3943. #+BEGIN_SRC: bash
  3944. editor /etc/php5/apache2/php.ini
  3945. #+END_SRC
  3946. Set the following:
  3947. #+BEGIN_SRC: bash
  3948. upload_max_filesize = 512M
  3949. post_max_size = 512M
  3950. #+END_SRC
  3951. Save and exit, then edit your Apache configuration.
  3952. #+BEGIN_SRC: bash
  3953. export HOSTNAME=mydomainname.com
  3954. editor /etc/apache2/sites-available/$HOSTNAME
  3955. #+END_SRC
  3956. 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.
  3957. #+BEGIN_SRC: bash
  3958. <Directory /var/www/mydomainname.com/htdocs/owncloud>
  3959. Options Indexes FollowSymLinks MultiViews
  3960. AllowOverride All
  3961. Order allow,deny
  3962. allow from all
  3963. </Directory>
  3964. #+END_SRC
  3965. To ensure that nobody logs in insecurely add the following to the 80 VirtualHost section.
  3966. #+BEGIN_SRC: bash
  3967. <Directory /var/www/mydomainname.com/htdocs/owncloud>
  3968. deny from all
  3969. </Directory>
  3970. #+END_SRC
  3971. Save and exit, then restart apache.
  3972. #+BEGIN_SRC: bash
  3973. service apache2 restart
  3974. #+END_SRC
  3975. Download owncloud.
  3976. #+BEGIN_SRC: bash
  3977. cd /tmp
  3978. wget http://freedombone.uk.to/owncloud.tar.bz2
  3979. #+END_SRC
  3980. Verify the download:
  3981. #+BEGIN_SRC: bash
  3982. sha256sum owncloud.tar.bz2
  3983. 92b53fdfa7c4165b83dd2f8447f63928454a5815d08ff2d6165dd1a8969ecbe1 owncloud.tar.bz2
  3984. #+END_SRC
  3985. Extract the archive. This may take a couple of minutes, so don't be alarmed that the system has crashed.
  3986. #+BEGIN_SRC: bash
  3987. export HOSTNAME=mydomainname.com
  3988. tar -xjf owncloud.tar.bz2
  3989. #+END_SRC
  3990. Move the extracted files to your site and set file permissions.
  3991. #+BEGIN_SRC: bash
  3992. cp -r owncloud /var/www/$HOSTNAME/htdocs
  3993. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/apps
  3994. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/config
  3995. chown www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud
  3996. #+END_SRC
  3997. Edit the htaccess file for Owncloud.
  3998. #+BEGIN_SRC: bash
  3999. editor /var/www/$HOSTNAME/htdocs/owncloud/.htaccess
  4000. #+END_SRC
  4001. Set the following.
  4002. #+BEGIN_SRC: bash
  4003. php_value upload_max_filesize 512M
  4004. php_value post_max_size 512M
  4005. php_value memory_limit 32M
  4006. #+END_SRC
  4007. Save and exit.
  4008. With a web browser visit your domain (mydomainname.com/owncloud) and enter an administrator username and password.
  4009. *** Owncloud on Android
  4010. 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.
  4011. ** Install a Wiki
  4012. #+BEGIN_VERSE
  4013. /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./
  4014. -- Tom Barbalet
  4015. #+END_VERSE
  4016. Dokuwiki is based upon flat files, and so is easy to move from one server to another without a lot of database complications.
  4017. Download the wiki.
  4018. #+BEGIN_SRC: bash
  4019. cd /tmp
  4020. wget http://freedombone.uk.to/dokuwiki.tgz
  4021. #+END_SRC
  4022. Verify it.
  4023. #+BEGIN_SRC: bash
  4024. sha256sum dokuwiki.tgz
  4025. 6b126f90979463d9ddaa74acc6f96aa230cfdc789946f241c3646086d9574be8 dokuwiki.tgz
  4026. #+END_SRC
  4027. Then extract and install it.
  4028. #+BEGIN_SRC: bash
  4029. export HOSTNAME=mywikidomainname.com
  4030. tar -xzvf dokuwiki.tgz
  4031. mv /var/www/$HOSTNAME/htdocs /var/www/$HOSTNAME/htdocs_old
  4032. mv dokuwiki /var/www/$HOSTNAME/htdocs
  4033. #+END_SRC
  4034. Edit the Apache configuration for your wiki site.
  4035. #+BEGIN_SRC: bash
  4036. editor /etc/apache2/sites-available/$HOSTNAME
  4037. #+END_SRC
  4038. The settings should look something like the following. Replace /mywikidomainname.com/ with your wiki domain name.
  4039. #+BEGIN_SRC: bash
  4040. <VirtualHost *:80>
  4041. ServerAdmin myusername@mywikidomainname.com
  4042. ServerName mydomainname.com
  4043. DocumentRoot /var/www/mywikidomainname.com/htdocs
  4044. <Directory /var/www/mywikidomainname.com/htdocs>
  4045. order deny,allow
  4046. allow from all
  4047. </Directory>
  4048. <LocationMatch "/(data|conf|bin|inc)/">
  4049. order allow,deny
  4050. deny from all
  4051. satisfy all
  4052. </LocationMatch>
  4053. <Directory />
  4054. Options FollowSymLinks
  4055. AllowOverride All
  4056. </Directory>
  4057. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  4058. <Directory "/usr/lib/cgi-bin">
  4059. AllowOverride All
  4060. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  4061. Order allow,deny
  4062. Allow from all
  4063. </Directory>
  4064. ErrorLog ${APACHE_LOG_DIR}/error.log
  4065. # Possible values include: debug, info, notice, warn, error, crit,
  4066. # alert, emerg.
  4067. LogLevel error
  4068. CustomLog ${APACHE_LOG_DIR}/access.log combined
  4069. </VirtualHost>
  4070. <IfModule mod_ssl.c>
  4071. <VirtualHost *:443>
  4072. ServerAdmin myusername@mywikidomainname.com
  4073. ServerName mywikidomainname.com
  4074. DocumentRoot /var/www/mywikidomainname.com/htdocs
  4075. <Directory /var/www/mywikidomainname.com/htdocs>
  4076. order deny,allow
  4077. allow from all
  4078. </Directory>
  4079. <LocationMatch "/(data|conf|bin|inc)/">
  4080. order allow,deny
  4081. deny from all
  4082. satisfy all
  4083. </LocationMatch>
  4084. <Directory />
  4085. Options FollowSymLinks
  4086. AllowOverride All
  4087. </Directory>
  4088. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  4089. <Directory "/usr/lib/cgi-bin">
  4090. AllowOverride All
  4091. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  4092. Order allow,deny
  4093. Allow from all
  4094. </Directory>
  4095. ErrorLog ${APACHE_LOG_DIR}/error.log
  4096. # Possible values include: debug, info, notice, warn, error, crit,
  4097. # alert, emerg.
  4098. LogLevel error
  4099. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  4100. # SSL Engine Switch:
  4101. # Enable/Disable SSL for this virtual host.
  4102. SSLEngine on
  4103. # A self-signed certificate
  4104. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  4105. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  4106. # Options based on bettercrypto.org
  4107. SSLProtocol All -SSLv2 -SSLv3
  4108. SSLHonorCipherOrder On
  4109. SSLCompression off
  4110. 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
  4111. # SSL Engine Options:
  4112. # Set various options for the SSL engine.
  4113. # o FakeBasicAuth:
  4114. # Translate the client X.509 into a Basic Authorisation. This means that
  4115. # the standard Auth/DBMAuth methods can be used for access control. The
  4116. # user name is the `one line' version of the client's X.509 certificate.
  4117. # Note that no password is obtained from the user. Every entry in the user
  4118. # file needs this password: `xxj31ZMTZzkVA'.
  4119. # o ExportCertData:
  4120. # This exports two additional environment variables: SSL_CLIENT_CERT and
  4121. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  4122. # server (always existing) and the client (only existing when client
  4123. # authentication is used). This can be used to import the certificates
  4124. # into CGI scripts.
  4125. # o StdEnvVars:
  4126. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  4127. # Per default this exportation is switched off for performance reasons,
  4128. # because the extraction step is an expensive operation and is usually
  4129. # useless for serving static content. So one usually enables the
  4130. # exportation for CGI and SSI requests only.
  4131. # o StrictRequire:
  4132. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  4133. # under a "Satisfy any" situation, i.e. when it applies access is denied
  4134. # and no other module can change it.
  4135. # o OptRenegotiate:
  4136. # This enables optimized SSL connection renegotiation handling when SSL
  4137. # directives are used in per-directory context.
  4138. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  4139. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  4140. SSLOptions +StdEnvVars
  4141. </FilesMatch>
  4142. <Directory /usr/lib/cgi-bin>
  4143. SSLOptions +StdEnvVars
  4144. </Directory>
  4145. # SSL Protocol Adjustments:
  4146. # The safe and default but still SSL/TLS standard compliant shutdown
  4147. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  4148. # the close notify alert from client. When you need a different shutdown
  4149. # approach you can use one of the following variables:
  4150. # o ssl-unclean-shutdown:
  4151. # This forces an unclean shutdown when the connection is closed, i.e. no
  4152. # SSL close notify alert is send or allowed to received. This violates
  4153. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  4154. # this when you receive I/O errors because of the standard approach where
  4155. # mod_ssl sends the close notify alert.
  4156. # o ssl-accurate-shutdown:
  4157. # This forces an accurate shutdown when the connection is closed, i.e. a
  4158. # SSL close notify alert is send and mod_ssl waits for the close notify
  4159. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  4160. # practice often causes hanging connections with brain-dead browsers. Use
  4161. # this only for browsers where you know that their SSL implementation
  4162. # works correctly.
  4163. # Notice: Most problems of broken clients are also related to the HTTP
  4164. # keep-alive facility, so you usually additionally want to disable
  4165. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  4166. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  4167. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  4168. # "force-response-1.0" for this.
  4169. BrowserMatch "MSIE [2-6]" \
  4170. nokeepalive ssl-unclean-shutdown \
  4171. downgrade-1.0 force-response-1.0
  4172. # MSIE 7 and newer should be able to use keepalive
  4173. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  4174. </VirtualHost>
  4175. </IfModule>
  4176. #+END_SRC
  4177. Enable your site with:
  4178. #+BEGIN_SRC: bash
  4179. a2ensite
  4180. #+END_SRC
  4181. then select the domain name and reload.
  4182. #+BEGIN_SRC: bash
  4183. service apache2 reload
  4184. #+END_SRC
  4185. and alter permissions:
  4186. #+BEGIN_SRC: bash
  4187. chmod -R 755 /var/www/$HOSTNAME/htdocs
  4188. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs
  4189. #+END_SRC
  4190. Open a browser and visit http://$HOSTNAME/install.php, then fill out the details. Once everything has been accepted without errors:
  4191. #+BEGIN_SRC: bash
  4192. rm /var/www/$HOSTNAME/htdocs/install.php
  4193. #+END_SRC
  4194. Add a few extra mime types:
  4195. #+BEGIN_SRC: bash
  4196. editor /var/www/$HOSTNAME/htdocs/conf/mime.conf
  4197. #+END_SRC
  4198. Append the following:
  4199. #+BEGIN_SRC: bash
  4200. ogv video/ogg
  4201. mp4 video/mp4
  4202. webm video/webm
  4203. #+END_SRC
  4204. Save and exit.
  4205. 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*.
  4206. Now you can visit your wiki and begin editing.
  4207. ** Install Bitmessage
  4208. #+BEGIN_VERSE
  4209. /The weakness of mass surveillance is that it can very easily be made much more expensive through changes in technical standards: pervasive, end-to-end encryption can quickly make indiscriminate surveillance impossible on a cost-effective basis/
  4210. -- Edward J. Snowden, testimony to the EU parliament
  4211. #+END_VERSE
  4212. *** A new kind of Email
  4213. [[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.
  4214. 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.
  4215. Installing Bitmessage as a daemon will increase the size of the network, and therefore the level of security for all users.
  4216. *** The Daemon
  4217. Install from the current source code.
  4218. #+BEGIN_SRC: bash
  4219. apt-get install python screen
  4220. cd /tmp
  4221. git clone https://github.com/Bitmessage/PyBitmessage.git
  4222. cd PyBitmessage
  4223. make install
  4224. #+END_SRC
  4225. Now create the daemon.
  4226. #+BEGIN_SRC: bash
  4227. editor /etc/init.d/pybitmessage
  4228. #+END_SRC
  4229. Add the following text:
  4230. #+BEGIN_SRC: bash
  4231. #!/bin/bash
  4232. # /etc/init.d/bitmessage
  4233. ### BEGIN INIT INFO
  4234. # Provides: pybitmessage
  4235. # Required-Start: $remote_fs $syslog
  4236. # Required-Stop: $remote_fs $syslog
  4237. # Default-Start: 2 3 4 5
  4238. # Default-Stop: 0 1 6
  4239. # Short-Description: starts bitmessage as a background daemon, suitable for servers
  4240. # Description: This file should be used to construct scripts to be
  4241. # placed in /etc/init.d.
  4242. ### END INIT INFO
  4243. # Author: Super-Nathan <BM-Gu2k3Wy2hpTMYBxSoM2937SPcuU6xzEj>
  4244. #Settings
  4245. SERVICE='pybitmessage'
  4246. LOGFILE='/dev/null' # this disables logging
  4247. # LOGFILE='/var/log/bitmessage.log' # comment out the above line and un-comment this line to save a log
  4248. COMMAND="python bitmessagemain.py > $LOGFILE"
  4249. USERNAME='bitmsg'
  4250. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  4251. HISTORY=1024
  4252. PBM_LOCATION="/usr/local/share/pybitmessage"
  4253. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4254. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin:/usr/local/share/pybitmessage'
  4255. bm_start() {
  4256. echo "Starting $SERVICE..."
  4257. cd ${PBM_LOCATION}
  4258. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4259. }
  4260. bm_stop() {
  4261. echo "Stopping $SERVICE"
  4262. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  4263. }
  4264. #Start-Stop here
  4265. case "$1" in
  4266. start)
  4267. bm_start
  4268. ;;
  4269. stop)
  4270. bm_stop
  4271. ;;
  4272. restart)
  4273. bm_stop
  4274. sleep 60s
  4275. bm_start
  4276. ;;
  4277. *)
  4278. echo "Usage: $0 {start|stop|restart}"
  4279. exit 1
  4280. ;;
  4281. esac
  4282. exit 0
  4283. #+END_SRC
  4284. Save and exit.
  4285. 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.
  4286. #+BEGIN_SRC: bash
  4287. adduser bitmsg
  4288. #+END_SRC
  4289. Create a /keys.dat/ file which is used to configure Bitmessage.
  4290. #+BEGIN_SRC: bash
  4291. mkdir /home/bitmsg/.config
  4292. mkdir /home/bitmsg/.config/PyBitmessage
  4293. editor /home/bitmsg/.config/PyBitmessage/keys.dat
  4294. #+END_SRC
  4295. Add the following:
  4296. #+BEGIN_SRC: bash
  4297. [bitmessagesettings]
  4298. settingsversion = 8
  4299. port = 8444
  4300. timeformat = %%a, %%d %%b %%Y %%I:%%M %%p
  4301. blackwhitelist = black
  4302. startonlogon = False
  4303. minimizetotray = False
  4304. showtraynotifications = True
  4305. startintray = False
  4306. socksproxytype = none
  4307. sockshostname = localhost
  4308. socksport = 9050
  4309. socksauthentication = False
  4310. sockslisten = False
  4311. socksusername =
  4312. sockspassword =
  4313. keysencrypted = false
  4314. messagesencrypted = false
  4315. defaultnoncetrialsperbyte = 640
  4316. defaultpayloadlengthextrabytes = 14000
  4317. minimizeonclose = false
  4318. maxacceptablenoncetrialsperbyte = 0
  4319. maxacceptablepayloadlengthextrabytes = 0
  4320. userlocale = system
  4321. useidenticons = True
  4322. identiconsuffix = re9E9UtSEaWD
  4323. replybelow = False
  4324. stopresendingafterxdays = 4
  4325. stopresendingafterxmonths =
  4326. namecoinrpctype = namecoind
  4327. namecoinrpchost = localhost
  4328. namecoinrpcuser =
  4329. namecoinrpcpassword =
  4330. namecoinrpcport = 8336
  4331. sendoutgoingconnections = True
  4332. willinglysendtomobile = False
  4333. daemon = true
  4334. #+END_SRC
  4335. Save and exit. Then enable the daemon and run it.
  4336. #+BEGIN_SRC: bash
  4337. rm -f /tmp/-usr-local-share-pybitmessage-*.lock
  4338. chown -R bitmsg:bitmsg /home/bitmsg
  4339. chmod +x /etc/init.d/pybitmessage
  4340. update-rc.d pybitmessage defaults
  4341. service pybitmessage start
  4342. #+END_SRC
  4343. Now open port 8444 on your internet router or firewall and direct it to the BBB.
  4344. *** Using Bitmessage
  4345. 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.
  4346. 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:
  4347. #+BEGIN_SRC: bash
  4348. cd /tmp
  4349. git clone https://github.com/Bitmessage/PyBitmessage.git
  4350. cd PyBitmessage
  4351. make install
  4352. pybitmessage
  4353. #+END_SRC
  4354. ** Overcome restrictive environments
  4355. #+BEGIN_VERSE
  4356. /Censorship reflects a society's lack of confidence in itself. It is a hallmark of an authoritarian regime./
  4357. -- Potter Stewart
  4358. #+END_VERSE
  4359. 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.
  4360. 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.
  4361. #+BEGIN_SRC: bash
  4362. apt-get install shellinabox libapache2-mod-proxy-html
  4363. #+END_SRC
  4364. Update your Apache configuration.
  4365. #+BEGIN_SRC: bash
  4366. export HOSTNAME=mydomainname.com
  4367. editor /etc/apache2/sites-available/$HOSTNAME
  4368. #+END_SRC
  4369. Within the section which begins with *<VirtualHost *:443>* add the following, replacing /mydomainname.com/ with your domain name and /myusername/ with your username.
  4370. #+BEGIN_SRC: bash
  4371. <Location /shell>
  4372. ProxyPass http://localhost:4200/
  4373. Order allow,deny
  4374. Allow from all
  4375. AuthName "Authentication for shellinabox"
  4376. AuthUserFile /home/mydomainname.com/public_html/.htpasswd
  4377. AuthGroupFile /home/mydomainname.com/public_html/.htgroup
  4378. AuthType Basic
  4379. Require group shellinabox
  4380. Require user myusername
  4381. </Location>
  4382. #+END_SRC
  4383. 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.
  4384. #+BEGIN_SRC: bash
  4385. mkdir /home/$HOSTNAME
  4386. mkdir /home/$HOSTNAME/public_html
  4387. htpasswd -c /home/$HOSTNAME/public_html/.htpasswd myusername
  4388. #+END_SRC
  4389. Create a user group.
  4390. #+BEGIN_SRC: bash
  4391. editor /home/$HOSTNAME/public_html/.htgroup
  4392. #+END_SRC
  4393. Add the following:
  4394. #+BEGIN_SRC: bash
  4395. shellinabox: myusername
  4396. #+END_SRC
  4397. Save and exit, then restart Apache.
  4398. #+BEGIN_SRC: bash
  4399. a2enmod proxy_http
  4400. service apache2 restart
  4401. #+END_SRC
  4402. Now with a web browser navigate to https://mydomainname.com/shell and log in.
  4403. 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/.
  4404. ** Set up a mailing list
  4405. #+BEGIN_VERSE
  4406. /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./
  4407. -- Jono Bacon
  4408. #+END_VERSE
  4409. *** Public mailing list
  4410. 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.
  4411. **** Installation
  4412. #+BEGIN_SRC: bash
  4413. export HOSTNAME=mydomainname.com
  4414. apt-get install mailman
  4415. newlist mailman
  4416. #+END_SRC
  4417. Enter an email address for the list administrator and a password.
  4418. #+BEGIN_SRC: bash
  4419. editor /etc/mailman/mm_cfg.py
  4420. #+END_SRC
  4421. Set *MTA=None* and change *http:* to *https:*, then save and exit.
  4422. Add some settings.
  4423. #+BEGIN_SRC: bash
  4424. editor /etc/exim4/conf.d/main/04_mailman_options
  4425. #+END_SRC
  4426. Add the following, replacing /mydomainname.com/ with your domain name.
  4427. #+BEGIN_SRC: bash
  4428. # Mailman macro definitions
  4429. # Home dir for the Mailman installation
  4430. MM_HOME=/var/lib/mailman
  4431. # User and group for Mailman
  4432. MM_UID=list
  4433. MM_GID=list
  4434. #
  4435. # Domains that your lists are in - colon separated list
  4436. # you may wish to add these into local_domains as well
  4437. domainlist mm_domains=mydomainname.com
  4438. # The path of the Mailman mail wrapper script
  4439. MM_WRAP=MM_HOME/mail/mailman
  4440. #
  4441. # The path of the list config file (used as a required file when
  4442. # verifying list addresses)
  4443. MM_LISTCHK=MM_HOME/lists/${lc::$local_part}/config.pck
  4444. #+END_SRC
  4445. Save and exit.
  4446. #+BEGIN_SRC: bash
  4447. editor /etc/exim4/conf.d/main/000_localmacros
  4448. #+END_SRC
  4449. Append the following:
  4450. #+BEGIN_SRC: bash
  4451. SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe
  4452. SYSTEM_ALIASES_USER = list
  4453. SYSTEM_ALIASES_GROUP = list
  4454. #+END_SRC
  4455. Save and exit.
  4456. #+BEGIN_SRC: bash
  4457. editor /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
  4458. #+END_SRC
  4459. Append the following, before the final /accept/:
  4460. #+BEGIN_SRC: bash
  4461. # Do callback verification unless Mailman incoming bounce
  4462. deny !local_parts = *-bounces : *-bounces+*
  4463. !verify = sender/callout=30s,defer_ok
  4464. #+END_SRC
  4465. Save and exit.
  4466. #+BEGIN_SRC: bash
  4467. editor
  4468. /etc/exim4/conf.d/router/450_exim4-config_mailman_aliases
  4469. #+END_SRC
  4470. Add the following:
  4471. #+BEGIN_SRC: bash
  4472. mailman:
  4473. driver = accept
  4474. domains = +mm_domains
  4475. require_files = MM_LISTCHK
  4476. local_part_suffix_optional
  4477. local_part_suffix = -admin : \
  4478. -bounces : -bounces+* : \
  4479. -confirm : -confirm+* : \
  4480. -join : -leave : \
  4481. -owner : -request : \
  4482. -subscribe : -unsubscribe
  4483. transport = mailman_transport
  4484. #+END_SRC
  4485. Save and exit.
  4486. #+BEGIN_SRC: bash
  4487. editor /etc/exim4/conf.d/transport/40_exim4-config_mailman_pipe
  4488. #+END_SRC
  4489. Add the following:
  4490. #+BEGIN_SRC: bash
  4491. mailman_transport:
  4492. driver = pipe
  4493. command = MM_WRAP \
  4494. '${if def:local_part_suffix \
  4495. {${sg{$local_part_suffix}{-(\\w+)(\\+.*)?}{\$1}}} \
  4496. {post}}' \
  4497. $local_part
  4498. current_directory = MM_HOME
  4499. home_directory = MM_HOME
  4500. user = MM_UID
  4501. group = MM_GID
  4502. #+END_SRC
  4503. Save and exit.
  4504. #+BEGIN_SRC: bash
  4505. chown root:list /var/lib/mailman/mail/mailman
  4506. update-exim4.conf.template -r
  4507. update-exim4.conf
  4508. service exim4 restart
  4509. editor /etc/apache2/conf.d/mailman
  4510. #+END_SRC
  4511. Add the following:
  4512. #+BEGIN_SRC: bash
  4513. Alias /pipermail /var/lib/mailman/archives/public
  4514. Alias /images/mailman /usr/share/images/mailman
  4515. <directory /var/lib/mailman/archives/public>
  4516. DirectoryIndex index.html
  4517. </directory>
  4518. #+END_SRC
  4519. Save and exit.
  4520. #+BEGIN_SRC: bash
  4521. editor /etc/apache2/sites-available/$HOSTNAME
  4522. #+END_SRC
  4523. Add the following to the 443 section.
  4524. #+BEGIN_SRC: bash
  4525. <Location /mailman>
  4526. Options Indexes FollowSymLinks MultiViews
  4527. Order allow,deny
  4528. Allow from all
  4529. RedirectMatch ^/$ /cgi-bin/mailman/listinfo
  4530. </Location>
  4531. #+END_SRC
  4532. Save and exit.
  4533. #+BEGIN_SRC: bash
  4534. service apache2 restart
  4535. #+END_SRC
  4536. Now add your mailing list. The list name should not include any spaces.
  4537. #+BEGIN_SRC: bash
  4538. newlist mymailinglistname
  4539. #+END_SRC
  4540. With a browser visit https://$HOSTNAME/cgi-bin/mailman/admin/mymailinglistname to configure the mailing list.
  4541. Under *General Options* add an email address for a moderator (could be the same as the administrator) and click *Submit your changes*.
  4542. Under *Privacy Options* set steps required for subscription to *Confirm and approve* and click *Submit your changes*.
  4543. Also change these settings for the account within https://$HOSTNAME/cgi-bin/mailman/admin/mailman
  4544. Then to test that the mailing list works:
  4545. #+BEGIN_SRC: bash
  4546. exim -d+route -bt mymailinglistname@$HOSTNAME
  4547. #+END_SRC
  4548. If everything is working then this shouldn't show any problems.
  4549. **** Using the mailing list
  4550. Direct subscribers towards:
  4551. #+BEGIN_SRC: bash
  4552. https://mydomainname.com/cgi-bin/mailman/listinfo/mymailinglistname
  4553. #+END_SRC
  4554. To administrate the list visit:
  4555. #+BEGIN_SRC: bash
  4556. https://mydomainname.com/cgi-bin/mailman/admin/mymailinglistname
  4557. #+END_SRC
  4558. To add another mailing list:
  4559. #+BEGIN_SRC: bash
  4560. newlist mymailinglistname
  4561. #+END_SRC
  4562. To delete a mailing list:
  4563. #+BEGIN_SRC: bash
  4564. rmlist -a mymailinglistname
  4565. #+END_SRC
  4566. *** Private (encrypted) mailing list
  4567. In addition to conventional public email lists it's also possible to set up a private mailing list which is only readable by members. A private email list uses [[https://en.wikipedia.org/wiki/GNU_Privacy_Guard][GPG]] and a public/private key pair for the server which can then be used to send emails to the list in an encrypted form. The email addresses and public GPG keys of members may be added to the list so that any new messages can be distributed to them in a secure manner.
  4568. Private mailing lists are likely to be able to keep the contents of the discussion out of the clutches of warrantless mass surveillance but, as with all conventional email, it won't prevent such systems from generating social graphs of who is communicating with the list since the /from/ and /to/ attributes are always transmitted in the clear.
  4569. **** Installation
  4570. #+BEGIN_SRC: bash
  4571. apt-get install schleuder
  4572. #+END_SRC
  4573. Edit the configuration:
  4574. #+BEGIN_SRC: bash
  4575. editor /etc/schleuder/schleuder.conf
  4576. #+END_SRC
  4577. Set the following parameters, replacing /mydomainname.com/ with your domain name:
  4578. #+BEGIN_SRC: bash
  4579. smtp_port: 465
  4580. superadminaddr: root@mydomainname.com
  4581. #+END_SRC
  4582. Save and exit.
  4583. Get your GPG public key, replacing /myGPGkeyID/ with your GPG key ID:
  4584. #+BEGIN_SRC: bash
  4585. export MYKEYID=myGPGkeyID
  4586. gpg --search-keys $MYKEYID
  4587. gpg --output /tmp/mypublickey.txt --armor --export $MYKEYID
  4588. #+END_SRC
  4589. Then to create a mailing list, replacing /mydomainname.com/ with your domain name, /myusername/ with your username and /mailinglistname/ with the name of the mailing list. /mailinglistname/ should be all one word, with no spaces.
  4590. #+BEGIN_SRC: bash
  4591. export MAILINGLISTNAME=mailinglistname
  4592. export MYUSERNAME=myusername
  4593. export HOSTNAME=mydomainname.com
  4594. export EMAILADDRESS=$MYUSERNAME@$HOSTNAME
  4595. schleuder-newlist $MAILINGLISTNAME@$HOSTNAME -realname "mailing list name" -adminaddress $EMAILADDRESS -initmember $EMAILADDRESS -initmemberkey /tmp/mypublickey.txt -nointeractive
  4596. #+END_SRC
  4597. Now add a mailing list rule:
  4598. #+BEGIN_SRC: bash
  4599. emailrule $MYUSERNAME $MAILINGLISTNAME@$HOSTNAME $MAILINGLISTNAME
  4600. #+END_SRC
  4601. Edit your Mutt configuration.
  4602. #+BEGIN_SRC: bash
  4603. editor /home/$MYUSERNAME/.muttrc
  4604. #+END_SRC
  4605. Search for the /mailboxes/ parameter and add "=mailinglistname". For example:
  4606. #+BEGIN_SRC: bash
  4607. mailboxes = =Sent =Drafts =mailinglistname
  4608. #+END_SRC
  4609. Save and exit.
  4610. Update Exim routing.
  4611. #+BEGIN_SRC: bash
  4612. editor /etc/exim4/conf.d/router/550_exim4-config_schleuder
  4613. #+END_SRC
  4614. Add the following:
  4615. #+BEGIN_SRC: bash
  4616. schleuder:
  4617. debug_print = "R: schleuder for $local_part@$domain"
  4618. driver = accept
  4619. local_part_suffix_optional
  4620. local_part_suffix = +* : -bounce : -sendkey
  4621. domains = +local_domains
  4622. user = schleuder
  4623. group = schleuder
  4624. require_files = schleuder:+/var/lib/schleuder/$domain/${local_part}
  4625. transport = schleuder_transport
  4626. #+END_SRC
  4627. Save and exit.
  4628. #+BEGIN_SRC: bash
  4629. editor /etc/exim4/conf.d/transport/30_exim4-config_schleuder
  4630. #+END_SRC
  4631. Add the following.
  4632. #+BEGIN_SRC: bash
  4633. schleuder_transport:
  4634. debug_print = "T: schleuder_transport for $local_part@$domain"
  4635. driver = pipe
  4636. home_directory = "/var/lib/schleuder/$domain/$local_part"
  4637. command = "/usr/bin/schleuder $local_part@$domain"
  4638. #+END_SRC
  4639. Save and exit.
  4640. #+BEGIN_SRC: bash
  4641. chown -R schleuder:schleuder /var/lib/schleuder
  4642. update-exim4.conf.template -r
  4643. update-exim4.conf
  4644. service exim4 restart
  4645. useradd -d /var/schleuderlists -s /bin/false schleuder
  4646. adduser Debian-exim schleuder
  4647. usermod -a -G mail schleuder
  4648. #+END_SRC
  4649. Test the routing.
  4650. #+BEGIN_SRC: bash
  4651. exim -d -bt mailinglistname@mydomainname.com
  4652. #+END_SRC
  4653. **** Importing the public key of the mailing list
  4654. Before you can use the mailing list you will first need to import its public key. How you do this depends upon which email client you're using.
  4655. ***** Using Mutt
  4656. Send an email to /mailinglistname-sendkey@mydomainname.com/ to have the list public key emailed to you.
  4657. When you receive the email open it and press *CTRL-k* to import it.
  4658. ***** Using Thunderbird
  4659. Send an email to /mailinglistname-sendkey@mydomainname.com/ to have the list public key emailed to you.
  4660. When you receive the email open it, select all the text with *CTRL-a* then *CTRL-c*.
  4661. On the menu select *OpenPGP* followed by *Key Management*.
  4662. You will now see a new menu bar. Select *Edit* followed by *Import keys from clipboard*.
  4663. Click on *Import* followed by *Ok*.
  4664. **** Using the list
  4665. To obtain the public keys of list members send an email to /mailinglistname-request@mydomainname.com/ containing *X-LIST-KEYS* in the message body.
  4666. To add a member: *X-ADD-MEMBER: othermember@otherdomain.net*
  4667. An example of adding a public key to the list:
  4668. #+BEGIN_SRC: bash
  4669. X-ADD-KEY:
  4670. -----BEGIN PGP PUBLIC KEY BLOCK-----
  4671. Version: GnuPG v1.4.9 (GNU/Linux)
  4672. mQGiBEjVO7oRBADQvT6wtD2IzzIiK0NbrcilCKCp4MWb8cYXTXguwPQI6y0Nerz4
  4673. dsK6J0X1Vgeo02tqA4xd3EDK8rdqL2yZfl/2egH8+85R3gDk+kqkfEp4pwCgp6VO
  4674. [...]
  4675. pNlF/qkaWwRb048h+iMrW21EkouLKTDPFkdFbapV2X5KJZIcfhO1zEbwc1ZKF3Ju
  4676. Q9X5GRmY62hz9SCZnsC0jeYAni8OUQV9NXfXlS/vePBUnOL08NQB
  4677. =xTv3
  4678. -----END PGP PUBLIC KEY BLOCK-----
  4679. #+END_SRC
  4680. To get details for a member: *X-GET-MEMBER: othermember@otherdomain.net*
  4681. To delete a member: *X-DELETE-MEMBER: othermember@otherdomain.net*
  4682. To delete a public key: *X-DELETE-KEY: keyID*
  4683. You can unsubscribe from the list with *X-UNSUBSCRIBE* in the message body.
  4684. *** Decentralised mailing list
  4685. A disadvantage with encrypted mailing lists which use the conventional email system is that there is a single server on which the list resides, and this creates a single point of failure and a bandwidth bottleneck for more heavily subscribed lists. If the mailing list server goes down for whatever reason then that may cause a lot of disruption to its users.
  4686. An alternative is to use a decentralised mailing list, implemented using Bitmessage. 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/".
  4687. With Bitmessage if any one computer goes offline then the conversation can still keep going since there is no central mailing list server. Bitmessages are also encrypted with public/private key pairs and the manner in which the system operates makes it very difficult for the surveillance apparatus to exfiltrate the social graph of list users.
  4688. On a Debian based system:
  4689. #+BEGIN_SRC: bash
  4690. sudo apt-get install makepasswd
  4691. #+END_SRC
  4692. or on an RPM based system:
  4693. #+BEGIN_SRC: bash
  4694. sudo yum install makepasswd
  4695. #+END_SRC
  4696. Create a name for your mailing list. This will be a random string.
  4697. #+BEGIN_SRC: bash
  4698. makepasswd -c 40
  4699. #+END_SRC
  4700. Keep a note of this.
  4701. Run the Bitmessage client and on the menu select *File/Join-Create Chan/Create new chan*
  4702. 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.
  4703. 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.
  4704. 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.
  4705. 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.
  4706. ** Install a microblog
  4707. #+BEGIN_VERSE
  4708. /If you want to have more control over how you interact on the web, and regain your freedom, privacy and autonomy from outside interference, you need to start moving towards using programs like GNU Social/
  4709. -- Jason Self
  4710. #+END_VERSE
  4711. For a microblog you will need a separate domain/subdomain, so see [[Setting up a web site]] for details of how to create an Apache configuration for your microblog. If you're using freedns then you will need to create a new subdomain.
  4712. Install some dependencies:
  4713. #+BEGIN_SRC: bash
  4714. apt-get install php5-xcache php-gettext php5-curl php5-gd php5-mysql
  4715. #+END_SRC
  4716. Download GNU Social
  4717. #+BEGIN_SRC: bash
  4718. cd /tmp
  4719. wget http://freedombone.uk.to/gnu-social.tar.gz
  4720. #+END_SRC
  4721. Verify it.
  4722. #+BEGIN_SRC: bash
  4723. sha256sum gnu-social.tar.gz
  4724. 1f886241c7f1a175e7be3cccbcb944ab6c03617fb75aefa4d62d37abed87d2b4
  4725. #+END_SRC
  4726. Extract the files and set permissions on them, where /mydomainname.com/ is your domain name.
  4727. #+BEGIN_SRC: bash
  4728. export HOSTNAME=mydomainname.com
  4729. tar zxf gnu-social.tar.gz
  4730. rm -rf /var/www/$HOSTNAME/htdocs
  4731. mv statusnet-gnu-social /var/www/$HOSTNAME/htdocs
  4732. chmod a+w /var/www/$HOSTNAME/htdocs
  4733. chown www-data:www-data /var/www/$HOSTNAME/htdocs
  4734. chmod a+w /var/www/$HOSTNAME/htdocs/avatar
  4735. chmod a+w /var/www/$HOSTNAME/htdocs/background
  4736. chmod a+w /var/www/$HOSTNAME/htdocs/file
  4737. chmod +x /var/www/$HOSTNAME/htdocs/scripts/maildaemon.php
  4738. #+END_SRC
  4739. Edit the Apache access settings.
  4740. #+BEGIN_SRC: bash
  4741. editor /var/www/$HOSTNAME/htdocs/.htaccess
  4742. #+END_SRC
  4743. Add the following:
  4744. #+BEGIN_SRC: bash
  4745. <IfModule mod_rewrite.c>
  4746. RewriteEngine On
  4747. RewriteBase /
  4748. ## Uncomment these if having trouble with API authentication
  4749. ## when PHP is running in CGI or FastCGI mode.
  4750. #
  4751. #RewriteCond %{HTTP:Authorization} ^(.*)
  4752. #RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
  4753. RewriteCond %{REQUEST_FILENAME} !-f
  4754. RewriteCond %{REQUEST_FILENAME} !-d
  4755. RewriteRule (.*) index.php?p=$1 [L,QSA]
  4756. </IfModule>
  4757. <FilesMatch "\.(ini)">
  4758. Order allow,deny
  4759. </FilesMatch>
  4760. #+END_SRC
  4761. Save and exit, then create a database.
  4762. #+BEGIN_SRC: bash
  4763. mysql -u root -p
  4764. create database gnusocial;
  4765. CREATE USER 'gnusocialadmin'@'localhost' IDENTIFIED BY 'gnusocialpassword';
  4766. GRANT ALL PRIVILEGES ON gnusocial.* TO 'gnusocialadmin'@'localhost';
  4767. quit
  4768. #+END_SRC
  4769. Add the mailer script to the aliases file:
  4770. #+BEGIN_SRC: bash
  4771. editor /etc/aliases
  4772. #+END_SRC
  4773. Add the following, replacing /mydomainname.com/ with your domain name.
  4774. #+BEGIN_SRC: bash
  4775. www-data: root
  4776. *: /var/www/mydomainname.com/htdocs/scripts/maildaemon.php
  4777. #+END_SRC
  4778. Save and exit. Update the aliases by typing:
  4779. #+BEGIN_SRC: bash
  4780. newaliases
  4781. #+END_SRC
  4782. Then with a web browser navigate to:
  4783. https://$HOSTNAME/install.php
  4784. Set a name for the site.
  4785. Server SSL: enable
  4786. Hostname: localhost
  4787. Type: MySql
  4788. Name: gnusocial
  4789. DB username: gnusocialadmin
  4790. DB Password; your gnu social admin password goes here
  4791. Administrator nickname: myusername
  4792. Administrator password: mylongrandompassword
  4793. Subscribe to announcements: ticked
  4794. Site profile: Community
  4795. Press the *Submit* button. It may take a few minutes, so don't be concerned that it has crashed. When the process completes you will see a lot of "Strict standards" warnings which you can ignore.
  4796. Navigate to http://$HOSTNAME/gnusocial and you can then complete the configuration via the *Admin* section on the header bar. Some recommended admin settings are:
  4797. Under the *Site* settings:
  4798. Text limit: 140
  4799. Dupe Limit: 60000
  4800. Under the *User* settings:
  4801. Bio limit: 1000
  4802. Under the *Access* settings:
  4803. /Invite only/ ticked
  4804. Under the License section select a license if you wish. Details for Creative Commons licenses [[https://creativecommons.org/licenses/][can be found here]]. If you only intend to do private microblogging then just leave these settings as they are.
  4805. If you want to invite more users then click on the big button *Invite more colleagues*, then enter their email addresses and hit the *send* button. The invite only configuration which you've just installed is useful because it prevents spammers, or other [[https://en.wikipedia.org/wiki/Joint_Threat_Research_Intelligence_Group]["bad actors"]], from clogging your system with nonsense.
  4806. Edit the config file.
  4807. #+BEGIN_SRC: bash
  4808. editor /var/www/$HOSTNAME/htdocs/config.php
  4809. #+END_SRC
  4810. Change the ssl setting from *always* to *sometimes*, hten save and exit.
  4811. So, you're now microblogging on the open web, with no companies in the middle. Congratulations! To find some other people to connect to you can try searching other nodes listed at http://gnu.io/try/
  4812. When following other GNU Social users enter the URL of your profile. For example, https://mygnusocialdomain/myusername
  4813. ** Install Mediagoblin
  4814. #+BEGIN_VERSE
  4815. /The silos that are the main current points of media sharing are not only vulnerable to attacks on free speech, but also hamper important grassroots economic activity by privileging the interests of a tiny minority over those of most of the world./
  4816. #+END_VERSE
  4817. Mediagoblin allows you to have a YouTube/Soundcloud/Flickr/Picasa type of site to share your pictures, videos or audio files. An advantage of not having any company in the middle is that you can't be arbitrarily censored without any explanation, as seems to frequently occur on YouTube. It is recommended that you use media formats which are not encumbered by patents, such as /ogg/ or /ogv/.
  4818. For a mediagoblin site it is recommended to use a separate domain/subdomain, so see [[Setting up a web site]] for details of how to create an Apache configuration for your microblog. If you're using freedns then you will need to create a new subdomain.
  4819. Install some dependencies.
  4820. #+BEGIN_SRC: bash
  4821. apt-get install git-core python python-dev python-lxml python-imaging python-virtualenv python-gst0.10 libjpeg8-dev sqlite3 libapache2-mod-fcgid gstreamer0.10-plugins-base gstreamer0.10-plugins-bad gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-ffmpeg python-numpy python-scipy libsndfile1-dev
  4822. #+END_SRC
  4823. Create a user, replacing /mymediagoblindomain/ with the domain name for your mediagoblin site.
  4824. #+BEGIN_SRC: bash
  4825. export HOSTNAME=mymediagoblindomain
  4826. adduser mediagoblin
  4827. #+END_SRC
  4828. Give the user a long random password.
  4829. #+BEGIN_SRC: bash
  4830. mkdir -p /srv/$HOSTNAME
  4831. chown -hR mediagoblin:mediagoblin /srv/$HOSTNAME
  4832. su - mediagoblin
  4833. export HOSTNAME=mymediagoblindomain
  4834. cd /srv/$HOSTNAME
  4835. git clone git://gitorious.org/mediagoblin/mediagoblin.git
  4836. cd mediagoblin
  4837. git submodule init
  4838. git submodule update
  4839. virtualenv --system-site-packages .
  4840. ./bin/python setup.py develop
  4841. ./bin/easy_install flup
  4842. cp mediagoblin.ini mediagoblin_local.ini
  4843. cp paste.ini paste_local.ini
  4844. editor mediagoblin_local.ini
  4845. #+END_SRC
  4846. Change *email_sender_address* to your email address and set *email_debug_mode* to false. Also append the following to the bottom of the file, under the *plugins* section.
  4847. #+BEGIN_SRC: bash
  4848. [[mediagoblin.media_types.audio]]
  4849. [[mediagoblin.media_types.video]]
  4850. [[mediagoblin.media_types.stl]]
  4851. #+END_SRC
  4852. Then save and exit.
  4853. #+BEGIN_SRC: bash
  4854. ./bin/pip install scikits.audiolab
  4855. ./bin/gmg dbupdate
  4856. exit # to go back to the root user
  4857. editor /etc/init.d/mediagoblin
  4858. #+END_SRC
  4859. Add the following, replacing /mymediagoblindomain/ with the domain name for your mediagoblin site.
  4860. #+BEGIN_SRC: bash
  4861. #!/bin/bash
  4862. # /etc/init.d/mediagoblin
  4863. ### BEGIN INIT INFO
  4864. # Provides: mediagoblin
  4865. # Required-Start: $remote_fs $syslog
  4866. # Required-Stop: $remote_fs $syslog
  4867. # Default-Start: 2 3 4 5
  4868. # Default-Stop: 0 1 6
  4869. # Short-Description: starts mediagoblin
  4870. # Description: Other methods may work, but I found this the easiest
  4871. ### END INIT INFO
  4872. # Author: Bob Mottram <bob@robotics.uk.to>
  4873. #Settings
  4874. SERVICE='mediagoblin'
  4875. LOGFILE='/srv/mymediagoblindomain/mediagoblin.log'
  4876. COMMAND="./lazyserver.sh > $LOGFILE"
  4877. USERNAME='mediagoblin'
  4878. NICELEVEL=15 # from 0-19 the bigger the number, the less the impact on system resources
  4879. HISTORY=1024
  4880. MG_LOCATION="/srv/mymediagoblindomain/mediagoblin"
  4881. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4882. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin'
  4883. mg_start() {
  4884. echo "Starting $SERVICE..."
  4885. cd ${MG_LOCATION}
  4886. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4887. }
  4888. mg_stop() {
  4889. echo "Stopping $SERVICE"
  4890. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  4891. }
  4892. #Start-Stop here
  4893. case "$1" in
  4894. start)
  4895. mg_start
  4896. ;;
  4897. stop)
  4898. mg_stop
  4899. ;;
  4900. restart)
  4901. mg_stop
  4902. sleep 10s
  4903. mg_start
  4904. ;;
  4905. *)
  4906. echo "Usage: $0 {start|stop|restart}"
  4907. exit 1
  4908. ;;
  4909. esac
  4910. exit 0
  4911. #+END_SRC
  4912. Save and exit.
  4913. #+BEGIN_SRC: bash
  4914. chmod +x /etc/init.d/mediagoblin
  4915. update-rc.d mediagoblin defaults
  4916. service mediagoblin start
  4917. #+END_SRC
  4918. Edit the Apache configuration for your mediagoblin site.
  4919. #+BEGIN_SRC: bash
  4920. editor /etc/apache2/sites-available/mymediagoblindomain
  4921. #+END_SRC
  4922. Delete the existing configuration (in Emacs it's CTRL-x h then CTRL-w) and paste the following, replacing /mymediagoblindomain/ with your mediagoblin domain name and /myusername@mydomainname.com/ with your email address.
  4923. #+BEGIN_SRC: bash
  4924. <VirtualHost *:80>
  4925. ServerAdmin myusername@mydomainname.com
  4926. DocumentRoot /srv/mymediagoblindomain/mediagoblin
  4927. ServerName mymediagoblindomain
  4928. <Directory />
  4929. Options FollowSymLinks
  4930. AllowOverride None
  4931. </Directory>
  4932. <Directory /srv/mymediagoblindomain/mediagoblin/>
  4933. Options Indexes FollowSymLinks MultiViews
  4934. AllowOverride All
  4935. Order allow,deny
  4936. allow from all
  4937. </Directory>
  4938. LogLevel warn
  4939. ProxyVia On
  4940. ProxyRequests off
  4941. ProxyPreserveHost on
  4942. ProxyPass / http://localhost:6543/
  4943. ErrorLog "/var/log/apache2/error.log"
  4944. CustomLog "/var/log/apache2/access.log" combined
  4945. RewriteEngine On
  4946. RewriteOptions Inherit
  4947. </VirtualHost>
  4948. #+END_SRC
  4949. Save and exit.
  4950. Now in a browser visit http://mymediagoblindomain and create a user. If you wish this to be a single user installation to prevent a lot of spammers signing up.
  4951. #+BEGIN_SRC: bash
  4952. editor /srv/mymediagoblindomain/mediagoblin/mediagoblin_local.ini
  4953. #+END_SRC
  4954. Then set:
  4955. #+BEGIN_SRC: bash
  4956. allow_registration = false
  4957. #+END_SRC
  4958. Save and exit.
  4959. ** Run a pastebin service
  4960. If you need to be able to share short text files or other kinds of files on a temporary basis (doing technical support or reporting a bug, for example) then it's useful to have a pastebin system running on your server.
  4961. For this you will need to set up a new subdomain and create a new Apache configuration. For details on how to do that see [[Getting onto the web]] and [[Setting up a web site]].
  4962. #+BEGIN_SRC: bash
  4963. adduser --disabled-login zerobin
  4964. cd /tmp
  4965. git clone https://github.com/sametmax/0bin.git
  4966. cd 0bin
  4967. python setup.py install
  4968. #+END_SRC
  4969. Now create the daemon.
  4970. #+BEGIN_SRC: bash
  4971. editor /etc/init.d/zerobin
  4972. #+END_SRC
  4973. Add the following text:
  4974. #+BEGIN_SRC: bash
  4975. #!/bin/bash
  4976. # /etc/init.d/zerobin
  4977. ### BEGIN INIT INFO
  4978. # Provides: zerobin
  4979. # Required-Start: $remote_fs $syslog
  4980. # Required-Stop: $remote_fs $syslog
  4981. # Default-Start: 2 3 4 5
  4982. # Default-Stop: 0 1 6
  4983. # Short-Description: starts zerobin as a background daemon
  4984. # Description: starts zerobin as a background daemon
  4985. ### END INIT INFO
  4986. # Author: Bob Mottram <bob@robotics.uk.to>
  4987. #Settings
  4988. SERVICE='zerobin'
  4989. LOGFILE='/home/zerobin/zerobin.log'
  4990. COMMAND="zerobin > $LOGFILE"
  4991. USERNAME='zerobin'
  4992. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  4993. HISTORY=1024
  4994. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4995. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  4996. zerobin_start() {
  4997. echo "Starting $SERVICE..."
  4998. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4999. }
  5000. zerobin_stop() {
  5001. echo "Stopping $SERVICE"
  5002. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  5003. }
  5004. #Start-Stop here
  5005. case "$1" in
  5006. start)
  5007. zerobin_start
  5008. ;;
  5009. stop)
  5010. zerobin_stop
  5011. ;;
  5012. restart)
  5013. zerobin_stop
  5014. sleep 2s
  5015. zerobin_start
  5016. ;;
  5017. *)
  5018. echo "Usage: $0 {start|stop|restart}"
  5019. exit 1
  5020. ;;
  5021. esac
  5022. exit 0
  5023. #+END_SRC
  5024. Save and exit.
  5025. #+BEGIN_SRC: bash
  5026. chmod +x /etc/init.d/zerobin
  5027. update-rc.d zerobin defaults
  5028. service zerobin start
  5029. #+END_SRC
  5030. Now edit the Apache configuration, delete anything which already exists and add the following, changing /mypastedomainname.com/ to your pastebin subdomain and /username@mydomainname.com/ to your email address:
  5031. #+BEGIN_SRC: bash
  5032. <VirtualHost *:80>
  5033. ServerAdmin username@mydomainname.com
  5034. ServerName mypastedomainname.com
  5035. <Location />
  5036. ProxyPass http://localhost:8000/
  5037. Order allow,deny
  5038. Allow from all
  5039. LimitRequestBody 256000
  5040. </Location>
  5041. ErrorLog ${APACHE_LOG_DIR}/paste_error.log
  5042. # Possible values include: debug, info, notice, warn, error, crit,
  5043. # alert, emerg.
  5044. LogLevel error
  5045. CustomLog ${APACHE_LOG_DIR}/paste.log combined
  5046. </VirtualHost>
  5047. #+END_SRC
  5048. Save and exit.
  5049. The encryption used here is really just intended to provide you with plausible deniability for content which other users may post to your server. Pastes aren't really intended to be totally private, so if your intention is to send private messages then Bitmessage, an XMPP chat session with OTR or a GPG encrypted email is a far better solution.
  5050. #+BEGIN_SRC: bash
  5051. service apache2 restart
  5052. #+END_SRC
  5053. You can now visit your new site and paste things for others to see, and vice versa. Uploads are limited to 256K in size to prevent your storage space from being used up.
  5054. ** Install Tripwire
  5055. #+BEGIN_VERSE
  5056. /...by the time you get done with all of that, we have a freedom box/
  5057. -- Eben Moglen
  5058. #+END_VERSE
  5059. 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.
  5060. #+BEGIN_SRC: bash
  5061. apt-get install tripwire
  5062. export HOSTNAME=mydomainname.com
  5063. cd /etc/tripwire
  5064. cp arm-local.key $HOSTNAME-local.key
  5065. cp site.key $HOSTNAME-site.key
  5066. tripwire --init
  5067. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  5068. tripwire --check --interactive
  5069. #+END_SRC
  5070. you will be asked for two passphrases ("site" and "local"). Make a note of these.
  5071. Turn off reporting of changes to system logs.
  5072. #+BEGIN_SRC: bash
  5073. editor /etc/tripwire/twcfg.txt
  5074. #+END_SRC
  5075. Set *SYSLOGREPORTING* to false and comment out the line, then save and exit.
  5076. #+BEGIN_SRC: bash
  5077. editor /etc/tripwire/twpol.txt
  5078. #+END_SRC
  5079. Comment out the lines:
  5080. #+BEGIN_SRC: bash
  5081. /var/log -> $(SEC_CONFIG) ;
  5082. /proc -> $(Device) ;
  5083. #+END_SRC
  5084. Then save and exit.
  5085. #+BEGIN_SRC: bash
  5086. editor /usr/bin/reset-tripwire
  5087. #+END_SRC
  5088. Add the following:
  5089. #+BEGIN_SRC: bash
  5090. #!/bin/sh
  5091. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  5092. #+END_SRC
  5093. Save and exit.
  5094. #+BEGIN_SRC: bash
  5095. chmod +x /usr/bin/reset-tripwire
  5096. #+END_SRC
  5097. If you subsequently install any more packages or make configuration changes then update the policy again with:
  5098. #+BEGIN_SRC: bash
  5099. reset-tripwire
  5100. #+END_SRC
  5101. Also, to look for any rootkits.
  5102. #+BEGIN_SRC: bash
  5103. apt-get install rkhunter
  5104. #+END_SRC
  5105. * Router/Firewall ports
  5106. The following ports on your internet router/firewall should be forwarded to the BBB.
  5107. | Protocol | Port/s |
  5108. |---------------+------------|
  5109. | Gopher | 70 |
  5110. | HTTP | 80 |
  5111. | HTTPS | 443 |
  5112. | IMAP | 143 |
  5113. | IRC SSL | 6697 |
  5114. | SIP | 5060..5061 |
  5115. | SMTP | 25,587 |
  5116. | SMTPS | 465 |
  5117. | SSH | 22 |
  5118. | XMPP | 5222..5223 |
  5119. | XMPP (server) | 5269 |
  5120. | XMPP (BOSH) | 5280..5281 |
  5121. | Bitmessage | 8444 |
  5122. | Convergence | 8432..8433 |
  5123. * Hints and Tips
  5124. ** Example software sources
  5125. If you get errors when running *apt-get update* then you may need to check your repositories list. Here are examples of repositories within */etc/apt/sources.list*
  5126. *** Beaglebone Black
  5127. #+BEGIN_SRC: bash
  5128. deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5129. deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5130. deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5131. deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5132. deb http://security.debian.org/ wheezy/updates main contrib non-free
  5133. deb-src http://security.debian.org/ wheezy/updates main contrib non-free
  5134. deb http://ftp.us.debian.org/debian wheezy-backports main contrib non-free
  5135. #+END_SRC
  5136. *** Cubieboard
  5137. #+BEGIN_SRC: bash
  5138. deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5139. deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5140. deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5141. deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5142. deb http://security.debian.org/ wheezy/updates main contrib non-free
  5143. deb-src http://security.debian.org/ wheezy/updates main contrib non-free
  5144. deb http://ftp.us.debian.org/debian wheezy-backports main contrib non-free
  5145. deb http://mirrors.sohu.com/debian/ wheezy main contrib non-free
  5146. deb-src http://mirrors.sohu.com/debian/ wheezy main contrib non-free
  5147. deb http://packages.cubian.org/ wheezy main non-free
  5148. deb http://repo.ajenti.org/debian main main debian
  5149. #+END_SRC
  5150. ** Messaging security
  5151. 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.
  5152. ** Moving Domains
  5153. 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:
  5154. #+BEGIN_SRC: bash
  5155. find /var/www/mynewdomain/htdocs -type f -exec sed -i 's@myolddomain@mynewdomain@g' {} \;
  5156. #+END_SRC
  5157. If you're moving the blog to a new domain then you will need to delete the lock file:
  5158. #+BEGIN_SRC: bash
  5159. rm /var/www/myblogdomainname.com/htdocs/fp-content/%%setup.lock
  5160. #+END_SRC
  5161. Then visit your blog and reinstall it. Your existing content will be unaffected but you will need to delete the welcome post which gets added and also re-select your chosen theme.
  5162. If you need to import blog posts from another blog then copy the *fp-content/content* directory from the old blog to the new blog, then within the admin panel select *maintain* and *rebuild index*.
  5163. ** MySql foo
  5164. *** Backup all databases
  5165. To back up all mysql databases:
  5166. #+BEGIN_SRC: bash
  5167. mysqldump -u root -p --all-databases --events > /var/backups/databasebackup.sql
  5168. #+END_SRC
  5169. *** Restoring a particular mysql database
  5170. To restore yesterday's friendica backup:
  5171. #+BEGIN_SRC: bash
  5172. mysql -D friendica -o < /var/backups/friendica_daily.sql
  5173. #+END_SRC
  5174. To restore yesterday's mediawiki backup:
  5175. #+BEGIN_SRC: bash
  5176. mysql -D wikidb -o < /var/backups/wikidb_daily.sql
  5177. #+END_SRC
  5178. *** Removing mysql server
  5179. If you manage to screw up sql server completely then it can be fully deleted with:
  5180. #+BEGIN_SRC: bash
  5181. ps aux | grep mysql
  5182. #+END_SRC
  5183. and use /kill -9 <pid>/ to kill all mysql processes.
  5184. #+BEGIN_SRC: bash
  5185. apt-get remove --purge mysql\*
  5186. apt-get clean
  5187. updatedb
  5188. #+END_SRC
  5189. ** Regenerating SSL certificates
  5190. If a security vulnerability arrises which requires you to regenerate your SSL certificates, such as [[http://filippo.io/Heartbleed]["heartbleed"]], then this can be done as follows:
  5191. Obtain the latest updates:
  5192. #+BEGIN_SRC: bash
  5193. apt-get update
  5194. apt-get upgrade
  5195. #+END_SRC
  5196. Run *makecert <domain>* for each of your sites.
  5197. Recreate the XMPP certificate:
  5198. #+BEGIN_SRC: bash
  5199. openssl genrsa -out /etc/ssl/private/xmpp.key 4096
  5200. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  5201. chmod 600 /etc/ssl/private/xmpp.key
  5202. chmod 600 /etc/ssl/certs/xmpp.crt
  5203. chown prosody:prosody /etc/ssl/private/xmpp.key
  5204. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  5205. #+END_SRC
  5206. And regenerate the IRC server keys:
  5207. #+BEGIN_SRC: bash
  5208. openssl genrsa -out /etc/ircd-hybrid/key/ircd.key 4096
  5209. openssl req -new -x509 -key /etc/ircd-hybrid/key/ircd.key -out /etc/ircd-hybrid/key/ircd.pem -days 3650
  5210. chmod 600 /etc/ircd-hybrid/key/ircd.key
  5211. chmod 600 /etc/ircd-hybrid/key/ircd.pem
  5212. #+END_SRC
  5213. Regenerate email certificate.
  5214. #+BEGIN_SRC: bash
  5215. exim-gencert --force
  5216. #+END_SRC
  5217. As an added precaution you may wish to regenerate your ssh host keys:
  5218. #+BEGIN_SRC: bash
  5219. rm /etc/ssh/ssh_host_*
  5220. dpkg-reconfigure openssh-server
  5221. #+END_SRC
  5222. Then reboot the server with:
  5223. #+BEGIN_SRC: bash
  5224. reboot
  5225. #+END_SRC
  5226. ** Example crontab file
  5227. This is an example of what your crontab file might look like, with the more frequently run tasks at the top. For the two most frequent tasks specific minutes within each hour are given and they're arranged to try to minimise the number of things running simultaneously.
  5228. #+BEGIN_SRC: bash
  5229. # /etc/crontab: system-wide crontab
  5230. # Unlike any other crontab you don't have to run the `crontab'
  5231. # command to install the new version when you edit this file
  5232. # and files in /etc/cron.d. These files also have username fields,
  5233. # that none of the other crontabs do.
  5234. SHELL=/bin/sh
  5235. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  5236. # m h dom mon dow user command
  5237. 10,20,30,40,50 * * * * root /usr/bin/timeout 120 /usr/bin/dynamicdns && /usr/bin/spamfilter myusername
  5238. 15,35,55 * * * * root cd /var/www/mydomainname/htdocs; /usr/bin/timeout 240 /usr/bin/php include/poller.php
  5239. 17 * * * * root cd / && run-parts --report /etc/cron.hourly
  5240. 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
  5241. 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
  5242. 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
  5243. #+END_SRC
  5244. ** Using your own domain
  5245. Suppose that you have bought a domain name (rather than using a free subdomain on freedns) and you want to use that instead.
  5246. Remove any existing nameservers for your domain (or select "custom" nameservers), then add:
  5247. #+BEGIN_SRC: bash
  5248. NS1.AFRAID.ORG
  5249. NS2.AFRAID.ORG
  5250. NS3.AFRAID.ORG
  5251. NS4.AFRAID.ORG
  5252. #+END_SRC
  5253. It might take a few minutes for the above change to take effect. Within freedns click on "Domains" and add your domains (this might only be available to paid members). Make sure that they're marked as "private".
  5254. Select "Subdomains" from the menu on the left then select the MX entry for your domain and change the destination to *10:mydomainname* rather than *10:mail.mydomainname*.
  5255. To route email to one of your freedns domains:
  5256. #+BEGIN_SRC: bash
  5257. editor /etc/mailname
  5258. #+END_SRC
  5259. Add any extra domains which you own, then save and exit.
  5260. #+BEGIN_SRC: bash
  5261. editor /etc/exim4/update-exim4.conf.conf
  5262. #+END_SRC
  5263. Within dc_other_hostnames add your extra domain names, separated by a colon ':' character.
  5264. Save and exit, then restart exim.
  5265. #+BEGIN_SRC: bash
  5266. update-exim4.conf.template -r
  5267. update-exim4.conf
  5268. service exim4 restart
  5269. #+END_SRC
  5270. You should now be able to send an email from /postmaster@mynewdomainname/ and it should arrive in your inbox.
  5271. ** Obtaining an "official" SSL certificate
  5272. You can obtain a free "official" (as in recognised by default by web browsers) SSL certificate from [[https://www.startssl.com/][StartSSL]]. You will first need to have bought a domain name, since it's not possible to obtain one for a freedns subdomain, so see [[Using your own domain]] for details of how to do that. You should also have tested that you can send email to the domain and receive it on the BBB (via Mutt or any other email client).
  5273. When creating a SSL certificate it's important that the private key (the private component of the public/private pair in [[https://en.wikipedia.org/wiki/Public-key_cryptography][public key cryptography]]) be generated on the BBB /and remain there/. Don't generate the private key via the StartSSL certificate wizard because this means that potentially they may retain a copy of it which could then be exfiltrated either via [[https://en.wikipedia.org/wiki/Lavabit][Lavabit]] style methodology, "implants", compromised sysadmins or other "side channel" methods. So that the private key isn't broadcast on the internet we can instead generate a certificate request, which is really just a request for authorisation of a public key.
  5274. Firstly you should have an Apache web site configutaion ready to go. See [[Setting up a web site]] for details.
  5275. Within StartSSL under the validations wizard validate your domain, which means sending an email to it and confirming a code.
  5276. Now we can generate the certificate request as follows.
  5277. #+BEGIN_SRC: bash
  5278. export HOSTNAME=mydomainname.com
  5279. openssl genrsa -out /etc/ssl/private/$HOSTNAME.key 2048
  5280. chown root:ssl-cert /etc/ssl/private/$HOSTNAME.key
  5281. chmod 440 /etc/ssl/private/$HOSTNAME.key
  5282. mkdir /etc/ssl/requests
  5283. #+END_SRC
  5284. Now make a certificate request as follows. You should copy and paste the whole of this, not just line by line.
  5285. #+BEGIN_SRC: bash
  5286. openssl req -new -key /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/requests/$HOSTNAME.csr
  5287. #+END_SRC
  5288. For the email address it's a good idea to use postmaster@mydomainname.
  5289. Use a random 20 character password, and keep a note of it. We'll remove this later.
  5290. View the request with:
  5291. #+BEGIN_SRC: bash
  5292. cat /etc/ssl/requests/$HOSTNAME.csr
  5293. #+END_SRC
  5294. You can then click on "skip" within the StartSSL certificates wizard and copy and paste the encrypted request into the text entry box. A confirmation will be emailed back to you normally within a few hours.
  5295. Log into your StartSSL account and select *Retrieve Certificate* from the *Tool Box* tab. Copy the text.
  5296. #+BEGIN_SRC: bash
  5297. editor /etc/ssl/certs/$HOSTNAME.crt
  5298. #+END_SRC
  5299. Paste the public key, then save and exit. Then on the BBB.
  5300. #+BEGIN_SRC: bash
  5301. mkdir /etc/ssl/roots
  5302. mkdir /etc/ssl/chains
  5303. wget "http://www.startssl.com/certs/ca.pem" --output-document="/etc/ssl/roots/startssl-root.ca"
  5304. wget "http://www.startssl.com/certs/sub.class1.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class1.server.ca.pem"
  5305. wget "http://www.startssl.com/certs/sub.class2.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class2.server.ca.pem"
  5306. wget "http://www.startssl.com/certs/sub.class3.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class3.server.ca.pem"
  5307. ln -s "/etc/ssl/roots/startssl-root.ca" "/etc/ssl/roots/$HOSTNAME-root.ca"
  5308. ln -s "/etc/ssl/chains/startssl-sub.class1.server.ca.pem" "/etc/ssl/chains/$HOSTNAME.ca"
  5309. cp "/etc/ssl/certs/$HOSTNAME.crt" "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5310. test -e "/etc/ssl/chains/$HOSTNAME.ca" && cat "/etc/ssl/chains/$HOSTNAME.ca" >> "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5311. test -e "/etc/ssl/roots/$HOSTNAME-root.ca" && cat "/etc/ssl/roots/$HOSTNAME-root.ca" >> "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5312. #+END_SRC
  5313. To avoid any possibility of the certificates being accidentally overwritten by self-signed ones at a later date you can create backups.
  5314. #+BEGIN_SRC: bash
  5315. mkdir /etc/ssl/backups
  5316. mkdir /etc/ssl/backups/certs
  5317. mkdir /etc/ssl/backups/private
  5318. cp /etc/ssl/certs/$HOSTNAME* /etc/ssl/backups/certs/
  5319. cp /etc/ssl/private/$HOSTNAME* /etc/ssl/backups/private/
  5320. chmod -R 400 /etc/ssl/backups/certs/*
  5321. chmod -R 400 /etc/ssl/backups/private/*
  5322. #+END_SRC
  5323. Remove the certificate password, so if the server is rebooted then it won't wait indefinitely for a non-existant keyboard user to type in a password.
  5324. #+BEGIN_SRC: bash
  5325. openssl rsa -in /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/private/$HOSTNAME.new.key
  5326. cp /etc/ssl/private/$HOSTNAME.new.key /etc/ssl/private/$HOSTNAME.key
  5327. shred -zu /etc/ssl/private/$HOSTNAME.new.key
  5328. #+END_SRC
  5329. Edit your Apache configuration file.
  5330. #+BEGIN_SRC: bash
  5331. editor /etc/apache2/sites-available/$HOSTNAME
  5332. #+END_SRC
  5333. Add the following to the section which starts with *<VirtualHost *:443>*
  5334. #+BEGIN_SRC: bash
  5335. SSLCertificateChainFile /etc/ssl/chains/startssl-sub.class1.server.ca.pem
  5336. #+END_SRC
  5337. Save and exit, then restart apache.
  5338. #+BEGIN_SRC: bash
  5339. service apache2 restart
  5340. #+END_SRC
  5341. Now visit your web site at https://mydomainname.com and you should notice that there is no certificate warning displayed. You will now be able to install systems which don't allow the use of self-signed certificates, such as [[https://redmatrix.me/&JS=1][Red Matrix]].
  5342. * Deprecated
  5343. The following items have been deprecated until such time as a successful installation is achieved.
  5344. ** Gitlab
  5345. Install some dependencies:
  5346. #+BEGIN_SRC: bash
  5347. apt-get update -y
  5348. apt-get upgrade -y
  5349. apt-get install sudo -y
  5350. apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate git-core
  5351. #+END_SRC
  5352. Install bundler
  5353. #+BEGIN_SRC: bash
  5354. gem install bundler --no-ri --no-rdoc
  5355. #+END_SRC
  5356. Create a user for running Gitlab.
  5357. #+BEGIN_SRC: bash
  5358. adduser --disabled-login --gecos 'GitLab' git
  5359. #+END_SRC
  5360. Install mysql (it may already be installed).
  5361. #+BEGIN_SRC: bash
  5362. apt-get install -y mysql-server mysql-client libmysqlclient-dev
  5363. mysql_secure_installation
  5364. mysql -u root -p
  5365. #+END_SRC
  5366. Enter the following commands, substituting /gitlabpassword/ with a password to be used for the Gitlab installation.
  5367. #+BEGIN_SRC: bash
  5368. CREATE USER 'git'@'localhost' IDENTIFIED BY 'gitlabpassword';
  5369. SET storage_engine=INNODB;
  5370. CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  5371. GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
  5372. quit
  5373. #+END_SRC
  5374. Obtain the code and install it.
  5375. #+BEGIN_SRC: bash
  5376. cd /home/git
  5377. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-8-stable gitlab
  5378. cd /home/git/gitlab
  5379. sudo -u git -H cp /home/git/gitlab/config/gitlab.yml.example /home/git/gitlab/config/gitlab.yml
  5380. sudo -u git -H editor /home/git/gitlab/config/gitlab.yml
  5381. #+END_SRC
  5382. Set /host/ to your gitlab domain name, /port/ to 443 and /https/ to true, then save and exit.
  5383. #+BEGIN_SRC: bash
  5384. chown -R git /home/git/gitlab/log/
  5385. chown -R git /home/git/gitlab/tmp/
  5386. chmod -R u+rwX /home/git/gitlab/log/
  5387. chmod -R u+rwX /home/git/gitlab/tmp/
  5388. sudo -u git -H mkdir /home/git/gitlab-satellites
  5389. chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites
  5390. chmod -R u+rwX /home/git/gitlab/tmp/pids/
  5391. chmod -R u+rwX /home/git/gitlab/tmp/sockets/
  5392. chmod -R u+rwX /home/git/gitlab/public/uploads
  5393. sudo -u git -H cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb
  5394. #sudo -u git -H editor /home/git/gitlab/config/unicorn.rb
  5395. sudo -u git -H cp /home/git/gitlab/config/initializers/rack_attack.rb.example /home/git/gitlab/config/initializers/rack_attack.rb
  5396. sudo -u git -H git config --global user.name "GitLab"
  5397. sudo -u git -H git config --global user.email "gitlab@localhost"
  5398. sudo -u git -H git config --global core.autocrlf input
  5399. sudo -u git cp /home/git/gitlab/config/database.yml.mysql /home/git/gitlab/config/database.yml
  5400. sudo -u git -H chmod o-rwx /home/git/gitlab/config/database.yml
  5401. sudo -u git -H bundle install --deployment --without development test postgres aws
  5402. #+END_SRC
  5403. Fails here with:
  5404. /Could not find libv8-3.16.14.3 in any of the sources/
  5405. /Run `bundle install` to install missing gems./
  5406. #+BEGIN_SRC: bash
  5407. sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  5408. sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.3] REDIS_URL=redis://localhost:6379
  5409. sudo -u git -H editor /home/git/gitlab-shell/config.yml
  5410. cp lib/support/init.d/gitlab /etc/init.d/gitlab
  5411. update-rc.d gitlab defaults 21
  5412. cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
  5413. sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
  5414. sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
  5415. service gitlab start
  5416. #+END_SRC
  5417. Set up the Apache configuration.
  5418. #+BEGIN_SRC: bash
  5419. cp lib/support/apache/gitlab /etc/apache2/sites-available/mygitlabdomain
  5420. editor /etc/apache2/sites-available/mygitlabdomain
  5421. #+END_SRC
  5422. Set your domain name and email accordingly.
  5423. #+BEGIN_SRC: bash
  5424. a2ensite mygitlabdomain
  5425. #+END_SRC
  5426. ** Monkeysphere
  5427. #+BEGIN_SRC: bash
  5428. aptitude install monkeysphere
  5429. aptitude install msva-perl
  5430. aptitude install xul-ext-monkeysphere
  5431. export HOSTNAME=mydomainname.com
  5432. monkeysphere-host import-key /etc/ssh/ssh_host_rsa_key ssh://$HOSTNAME
  5433. monkeysphere-host publish-key
  5434. #+END_SRC
  5435. ** Diaspora
  5436. First install some dependencies:
  5437. #+BEGIN_SRC: bash
  5438. aptitude install build-essential libssl-dev libcurl4-openssl-dev libxml2-dev libxslt-dev imagemagick git-core redis-server curl libmysqlclient-dev libmagickwand-dev librtmp-dev libgnutls-dev libp11-kit-dev libp11-kit0 curl
  5439. #+END_SRC
  5440. If there is trouble with dependencies select 'n' then 'y' to the solution.
  5441. Create a diaspora user.
  5442. #+BEGIN_SRC: bash
  5443. adduser --disabled-login diaspora
  5444. su diaspora
  5445. cd ~/
  5446. curl -L dspr.tk/1t | bash
  5447. echo "[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"" >> ~/.bashrc
  5448. . ~/.bashrc
  5449. rvm autolibs read-only
  5450. rvm install 2.0.0-p353
  5451. git clone -b master git://github.com/diaspora/diaspora.git
  5452. cd diaspora
  5453. #+END_SRC
  5454. Select 'y' to trust /home/diaspora/diaspora/.rvmrc
  5455. #+BEGIN_SRC: bash
  5456. cp config/database.yml.example config/database.yml
  5457. cp config/diaspora.yml.example config/diaspora.yml
  5458. editor config/diaspora.yml
  5459. #+END_SRC
  5460. Set *url* to https://mydiasporadomainname.com/
  5461. Set *certificate_authorities* to */etc/ssl/certs/ca-certificates.crt*
  5462. Set *require_ssl* to *true*
  5463. Set *single_process_mode* to *false*
  5464. Set *port* to 3001
  5465. Set *rails_environment* to 'production'.
  5466. Set *pod_name* to the name of your pod.
  5467. Set *enable_registrations* to *true*.
  5468. Set *autofollow_on_join* to *false*
  5469. Under *captcha* set *enable* to *false*
  5470. Under *invitations* set *open* to *true*
  5471. Set *bitcoin_address* if you wish to accept donations.
  5472. Under *mail* set *enable* to *true*
  5473. Set *sender_address* to no-reply@mydiasporadomainname.com
  5474. Set *method* to *sendmail*
  5475. Set *exim_fix* to true.
  5476. Under *admins* set *account* to *podmaster*
  5477. Under *admins* set *podmin_email* to podmin@mydiasporadomainname.com
  5478. Save and exit.
  5479. #+BEGIN_SRC: bash
  5480. RAILS_ENV=production bundle install --without test development
  5481. #+END_SRC
  5482. This will take quite a while to install.
  5483. #+BEGIN_SRC: bash
  5484. RAILS_ENV=production bundle exec rake db:create db:schema:load
  5485. bundle exec rake assets:precompile
  5486. #+END_SRC
  5487. Alter the Apache configuration.
  5488. #+BEGIN_SRC: bash
  5489. exit
  5490. export HOSTNAME=mydiasporadomainname.com
  5491. editor /etc/apache2/sites-available/$HOSTNAME
  5492. #+END_SRC
  5493. Delete anything which already exists and add the following:
  5494. #+BEGIN_SRC: bash
  5495. <VirtualHost *:80>
  5496. ServerName mydiasporadomainname.com
  5497. ServerAlias www.mydiasporadomainname.com
  5498. RedirectPermanent / https://mydiasporadomainname.com/
  5499. </VirtualHost>
  5500. <VirtualHost *:443>
  5501. ServerName mydiasporadomainname.com
  5502. ServerAlias www.mydiasporadomainname.com
  5503. DocumentRoot /home/diaspora/diaspora/public
  5504. RewriteEngine On
  5505. RewriteCond %{HTTP_HOST} !^mydiasporadomainname\.com [NC]
  5506. RewriteRule ^/(.*)$ https://mydiasporadomainname\.com/$1 [L,R,QSA]
  5507. RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  5508. RewriteRule ^/(.*)$ balancer://upstream%{REQUEST_URI} [P,QSA,L]
  5509. <Proxy balancer://upstream>
  5510. BalancerMember http://127.0.0.1:3001
  5511. </Proxy>
  5512. ProxyRequests Off
  5513. ProxyVia On
  5514. ProxyPreserveHost On
  5515. RequestHeader set X_FORWARDED_PROTO https
  5516. <Proxy *>
  5517. # Apache < 2.4
  5518. Order allow,deny
  5519. Allow from all
  5520. # Apache >= 2.4
  5521. #Require all granted
  5522. </Proxy>
  5523. <Directory /home/diaspora/diaspora/public>
  5524. Options -MultiViews
  5525. # Apache < 2.4
  5526. Allow from all
  5527. AllowOverride all
  5528. # Apache >= 2.4
  5529. #Require all granted
  5530. </Directory>
  5531. SSLEngine On
  5532. SSLCertificateFile /etc/ssl/certs/mydiasporadomainname.com.crt
  5533. SSLCertificateKeyFile /etc/ssl/private/mydiasporadomainname.com.key
  5534. # maybe not needed, need for example for startssl to point to a local
  5535. # copy of http://www.startssl.com/certs/sub.class1.server.ca.pem
  5536. SSLCertificateChainFile /etc/ssl/chains/startssl-sub.class1.server.ca.pem
  5537. # Based on https://wiki.mozilla.org/Security/Server_Side_TLS - consider as global configuration
  5538. SSLProtocol all -SSLv2
  5539. SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:AES128:AES256:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK
  5540. SSLHonorCipherOrder on
  5541. SSLCompression off
  5542. </VirtualHost>
  5543. #+END_SRC
  5544. Save and exit.
  5545. #+BEGIN_SRC: bash
  5546. editor /usr/bin/rundiaspora
  5547. #+END_SRC
  5548. Add the following.
  5549. #+BEGIN_SRC: bash
  5550. #!/bin/sh
  5551. USERNAME=diaspora
  5552. COMMAND="cd /home/$USERNAME/diaspora; /bin/sh /home/$USERNAME/diaspora/script/server > /home/$USERNAME/diaspora.log"
  5553. su -l $USERNAME -c '$COMMAND'
  5554. #+END_SRC
  5555. Save and exit.
  5556. Create an init script:
  5557. #+BEGIN_SRC: bash
  5558. chmod +x /usr/bin/rundiaspora
  5559. editor /etc/init.d/diaspora
  5560. #+END_SRC
  5561. Add the following.
  5562. #+BEGIN_SRC: bash
  5563. #!/bin/bash
  5564. # /etc/init.d/diaspora
  5565. ### BEGIN INIT INFO
  5566. # Provides: diaspora
  5567. # Required-Start: $remote_fs $syslog
  5568. # Required-Stop: $remote_fs $syslog
  5569. # Default-Start: 2 3 4 5
  5570. # Default-Stop: 0 1 6
  5571. # Short-Description: starts diaspora
  5572. # Description: Starts Diaspora.
  5573. ### END INIT INFO
  5574. # Author: Bob Mottram <bob@robotics.uk.to>
  5575. #Settings
  5576. SERVICE='diaspora'
  5577. HISTORY=1024
  5578. USERNAME='diaspora'
  5579. COMMAND="rundiaspora"
  5580. NICELEVEL=19 # from 0-19
  5581. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  5582. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  5583. diaspora_start() {
  5584. echo -n $"Starting $SERVICE service"
  5585. screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}
  5586. # su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  5587. # su -l $USERNAME -c "$COMMAND"
  5588. # RETVAL=$?
  5589. echo
  5590. }
  5591. diaspora_stop() {
  5592. echo -n $"Stopping $SERVICE service"
  5593. screen -p 0 -S ${SERVICE} -X stuff "'^C'"
  5594. # su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  5595. # su -l $USERNAME -c "/home/$USERNAME/diaspora/script/server"
  5596. # RETVAL=$?
  5597. echo
  5598. }
  5599. #Start-Stop here
  5600. case "$1" in
  5601. start)
  5602. diaspora_start
  5603. ;;
  5604. stop)
  5605. diaspora_stop
  5606. ;;
  5607. restart)
  5608. diaspora_stop
  5609. diaspora_start
  5610. ;;
  5611. *)
  5612. echo "Usage: $0 {start|stop|restart}"
  5613. exit 1
  5614. ;;
  5615. esac
  5616. exit 0
  5617. #+END_SRC
  5618. Save and exit.
  5619. #+BEGIN_SRC: bash
  5620. chmod +x /etc/init.d/diaspora
  5621. update-rc.d diaspora defaults
  5622. service diaspora start
  5623. #+END_SRC
  5624. Now enable the site:
  5625. #+BEGIN_SRC: bash
  5626. a2enmod ssl
  5627. a2enmod rewrite
  5628. a2enmod headers
  5629. a2enmod proxy
  5630. a2enmod proxy_connect
  5631. a2enmod proxy_http
  5632. a2enmod proxy_balancer
  5633. a2ensite $HOSTNAME
  5634. service apache2 restart
  5635. #+END_SRC
  5636. * Related projects
  5637. * [[https://freedomboxfoundation.org/][Freedombox]]
  5638. * [[https://arkos.io/][ArkOS]]
  5639. * [[https://github.com/JoshData/mailinabox][Mail-in-a-Box]]