beaglebone.txt 260KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103
  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). The frequently cited and often absurd mantra is that there is "/no reasonable expectation of privacy/".
  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. Newer kernels are also available at http://rcn-ee.net/deb/wheezy-armhf ("bone" in the name indicates kernels with BBB specific patches).
  297. #+BEGIN_SRC: bash
  298. mkdir ~/build
  299. cd ~/build
  300. wget http://freedombone.uk.to/kernel-3.15.tar.gz
  301. #+END_SRC
  302. Verify it.
  303. #+BEGIN_SRC: bash
  304. sha256sum kernel-3.15.tar.gz
  305. abf3e1077bed32a2d7b8e751a6002488032ada7611825c46b0fb548fc838fd99
  306. #+END_SRC
  307. Then extract and install it.
  308. #+BEGIN_SRC: bash
  309. tar -xzvf kernel-3.15.tar.gz
  310. cd kernel-3.15
  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. mkdir ~/build
  485. cd ~/build
  486. git clone https://github.com/bashrc/hashlet.git
  487. #+END_SRC
  488. Now install the driver.
  489. #+BEGIN_SRC: bash
  490. cd hashlet
  491. chmod o+rw /dev/i2c*
  492. ./autogen.sh
  493. make check
  494. make install
  495. #+END_SRC
  496. To check the initial state of the device:
  497. #+BEGIN_SRC: bash
  498. hashlet --bus=/dev/i2c-2 state
  499. #+END_SRC
  500. 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/.
  501. #+BEGIN_SRC: bash
  502. hashlet --bus=/dev/i2c-2 personalize
  503. #+END_SRC
  504. 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:
  505. #+BEGIN_SRC: bash
  506. chmod 400 ~/.hashlet
  507. #+END_SRC
  508. Now create a daemon which will create a random number generator device */dev/hashletrng*.
  509. #+BEGIN_SRC: bash
  510. editor /usr/bin/hashletd
  511. #+END_SRC
  512. #+BEGIN_SRC: bash
  513. #!/bin/sh
  514. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  515. I2CBUS=2
  516. BYTES=32
  517. DEVICE=/dev/hashletrng
  518. # create a device
  519. if [ ! -e ${DEVICE} ]; then
  520. chmod o+rw /dev/i2c*
  521. mknod ${DEVICE} p
  522. fi
  523. while :
  524. do
  525. hashlet --bus=/dev/i2c-${I2CBUS} --Bytes ${BYTES} random-bytes > ${DEVICE}
  526. done
  527. #+END_SRC
  528. Save and exit. Now create an init script to run it.
  529. #+BEGIN_SRC: bash
  530. editor /etc/init.d/hashlet
  531. #+END_SRC
  532. Add the following:
  533. #+BEGIN_SRC: bash
  534. #!/bin/bash
  535. # /etc/init.d/hashlet
  536. ### BEGIN INIT INFO
  537. # Provides: hashlet
  538. # Required-Start: $remote_fs $syslog
  539. # Required-Stop: $remote_fs $syslog
  540. # Default-Start: 2 3 4 5
  541. # Default-Stop: 0 1 6
  542. # Short-Description: hashlet
  543. # Description: Creates a random number generator device
  544. ### END INIT INFO
  545. # Author: Bob Mottram <bob@robotics.uk.to>
  546. #Settings
  547. SERVICE='hashlet'
  548. LOGFILE='/dev/null'
  549. COMMAND="/usr/bin/hashletd"
  550. USERNAME='root'
  551. NICELEVEL=19
  552. HISTORY=1024
  553. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  554. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  555. hashlet_start() {
  556. echo "Starting $SERVICE..."
  557. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  558. }
  559. hashlet_stop() {
  560. echo "Stopping $SERVICE"
  561. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  562. }
  563. #Start-Stop here
  564. case "$1" in
  565. start)
  566. hashlet_start
  567. ;;
  568. stop)
  569. hashlet_stop
  570. ;;
  571. restart)
  572. hashlet_stop
  573. sleep 10s
  574. hashlet_start
  575. ;;
  576. *)
  577. echo "Usage: $0 {start|stop|restart}"
  578. exit 1
  579. ;;
  580. esac
  581. exit 0
  582. #+END_SRC
  583. Save and exit, then start the daemon.
  584. #+BEGIN_SRC: bash
  585. chmod +x /usr/bin/hashletd
  586. chmod +x /etc/init.d/hashlet
  587. update-rc.d hashlet defaults
  588. service hashlet start
  589. #+END_SRC
  590. Then to obtain some random bytes:
  591. #+BEGIN_SRC: bash
  592. cat /dev/hashletrng
  593. #+END_SRC
  594. 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.
  595. ** Alter ssh configuration
  596. #+BEGIN_VERSE
  597. /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./
  598. -- US Department Of Justice
  599. #+END_VERSE
  600. Altering the ssh configuration will make it a little more secure than the standard Debian settings.
  601. #+BEGIN_SRC: bash
  602. editor /etc/ssh/sshd_config
  603. #+END_SRC
  604. Check the following values:
  605. #+BEGIN_SRC: bash
  606. PermitRootLogin no
  607. X11Forwarding no
  608. ServerKeyBits 4096
  609. Protocol 2
  610. PermitEmptyPasswords no
  611. StrictModes yes
  612. TCPKeepAlive no
  613. #+END_SRC
  614. Comment out:
  615. #+BEGIN_SRC: bash
  616. #HostKey /etc/ssh/ssh_host_dsa_key
  617. #HostKey /etc/ssh/ssh_host_ecdsa_key
  618. #+END_SRC
  619. Append the following:
  620. #+BEGIN_SRC: bash
  621. ClientAliveInterval 60
  622. ClientAliveCountMax 3
  623. Ciphers aes256-ctr,aes128-ctr
  624. MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
  625. KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1
  626. #+END_SRC
  627. 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.
  628. #+BEGIN_SRC: bash
  629. rm /etc/ssh/ssh_host_*
  630. dpkg-reconfigure openssh-server
  631. service ssh restart
  632. #+END_SRC
  633. To test the new settings log out by typing "exit" a couple of times, then log back in again with:
  634. #+BEGIN_SRC: bash
  635. ssh -vvv myusername@192.168.1.60
  636. #+END_SRC
  637. and check that some number of bits are set within a 4096 bit sized key:
  638. #+BEGIN_SRC: bash
  639. debug2: bits set: */4096
  640. #+END_SRC
  641. ** Getting onto the web
  642. 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.
  643. Select "/dynamic DNS/" then click "/quick cron example/"
  644. An example would look like:
  645. #+BEGIN_SRC: bash
  646. 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 &
  647. #+END_SRC
  648. 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.
  649. Edit */etc/crontab* and append that to the top of the file, underneath the heading line which looks like this:
  650. #+BEGIN_SRC: bash
  651. # m h dom mon dow user command
  652. #+END_SRC
  653. In general the most frequently run crontab entries should be at the top. Then save and exit.
  654. 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.
  655. The freeDNS subdomain which you just created will hereafter just be refered to as "/your domain name/".
  656. 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:
  657. #+BEGIN_SRC: bash
  658. editor /usr/bin/dynamicdns
  659. #+END_SRC
  660. Add however many freedns subdomains you have.
  661. #+BEGIN_SRC: bash
  662. #!/bin/bash
  663. # subdomain name 1
  664. wget -O - https://freedns.afraid.org/dynamic/update.php?<subdomain code 1>== >> /dev/null 2>&1
  665. # subdomain name 2
  666. wget -O - https://freedns.afraid.org/dynamic/update.php?<subdomain code 2>== >> /dev/null 2>&1
  667. ...
  668. #+END_SRC
  669. Save and exit, then make the script runnable and only readable by the root user.
  670. #+BEGIN_SRC: bash
  671. chmod 600 /usr/bin/dynamicdns
  672. chmod +x /usr/bin/dynamicdns
  673. #+END_SRC
  674. Then within */etc/crontab*
  675. #+BEGIN_SRC: bash
  676. editor /etc/crontab
  677. #+END_SRC
  678. You can replace the multiple freedns entries with a single line:
  679. #+BEGIN_SRC: bash
  680. */10 * * * * root /usr/bin/timeout 200 /usr/bin/dynamicdns
  681. #+END_SRC
  682. Then save and exit and restart the cron daemon.
  683. #+BEGIN_SRC: bash
  684. service cron restart
  685. #+END_SRC
  686. If you want to know what a typical /crontab/ file might look like then see the [[Example crontab file]]
  687. ** Set the host name
  688. #+BEGIN_SRC: bash
  689. editor /etc/hostname
  690. #+END_SRC
  691. CTRL-x CTRL-s to save, then CTRL-x CTRL-c to exit.
  692. Also issue the command, replacing /mydomainname.com/ with your domain name.
  693. #+BEGIN_SRC: bash
  694. hostname mydomainname.com
  695. #+END_SRC
  696. You may also need to assign the same hostname separately via your router's web interface.
  697. #+BEGIN_SRC: bash
  698. editor /etc/hosts
  699. #+END_SRC
  700. Append the following, replacing /mydomainname.com/ with your domain name.
  701. #+BEGIN_SRC: bash
  702. 127.0.1.1 mydomainname.com
  703. #+END_SRC
  704. If you then run the command:
  705. #+BEGIN_SRC: bash
  706. hostname -f
  707. #+END_SRC
  708. it should return your domain name.
  709. ** Install time synchronisation
  710. #+BEGIN_VERSE
  711. /You may delay, but time will not./
  712. -- Benjamin Franklin
  713. #+END_VERSE
  714. 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.
  715. First install some prerequisites.
  716. #+BEGIN_SRC: bash
  717. apt-get install build-essential automake git pkg-config autoconf libtool libssl-dev
  718. apt-get remove ntpdate
  719. #+END_SRC
  720. Now download and install tlsdate.
  721. #+BEGIN_SRC: bash
  722. mkdir ~/build
  723. cd ~/build
  724. git clone https://github.com/ioerror/tlsdate.git
  725. cd ~/build/tlsdate
  726. ./autogen.sh
  727. ./configure
  728. make
  729. make install
  730. #+END_SRC
  731. If you get errors during the /configure/ stage then you may need to reboot so that some of the installed dependencies take effect.
  732. #+BEGIN_SRC: bash
  733. editor /usr/bin/updatedate
  734. #+END_SRC
  735. Add the following, changing /username@mydomainname.com/ to your email address:
  736. #+BEGIN_SRC: bash
  737. #!/bin/bash
  738. TIMESOURCE=google.com
  739. TIMESOURCE2=www.ptb.de
  740. LOGFILE=/var/log/tlsdate.log
  741. TIMEOUT=5
  742. EMAIL=username@mydomainname.com
  743. # File which contains the previous date as a number
  744. BEFORE_DATE_FILE=/var/log/tlsdateprevious.txt
  745. # File which contains the previous date as a string
  746. BEFORE_FULLDATE_FILE=/var/log/tlsdate.txt
  747. DATE_BEFORE=$(date)
  748. BEFORE=$(date -d "$Y-$M-$D" '+%s')
  749. # If the date was previously set
  750. if [[ -f "$BEFORE_DATE_FILE" ]]; then
  751. BEFORE_FILE=$(cat $BEFORE_DATE_FILE)
  752. BEFORE_FULLDATE=$(cat $BEFORE_FULLDATE_FILE)
  753. # is the date going backwards?
  754. if (( BEFORE_FILE > BEFORE )); then
  755. echo -n "Date went backwards between tlsdate updates. " \
  756. >> $LOGFILE
  757. echo -n "$BEFORE_FILE > $BEFORE, " >> $LOGFILE
  758. echo "$BEFORE_FULLDATE > $DATE_BEFORE" >> $LOGFILE
  759. # Send a warning email
  760. echo $(tail $LOGFILE -n 2) | mail -s "tlsdate anomaly" $EMAIL
  761. # Try another time source
  762. TIMESOURCE=$TIMESOURCE2
  763. fi
  764. fi
  765. # Set the date
  766. /usr/bin/timeout $TIMEOUT tlsdate -l -t -H $TIMESOURCE -p 443 >> $LOGFILE
  767. DATE_AFTER=$(date)
  768. AFTER=$(date -d "$Y-$M-$D" '+%s')
  769. # After setting the date did it go backwards?
  770. if (( AFTER < BEFORE )); then
  771. echo "Incorrect date: $DATE_BEFORE -> $DATE_AFTER" >> $LOGFILE
  772. # Send a warning email
  773. echo $(tail $LOGFILE -n 2) | mail -s "tlsdate anomaly" $EMAIL
  774. # Try resetting the date from another time source
  775. /usr/bin/timeout $TIMEOUT tlsdate -l -t -H $TIMESOURCE2 -p 443 >> $LOGFILE
  776. DATE_AFTER=$(date)
  777. AFTER=$(date -d "$Y-$M-$D" '+%s')
  778. else
  779. echo -n $TIMESOURCE >> $LOGFILE
  780. if [[ -f "$BEFORE_DATE_FILE" ]]; then
  781. echo -n " " >> $LOGFILE
  782. echo -n $BEFORE_FILE >> $LOGFILE
  783. fi
  784. echo -n " " >> $LOGFILE
  785. echo -n $BEFORE >> $LOGFILE
  786. echo -n " " >> $LOGFILE
  787. echo -n $AFTER >> $LOGFILE
  788. echo -n " " >> $LOGFILE
  789. echo $DATE_AFTER >> $LOGFILE
  790. fi
  791. # Log the last date
  792. echo "$AFTER" > $BEFORE_DATE_FILE
  793. echo "$DATE_AFTER" > $BEFORE_FULLDATE_FILE
  794. #+END_SRC
  795. Save and exit.
  796. #+BEGIN_SRC: bash
  797. chmod +x /usr/bin/updatedate
  798. editor /etc/crontab
  799. #+END_SRC
  800. Add the following near the top of the list of tasks.
  801. #+BEGIN_SRC: bash
  802. */15 * * * * root /usr/bin/updatedate
  803. #+END_SRC
  804. Save and exit.
  805. #+BEGIN_SRC: bash
  806. service cron restart
  807. #+END_SRC
  808. 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.
  809. To ensure that the system always gets the correct time on initial bootup create an init script.
  810. #+BEGIN_SRC: bash
  811. editor /etc/init.d/tlsdate
  812. #+END_SRC
  813. Add the following:
  814. #+BEGIN_SRC: bash
  815. #!/bin/bash
  816. # /etc/init.d/tlsdate
  817. ### BEGIN INIT INFO
  818. # Provides: tlsdate
  819. # Required-Start: $remote_fs $syslog
  820. # Required-Stop: $remote_fs $syslog
  821. # Default-Start: 2 3 4 5
  822. # Default-Stop: 0 1 6
  823. # Short-Description: Initially calls tlsdate with the timewarp option
  824. # Description: Initially calls tlsdate with the timewarp option
  825. ### END INIT INFO
  826. # Author: Bob Mottram <bob@robotics.uk.to>
  827. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  828. LOGFILE="/var/log/tlsdate.log"
  829. TLSDATECOMMAND="tlsdate --timewarp -l -H www.ptb.de -p 443 >> $LOGFILE"
  830. #Start-Stop here
  831. case "$1" in
  832. start)
  833. echo "tlsdate started"
  834. $TLSDATECOMMAND
  835. ;;
  836. stop)
  837. echo "tlsdate stopped"
  838. ;;
  839. restart)
  840. echo "tlsdate restarted"
  841. $TLSDATECOMMAND
  842. ;;
  843. *)
  844. echo "Usage: $0 {start|stop|restart}"
  845. exit 1
  846. ;;
  847. esac
  848. exit 0
  849. #+END_SRC
  850. Save and exit, then start the daemon.
  851. #+BEGIN_SRC: bash
  852. chmod +x /etc/init.d/tlsdate
  853. update-rc.d tlsdate defaults
  854. service tlsdate start
  855. #+END_SRC
  856. ** Install fail2ban
  857. #+BEGIN_SRC: bash
  858. apt-get install fail2ban
  859. #+END_SRC
  860. ** Set up a firewall
  861. #+BEGIN_VERSE
  862. /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./
  863. -- Bruce Schneier
  864. #+END_VERSE
  865. 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.
  866. #+BEGIN_SRC: bash
  867. apt-get install portsentry
  868. editor /etc/portsentry/portsentry.conf
  869. #+END_SRC
  870. Uncomment the entry for *iptables support for Linux*
  871. Set the following properties:
  872. #+BEGIN_SRC: bash
  873. 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"
  874. 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"
  875. 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"
  876. ADVANCED_EXCLUDE_UDP="520,138,137,67,70,80,443,143,6697,993, 5060,5061,25,465,22,5222,5223,5269,5280,5281,8444"
  877. SCAN_TRIGGER="2"
  878. BLOCK_UDP="2"
  879. BLOCK_TCP="2"
  880. #+END_SRC
  881. Save and exit.
  882. #+BEGIN_SRC: bash
  883. service portsentry restart
  884. editor /tmp/firewall.sh
  885. #+END_SRC
  886. Enter the following:
  887. #+BEGIN_SRC: bash
  888. #!/bin/bash
  889. # First of all delete any existing rules.
  890. # This means you're back to a known state:
  891. iptables -P INPUT ACCEPT
  892. ip6tables -P INPUT ACCEPT
  893. iptables -F
  894. ip6tables -F
  895. iptables -X
  896. ip6tables -X
  897. # Drop any IPv6 traffic
  898. ip6tables -A INPUT -p icmp -j DROP
  899. ip6tables -A INPUT -p tcp -j DROP
  900. ip6tables -A INPUT -p udp -j DROP
  901. # Drop access to unused ports
  902. iptables -A INPUT -p tcp --destination-port 1 -j DROP
  903. iptables -A INPUT -p tcp --destination-port 7 -j DROP
  904. iptables -A INPUT -p tcp --destination-port 109:111 -j DROP
  905. iptables -A INPUT -p tcp --destination-port 995 -j DROP
  906. iptables -A INPUT -p tcp --destination-port 139 -j DROP
  907. iptables -A INPUT -p tcp --destination-port 6000:6001 -j DROP
  908. iptables -A INPUT -p tcp --destination-port 9 -j DROP
  909. iptables -A INPUT -p tcp --destination-port 79 -j DROP
  910. iptables -A INPUT -p tcp --destination-port 515 -j DROP
  911. iptables -A INPUT -p tcp --destination-port 4001 -j DROP
  912. iptables -A INPUT -p tcp --destination-port 1524 -j DROP
  913. iptables -A INPUT -p tcp --destination-port 1080 -j DROP
  914. iptables -A INPUT -p tcp --destination-port 512:514 -j DROP
  915. iptables -A INPUT -p tcp --destination-port 31337 -j DROP
  916. iptables -A INPUT -p tcp --destination-port 2000:2001 -j DROP
  917. iptables -A INPUT -p tcp --destination-port 12345 -j DROP
  918. iptables -A INPUT -p tcp --destination-port 32771:32774 -j DROP
  919. iptables -A INPUT -p tcp --destination-port 6665:6669 -j DROP
  920. iptables -A INPUT -p tcp --destination-port 4000 -j DROP
  921. iptables -A INPUT -p tcp --destination-port 119 -j DROP
  922. iptables -A INPUT -p tcp --destination-port 137 -j DROP
  923. iptables -A INPUT -p tcp --destination-port 4242 -j DROP
  924. iptables -A INPUT -p tcp --destination-port 9050 -j DROP
  925. iptables -A INPUT -p tcp --destination-port 3000 -j DROP
  926. iptables -A INPUT -p tcp --destination-port 3306 -j DROP
  927. iptables -A INPUT -p udp --destination-port 1 -j DROP
  928. iptables -A INPUT -p udp --destination-port 7 -j DROP
  929. iptables -A INPUT -p udp --destination-port 109:111 -j DROP
  930. iptables -A INPUT -p udp --destination-port 995 -j DROP
  931. iptables -A INPUT -p udp --destination-port 139 -j DROP
  932. iptables -A INPUT -p udp --destination-port 6000:6001 -j DROP
  933. iptables -A INPUT -p udp --destination-port 9 -j DROP
  934. iptables -A INPUT -p udp --destination-port 79 -j DROP
  935. iptables -A INPUT -p udp --destination-port 515 -j DROP
  936. iptables -A INPUT -p udp --destination-port 4001 -j DROP
  937. iptables -A INPUT -p udp --destination-port 1524 -j DROP
  938. iptables -A INPUT -p udp --destination-port 1080 -j DROP
  939. iptables -A INPUT -p udp --destination-port 512:514 -j DROP
  940. iptables -A INPUT -p udp --destination-port 31337 -j DROP
  941. iptables -A INPUT -p udp --destination-port 2000:2001 -j DROP
  942. iptables -A INPUT -p udp --destination-port 12345 -j DROP
  943. iptables -A INPUT -p udp --destination-port 32771:32774 -j DROP
  944. iptables -A INPUT -p udp --destination-port 6665:6669 -j DROP
  945. iptables -A INPUT -p udp --destination-port 4000 -j DROP
  946. iptables -A INPUT -p udp --destination-port 119 -j DROP
  947. iptables -A INPUT -p udp --destination-port 137 -j DROP
  948. iptables -A INPUT -p udp --destination-port 8432 -j DROP
  949. iptables -A INPUT -p udp --destination-port 8433 -j DROP
  950. iptables -A INPUT -p udp --destination-port 3306 -j DROP
  951. iptables -A INPUT -p udp --destination-port 4242 -j DROP
  952. iptables -A INPUT -p udp --destination-port 9050 -j DROP
  953. iptables -A INPUT -p udp --destination-port 3000 -j DROP
  954. iptables -A INPUT -p udp --destination-port 8442 -j DROP
  955. # Make sure NEW incoming tcp connections are SYN packets
  956. iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
  957. # Drop packets with incoming fragments
  958. iptables -A INPUT -f -j DROP
  959. # Incoming malformed XMAS packets drop them
  960. iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
  961. iptables -A INPUT -p tcp --tcp-flags ALL FIN,PSH,URG -j DROP
  962. iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
  963. # Incoming malformed NULL packets:
  964. iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
  965. # Drop UDP to used ports
  966. iptables -A INPUT -p udp --match multiport --dports 70,80,443,143,6697,993,5060,5061,25 -j DROP
  967. iptables -A INPUT -p udp --match multiport --dports 465,587,22,5222,5223,5269,5280,5281,8444 -j DROP
  968. # Limit ssh logins
  969. iptables -A INPUT -p tcp --dport 22 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  970. # Limit web connections
  971. iptables -A INPUT -p tcp --dport 80 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  972. iptables -A INPUT -p tcp --dport 443 -m limit --limit 10/minute --limit-burst 1 -j ACCEPT
  973. # Limit number of XMPP connections
  974. iptables -A INPUT -p tcp --match multiport --dports 5222:5223,5269,5280:5281 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  975. # Limit IRC connections
  976. iptables -A INPUT -p tcp --dport 6697 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  977. # Limit gopher connections
  978. iptables -A INPUT -p tcp --dport 70 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  979. # Limit IMAP connections
  980. iptables -A INPUT -p tcp --dport 143 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  981. iptables -A INPUT -p tcp --dport 993 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  982. # Limit SIP connections
  983. iptables -A INPUT -p tcp --dport 5060:5061 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  984. # Limit SMTP/SMTPS connections
  985. iptables -A INPUT -p tcp --dport 25 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  986. iptables -A INPUT -p tcp --dport 465 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  987. iptables -A INPUT -p tcp --dport 587 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  988. # Limit Bitmessage connections
  989. iptables -A INPUT -p tcp --dport 8444 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  990. # Limit Convergence notary
  991. iptables -A INPUT -p tcp --dport 8432:8433 -m limit --limit 3/minute --limit-burst 1 -j ACCEPT
  992. # Limit the number of incoming tcp connections
  993. # Interface 0 incoming syn-flood protection
  994. iptables -N syn_flood
  995. iptables -A INPUT -p tcp --syn -j syn_flood
  996. iptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
  997. iptables -A syn_flood -j DROP
  998. # Limiting the incoming icmp ping request:
  999. #iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j ACCEPT
  1000. #iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j LOG --log-prefix PING-DROP:
  1001. iptables -A INPUT -p icmp -j DROP
  1002. #iptables -A OUTPUT -p icmp -j ACCEPT
  1003. # Block malware servers (See Der Spiegel Snowden files)
  1004. iptables -A INPUT -s 146.185.26.163 -j DROP
  1005. iptables -A INPUT -s 37.130.229.100 -j DROP
  1006. iptables -A INPUT -s 85.237.211.198 -j DROP
  1007. iptables -A INPUT -s 85.237.212.52 -j DROP
  1008. iptables -A INPUT -s 85.237.211.177 -j DROP
  1009. iptables -A INPUT -s 212.118.232.184 -j DROP
  1010. iptables -A INPUT -s 212.118.232.50 -j DROP
  1011. iptables -A INPUT -s 176.249.28.104 -j DROP
  1012. iptables -A INPUT -s 212.118.232.140 -j DROP
  1013. iptables -A INPUT -s 37.130.229.101 -j DROP
  1014. iptables -A INPUT -s 31.6.17.94 -j DROP
  1015. iptables -A INPUT -s 84.45.121.218 -j DROP
  1016. iptables -A INPUT -s 80.84.63.242 -j DROP
  1017. iptables -A INPUT -s 37.220.10.28 -j DROP
  1018. iptables -A INPUT -s 94.229.78.58 -j DROP
  1019. iptables -A OUTPUT -s 146.185.26.163 -j DROP
  1020. iptables -A OUTPUT -s 37.130.229.100 -j DROP
  1021. iptables -A OUTPUT -s 85.237.211.198 -j DROP
  1022. iptables -A OUTPUT -s 85.237.212.52 -j DROP
  1023. iptables -A OUTPUT -s 85.237.211.177 -j DROP
  1024. iptables -A OUTPUT -s 212.118.232.184 -j DROP
  1025. iptables -A OUTPUT -s 212.118.232.50 -j DROP
  1026. iptables -A OUTPUT -s 176.249.28.104 -j DROP
  1027. iptables -A OUTPUT -s 212.118.232.140 -j DROP
  1028. iptables -A OUTPUT -s 37.130.229.101 -j DROP
  1029. iptables -A OUTPUT -s 31.6.17.94 -j DROP
  1030. iptables -A OUTPUT -s 84.45.121.218 -j DROP
  1031. iptables -A OUTPUT -s 80.84.63.242 -j DROP
  1032. iptables -A OUTPUT -s 37.220.10.28 -j DROP
  1033. iptables -A OUTPUT -s 94.229.78.58 -j DROP
  1034. # Save the settings
  1035. iptables-save > /etc/firewall.conf
  1036. ip6tables-save > /etc/firewall6.conf
  1037. printf '#!/bin/sh\n' > /etc/network/if-up.d/iptables
  1038. printf 'iptables-restore < /etc/firewall.conf\n' >> /etc/network/if-up.d/iptables
  1039. printf 'ip6tables-restore < /etc/firewall6.conf\n' >> /etc/network/if-up.d/iptables
  1040. chmod +x /etc/network/if-up.d/iptables
  1041. #+END_SRC
  1042. Save and exit.
  1043. 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.
  1044. #+BEGIN_SRC: bash
  1045. chmod +x /tmp/firewall.sh
  1046. . /tmp/firewall.sh
  1047. rm /tmp/firewall.sh
  1048. #+END_SRC
  1049. 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.
  1050. #+BEGIN_SRC: bash
  1051. editor /etc/sysctl.conf
  1052. #+END_SRC
  1053. Uncomment or change the following:
  1054. #+BEGIN_SRC: bash
  1055. net.ipv4.tcp_syncookies = 1
  1056. net.ipv4.conf.all.accept_redirects = 0
  1057. net.ipv6.conf.all.accept_redirects = 0
  1058. net.ipv4.conf.all.send_redirects = 0
  1059. net.ipv4.conf.all.accept_source_route = 0
  1060. net.ipv6.conf.all.accept_source_route = 0
  1061. net.ipv4.conf.default.rp_filter=1
  1062. net.ipv4.conf.all.rp_filter=1
  1063. net.ipv4.ip_forward=0
  1064. net.ipv6.conf.all.forwarding=0
  1065. #+END_SRC
  1066. And append the following:
  1067. #+BEGIN_SRC: bash
  1068. # ignore pings
  1069. net.ipv4.icmp_echo_ignore_all = 1
  1070. net.ipv6.icmp_echo_ignore_all = 1
  1071. # disable ipv6
  1072. net.ipv6.conf.all.disable_ipv6 = 1
  1073. net.ipv4.tcp_synack_retries = 2
  1074. net.ipv4.tcp_syn_retries = 1
  1075. # keepalive
  1076. net.ipv4.tcp_keepalive_probes = 9
  1077. net.ipv4.tcp_keepalive_intvl = 75
  1078. net.ipv4.tcp_keepalive_time = 7200
  1079. #+END_SRC
  1080. 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:
  1081. #+BEGIN_SRC: bash
  1082. reboot
  1083. #+END_SRC
  1084. After reboot and logging back in to the root account via /ssh/ you can verify that the firewall rules were restored correctly with:
  1085. #+BEGIN_SRC: bash
  1086. iptables -L
  1087. #+END_SRC
  1088. and
  1089. #+BEGIN_SRC: bash
  1090. ip6tables -L
  1091. #+END_SRC
  1092. ** Install Email
  1093. #+BEGIN_VERSE
  1094. /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/
  1095. -- Ladar Levison
  1096. #+END_VERSE
  1097. 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.
  1098. Exim4 seems much easier to install and configure than Postfix.
  1099. #+BEGIN_SRC: bash
  1100. service postfix stop
  1101. apt-get remove postfix
  1102. aptitude install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
  1103. #+END_SRC
  1104. You will be prompted to remove postfix. Say yes and yes again.
  1105. #+BEGIN_SRC: bash
  1106. dpkg-reconfigure exim4-config
  1107. #+END_SRC
  1108. Settings as follows:
  1109. #+BEGIN_SRC: bash
  1110. internet site
  1111. System mail name: mydomainname.com
  1112. IP addresses to listen on: blank
  1113. Destinations: mydomainname.com (and any other domains that you own)
  1114. Domains to relay mail: blank
  1115. Smarthost Relay: 192.168.1.0/24 (the range of addresses on your LAN)
  1116. Dial on demand = no
  1117. Maildir format in home directory
  1118. Split configuration = no
  1119. Root and postmaster: root email
  1120. #+END_SRC
  1121. To test the installation:
  1122. #+BEGIN_SRC: bash
  1123. telnet 192.168.1.60 25
  1124. ehlo xxx
  1125. quit
  1126. #+END_SRC
  1127. #+BEGIN_SRC: bash
  1128. editor /etc/default/saslauthd
  1129. #+END_SRC
  1130. set START=yes then save and exit.
  1131. #+BEGIN_SRC: bash
  1132. /etc/init.d/saslauthd start
  1133. editor /usr/bin/exim-gencert
  1134. #+END_SRC
  1135. Add the following:
  1136. #+BEGIN_SRC: bash
  1137. #!/bin/sh -e
  1138. if [ -n "$EX4DEBUG" ]; then
  1139. echo "now debugging $0 $@"
  1140. set -x
  1141. fi
  1142. DIR=/etc/exim4
  1143. CERT=$DIR/exim.crt
  1144. KEY=$DIR/exim.key
  1145. # This exim binary was built with GnuTLS which does not support dhparams
  1146. # from a file. See /usr/share/doc/exim4-base/README.Debian.gz
  1147. #DH=$DIR/exim.dhparam
  1148. if ! which openssl > /dev/null ;then
  1149. echo "$0: openssl is not installed, exiting" 1>&2
  1150. exit 1
  1151. fi
  1152. # valid for ten years
  1153. DAYS=3650
  1154. if [ "$1" != "--force" ] && [ -f $CERT ] && [ -f $KEY ]; then
  1155. echo "[*] $CERT and $KEY exists!"
  1156. echo " Use \"$0 --force\" to force generation!"
  1157. exit 0
  1158. fi
  1159. if [ "$1" = "--force" ]; then
  1160. shift
  1161. fi
  1162. #SSLEAY=/tmp/exim.ssleay.$$.cnf
  1163. SSLEAY="$(tempfile -m600 -pexi)"
  1164. cat > $SSLEAY <<EOM
  1165. RANDFILE = $HOME/.rnd
  1166. [ req ]
  1167. default_bits = 4096
  1168. default_keyfile = exim.key
  1169. distinguished_name = req_distinguished_name
  1170. [ req_distinguished_name ]
  1171. countryName = Country Code (2 letters)
  1172. countryName_default = GB
  1173. countryName_min = 2
  1174. countryName_max = 2
  1175. stateOrProvinceName = State or Province Name (full name)
  1176. localityName = Locality Name (eg, city)
  1177. organizationName = Organization Name (eg, company; recommended)
  1178. organizationName_max = 64
  1179. organizationalUnitName = Organizational Unit Name (eg, section)
  1180. organizationalUnitName_max = 64
  1181. commonName = Server name (eg. ssl.domain.tld; required!!!)
  1182. commonName_max = 64
  1183. emailAddress = Email Address
  1184. emailAddress_max = 40
  1185. EOM
  1186. echo "[*] Creating a self signed SSL certificate for Exim!"
  1187. echo " This may be sufficient to establish encrypted connections but for"
  1188. echo " secure identification you need to buy a real certificate!"
  1189. echo " "
  1190. echo " Please enter the hostname of your MTA at the Common Name (CN) prompt!"
  1191. echo " "
  1192. openssl req -config $SSLEAY -x509 -sha256 -newkey rsa:4096 -keyout $KEY -out $CERT -days $DAYS -nodes
  1193. #see README.Debian.gz*# openssl dhparam -check -text -5 512 -out $DH
  1194. rm -f $SSLEAY
  1195. chown root:Debian-exim $KEY $CERT $DH
  1196. chmod 640 $KEY $CERT $DH
  1197. echo "[*] Done generating self signed certificates for exim!"
  1198. echo " Refer to the documentation and example configuration files"
  1199. echo " over at /usr/share/doc/exim4-base/ for an idea on how to enable TLS"
  1200. echo " support in your mail transfer agent."
  1201. #+END_SRC
  1202. Save and exit
  1203. #+BEGIN_SRC: bash
  1204. chmod +x /usr/bin/exim-gencert
  1205. exim-gencert --force
  1206. #+END_SRC
  1207. 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.
  1208. #+BEGIN_SRC: bash
  1209. editor /etc/exim4/exim4.conf.template
  1210. #+END_SRC
  1211. Uncomment the section which begins with *login_saslauthd_server*
  1212. Search for the line *.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME* and above it insert the lines:
  1213. #+BEGIN_SRC: bash
  1214. MAIN_HARDCODE_PRIMARY_HOSTNAME = mydomainname.com
  1215. MAIN_TLS_ENABLE = true
  1216. #+END_SRC
  1217. Save and exit.
  1218. #+BEGIN_SRC: bash
  1219. editor /etc/default/exim4
  1220. change SMTPLISTENEROPTIONS to:
  1221. SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'
  1222. #+END_SRC
  1223. save and exit
  1224. #+BEGIN_SRC: bash
  1225. editor /etc/exim4/exim4.conf.template
  1226. #+END_SRC
  1227. Under the section *main/03_exim4-config_tlsoptions* add the following:
  1228. #+BEGIN_SRC: bash
  1229. tls_on_connect_ports=465
  1230. #+END_SRC
  1231. save and exit
  1232. #+BEGIN_SRC: bash
  1233. adduser myusername sasl
  1234. addgroup Debian-exim sasl
  1235. /etc/init.d/exim4 restart
  1236. mkdir -m 700 /etc/skel/Maildir
  1237. mkdir -m 700 /etc/skel/Maildir/Sent
  1238. mkdir -m 700 /etc/skel/Maildir/Sent/tmp
  1239. mkdir -m 700 /etc/skel/Maildir/Sent/cur
  1240. mkdir -m 700 /etc/skel/Maildir/Sent/new
  1241. mkdir -m 700 /etc/skel/Maildir/.learn-spam
  1242. mkdir -m 700 /etc/skel/Maildir/.learn-spam/cur
  1243. mkdir -m 700 /etc/skel/Maildir/.learn-spam/new
  1244. mkdir -m 700 /etc/skel/Maildir/.learn-spam/tmp
  1245. mkdir -m 700 /etc/skel/Maildir/.learn-ham
  1246. mkdir -m 700 /etc/skel/Maildir/.learn-ham/cur
  1247. mkdir -m 700 /etc/skel/Maildir/.learn-ham/new
  1248. mkdir -m 700 /etc/skel/Maildir/.learn-ham/tmp
  1249. ln -s /etc/skel/Maildir/.learn-spam /etc/skel/Maildir/spam
  1250. ln -s /etc/skel/Maildir/.learn-ham /etc/skel/Maildir/ham
  1251. #+END_SRC
  1252. If you're starting from scratch and don't already have a /Maildir/ directory in your home directory, then create one as follows:
  1253. #+BEGIN_SRC: bash
  1254. export MYUSERNAME=myusername
  1255. mkdir -m 700 /home/$MYUSERNAME/Maildir
  1256. mkdir -m 700 /home/$MYUSERNAME/Maildir/cur
  1257. mkdir -m 700 /home/$MYUSERNAME/Maildir/tmp
  1258. mkdir -m 700 /home/$MYUSERNAME/Maildir/new
  1259. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent
  1260. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/cur
  1261. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/tmp
  1262. mkdir -m 700 /home/$MYUSERNAME/Maildir/Sent/new
  1263. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam
  1264. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/cur
  1265. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/new
  1266. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-spam/tmp
  1267. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham
  1268. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/cur
  1269. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/new
  1270. mkdir -m 700 /home/$MYUSERNAME/Maildir/.learn-ham/tmp
  1271. ln -s /home/$MYUSERNAME/Maildir/.learn-spam /home/$MYUSERNAME/Maildir/spam
  1272. ln -s /home/$MYUSERNAME/Maildir/.learn-ham /home/$MYUSERNAME/Maildir/ham
  1273. chown -R $MYUSERNAME:$MYUSERNAME /home/$MYUSERNAME/Maildir
  1274. #+END_SRC
  1275. ** Spam filtering
  1276. #+BEGIN_SRC: bash
  1277. aptitude install spamassassin exim4-daemon-heavy
  1278. #+END_SRC
  1279. 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.
  1280. #+BEGIN_SRC: bash
  1281. editor /etc/default/spamassassin
  1282. #+END_SRC
  1283. Set *ENABLED=1* then save and exit.
  1284. #+BEGIN_SRC: bash
  1285. editor /etc/exim4/exim4.conf.template
  1286. #+END_SRC
  1287. Uncomment or change according to your configuration
  1288. #+BEGIN_SRC: bash
  1289. # For spam scanning, there is a similar option that defines the interface to
  1290. # SpamAssassin. You do not need to set this if you are using the default, which
  1291. # is shown in this commented example. As for virus scanning, you must also
  1292. # modify the acl_check_data access control list to enable spam scanning.
  1293. spamd_address = 127.0.0.1 783
  1294. #+END_SRC
  1295. Add spam header in the /acl_check_data/ section:
  1296. #+BEGIN_SRC: bash
  1297. ### acl/40_exim4-config_check_data
  1298. #################################
  1299. # This ACL is used after the contents of a message have been received. This
  1300. # is the ACL in which you can test a message's headers or body, and in
  1301. # particular, this is where you can invoke external virus or spam scanners.
  1302. acl_check_data:
  1303. ...
  1304. ...
  1305. ...
  1306. # See the exim docs and the exim wiki for more suitable examples.
  1307. #
  1308. # warn
  1309. # spam = Debian-exim:true
  1310. # add_header = X-Spam_score: $spam_score\n\
  1311. # X-Spam_score_int: $spam_score_int\n\
  1312. # X-Spam_bar: $spam_bar\n\
  1313. # X-Spam_report: $spam_report
  1314. # put headers in all messages (no matter if spam or not)
  1315. warn spam = nobody:true
  1316. add_header = X-Spam-Score: $spam_score ($spam_bar)
  1317. add_header = X-Spam-Report: $spam_report
  1318. # add second subject line with *SPAM* marker when message
  1319. # is over threshold
  1320. warn spam = nobody
  1321. add_header = Subject: ***SPAM (score:$spam_score)*** $h_Subject:
  1322. #+END_SRC
  1323. Save and exit, then restart
  1324. #+BEGIN_SRC: bash
  1325. exit
  1326. editor ~/.procmailrc
  1327. #+END_SRC
  1328. The text should look like the following.
  1329. #+BEGIN_SRC: sh
  1330. MAILDIR=$HOME/Maildir
  1331. DEFAULT=$MAILDIR/
  1332. LOGFILE=$HOME/log/procmail.log
  1333. LOGABSTRACT=all
  1334. # get spamassassin to check emails
  1335. :0fw: .spamassassin.lock
  1336. * < 256000
  1337. | spamc
  1338. # strong spam are discarded
  1339. :0
  1340. * ^X-Spam-Level: \*\*\*\*\*\*
  1341. /dev/null
  1342. # weak spam are kept just in case - clear this out every now and then
  1343. :0
  1344. * ^X-Spam-Level: \*\*\*\*\*
  1345. .0-spam/
  1346. # otherwise, marginal spam goes here for revision
  1347. :0
  1348. * ^X-Spam-Level: \*\*
  1349. .spam/
  1350. #+END_SRC
  1351. Save and exit.
  1352. #+BEGIN_SRC: bash
  1353. su
  1354. editor /usr/bin/filterspam
  1355. #+END_SRC
  1356. Add the following contents:
  1357. #+BEGIN_SRC: bash
  1358. #!/bin/bash
  1359. USERNAME=$1
  1360. MAILDIR=/home/$USERNAME/Maildir/.learn-spam
  1361. if [ ! -d "$MAILDIR" ]; then
  1362. exit
  1363. fi
  1364. for f in `ls $MAILDIR/cur`
  1365. do
  1366. spamc -L spam < "$MAILDIR/cur/$f" > /dev/null
  1367. rm "$MAILDIR/cur/$f"
  1368. done
  1369. for f in `ls $MAILDIR/new`
  1370. do
  1371. spamc -L spam < "$MAILDIR/new/$f" > /dev/null
  1372. rm "$MAILDIR/new/$f"
  1373. done
  1374. #+END_SRC
  1375. Save and exit.
  1376. #+BEGIN_SRC: bash
  1377. editor /usr/bin/filterham
  1378. #+END_SRC
  1379. Add the following contents:
  1380. #+BEGIN_SRC: bash
  1381. #!/bin/bash
  1382. USERNAME=$1
  1383. MAILDIR=/home/$USERNAME/Maildir/.learn-ham
  1384. if [ ! -d "$MAILDIR" ]; then
  1385. exit
  1386. fi
  1387. for f in `ls $MAILDIR/cur`
  1388. do
  1389. spamc -L ham < "$MAILDIR/cur/$f" > /dev/null
  1390. rm "$MAILDIR/cur/$f"
  1391. done
  1392. for f in `ls $MAILDIR/new`
  1393. do
  1394. spamc -L ham < "$MAILDIR/new/$f" > /dev/null
  1395. rm "$MAILDIR/new/$f"
  1396. done
  1397. #+END_SRC
  1398. Save and exit.
  1399. #+BEGIN_SRC: bash
  1400. editor /etc/crontab
  1401. #+END_SRC
  1402. Append the following, replacing *myusername* with your username.
  1403. #+BEGIN_SRC: bash
  1404. */3 * * * * root /usr/bin/timeout 120 /usr/bin/filterspam myusername
  1405. */3 * * * * root /usr/bin/timeout 120 /usr/bin/filterham myusername
  1406. #+END_SRC
  1407. Save and exit.
  1408. #+BEGIN_SRC: bash
  1409. chmod 655 /usr/bin/filterspam /usr/bin/filterham
  1410. service spamassassin restart
  1411. service exim4 restart
  1412. service cron restart
  1413. #+END_SRC
  1414. ** Install Dovecot
  1415. #+BEGIN_VERSE
  1416. /I dreamt last night that I was living in a surveillance state. I woke up and… I’m still in a surveillance state./
  1417. -- Conrad Kramer
  1418. #+END_VERSE
  1419. Install the required packages.
  1420. #+BEGIN_SRC: bash
  1421. aptitude -y install dovecot-common dovecot-imapd
  1422. #+END_SRC
  1423. Edit the configuration file.
  1424. #+BEGIN_SRC: bash
  1425. editor /etc/dovecot/dovecot.conf
  1426. #+END_SRC
  1427. Line 26: change:
  1428. #+BEGIN_SRC: bash
  1429. listen = *
  1430. #+END_SRC
  1431. Save and exit.
  1432. #+BEGIN_SRC: bash
  1433. editor /etc/dovecot/conf.d/10-auth.conf
  1434. #+END_SRC
  1435. Line 9: uncomment and change (allow plain text auth)
  1436. #+BEGIN_SRC: bash
  1437. disable_plaintext_auth = no
  1438. #+END_SRC
  1439. Line 99: add:
  1440. #+BEGIN_SRC: bash
  1441. auth_mechanisms = plain login
  1442. #+END_SRC
  1443. Save and exit.
  1444. #+BEGIN_SRC: bash
  1445. editor /etc/dovecot/conf.d/10-mail.conf
  1446. #+END_SRC
  1447. Line 30: uncomment and add:
  1448. #+BEGIN_SRC: bash
  1449. mail_location = maildir:~/Maildir:LAYOUT=fs
  1450. #+END_SRC
  1451. Save and exit.
  1452. #+BEGIN_SRC: bash
  1453. editor /etc/dovecot/conf.d/10-ssl.conf
  1454. #+END_SRC
  1455. Append the following:
  1456. #+BEGIN_SRC: bash
  1457. 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'
  1458. #+END_SRC
  1459. Save and exit, then start the dovecot service.
  1460. #+BEGIN_SRC: bash
  1461. service dovecot restart
  1462. #+END_SRC
  1463. ** Create a GPG key
  1464. #+BEGIN_VERSE
  1465. /If privacy is outlawed, only outlaws will have privacy./
  1466. -- Philip Zimmermann
  1467. #+END_VERSE
  1468. *** Initial installation
  1469. Assuming that you are logged in as root, first ensure that GPG is installed and then exit to your user account.
  1470. #+BEGIN_SRC: bash
  1471. apt-get install gnupg
  1472. exit
  1473. #+END_SRC
  1474. Now we will add some settings:
  1475. #+BEGIN_SRC: bash
  1476. mkdir ~/.gnupg
  1477. editor ~/.gnupg/gpg.conf
  1478. #+END_SRC
  1479. The configuration should look like the following. Of particular importance are the default preferences at the end.
  1480. #+BEGIN_SRC: bash
  1481. # Options for GnuPG
  1482. # Copyright 1998, 1999, 2000, 2001, 2002, 2003,
  1483. # 2010 Free Software Foundation, Inc.
  1484. #
  1485. # This file is free software; as a special exception the author gives
  1486. # unlimited permission to copy and/or distribute it, with or without
  1487. # modifications, as long as this notice is preserved.
  1488. #
  1489. # This file is distributed in the hope that it will be useful, but
  1490. # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
  1491. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  1492. #
  1493. # Unless you specify which option file to use (with the command line
  1494. # option "--options filename"), GnuPG uses the file ~/.gnupg/gpg.conf
  1495. # by default.
  1496. #
  1497. # An options file can contain any long options which are available in
  1498. # GnuPG. If the first non white space character of a line is a '#',
  1499. # this line is ignored. Empty lines are also ignored.
  1500. #
  1501. # See the man page for a list of options.
  1502. # Uncomment the following option to get rid of the copyright notice
  1503. #no-greeting
  1504. # If you have more than 1 secret key in your keyring, you may want to
  1505. # uncomment the following option and set your preferred keyid.
  1506. #default-key 621CC013
  1507. # If you do not pass a recipient to gpg, it will ask for one. Using
  1508. # this option you can encrypt to a default key. Key validation will
  1509. # not be done in this case. The second form uses the default key as
  1510. # default recipient.
  1511. #default-recipient some-user-id
  1512. #default-recipient-self
  1513. # Use --encrypt-to to add the specified key as a recipient to all
  1514. # messages. This is useful, for example, when sending mail through a
  1515. # mail client that does not automatically encrypt mail to your key.
  1516. # In the example, this option allows you to read your local copy of
  1517. # encrypted mail that you've sent to others.
  1518. #encrypt-to some-key-id
  1519. # By default GnuPG creates version 4 signatures for data files as
  1520. # specified by OpenPGP. Some earlier (PGP 6, PGP 7) versions of PGP
  1521. # require the older version 3 signatures. Setting this option forces
  1522. # GnuPG to create version 3 signatures.
  1523. #force-v3-sigs
  1524. # Because some mailers change lines starting with "From " to ">From "
  1525. # it is good to handle such lines in a special way when creating
  1526. # cleartext signatures; all other PGP versions do it this way too.
  1527. #no-escape-from-lines
  1528. # If you do not use the Latin-1 (ISO-8859-1) charset, you should tell
  1529. # GnuPG which is the native character set. Please check the man page
  1530. # for supported character sets. This character set is only used for
  1531. # metadata and not for the actual message which does not undergo any
  1532. # translation. Note that future version of GnuPG will change to UTF-8
  1533. # as default character set. In most cases this option is not required
  1534. # as GnuPG is able to figure out the correct charset at runtime.
  1535. #charset utf-8
  1536. # Group names may be defined like this:
  1537. # group mynames = paige 0x12345678 joe patti
  1538. #
  1539. # Any time "mynames" is a recipient (-r or --recipient), it will be
  1540. # expanded to the names "paige", "joe", and "patti", and the key ID
  1541. # "0x12345678". Note there is only one level of expansion - you
  1542. # cannot make an group that points to another group. Note also that
  1543. # if there are spaces in the recipient name, this will appear as two
  1544. # recipients. In these cases it is better to use the key ID.
  1545. #group mynames = paige 0x12345678 joe patti
  1546. # Lock the file only once for the lifetime of a process. If you do
  1547. # not define this, the lock will be obtained and released every time
  1548. # it is needed, which is usually preferable.
  1549. #lock-once
  1550. # GnuPG can send and receive keys to and from a keyserver. These
  1551. # servers can be HKP, email, or LDAP (if GnuPG is built with LDAP
  1552. # support).
  1553. #
  1554. # Example HKP keyserver:
  1555. # hkp://keys.gnupg.net
  1556. # hkp://subkeys.pgp.net
  1557. #
  1558. # Example email keyserver:
  1559. # mailto:pgp-public-keys@keys.pgp.net
  1560. #
  1561. # Example LDAP keyservers:
  1562. # ldap://keyserver.pgp.com
  1563. #
  1564. # Regular URL syntax applies, and you can set an alternate port
  1565. # through the usual method:
  1566. # hkp://keyserver.example.net:22742
  1567. #
  1568. # Most users just set the name and type of their preferred keyserver.
  1569. # Note that most servers (with the notable exception of
  1570. # ldap://keyserver.pgp.com) synchronize changes with each other. Note
  1571. # also that a single server name may actually point to multiple
  1572. # servers via DNS round-robin. hkp://keys.gnupg.net is an example of
  1573. # such a "server", which spreads the load over a number of physical
  1574. # servers. To see the IP address of the server actually used, you may use
  1575. # the "--keyserver-options debug".
  1576. keyserver hkp://keys.gnupg.net
  1577. #keyserver mailto:pgp-public-keys@keys.nl.pgp.net
  1578. #keyserver ldap://keyserver.pgp.com
  1579. # Common options for keyserver functions:
  1580. #
  1581. # include-disabled : when searching, include keys marked as "disabled"
  1582. # on the keyserver (not all keyservers support this).
  1583. #
  1584. # no-include-revoked : when searching, do not include keys marked as
  1585. # "revoked" on the keyserver.
  1586. #
  1587. # verbose : show more information as the keys are fetched.
  1588. # Can be used more than once to increase the amount
  1589. # of information shown.
  1590. #
  1591. # use-temp-files : use temporary files instead of a pipe to talk to the
  1592. # keyserver. Some platforms (Win32 for one) always
  1593. # have this on.
  1594. #
  1595. # keep-temp-files : do not delete temporary files after using them
  1596. # (really only useful for debugging)
  1597. #
  1598. # http-proxy="proxy" : set the proxy to use for HTTP and HKP keyservers.
  1599. # This overrides the "http_proxy" environment variable,
  1600. # if any.
  1601. #
  1602. # auto-key-retrieve : automatically fetch keys as needed from the keyserver
  1603. # when verifying signatures or when importing keys that
  1604. # have been revoked by a revocation key that is not
  1605. # present on the keyring.
  1606. #
  1607. # no-include-attributes : do not include attribute IDs (aka "photo IDs")
  1608. # when sending keys to the keyserver.
  1609. keyserver-options auto-key-retrieve
  1610. # Display photo user IDs in key listings
  1611. # list-options show-photos
  1612. # Display photo user IDs when a signature from a key with a photo is
  1613. # verified
  1614. # verify-options show-photos
  1615. # Use this program to display photo user IDs
  1616. #
  1617. # %i is expanded to a temporary file that contains the photo.
  1618. # %I is the same as %i, but the file isn't deleted afterwards by GnuPG.
  1619. # %k is expanded to the key ID of the key.
  1620. # %K is expanded to the long OpenPGP key ID of the key.
  1621. # %t is expanded to the extension of the image (e.g. "jpg").
  1622. # %T is expanded to the MIME type of the image (e.g. "image/jpeg").
  1623. # %f is expanded to the fingerprint of the key.
  1624. # %% is %, of course.
  1625. #
  1626. # If %i or %I are not present, then the photo is supplied to the
  1627. # viewer on standard input. If your platform supports it, standard
  1628. # input is the best way to do this as it avoids the time and effort in
  1629. # generating and then cleaning up a secure temp file.
  1630. #
  1631. # If no photo-viewer is provided, GnuPG will look for xloadimage, eog,
  1632. # or display (ImageMagick). On Mac OS X and Windows, the default is
  1633. # to use your regular JPEG image viewer.
  1634. #
  1635. # Some other viewers:
  1636. # photo-viewer "qiv %i"
  1637. # photo-viewer "ee %i"
  1638. #
  1639. # This one saves a copy of the photo ID in your home directory:
  1640. # photo-viewer "cat > ~/photoid-for-key-%k.%t"
  1641. #
  1642. # Use your MIME handler to view photos:
  1643. # photo-viewer "metamail -q -d -b -c %T -s 'KeyID 0x%k' -f GnuPG"
  1644. # Passphrase agent
  1645. #
  1646. # We support the old experimental passphrase agent protocol as well as
  1647. # the new Assuan based one (currently available in the "newpg" package
  1648. # at ftp.gnupg.org/gcrypt/alpha/aegypten/). To make use of the agent,
  1649. # you have to run an agent as daemon and use the option
  1650. #
  1651. # use-agent
  1652. #
  1653. # which tries to use the agent but will fallback to the regular mode
  1654. # if there is a problem connecting to the agent. The normal way to
  1655. # locate the agent is by looking at the environment variable
  1656. # GPG_AGENT_INFO which should have been set during gpg-agent startup.
  1657. # In certain situations the use of this variable is not possible, thus
  1658. # the option
  1659. #
  1660. # --gpg-agent-info=<path>:<pid>:1
  1661. #
  1662. # may be used to override it.
  1663. # Automatic key location
  1664. #
  1665. # GnuPG can automatically locate and retrieve keys as needed using the
  1666. # auto-key-locate option. This happens when encrypting to an email
  1667. # address (in the "user@example.com" form), and there are no
  1668. # user@example.com keys on the local keyring. This option takes the
  1669. # following arguments, in the order they are to be tried:
  1670. #
  1671. # cert = locate a key using DNS CERT, as specified in RFC-4398.
  1672. # GnuPG can handle both the PGP (key) and IPGP (URL + fingerprint)
  1673. # CERT methods.
  1674. #
  1675. # pka = locate a key using DNS PKA.
  1676. #
  1677. # ldap = locate a key using the PGP Universal method of checking
  1678. # "ldap://keys.(thedomain)". For example, encrypting to
  1679. # user@example.com will check ldap://keys.example.com.
  1680. #
  1681. # keyserver = locate a key using whatever keyserver is defined using
  1682. # the keyserver option.
  1683. #
  1684. # You may also list arbitrary keyservers here by URL.
  1685. #
  1686. # Try CERT, then PKA, then LDAP, then hkp://subkeys.net:
  1687. #auto-key-locate cert pka ldap hkp://subkeys.pgp.net
  1688. # default preferences
  1689. personal-digest-preferences SHA256
  1690. cert-digest-algo SHA256
  1691. default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
  1692. #+END_SRC
  1693. Save and exit.
  1694. *** If you have an existing key
  1695. #+BEGIN_SRC: bash
  1696. gpg --import ~/public_key.txt
  1697. gpg --allow-secret-key-import --import ~/private_key.txt
  1698. shred -zu ~/private_key.txt
  1699. #+END_SRC
  1700. 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.
  1701. #+BEGIN_SRC: bash
  1702. export MYGPGKEYID=keyID
  1703. gpg --edit-key $MYGPGKEYID
  1704. setpref SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
  1705. save
  1706. gpg --send-keys $MYGPGKEYID
  1707. #+END_SRC
  1708. *** To create a new key
  1709. Generate a key with the following command:
  1710. #+BEGIN_SRC: bash
  1711. gpg --gen-key
  1712. #+END_SRC
  1713. You can find your GPG key ID by entering:
  1714. #+BEGIN_SRC: bash
  1715. gpg --list-keys
  1716. #+END_SRC
  1717. The key ID is the second part of the string of numbers and letters. So for example in:
  1718. #+BEGIN_SRC: bash
  1719. pub 4096R/EA982E38 2012-05-20
  1720. #+END_SRC
  1721. the key ID is EA982E38. Now send your public key to a server so that others can find it.
  1722. #+BEGIN_SRC: bash
  1723. gpg --send-keys $MYGPGKEYID
  1724. #+END_SRC
  1725. *** root settings
  1726. 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:
  1727. #+BEGIN_SRC: bash
  1728. su
  1729. cp -r /home/myusername/.gnupg ~/
  1730. chown -R root:root ~/.gnupg
  1731. #+END_SRC
  1732. ** Protect processes
  1733. 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.
  1734. #+BEGIN_SRC: bash
  1735. editor /usr/bin/protectprocesses
  1736. #+END_SRC
  1737. Add the following:
  1738. #+BEGIN_SRC: bash
  1739. #!/bin/bash
  1740. declare -a protect=('/usr/sbin/sshd' '/usr/sbin/mysqld --basedir=/usr' '/bin/sh /usr/bin/mysqld_safe' '/usr/sbin/exim4')
  1741. for p in "${protect[@]}"
  1742. do
  1743. OOM_PROC_ID=$(ps aux | grep '$p' | grep -v grep | head -n 1 | awk -F ' ' '{print $2}')
  1744. if [ ! -z "$OOM_PROC_ID" ]; then
  1745. echo -1000 >/proc/$OOM_PROC_ID/oom_score_adj
  1746. echo -17 >/proc/$OOM_PROC_ID/oom_adj
  1747. fi
  1748. done
  1749. #+END_SRC
  1750. Save and exit, then edit the cron jobs:
  1751. #+BEGIN_SRC: bash
  1752. editor /etc/crontab
  1753. #+END_SRC
  1754. And add the line:
  1755. #+BEGIN_SRC: bash
  1756. */1 * * * * root /usr/bin/timeout 30 /usr/bin/protectprocesses
  1757. #+END_SRC
  1758. Then save and exit and restart cron.
  1759. #+BEGIN_SRC: bash
  1760. chmod +x /usr/bin/protectprocesses
  1761. service cron restart
  1762. #+END_SRC
  1763. 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
  1764. .
  1765. ** Setting up a web site
  1766. #+BEGIN_VERSE
  1767. /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./
  1768. -- Tim Berners-Lee
  1769. #+END_VERSE
  1770. Edit the apache configuration so that it doesn't run out of memory if there are a lot of connections.
  1771. #+BEGIN_SRC: bash
  1772. su
  1773. editor /etc/apache2/apache2.conf
  1774. #+END_SRC
  1775. Search for MaxClients and replace the value with 6. As an example the settings should look something like this:
  1776. #+BEGIN_SRC: bash
  1777. Timeout 30
  1778. KeepAlive On
  1779. MaxKeepAliveRequests 5
  1780. KeepAliveTimeout 10
  1781. <IfModule mpm_prefork_module>
  1782. StartServers 1
  1783. MinSpareServers 1
  1784. MaxSpareServers 3
  1785. MaxClients 10
  1786. MaxRequestsPerChild 3000
  1787. </IfModule>
  1788. <IfModule mpm_worker_module>
  1789. StartServers 1
  1790. MinSpareThreads 5
  1791. MaxSpareThreads 15
  1792. ThreadLimit 25
  1793. ThreadsPerChild 5
  1794. MaxClients 25
  1795. MaxRequestsPerChild 200
  1796. </IfModule>
  1797. <IfModule mpm_event_module>
  1798. StartServers 1
  1799. MinSpareThreads 5
  1800. MaxSpareThreads 15
  1801. ThreadLimit 25
  1802. ThreadsPerChild 5
  1803. MaxClients 25
  1804. MaxRequestsPerChild 200
  1805. </IfModule>
  1806. #+END_SRC
  1807. Also append the following:
  1808. #+BEGIN_SRC: bash
  1809. ServerSignature Off
  1810. ServerTokens Prod
  1811. #+END_SRC
  1812. Then save and exit. Install some extra security.
  1813. #+BEGIN_SRC: bash
  1814. apt-get install libapache2-modsecurity
  1815. apt-get install libapache2-mod-evasive
  1816. #+END_SRC
  1817. In the examples below replace /mydomainname.com/ with your own domain name.
  1818. #+BEGIN_SRC: bash
  1819. export HOSTNAME=mydomainname.com
  1820. mkdir /var/www/$HOSTNAME
  1821. mkdir /var/www/$HOSTNAME/htdocs
  1822. editor /etc/apache2/sites-available/$HOSTNAME
  1823. #+END_SRC
  1824. The Apache configuration for the site should look something like the following. Replace /mydonainname.com/ with the site domain name.
  1825. #+BEGIN_SRC: bash
  1826. <VirtualHost *:80>
  1827. ServerAdmin myusername@mydomainname.com
  1828. ServerName mydomainname.com
  1829. DocumentRoot /var/www/mydomainname.com/htdocs
  1830. <Directory />
  1831. Options FollowSymLinks
  1832. AllowOverride All
  1833. </Directory>
  1834. <Directory /var/www/mydomainname.com/htdocs/>
  1835. Options All
  1836. AllowOverride All
  1837. Order allow,deny
  1838. allow from all
  1839. LimitRequestBody 512000
  1840. </Directory>
  1841. # Don't serve .php~ or .php# files created by emacs
  1842. <Files ~ "(^#.*#|~|\.sw[op])$">
  1843. Order allow,deny
  1844. Deny from all
  1845. </Files>
  1846. <IfModule headers_module>
  1847. Header set X-Content-Type-Options nosniff
  1848. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  1849. Header set Pragma no-cache
  1850. </IfModule>
  1851. <Files .htaccess>
  1852. deny from all
  1853. </Files>
  1854. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1855. <Directory "/usr/lib/cgi-bin">
  1856. AllowOverride All
  1857. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1858. Order allow,deny
  1859. Allow from all
  1860. LimitRequestBody 512000
  1861. </Directory>
  1862. ErrorLog ${APACHE_LOG_DIR}/error.log
  1863. # Possible values include: debug, info, notice, warn, error, crit,
  1864. # alert, emerg.
  1865. LogLevel error
  1866. CustomLog ${APACHE_LOG_DIR}/access.log combined
  1867. </VirtualHost>
  1868. <IfModule mod_ssl.c>
  1869. <VirtualHost *:443>
  1870. ServerAdmin myusername@mydomainname.com
  1871. ServerName mydomainname.com
  1872. DocumentRoot /var/www/mydomainname.com/htdocs
  1873. <Directory />
  1874. Options FollowSymLinks
  1875. AllowOverride All
  1876. </Directory>
  1877. <Directory /var/www/mydomainname.com/htdocs/>
  1878. Options All
  1879. AllowOverride All
  1880. Order allow,deny
  1881. allow from all
  1882. LimitRequestBody 512000
  1883. </Directory>
  1884. # Don't serve .php~ or .php# files created by emacs
  1885. <Files ~ "(^#.*#|~|\.sw[op])$">
  1886. Order allow,deny
  1887. Deny from all
  1888. </Files>
  1889. <IfModule headers_module>
  1890. Header set X-Content-Type-Options nosniff
  1891. Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, private"
  1892. Header set Pragma no-cache
  1893. </IfModule>
  1894. <Files .htaccess>
  1895. deny from all
  1896. </Files>
  1897. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  1898. <Directory "/usr/lib/cgi-bin">
  1899. AllowOverride All
  1900. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  1901. Order allow,deny
  1902. Allow from all
  1903. LimitRequestBody 512000
  1904. </Directory>
  1905. ErrorLog ${APACHE_LOG_DIR}/error.log
  1906. # Possible values include: debug, info, notice, warn, error, crit,
  1907. # alert, emerg.
  1908. LogLevel error
  1909. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  1910. # SSL Engine Switch:
  1911. # Enable/Disable SSL for this virtual host.
  1912. SSLEngine on
  1913. # A self-signed certificate
  1914. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  1915. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  1916. # Options based on bettercrypto.org
  1917. SSLProtocol All -SSLv2 -SSLv3
  1918. SSLHonorCipherOrder On
  1919. SSLCompression off
  1920. 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
  1921. # Add six earth month HSTS header for all users ...
  1922. Header add Strict-Transport-Security "max-age=15768000"
  1923. # If you want to protect all subdomains , use the following header
  1924. # ALL subdomains HAVE TO support https if you use this !
  1925. # Strict-Transport-Security: max-age=15768000 ; includeSubDomains
  1926. # SSL Engine Options:
  1927. # Set various options for the SSL engine.
  1928. # o FakeBasicAuth:
  1929. # Translate the client X.509 into a Basic Authorisation. This means that
  1930. # the standard Auth/DBMAuth methods can be used for access control. The
  1931. # user name is the `one line' version of the client's X.509 certificate.
  1932. # Note that no password is obtained from the user. Every entry in the user
  1933. # file needs this password: `xxj31ZMTZzkVA'.
  1934. # o ExportCertData:
  1935. # This exports two additional environment variables: SSL_CLIENT_CERT and
  1936. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  1937. # server (always existing) and the client (only existing when client
  1938. # authentication is used). This can be used to import the certificates
  1939. # into CGI scripts.
  1940. # o StdEnvVars:
  1941. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  1942. # Per default this exportation is switched off for performance reasons,
  1943. # because the extraction step is an expensive operation and is usually
  1944. # useless for serving static content. So one usually enables the
  1945. # exportation for CGI and SSI requests only.
  1946. # o StrictRequire:
  1947. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  1948. # under a "Satisfy any" situation, i.e. when it applies access is denied
  1949. # and no other module can change it.
  1950. # o OptRenegotiate:
  1951. # This enables optimized SSL connection renegotiation handling when SSL
  1952. # directives are used in per-directory context.
  1953. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  1954. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  1955. SSLOptions +StdEnvVars
  1956. </FilesMatch>
  1957. <Directory /usr/lib/cgi-bin>
  1958. SSLOptions +StdEnvVars
  1959. </Directory>
  1960. # SSL Protocol Adjustments:
  1961. # The safe and default but still SSL/TLS standard compliant shutdown
  1962. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  1963. # the close notify alert from client. When you need a different shutdown
  1964. # approach you can use one of the following variables:
  1965. # o ssl-unclean-shutdown:
  1966. # This forces an unclean shutdown when the connection is closed, i.e. no
  1967. # SSL close notify alert is send or allowed to received. This violates
  1968. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  1969. # this when you receive I/O errors because of the standard approach where
  1970. # mod_ssl sends the close notify alert.
  1971. # o ssl-accurate-shutdown:
  1972. # This forces an accurate shutdown when the connection is closed, i.e. a
  1973. # SSL close notify alert is send and mod_ssl waits for the close notify
  1974. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  1975. # practice often causes hanging connections with brain-dead browsers. Use
  1976. # this only for browsers where you know that their SSL implementation
  1977. # works correctly.
  1978. # Notice: Most problems of broken clients are also related to the HTTP
  1979. # keep-alive facility, so you usually additionally want to disable
  1980. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  1981. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  1982. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  1983. # "force-response-1.0" for this.
  1984. BrowserMatch "MSIE [2-6]" \
  1985. nokeepalive ssl-unclean-shutdown \
  1986. downgrade-1.0 force-response-1.0
  1987. # MSIE 7 and newer should be able to use keepalive
  1988. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  1989. </VirtualHost>
  1990. </IfModule>
  1991. #+END_SRC
  1992. Then to enable the site:
  1993. #+BEGIN_SRC: bash
  1994. a2ensite
  1995. a2dissite default
  1996. a2dissite default-ssl
  1997. a2enmod rewrite
  1998. a2enmod headers
  1999. #+END_SRC
  2000. Ensure that "NameVirtualHost *:443" is added to /etc/apache2/ports.conf. It should look something like the following:
  2001. #+BEGIN_SRC: bash
  2002. NameVirtualHost *:80
  2003. Listen 80
  2004. <IfModule mod_ssl.c>
  2005. NameVirtualHost *:443
  2006. Listen 443
  2007. </IfModule>
  2008. <IfModule mod_gnutls.c>
  2009. NameVirtualHost *:443
  2010. Listen 443
  2011. </IfModule>
  2012. #+END_SRC
  2013. Create a self-signed certificate. The passphrase isn't important and will be removed, so make it easy (such as "password").
  2014. #+BEGIN_SRC: bash
  2015. editor /usr/bin/makecert
  2016. #+END_SRC
  2017. Enter the following:
  2018. #+BEGIN_SRC: bash
  2019. #!/bin/bash
  2020. HOSTNAME=$1
  2021. openssl genrsa -des3 -out $HOSTNAME.key 1024
  2022. openssl req -new -x509 -nodes -sha1 -days 3650 -key $HOSTNAME.key -out $HOSTNAME.crt
  2023. openssl rsa -in $HOSTNAME.key -out $HOSTNAME.new.key
  2024. cp $HOSTNAME.new.key $HOSTNAME.key
  2025. rm $HOSTNAME.new.key
  2026. cp $HOSTNAME.key /etc/ssl/private
  2027. chmod 400 /etc/ssl/private/$HOSTNAME.key
  2028. cp $HOSTNAME.crt /etc/ssl/certs
  2029. shred -zu $HOSTNAME.key $HOSTNAME.crt
  2030. a2enmod ssl
  2031. service apache2 restart
  2032. #+END_SRC
  2033. Save and exit.
  2034. #+BEGIN_SRC: bash
  2035. chmod +x /usr/bin/makecert
  2036. makecert mydomainname.com
  2037. #+END_SRC
  2038. 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.
  2039. 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.
  2040. Also limit the amount of memory which any php scripts can use.
  2041. #+BEGIN_SRC: bash
  2042. editor /etc/php5/apache2/php.ini
  2043. #+END_SRC
  2044. Set the following:
  2045. #+BEGIN_SRC: bash
  2046. memory_limit = 32M
  2047. #+END_SRC
  2048. 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.
  2049. ** Accessing your Email
  2050. #+BEGIN_VERSE
  2051. /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./
  2052. -- Article on the "Google-Military-Surveillance Complex" by Yasha Levine
  2053. #+END_VERSE
  2054. *** Mutt email client
  2055. #+BEGIN_SRC: bash
  2056. apt-get install mutt-patched lynx abook
  2057. exit
  2058. mkdir ~/.mutt
  2059. echo "text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^ //’; copiousoutput; needsterminal; nametemplate=%s.html" > ~/.mutt/mailcap
  2060. su
  2061. editor /etc/Muttrc
  2062. #+END_SRC
  2063. Append the following:
  2064. #+BEGIN_SRC: bash
  2065. set mbox_type=Maildir
  2066. set folder="~/Maildir"
  2067. set mask="!^\\.[^.]"
  2068. set mbox="~/Maildir"
  2069. set record="+Sent"
  2070. set postponed="+Drafts"
  2071. set trash="+Trash"
  2072. set spoolfile="~/Maildir"
  2073. auto_view text/x-vcard text/html text/enriched
  2074. set editor="emacs"
  2075. set header_cache="+.cache"
  2076. macro index S "<tag-prefix><save-message>=.learn-spam<enter>" "move to learn-spam"
  2077. macro pager S "<save-message>=.learn-spam<enter>" "move to learn-spam"
  2078. macro index H "<tag-prefix><copy-message>=.learn-ham<enter>" "copy to learn-ham"
  2079. macro pager H "<copy-message>=.learn-ham<enter>" "copy to learn-ham"
  2080. # set up the sidebar
  2081. set sidebar_width=12
  2082. set sidebar_visible=yes
  2083. set sidebar_delim='|'
  2084. set sidebar_sort=yes
  2085. set rfc2047_parameters
  2086. # Show inbox and sent items
  2087. mailboxes = =Sent
  2088. # Alter these colours as needed for maximum bling
  2089. color sidebar_new yellow default
  2090. color normal white default
  2091. color hdrdefault brightcyan default
  2092. color signature green default
  2093. color attachment brightyellow default
  2094. color quoted green default
  2095. color quoted1 white default
  2096. color tilde blue default
  2097. # ctrl-n, ctrl-p to select next, prev folder
  2098. # ctrl-o to open selected folder
  2099. bind index \Cp sidebar-prev
  2100. bind index \Cn sidebar-next
  2101. bind index \Co sidebar-open
  2102. bind pager \Cp sidebar-prev
  2103. bind pager \Cn sidebar-next
  2104. bind pager \Co sidebar-open
  2105. # ctrl-b toggles sidebar visibility
  2106. macro index,pager \Cb '<enter-command>toggle sidebar_visible<enter><redraw-screen>' "toggle sidebar"
  2107. # esc-m Mark new messages as read
  2108. macro index <esc>m "T~N<enter>;WNT~O<enter>;WO\CT~T<enter>" "mark all messages read"
  2109. # Collapsing threads
  2110. macro index [ "<collapse-thread>" "collapse/uncollapse thread"
  2111. macro index ] "<collapse-all>" "collapse/uncollapse all threads"
  2112. # threads containing new messages
  2113. uncolor index "~(~N)"
  2114. color index brightblue default "~(~N)"
  2115. # new messages themselves
  2116. uncolor index "~N"
  2117. color index brightyellow default "~N"
  2118. # GPG/PGP integration
  2119. # this set the number of seconds to keep in memory the passphrase used to encrypt/sign
  2120. set pgp_timeout=60
  2121. # automatically sign and encrypt with PGP/MIME
  2122. set pgp_autosign # autosign all outgoing mails
  2123. set pgp_replyencrypt # autocrypt replies to crypted
  2124. set pgp_replysign # autosign replies to signed
  2125. set pgp_auto_decode=yes # decode attachments
  2126. unset smime_is_default
  2127. set alias_file=~/.mutt-alias
  2128. source ~/.mutt-alias
  2129. set query_command= "abook --mutt-query '%s'"
  2130. macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"
  2131. #+END_SRC
  2132. Save and exit.
  2133. #+BEGIN_SRC: bash
  2134. editor /etc/mail/spamassassin/local.cf
  2135. #+END_SRC
  2136. Uncomment *use_bayes*, *bayes_auto_learn*
  2137. Save and exit, then run:
  2138. #+BEGIN_SRC: bash
  2139. service spamassassin restart
  2140. exit
  2141. cp /etc/Muttrc ~/.muttrc
  2142. touch ~/.mutt-alias
  2143. #+END_SRC
  2144. 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.
  2145. 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.
  2146. Some useful keys to know are:
  2147. | ESC / | Search for text within message contents |
  2148. | "/" | Search for text within headers |
  2149. | * | Move to the last message |
  2150. | TAB | Move to the next unread message |
  2151. | d | Delete a message |
  2152. | u | Undelete a mail which is pending deletion |
  2153. | $ | Delete all messages selected and check for new messages |
  2154. | a | Add to the address book |
  2155. | m | Send a new mail |
  2156. | ESC-m | Mark all messages as having been read |
  2157. | S | Mark a message as spam |
  2158. | H | Mark a message as ham |
  2159. | CTRL-b | Toggle side bar on/off |
  2160. | CTRL-n | Next mailbox (on side bar) |
  2161. | CTRL-p | Previous mailbox (on side bar) |
  2162. | CTRL-o | Open mailbox (on side bar) |
  2163. | ] | Expand or collapse all threads |
  2164. | [ | Expand of collapse the current thread |
  2165. | CTRL-k | Import a PGP/GPG public key |
  2166. 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.
  2167. *** K9 Android client
  2168. #+BEGIN_VERSE
  2169. /The surveillance state is robust. It is robust politically, legally, and technically./
  2170. -- Bruce Schneier
  2171. #+END_VERSE
  2172. **** Incoming server settings
  2173. * Select settings/account settings
  2174. * Select Fetching mail/incoming server
  2175. * Enter your username and password
  2176. * IMAP server should be your domain name
  2177. * Security: SSL/TLS (always)
  2178. * Authentication: Plain
  2179. * Port: 993
  2180. **** Outgoing (SMTP) server settings
  2181. * Select settings/account settings
  2182. * Select Sending mail/outgoing server
  2183. * Set SMTP server to your domain name
  2184. * Set Security to SSL/TLS (always)
  2185. * Set port to 465
  2186. * Set authentication to PLAIN
  2187. * Enter your username and password
  2188. * Accept the SSL certificate
  2189. **** Folders
  2190. 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*.
  2191. If your folder still doesn't show up then press the *menu button*, select *show folders* and select *all folders*.
  2192. *** Webmail
  2193. #+BEGIN_VERSE
  2194. /Most of the information extracted is "content", such as recordings of phone calls or the substance of email messages./
  2195. -- From a 2013 Guardian article on GCHQ/NSA bulk internet data interception.
  2196. #+END_VERSE
  2197. 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.
  2198. If you're not already logged in as root:
  2199. #+BEGIN_SRC: bash
  2200. su
  2201. #+END_SRC
  2202. Install dependencies.
  2203. #+BEGIN_SRC: bash
  2204. apt-get install mysql-server libapache2-mod-authz-unixgroup
  2205. #+END_SRC
  2206. Create a mysql database, specifying a password which should be a long random string generated with a password manager such as KeepassX.
  2207. #+BEGIN_SRC: bash
  2208. mysql -u root -p
  2209. create database roundcubemail;
  2210. CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'roundcubepassword';
  2211. GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
  2212. quit
  2213. #+END_SRC
  2214. Download roundcube.
  2215. #+BEGIN_SRC: bash
  2216. mkdir ~/build
  2217. cd ~/build
  2218. wget http://freedombone.uk.to/roundcubemail.tar.gz
  2219. #+END_SRC
  2220. Verify it.
  2221. #+BEGIN_SRC: bash
  2222. sha256sum roundcubemail.tar.gz
  2223. 1c1560a7a56e6884b45c49f52961dbbb3f6bacbc7e7c755440750a1ab027171c
  2224. #+END_SRC
  2225. Extract the files.
  2226. #+BEGIN_SRC: bash
  2227. tar -xzvf roundcubemail.tar.gz
  2228. export HOSTNAME=mydomainname.com
  2229. cp -r roundcubemail-* /var/www/$HOSTNAME/htdocs/mail
  2230. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/temp
  2231. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/mail/logs
  2232. rm /var/www/$HOSTNAME/htdocs/mail/.htaccess
  2233. #+END_SRC
  2234. Edit your web site configuration.
  2235. #+BEGIN_SRC: bash
  2236. editor /etc/apache2/sites-available/$HOSTNAME
  2237. #+END_SRC
  2238. Within the 80 VirtualHost section add the following:
  2239. #+BEGIN_SRC: bash
  2240. <Directory /var/www/mydomainname.com/htdocs/mail>
  2241. deny from all
  2242. </Directory>
  2243. #+END_SRC
  2244. Within the 443 VirtualHost section add the following:
  2245. #+BEGIN_SRC: bash
  2246. <Directory /var/www/mydomainname.com/htdocs/mail>
  2247. Options Indexes FollowSymLinks MultiViews
  2248. AllowOverride All
  2249. Order allow,deny
  2250. allow from all
  2251. </Directory>
  2252. #+END_SRC
  2253. Save and exit, then restart Apache.
  2254. #+BEGIN_SRC: bash
  2255. service apache2 restart
  2256. #+END_SRC
  2257. Now with a browser visit https://mydomainname.com/mail/installer. Scroll down and click "next". Give your webmail site a product name.
  2258. Change *spellcheck_engine* to *ATD*.
  2259. Under database settings change the database type to SQlite and leave all other fields blank.
  2260. Unser IMAP set *default_host* to ssl://mydomainname.com, *default_port* to 993 and *username_domain* to your domain name.
  2261. Set *smtp_port* to 465.
  2262. Check "Use the current IMAP username and password for SMTP authentication"
  2263. Change the *database password* to the password you gave when creating the MySql database above.
  2264. Click *create config*
  2265. Click download to download the file.
  2266. The config file which you downloaded should contain the following:
  2267. #+BEGIN_SRC: bash
  2268. $config['default_host'] = 'localhost';
  2269. $config['smtp_port'] = 465;
  2270. $config['username_domain'] = '';
  2271. #+END_SRC
  2272. In a terminal on your local machine (not logged into the BBB):
  2273. #+BEGIN_SRC: bash
  2274. cd ~/Downloads
  2275. scp config.inc.php myusername@mydomainname.com:/home/myusername
  2276. #+END_SRC
  2277. Then in a terminal ssh'd into the BBB:
  2278. #+BEGIN_SRC: bash
  2279. mv /home/myusername/config.inc.php /var/www/$HOSTNAME/htdocs/mail/config
  2280. chmod 755 /var/www/$HOSTNAME/htdocs/mail/config/config.inc.php
  2281. #+END_SRC
  2282. Click *continue*.
  2283. Click *initialize database*.
  2284. Under *Test SMTP config* you can use a [[mailinator.com]] address to check that mail can be sent.
  2285. Now we can delete the installer.
  2286. #+BEGIN_SRC: bash
  2287. rm -rf /var/www/$HOSTNAME/htdocs/mail/installer
  2288. #+END_SRC
  2289. Now with a browser navigate to https://mydomainname.com/mail and log in.
  2290. 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.
  2291. 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.
  2292. *** Thunderbird
  2293. #+BEGIN_VERSE
  2294. /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./
  2295. -- Brian Spector, on the shutting down of the PrivateSky encrypted email service
  2296. #+END_VERSE
  2297. 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.
  2298. The following instructions should be carried out on the client machines (laptop, etc), not on the BBB itself.
  2299. **** Initial setup
  2300. Install *Thunderbird* and *Enigmail*. How you do this just depends upon your distro and software manager or "app store".
  2301. Open Thinderbird
  2302. Select "*Skip this and use existing email*"
  2303. Enter your name, email address (myusername@mydomainname.com) and the password for your user (the one from [[Add a user]]).
  2304. You'll get a message saying "/Thunderbird failed to find the settings/"
  2305. The settings should be as follows, substituting /mydomainname.com/ for your domain name and /myusername/ for the username given previously in [[Add a user]].
  2306. * Incoming: IMAP, mydomainname.com, 993, SSL/TLS, Normal Password
  2307. * Outgoing: SMTP, mydomainname.com, 465, SSL/TLS, Normal Password
  2308. * Username: myusername
  2309. Click *Done*.
  2310. Click *Get Certificate* and make sure "*permanently store this exception*" is selected", then click *Store Security Exception*.
  2311. 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.
  2312. Select "*Yes, I want to sign all of my email*"
  2313. Select "*No, I will create per-recipient rules*"
  2314. Select "*yes*" to change default settings.
  2315. **** If you have existing GPG key
  2316. Export your GPG public and private keys.
  2317. #+BEGIN_SRC: bash
  2318. gpg --output ~/public_key.txt --armor --export KEY_ID
  2319. gpg --output ~/private_key.txt --armor --export-secret-key KEY_ID
  2320. #+END_SRC
  2321. Select "*I have existing public and private keys*".
  2322. Select your public and private GPG exported key files.
  2323. Select the account which you want to use and click *Next*, *Next* and *Finish*.
  2324. Remove your exported key files.
  2325. #+BEGIN_SRC: bash
  2326. shred -zu ~/public_key.txt
  2327. shred -zu ~/private_key.txt
  2328. #+END_SRC
  2329. **** If you don't have any existing GPG or PGP key
  2330. Select "*I want to create a new key pair*"
  2331. Enter a passphrase and click *Next* a couple of times.
  2332. Click *Generate Certificate* to generate a revocation certificate.
  2333. Enter the passphrase which you gave previously.
  2334. Click *Finish*
  2335. 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.
  2336. 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.
  2337. **** Using for the first time
  2338. Click on the Thunderbird menu, which looks like three horizontal bars on the right hand side.
  2339. Hover over *preferences* and then *Account settings*.
  2340. 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.
  2341. Select *Synchronization & Storage*.
  2342. Make sure that *Keep messages for this account on this computer* is unticked, then click *Ok*.
  2343. Click on *Inbox*. Depending upon how much email you have it may take a while to import the subject lines.
  2344. Note that when sending an email for the first time you will also need to accept the SSL certificate.
  2345. 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.
  2346. **** Making folders visible
  2347. 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:
  2348. *Menu*, hover over *Preferences*, select *Account Settings*, select *Server Settings* then click on the *Advanced* button.
  2349. 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.
  2350. ** Create Email folders and rules
  2351. #+BEGIN_VERSE
  2352. /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./
  2353. -- Aral Balkan
  2354. #+END_VERSE
  2355. *** Rules for mailing lists
  2356. 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.
  2357. We can make a script to make adding mailing list rules easy:
  2358. #+BEGIN_SRC: bash
  2359. editor /usr/bin/mailinglistrule
  2360. #+END_SRC
  2361. Add the following:
  2362. #+BEGIN_SRC: bash
  2363. #!/bin/bash
  2364. MYUSERNAME=$1
  2365. MAILINGLIST=$2
  2366. SUBJECTTAG=$3
  2367. MUTTRC=/home/$MYUSERNAME/.muttrc
  2368. PM=/home/$MYUSERNAME/.procmailrc
  2369. LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST
  2370. if [ ! -d "$LISTDIR" ]; then
  2371. mkdir -m 700 $LISTDIR
  2372. mkdir -m 700 $LISTDIR/tmp
  2373. mkdir -m 700 $LISTDIR/new
  2374. mkdir -m 700 $LISTDIR/cur
  2375. fi
  2376. chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
  2377. echo "" >> $PM
  2378. echo ":0" >> $PM
  2379. echo " * ^Subject:.*()\[$SUBJECTTAG\]" >> $PM
  2380. echo "$LISTDIR/new" >> $PM
  2381. chown $MYUSERNAME:$MYUSERNAME $PM
  2382. if [ ! -f "$MUTTRC" ]; then
  2383. cp /etc/Muttrc $MUTTRC
  2384. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  2385. fi
  2386. PROCMAILLOG=/home/$MYUSERNAME/log
  2387. if [ ! -d $PROCMAILLOG ]; then
  2388. mkdir $PROCMAILLOG
  2389. chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
  2390. fi
  2391. #+END_SRC
  2392. Save and exit, then make the script executable.
  2393. #+BEGIN_SRC: bash
  2394. chmod +x /usr/bin/mailinglistrule
  2395. #+END_SRC
  2396. 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.
  2397. #+BEGIN_SRC: bash
  2398. mailinglistrule [myusername] [mailinglistname] [subjecttag]
  2399. #+END_SRC
  2400. Repeat this command for as many mailing lists as you need. Then edit your local Mutt configuration.
  2401. #+BEGIN_SRC: bash
  2402. editor /home/myusername/.muttrc
  2403. #+END_SRC
  2404. Search for the *mailboxes* variable and add entries for the mailing lists you just created. For example:
  2405. #+BEGIN_SRC: bash
  2406. mailboxes = =Sent =mailinglistname
  2407. #+END_SRC
  2408. Then save and exit.
  2409. *** Rules for specific email addresses
  2410. You can also make a script which will allow you to move mail from specific email addresses to a folder.
  2411. #+BEGIN_SRC: bash
  2412. editor /usr/bin/emailrule
  2413. #+END_SRC
  2414. Add the following:
  2415. #+BEGIN_SRC: bash
  2416. #!/bin/bash
  2417. MYUSERNAME=$1
  2418. EMAILADDRESS=$2
  2419. MAILINGLIST=$3
  2420. MUTTRC=/home/$MYUSERNAME/.muttrc
  2421. PM=/home/$MYUSERNAME/.procmailrc
  2422. LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST
  2423. if [ ! -d "$LISTDIR" ]; then
  2424. mkdir -m 700 $LISTDIR
  2425. mkdir -m 700 $LISTDIR/tmp
  2426. mkdir -m 700 $LISTDIR/new
  2427. mkdir -m 700 $LISTDIR/cur
  2428. fi
  2429. chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR
  2430. echo "" >> $PM
  2431. echo ":0" >> $PM
  2432. echo " * ^From: $EMAILADDRESS" >> $PM
  2433. echo "$LISTDIR/new" >> $PM
  2434. chown $MYUSERNAME:$MYUSERNAME $PM
  2435. if [ ! -f "$MUTTRC" ]; then
  2436. cp /etc/Muttrc $MUTTRC
  2437. chown $MYUSERNAME:$MYUSERNAME $MUTTRC
  2438. fi
  2439. PROCMAILLOG=/home/$MYUSERNAME/log
  2440. if [ ! -d $PROCMAILLOG ]; then
  2441. mkdir $PROCMAILLOG
  2442. chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG
  2443. fi
  2444. #+END_SRC
  2445. Save and exit, then make the script executable.
  2446. #+BEGIN_SRC: bash
  2447. chmod +x /usr/bin/emailrule
  2448. #+END_SRC
  2449. Then to add a particular email address to a folder run the command:
  2450. #+BEGIN_SRC: bash
  2451. emailrule [myusername] [emailaddress] [foldername]
  2452. #+END_SRC
  2453. If you want any mail from the given email address to be deleted then set the /foldername/ to /Trash/.
  2454. To ensure that the folder appears within Mutt.
  2455. #+BEGIN_SRC: bash
  2456. editor /home/myusername/.muttrc
  2457. #+END_SRC
  2458. Search for the *mailboxes* variable and add entries for the mailing lists you just created. For example:
  2459. #+BEGIN_SRC: bash
  2460. mailboxes = =Sent =foldername
  2461. #+END_SRC
  2462. Then save and exit.
  2463. ** Install a Blog
  2464. #+BEGIN_VERSE
  2465. /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./
  2466. -- Nick Cohen
  2467. #+END_VERSE
  2468. 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.
  2469. 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.
  2470. Download flatpress.
  2471. #+BEGIN_SRC: bash
  2472. mkdir ~/build
  2473. cd ~/build
  2474. wget http://freedombone.uk.to/flatpress.tar.gz
  2475. #+END_SRC
  2476. Verify the download:
  2477. #+BEGIN_SRC: bash
  2478. sha256sum flatpress.tar.gz
  2479. 6312a49aab5aabd6371518dcaf081f489dff04d001bc34b4fe3f2a81170bbd4e flatpress.tar.gz
  2480. #+END_SRC
  2481. Extract and install it.
  2482. #+BEGIN_SRC: bash
  2483. tar -xzvf flatpress.tar.gz
  2484. cd flatpress-*
  2485. cp -r * /var/www/$HOSTNAME/htdocs
  2486. chmod -R 755 /var/www/$HOSTNAME/htdocs/fp-content
  2487. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/fp-content
  2488. cd ..
  2489. rm -rf flatpress-*
  2490. rm -f flatpress.tar.gz
  2491. #+END_SRC
  2492. 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
  2493. ** Install an IRC server
  2494. #+BEGIN_VERSE
  2495. /Give me the liberty to know, to utter, and to argue freely according to conscience, above all liberties./
  2496. -- John Milton
  2497. #+END_VERSE
  2498. *** Base install
  2499. 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.
  2500. Because hybrid doesn't support OpenSSL by default, you have to do a manual patch to get it working.
  2501. #+BEGIN_SRC: bash
  2502. cd ~/build
  2503. mkdir hybrid
  2504. cd hybrid
  2505. apt-get update
  2506. apt-get install build-essential openssl libssl-dev debhelper dpatch docbook-to-man flex bison libpcre3-dev screen
  2507. apt-get source ircd-hybrid
  2508. #+END_SRC
  2509. To enable SSL
  2510. #+BEGIN_SRC: bash
  2511. editor ircd-hybrid-*/debian/rules
  2512. #+END_SRC
  2513. At the top add:
  2514. #+BEGIN_SRC: bash
  2515. USE_OPENSSL = 1
  2516. #+END_SRC
  2517. So the file should looks like:
  2518. #+BEGIN_SRC: bash
  2519. 1# ...
  2520. 2# Some useful stuff to edit here.
  2521. 3# Beware: TOPICLEN may not exceed 390.
  2522. 4NICKLEN = 15
  2523. 5TOPICLEN = 350
  2524. 6MAXCLIENTS = 200
  2525. 7USE_OPENSSL = 1
  2526. 8# ...
  2527. #+END_SRC
  2528. Save and exit, then rebuild the deb-file and install it:
  2529. #+BEGIN_SRC: bash
  2530. cd ircd-hybrid-*
  2531. dpkg-buildpackage -rfakeroot -uc -b
  2532. cd ..
  2533. dpkg -i ircd-hybrid_*.deb
  2534. #+END_SRC
  2535. Edit connect, listen and operator settings:
  2536. #+BEGIN_SRC: bash
  2537. editor /etc/ircd-hybrid/ircd.conf
  2538. #+END_SRC
  2539. Edit the connect section. Set *name* to the name of your server, and set a description.
  2540. #+BEGIN_SRC: c
  2541. connect {
  2542. /* name: the name of the server */
  2543. name = "myircdomainname.com";
  2544. Set a *network_name* and *network_desc*.
  2545. /* host: the host or IP to connect to. If a hostname is used it
  2546. * must match the reverse dns of the server.
  2547. */
  2548. host = "127.0.0.1";
  2549. #+END_SRC
  2550. Set max_clients to 20.
  2551. #+BEGIN_SRC: c
  2552. /* passwords: the passwords we send (OLD C:) and accept (OLD N:).
  2553. * The remote server will have these passwords reversed.
  2554. */
  2555. send_password = "password";
  2556. accept_password = "password";
  2557. #+END_SRC
  2558. Within the admin section set your *name* and *email*.
  2559. Enable compression.
  2560. #+BEGIN_SRC: c
  2561. /* compressed: controls whether traffic is compressed via ziplinks.
  2562. * By default this is disabled
  2563. */
  2564. compressed = yes;
  2565. };
  2566. #+END_SRC
  2567. Within the *listen* section set host to your fixed IP address (in the earlier sections it was 192.168.1.60).
  2568. #+BEGIN_SRC: c
  2569. /* listen {}: contain information about the ports ircd listens on (OLD P:) */
  2570. listen {
  2571. /* port: the specific port to listen on. if no host is specified
  2572. * before, it will listen on all available IPs.
  2573. *
  2574. * ports are seperated via a comma, a range may be specified using ".."
  2575. */
  2576. /* port: listen on all available IPs, ports 6665 to 6669 */
  2577. host = "127.0.0.1";
  2578. port = 6665 .. 6669;
  2579. /* sslport: ports to accept ONLY ssl connections on */
  2580. flags = ssl;
  2581. port = 6697
  2582. };
  2583. #+END_SRC
  2584. Generate a password for the IRC operator using mkpasswd tool.
  2585. #+BEGIN_SRC: bash
  2586. mkpasswd -Hmd5
  2587. #+END_SRC
  2588. Search for operator block and change it to look like this, including the password which you just generated:
  2589. #+BEGIN_SRC: c
  2590. # ...
  2591. operator {
  2592. /* name: the name of the oper */
  2593. name = "root";
  2594. /* user: the user@host required for this operator. CIDR is not
  2595. * supported. multiple user="" lines are supported.
  2596. */
  2597. user = "*@*";
  2598. /* password: the password required to oper. By default this will
  2599. * need to be encrypted using '/usr/bin/mkpasswd'.
  2600. * WARNING: Please do not mix up the 'mkpasswd' program from
  2601. * /usr/sbin with this one. If you are root, typing 'mkpasswd'
  2602. * will run that one instead and you will receive a strange error.
  2603. *
  2604. * MD5 is supported. If you want to use it, use mkpasswd -Hmd5.
  2605. */
  2606. password = "#MD5 PASSWORD HERE#";
  2607. # ...
  2608. #+END_SRC
  2609. Within the *auth* section set user = "*@192.168.1.60" - or whatever the fixed IP address of the BBB is on your network.
  2610. Save and exit.
  2611. #+BEGIN_SRC: c
  2612. service ircd-hybrid restart
  2613. #+END_SRC
  2614. Now open ports 6665 to 6669 on your internet router/firewall.
  2615. After connecting to IRC server you should see something like this:
  2616. #+BEGIN_SRC: bash
  2617. 23:50 -!- - hybrid7.debian.local Message of the Day -
  2618. 23:50 -!- - _,met$$$$$gg. ircd-hybrid 7.2.2
  2619. 23:50 -!- - ,g$$$$$$$$$$$$$$$P. -----------------
  2620. 23:50 -!- - ,g$$P"" """Y$$.".
  2621. 23:50 -!- - ,$$P' `$$$. If you are seeing this, you have
  2622. 23:50 -!- - ',$$P ,ggs. `$$b: installed the ircd-hybrid package and
  2623. 23:50 -!- - `d$$' ,$P"' . $$$ you are now connected to your new IRC
  2624. 23:50 -!- - $$P d$' , $$P server -- congratulations.
  2625. 23:50 -!- - $$: $$. - ,d$$'
  2626. 23:50 -!- - $$; Y$b._ _,d$P' Since you have just installed the
  2627. 23:50 -!- - Y$$. `.`"Y$$$$P"' package, there are some things you
  2628. 23:50 -!- - `$$b "-.__ should do before going any further:
  2629. 23:50 -!- - `Y$$b
  2630. 23:50 -!- - `Y$$. 1. Edit /etc/ircd-hybrid/ircd.conf to
  2631. 23:50 -!- - `$$b. suit your needs. Beware some options have
  2632. 23:50 -!- - `Y$$b. been removed or moved into other blocks in
  2633. 23:50 -!- - `"Y$b._ the configuration file since
  2634. 23:50 -!- - `"""" ircd-hybrid 7.0.3.
  2635. 23:50 -!- -
  2636. 23:50 -!- - 2. Edit /etc/ircd-hybrid/ircd.motd (this
  2637. 23:50 -!- - MOTD) to suit your needs. You are free
  2638. 23:50 -!- - to use this Debian swirl under the
  2639. 23:50 -!- - Debian Open Use Logo License. :)
  2640. 23:50 -!- -
  2641. 23:50 -!- - 3. Restart the server using invoke-rc.d
  2642. 23:50 -!- - ircd-hybrid restart.
  2643. 23:50 -!- -
  2644. 23:50 -!- End of /MOTD command.
  2645. #+END_SRC
  2646. If necessary you can change the message of the day with:
  2647. #+BEGIN_SRC: bash
  2648. editor /etc/ircd-hybrid/ircd.motd
  2649. #+END_SRC
  2650. The restart the irc server.
  2651. #+BEGIN_SRC: bash
  2652. service ircd-hybrid start
  2653. #+END_SRC
  2654. *** Channel management
  2655. To to install channel management tools.
  2656. #+BEGIN_SRC: bash
  2657. mkdir ~/build
  2658. cd ~/build
  2659. wget http://freedombone.uk.to/hybserv_1.9.4-1_armhf.deb
  2660. #+END_SRC
  2661. Verify it.
  2662. #+BEGIN_SRC: bash
  2663. sha256sum hybserv_1.9.4-1_armhf.deb
  2664. 41bf4eb6e24c87610a80bc14db1103a57484835510eea7e4ba9709c523318615 hybserv_1.9.4-1_armhf.deb
  2665. #+END_SRC
  2666. Install it.
  2667. #+BEGIN_SRC: bash
  2668. dpkg -i hybserv_1.9.4-1_armhf.deb
  2669. #+END_SRC
  2670. Make a md5 version of the password for the IRC server operator.
  2671. #+BEGIN_SRC: bash
  2672. /usr/bin/mkpasswd <myoperatorpassword>
  2673. #+END_SRC
  2674. Edit the ircd-hybrid configuration.
  2675. #+BEGIN_SRC: bash
  2676. editor /etc/ircd-hybrid/ircd.conf
  2677. #+END_SRC
  2678. Enter the md5 password which you previously created within the /operator/ section. Also change /user/ to:
  2679. #+BEGIN_SRC: bash
  2680. user = "*@*";
  2681. #+END_SRC
  2682. Then save and exit.
  2683. #+BEGIN_SRC: bash
  2684. editor /etc/hybserv/hybserv.conf
  2685. #+END_SRC
  2686. 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/.
  2687. #+BEGIN_SRC: bash
  2688. A:mynickname <myemailaddress>
  2689. N:irc.mydomainname.com:Hybrid services
  2690. O:*@*:#MD5 PASSWORD HERE#:root:segj (comment out other Q: lines)
  2691. S:mysendacceptpassword:192.168.1.60:6697 (remove the other two services)
  2692. #+END_SRC
  2693. Also remove the line *#NOT-EDITED#*, then save and exit.
  2694. Now we need to restart the ircd and hybrid server to make things work:
  2695. #+BEGIN_SRC: bash
  2696. service ircd-hybrid restart
  2697. service hybserv start
  2698. #+END_SRC
  2699. *** Usage with Irssi
  2700. On another computer (not the BBB).
  2701. #+BEGIN_SRC: bash
  2702. sudo apt-get install irssi irssi-plugin-otr irssi-plugin-xmpp
  2703. irssi
  2704. #+END_SRC
  2705. 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".
  2706. #+BEGIN_SRC: bash
  2707. /network add -nick mynick mynetwork
  2708. /channel add -auto #mychannel mynetwork channelpassword
  2709. /server add -auto -network mynetwork -ssl mydonainname.com 6697 mysendacceptpassword
  2710. /connect mydomainname.com
  2711. /join #mychannel
  2712. /msg -servername chanserv REGISTER #mychannel channelpassword
  2713. /msg -servername chanserv set #mychannel mlock +k channelpassword
  2714. /set paste_join_multiline OFF
  2715. #+END_SRC
  2716. If you edit the irssi config file:
  2717. #+BEGIN_SRC: bash
  2718. editor ~/.irssi/config
  2719. #+END_SRC
  2720. It should look something like this:
  2721. #+BEGIN_SRC: bash
  2722. {
  2723. address = "mydomainname.com";
  2724. chatnet = "mynetwork";
  2725. port = "6697";
  2726. password = "mysendacceptpassword";
  2727. use_ssl = "yes";
  2728. ssl_verify = "no";
  2729. autoconnect = "yes";
  2730. },
  2731. #+END_SRC
  2732. If you're not using a self-signed certificate (self-signed is the default) then you can set *ssl_verify* to "yes".
  2733. By default irssi will use UTC time. An example of setting to some other time zone is as follows:
  2734. #+BEGIN_SRC: bash
  2735. echo "load perl" >> ~/.irssi/startup
  2736. echo "script exec $ENV{'TZ'}='Europe/London';" >> ~/.irssi/startup
  2737. #+END_SRC
  2738. Also enable /Off The Record/ (OTR) messaging.
  2739. #+BEGIN_SRC: bash
  2740. echo "load otr" >> ~/.irssi/startup
  2741. #+END_SRC
  2742. By default Irssi does not look especially attractive. To improve it's looks:
  2743. #+BEGIN_SRC: bash
  2744. cd ~/.irssi
  2745. wget http://freedombone.uk.to/irssi/xchat.theme
  2746. mkdir ~/.irssi/scripts
  2747. mkdir ~/.irssi/scripts/autorun
  2748. cd ~/.irssi/scripts/autorun
  2749. wget http://freedombone.uk.to/irssi/xchatnickcolor.pl
  2750. wget http://freedombone.uk.to/irssi/adv_windowlist.pl
  2751. #+END_SRC
  2752. Verify the files:
  2753. #+BEGIN_SRC: bash
  2754. sha256sum ~/.irssi/xchat.theme
  2755. 7a84130ad55aabd0b043a03b013628438e6c7f82a58e15267633bc7eb443e60b
  2756. sha256sum ~/.irssi/scripts/autorun/xchatnickcolor.pl
  2757. 8293e867a22d42ce5a28cd755237509b6f3587fd2b21d7d20af4a832081610ca
  2758. sha256sum ~/.irssi/scripts/autorun/adv_windowlist.pl
  2759. e4dd8f6d384bf4f2d0ab5ccf06df06e4a69d2647b08d37c8fc6cfd9326688395
  2760. #+END_SRC
  2761. Then run Irssi and enter the commands:
  2762. #+BEGIN_SRC: bash
  2763. /set theme xchat
  2764. /statusbar window remove act
  2765. /set awl
  2766. /set awl_block -14
  2767. /set awl_display_key $Q%K|$N%n $H$C$S
  2768. /set awl_display_key_active $Q%K|$N%n $H%U$C%n$S
  2769. /set awl_display_nokey [$N]$H$C$S
  2770. /run autorun/adv_windowlist.pl
  2771. /set awl_viewer off
  2772. /save
  2773. #+END_SRC
  2774. *** Using irssi with Off The Record messaging (OTR)
  2775. Once you're running irssi then you can enable OTR with:
  2776. #+BEGIN_SRC: bash
  2777. /statusbar window add otr
  2778. /otr genkey mynick@network (for example mynick@irc.freenode.net)
  2779. #+END_SRC
  2780. Then to see your OTR fingerprint:
  2781. #+BEGIN_SRC: bash
  2782. /otr info
  2783. #+END_SRC
  2784. And to trust or distrust someone else's fingerprint.
  2785. #+BEGIN_SRC: bash
  2786. /otr trust [fingerprint]
  2787. /otr distrust [fingerprint]
  2788. #+END_SRC
  2789. *** Usage with XChat
  2790. Within the network list click, *Add* and enter your domain name then click *Edit*.
  2791. Select the entry within the servers box, then enter *mydomainname.com/6697* and press *Enter*.
  2792. Uncheck *use global user information*.
  2793. Enter first and second nicknames and check *auto connect to this network on startup*.
  2794. Check *use SSL* and *accept invalid SSL certificate*.
  2795. Enter some favourite channels and within *server password* enter /mysendacceptpassword/ which you defined earlier when setting up the server.
  2796. Click *close* and then *connect*.
  2797. *** Install Irssi as a daemon
  2798. 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.
  2799. First install some prerequisites.
  2800. #+BEGIN_SRC: bash
  2801. apt-get install irssi irssi-plugin-otr irssi-plugin-xmpp screen
  2802. #+END_SRC
  2803. Create an initialisation script.
  2804. #+BEGIN_SRC: bash
  2805. editor /etc/init.d/irssid
  2806. #+END_SRC
  2807. Add the following:
  2808. #+BEGIN_SRC: bash
  2809. #!/bin/bash
  2810. ### BEGIN INIT INFO
  2811. # Provides: irssid
  2812. # Required-Start: $network
  2813. # Required-Stop: $network
  2814. # Default-Start: 2 3 4 5
  2815. # Default-Stop: 0 1 6
  2816. # Short-Description: Start irssi daemon within screen session at boot time
  2817. # Description: This init script will start an irssi session under screen using the settings provided in /etc/irssid.conf
  2818. ### END INIT INFO
  2819. # Include the LSB library functions
  2820. . /lib/lsb/init-functions
  2821. # Setup static variables
  2822. configFile='/etc/irssid.conf'
  2823. daemonExec='/usr/bin/screen'
  2824. daemonArgs='-D -m'
  2825. daemonName="$(basename "$daemonExec")"
  2826. pidFile='/var/run/irssid.pid'
  2827. #
  2828. # Checks if the environment is capable of running the script (such as
  2829. # availability of programs etc).
  2830. #
  2831. # Return: 0 if the environmnt is properly setup for execution of init script, 1
  2832. # if not all conditions have been met.
  2833. #
  2834. function checkEnvironment() {
  2835. # Verify that the necessary binaries are available for execution.
  2836. local binaries=(irssi screen)
  2837. for bin in "${binaries[@]}"; do
  2838. if ! which "$bin" > /dev/null; then
  2839. log_failure_msg "Binary '$bin' is not available. Please install \
  2840. package containing it."
  2841. exit 5
  2842. fi
  2843. done
  2844. }
  2845. #
  2846. # Checks if the configuration files are available and properly setup.
  2847. #
  2848. # Return: 0 if irssid if properly configured, 1 otherwise.
  2849. #
  2850. function checkConfig() {
  2851. # Make sure the configuration file has been created
  2852. if ! [[ -f $configFile ]]; then
  2853. log_failure_msg "Please populate the configuration file '$configFile' \
  2854. before running."
  2855. exit 6
  2856. fi
  2857. # Make sure the required options have been set
  2858. local reqOptions=(user group session)
  2859. for option in "${reqOptions[@]}"; do
  2860. if ! grep -q -e "^[[:blank:]]*$option=" "$configFile"; then
  2861. log_failure_msg "Mandatory option '$option' was not specified in \
  2862. '$configFile'"
  2863. exit 6
  2864. fi
  2865. done
  2866. }
  2867. #
  2868. # Loads the configuration file and performs any additional configuration steps.
  2869. #
  2870. function configure() {
  2871. . "$configFile"
  2872. daemonArgs="$daemonArgs -S $session irssi"
  2873. [[ -n $args ]] && daemonArgs="$daemonArgs $args"
  2874. daemonCommand="$daemonExec $daemonArgs"
  2875. }
  2876. #
  2877. # Starts the daemon.
  2878. #
  2879. # Return: LSB-compliant code.
  2880. #
  2881. function start() {
  2882. 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
  2883. }
  2884. #
  2885. # Stops the daemon.
  2886. #
  2887. # Return: LSB-compliant code.
  2888. #
  2889. function stop() {
  2890. start-stop-daemon --stop -x /bin/su -p /tmp/irssi.screen.session -q
  2891. }
  2892. checkEnvironment
  2893. checkConfig
  2894. configure
  2895. case "$1" in
  2896. start)
  2897. log_daemon_msg "Starting daemon" "irssid"
  2898. start && log_end_msg 0 || log_end_msg $?
  2899. ;;
  2900. stop)
  2901. log_daemon_msg "Stopping daemon" "irssid"
  2902. stop && log_end_msg 0 || log_end_msg $?
  2903. ;;
  2904. restart)
  2905. log_daemon_msg "Restarting daemon" "irssid"
  2906. stop
  2907. start && log_end_msg 0 || log_end_msg $?
  2908. ;;
  2909. force-reload)
  2910. log_daemon_msg "Restarting daemon" "irssid"
  2911. stop
  2912. start && log_end_msg 0 || log_end_msg $?
  2913. ;;
  2914. status)
  2915. status_of_proc -p "$pidFile" "$daemonExec" screen && exit 0 || exit $?
  2916. ;;
  2917. *)
  2918. echo "irssid (start|stop|restart|force-reload|status|help)"
  2919. ;;
  2920. esac
  2921. #+END_SRC
  2922. Save and exit.
  2923. #+BEGIN_SRC: bash
  2924. chmod +x /etc/init.d/irssid
  2925. #+END_SRC
  2926. Create a configuration file, replacing /myusername/ with your username.
  2927. #+BEGIN_SRC: bash
  2928. editor /etc/irssid.conf
  2929. #+END_SRC
  2930. #+BEGIN_SRC: bash
  2931. #
  2932. # Configuration file for irssid init script
  2933. #
  2934. # Mandatory options:
  2935. #
  2936. # user - Specify user for running irssi.
  2937. # group - Specify group for running irssi.
  2938. # session - Specify screen session name to be used for irssi.
  2939. #
  2940. # Non-mandatory options:
  2941. #
  2942. # args - Pass additional arguments to irssi.
  2943. #
  2944. user='myusername'
  2945. group='irssi'
  2946. session='irssi'
  2947. args='--config /home/myusername/.irssi/config'
  2948. #+END_SRC
  2949. Save and exit. Then add your user to the irssi group and start the daemon.
  2950. #+BEGIN_SRC: bash
  2951. groupadd irssi
  2952. usermod -aG irssi myusername
  2953. update-rc.d irssid defaults
  2954. chown -R myusername:irssi /home/myusername/.irssi
  2955. service irssid start
  2956. #+END_SRC
  2957. Create a script to make running IRC on the server easier.
  2958. #+BEGIN_SRC: bash
  2959. editor /usr/bin/irc
  2960. #+END_SRC
  2961. Add the following:
  2962. #+BEGIN_SRC: bash
  2963. #!/bin/bash
  2964. screen -r irssi
  2965. #+END_SRC
  2966. Save and exit.
  2967. #+BEGIN_SRC: bash
  2968. chmod +x /usr/bin/irc
  2969. chown myusername:myusername /usr/bin/irc
  2970. #+END_SRC
  2971. Then to subsequently access irssi log into the BBB using ssh and type:
  2972. #+BEGIN_SRC: bash
  2973. irc
  2974. #+END_SRC
  2975. To set UK time within Irssi:
  2976. #+BEGIN_SRC: bash
  2977. /script exec $ENV{'TZ'}='Europe/London';
  2978. /save
  2979. #+END_SRC
  2980. ** Install a Jabber/XMPP server
  2981. #+BEGIN_VERSE
  2982. /Well heck, it isn’t that hard to write an instant messaging system./
  2983. --Jeremie Miller
  2984. #+END_VERSE
  2985. *** The Server
  2986. Generate a SSL certificate.
  2987. #+BEGIN_SRC: bash
  2988. openssl genrsa -out /etc/ssl/private/xmpp.key 4096
  2989. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  2990. #+END_SRC
  2991. Change permissions.
  2992. #+BEGIN_SRC: bash
  2993. chmod 600 /etc/ssl/private/xmpp.key
  2994. chmod 600 /etc/ssl/certs/xmpp.crt
  2995. #+END_SRC
  2996. Install Prosody.
  2997. #+BEGIN_SRC: bash
  2998. apt-get install prosody
  2999. chown prosody:prosody /etc/ssl/private/xmpp.key
  3000. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  3001. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  3002. editor /etc/prosody/conf.avail/xmpp.cfg.lua
  3003. #+END_SRC
  3004. Change the *VirtualHost* name to your domain name and remove the line below it.
  3005. Set the ssl section to:
  3006. #+BEGIN_SRC: bash
  3007. ssl = {
  3008. key = "/etc/ssl/private/xmpp.key";
  3009. certificate = "/etc/ssl/certs/xmpp.crt";
  3010. }
  3011. #+END_SRC
  3012. And also append the following:
  3013. #+BEGIN_SRC: bash
  3014. modules_enabled = {
  3015. "bosh"; -- Enable mod_bosh
  3016. "tls"; -- Enable mod_tls
  3017. }
  3018. c2s_require_encryption = true
  3019. s2s_require_encryption = true
  3020. #+END_SRC
  3021. Save and exit. Create a symbolic link.
  3022. #+BEGIN_SRC: bash
  3023. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  3024. editor /etc/prosody/prosody.cfg.lua
  3025. #+END_SRC
  3026. Within the *ssl* section set:
  3027. #+BEGIN_SRC: bash
  3028. ssl = {
  3029. key = "/etc/ssl/private/xmpp.key";
  3030. certificate = "/etc/ssl/certs/xmpp.crt";
  3031. }
  3032. #+END_SRC
  3033. Uncomment and set the following to *true*
  3034. #+BEGIN_SRC: bash
  3035. c2s_require_encryption = true
  3036. s2s_require_encryption = true
  3037. #+END_SRC
  3038. Within the *modules_enabled* section uncomment *bosh*, then save and exit.
  3039. 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).
  3040. #+BEGIN_SRC: bash
  3041. prosodyctl adduser myusername@mydomainname.com
  3042. #+END_SRC
  3043. Restart the server
  3044. #+BEGIN_SRC: bash
  3045. service prosody restart
  3046. #+END_SRC
  3047. On your internet router/firewall open ports 5222, 5223, 5269, 5280 and 5281 and forward them to the BBB.
  3048. 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.
  3049. *** Managing users
  3050. To add a user:
  3051. #+BEGIN_SRC: bash
  3052. prosodyctl adduser myusername@mydomainname.com
  3053. #+END_SRC
  3054. To change a user password:
  3055. #+BEGIN_SRC: bash
  3056. prosodyctl passwd myusername@mydomainname.com
  3057. #+END_SRC
  3058. To remove a user:
  3059. #+BEGIN_SRC: bash
  3060. prosodyctl deluser myusername@mydomainname.com
  3061. #+END_SRC
  3062. Report the status of the XMPP server:
  3063. #+BEGIN_SRC: bash
  3064. prosodyctl status
  3065. #+END_SRC
  3066. *** Using with Jitsi
  3067. 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.
  3068. Jitsi can be downloaded from https://jitsi.org/
  3069. On your desktop/laptop open Jitsi and select *Options* from the *Tools* menu.
  3070. 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).
  3071. 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.
  3072. 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.
  3073. You can also [[https://www.youtube.com/watch?v=vgx7VSrDGjk][see this video]] as an example of using OTR.
  3074. *** Using with Ubuntu
  3075. 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.
  3076. Open *System Settings* and select *Online Accounts*, *Add account* and then *Jabber*.
  3077. Enter your username (myusername@mydomainname.com) and password.
  3078. 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*.
  3079. *** Using with Android
  3080. There are a few XMPP clients available on Android. Ideally choose ones which support off-the-record messaging. Here are some examples.
  3081. **** Xabber
  3082. Install [[https://f-droid.org/][F-Droid]]
  3083. Search for and install Xabber.
  3084. Add an account and enter your Jabber/XMPP ID and password.
  3085. From the menu select *Settings* then *Security* then *OTR mode*. Set the mode to *Required*.
  3086. Make sure that *Check server certificate* is not checked.
  3087. 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.
  3088. **** Gibberbot
  3089. Install [[https://f-droid.org/][F-Droid]]
  3090. Search for and install Gibberbot, otherwise known as ChatSecure.
  3091. From the menu open *Accounts*
  3092. Select *Add account*
  3093. Change the server port from 0 to 5222
  3094. Done
  3095. Accept unknown certificate? Select *Always*
  3096. Go back to the initial screen and then using the menu you can add contacts and begin chatting.
  3097. ** Social Networking
  3098. #+BEGIN_VERSE
  3099. /Facebook is not your friend, it is a surveillance engine./
  3100. -- Richard Stallman, Free Software Foundation
  3101. #+END_VERSE
  3102. *** Friendica
  3103. **** Installation
  3104. 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.
  3105. 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:
  3106. #+BEGIN_SRC: bash
  3107. editor /etc/apache2/sites-available/myfriendicadomainname.com
  3108. #+END_SRC
  3109. 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:
  3110. #+BEGIN_SRC: bash
  3111. <VirtualHost *:80>
  3112. ServerAdmin myusername@mydomainname.com
  3113. ServerName myfriendicadomainname.com
  3114. RewriteEngine On
  3115. RewriteCond %{HTTPS} off
  3116. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3117. </VirtualHost>
  3118. #+END_SRC
  3119. Save and exit, then restart the apache server.
  3120. #+BEGIN_SRC: bash
  3121. service apache2 restart
  3122. #+END_SRC
  3123. Now install some dependencies.
  3124. #+BEGIN_SRC: bash
  3125. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt php5-fpm php5-cgi php-apc
  3126. #+END_SRC
  3127. Enter an admin password for MySQL.
  3128. Reduce the memory use of mysql by using the "small" configuration.
  3129. #+BEGIN_SRC: bash
  3130. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3131. #+END_SRC
  3132. Create a mysql database, replacing /myfriendicapassword/ with a password used to administer the friendica database.
  3133. #+BEGIN_SRC: bash
  3134. mysql -u root -p
  3135. create database friendica;
  3136. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'myfriendicapassword';
  3137. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  3138. quit
  3139. #+END_SRC
  3140. You may need to fix Git SSL problems.
  3141. #+BEGIN_SRC: bash
  3142. git config --global http.sslVerify true
  3143. apt-get install ca-certificates
  3144. cd ~/
  3145. editor .gitconfig
  3146. #+END_SRC
  3147. The .gitconfig file should look something like this:
  3148. #+BEGIN_SRC: bash
  3149. [user]
  3150. name = yourname
  3151. email = myusername@mydomainname.com
  3152. [http]
  3153. sslVerify = true
  3154. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  3155. #+END_SRC
  3156. Get the source code.
  3157. #+BEGIN_SRC: bash
  3158. export HOSTNAME=myfriendicadomainname.com
  3159. cd /var/www/$HOSTNAME
  3160. rm -rf htdocs
  3161. git clone https://github.com/friendica/friendica.git htdocs
  3162. chmod -R 755 htdocs
  3163. chown -R www-data:www-data htdocs
  3164. chown -R www-data:www-data htdocs/view/smarty3
  3165. git clone https://github.com/friendica/friendica-addons.git htdocs/addon
  3166. #+END_SRC
  3167. Now visit the URL of your site and you should be taken through the rest of the installation procedure.
  3168. | Database Server Name | localhost |
  3169. | Database login name | friendicaadmin |
  3170. | Database Login Password | myfriendicapassword |
  3171. | Database Name | friendica |
  3172. 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.
  3173. 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.
  3174. Install the poller.
  3175. #+BEGIN_SRC: bash
  3176. editor /etc/crontab
  3177. #+END_SRC
  3178. and append the following, changing /myfriendicadomainname.com/ to whatever your Friendica domain is.
  3179. #+BEGIN_SRC: bash
  3180. */10 * * * * root cd /var/www/myfriendicadomainname.com/htdocs; /usr/bin/timeout 120 /usr/bin/php include/poller.php
  3181. #+END_SRC
  3182. Save and exit, then restart cron.
  3183. #+BEGIN_SRC: bash
  3184. service cron restart
  3185. #+END_SRC
  3186. You can improve the speed of Friendica database searches by adding the following indexes:
  3187. #+BEGIN_SRC: bash
  3188. mysql -u root -p
  3189. use friendica;
  3190. CREATE INDEX `uri_received` ON item(`uri`, `received`);
  3191. CREATE INDEX `received_uri` ON item(`received`, `uri`);
  3192. CREATE INDEX `contact-id_created` ON item(`contact-id`, created);
  3193. CREATE INDEX `uid_network_received` ON item(`uid`, `network`, `received`);
  3194. CREATE INDEX `uid_parent` ON item(`uid`, `parent`);
  3195. CREATE INDEX `uid_received` ON item(`uid`, `received`);
  3196. CREATE INDEX `uid_network_commented` ON item(`uid`, `network`, `commented`);
  3197. CREATE INDEX `uid_title` ON item(uid, `title`);
  3198. CREATE INDEX `created_contact-id` ON item(`created`, `contact-id`);
  3199. quit
  3200. #+END_SRC
  3201. Make sure that Friendica doesn't use too much memory.
  3202. #+BEGIN_SRC: bash
  3203. editor /var/www/$HOSTNAME/htdocs/.htaccess
  3204. #+END_SRC
  3205. Append the following:
  3206. #+BEGIN_SRC: bash
  3207. php_value memory_limit 32M
  3208. #+END_SRC
  3209. The save ane exit.
  3210. **** Backups
  3211. 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.
  3212. #+BEGIN_SRC: bash
  3213. editor /etc/cron.daily/backup
  3214. #+END_SRC
  3215. Enter the following, replacing /myusername@mydomainname.com/ with your email address and the mysql root password as appropriate.
  3216. #+BEGIN_SRC: bash
  3217. #!/bin/sh
  3218. EMAIL=myusername@mydomainname.com
  3219. MYSQL_PASSWORD=<mysql root password>
  3220. umask 0077
  3221. # stop the web server to avoid any changes to the databases during backup
  3222. service apache2 stop
  3223. # Save to a temporary file first so that it can be checked for non-zero size
  3224. TEMPFILE=/tmp/friendicared.sql
  3225. # Backup the Friendica database
  3226. DAILYFILE=/var/backups/friendica_daily.sql
  3227. mysqldump --password=$MYSQL_PASSWORD friendica > $TEMPFILE
  3228. FILESIZE=$(stat -c%s $TEMPFILE)
  3229. if [ "$FILESIZE" -eq "0" ]; then
  3230. if [ -f $DAILYFILE ]; then
  3231. cp $DAILYFILE $TEMPFILE
  3232. # try to restore yesterday's database
  3233. mysql -u root --password=$MYSQL_PASSWORD friendica -o < $DAILYFILE
  3234. # Send a warning email
  3235. echo "Unable to create a backup of the Friendica database. Attempted to restore from yesterday's backup." | mail -s "Friendica backup" $EMAIL
  3236. else
  3237. # Send a warning email
  3238. echo "Unable to create a backup of the Friendica database." | mail -s "Friendica backup" $EMAIL
  3239. fi
  3240. else
  3241. chmod 600 $TEMPFILE
  3242. mv $TEMPFILE $DAILYFILE
  3243. # Make the backup readable only by root
  3244. chmod 600 $DAILYFILE
  3245. fi
  3246. # Backup the Roundcube database
  3247. DAILYFILE=/var/backups/roundcubemail_daily.sql
  3248. mysqldump --password=$MYSQL_PASSWORD roundcubemail > $TEMPFILE
  3249. FILESIZE=$(stat -c%s $TEMPFILE)
  3250. if [ "$FILESIZE" -eq "0" ]; then
  3251. if [ -f $DAILYFILE ]; then
  3252. cp $DAILYFILE $TEMPFILE
  3253. # try to restore yesterday's database
  3254. mysql -u root --password=$MYSQL_PASSWORD roundcubemail -o < $DAILYFILE
  3255. # Send a warning email
  3256. echo "Unable to create a backup of the Roundcube database. Attempted to restore from yesterday's backup" | mail -s "Roundcube backup" $EMAIL
  3257. else
  3258. # Send a warning email
  3259. echo "Unable to create a backup of the Roundcube database." | mail -s "Roundcube backup" $EMAIL
  3260. fi
  3261. else
  3262. chmod 600 $TEMPFILE
  3263. mv $TEMPFILE $DAILYFILE
  3264. # Make the backup readable only by root
  3265. chmod 600 $DAILYFILE
  3266. fi
  3267. # Backup the Red Matrix database
  3268. DAILYFILE=/var/backups/redmatrix_daily.sql
  3269. #mysqldump --password=$MYSQL_PASSWORD redmatrix > $TEMPFILE
  3270. #FILESIZE=$(stat -c%s $TEMPFILE)
  3271. #if [ "$FILESIZE" -eq "0" ]; then
  3272. # if [ -f $DAILYFILE ]; then
  3273. # cp $DAILYFILE $TEMPFILE
  3274. # # try to restore yesterday's database
  3275. # mysql -u root --password=$MYSQL_PASSWORD redmatrix -o < $DAILYFILE
  3276. # # Send a warning email
  3277. # echo "Unable to create a backup of the Red Matrix database. Attempted to restore from yesterday's backup" | mail -s "Red Matrix backup" $EMAIL
  3278. # else
  3279. # # Send a warning email
  3280. # echo "Unable to create a backup of the Red Matrix database." | mail -s "Red Matrix backup" $EMAIL
  3281. # fi
  3282. #else
  3283. # chmod 600 $TEMPFILE
  3284. # mv $TEMPFILE $DAILYFILE
  3285. # # Make the backup readable only by root
  3286. # chmod 600 $DAILYFILE
  3287. #fi
  3288. # restart the web server
  3289. service apache2 start
  3290. exit 0
  3291. #+END_SRC
  3292. Save and exit.
  3293. #+BEGIN_SRC: bash
  3294. chmod 600 /etc/cron.daily/backup
  3295. chmod +x /etc/cron.daily/backup
  3296. editor /etc/cron.weekly/backup
  3297. #+END_SRC
  3298. Enter the following
  3299. #+BEGIN_SRC: bash
  3300. #!/bin/sh
  3301. umask 0077
  3302. # Friendica
  3303. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_2weekly.sql
  3304. cp -f /var/backups/friendica_daily.sql /var/backups/friendica_weekly.sql
  3305. # Roundcube
  3306. cp -f /var/backups/roundcubemail_weekly.sql /var/backups/roundcubemail_2weekly.sql
  3307. cp -f /var/backups/roundcubemail_daily.sql /var/backups/roundcubemail_weekly.sql
  3308. # Red Matrix
  3309. #cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_2weekly.sql
  3310. #cp -f /var/backups/redmatrix_daily.sql /var/backups/redmatrix_weekly.sql
  3311. #+END_SRC
  3312. Save and exit.
  3313. #+BEGIN_SRC: bash
  3314. chmod 600 /etc/cron.weekly/backup
  3315. chmod +x /etc/cron.weekly/backup
  3316. editor /etc/cron.monthly/backup
  3317. #+END_SRC
  3318. Enter the following
  3319. #+BEGIN_SRC: bash
  3320. #!/bin/sh
  3321. # Friendica
  3322. cp -f /var/backups/friendica_monthly.sql /var/backups/friendica_2monthly.sql
  3323. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_monthly.sql
  3324. # Roundcube
  3325. cp -f /var/backups/roundcubemail_monthly.sql /var/backups/roundcubemail_2monthly.sql
  3326. cp -f /var/backups/roundcubemail_weekly.sql /var/backups/roundcubemail_monthly.sql
  3327. # Red Matrix
  3328. #cp -f /var/backups/redmatrix_monthly.sql /var/backups/redmatrix_2monthly.sql
  3329. #cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_monthly.sql
  3330. #+END_SRC
  3331. Save and exit.
  3332. #+BEGIN_SRC: bash
  3333. chmod 600 /etc/cron.monthly/backup
  3334. chmod +x /etc/cron.monthly/backup
  3335. #+END_SRC
  3336. **** Recommended configuration
  3337. ***** Admin
  3338. 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.
  3339. 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.
  3340. Under the *themes* section select a few themes, including mobile themes which are suitable for phones or tablets.
  3341. 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.
  3342. If you also wish to publish your public posts to a Diaspora node then within the *site* settings select *enable Diaspora support*.
  3343. 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]].
  3344. ***** Settings
  3345. Each user has their own customisable settings, typically available either via an icon or by an entry on a drop down menu.
  3346. Under *additional features* enable "/richtext editor/", "/post preview/", "/group filter/", "/network filter/", "/edit sent posts/" and "/dislike posts/".
  3347. Under *display settings* select your desktop and mobile themes.
  3348. 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.
  3349. **** To access from an Android device
  3350. ***** App
  3351. 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.
  3352. 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.
  3353. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  3354. ***** Mobile Theme
  3355. 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.
  3356. *** Movim
  3357. #+BEGIN_VERSE
  3358. /The way we communicate with others and with ourselves ultimately determines the quality of our lives/
  3359. -- Anthony Robbins
  3360. #+END_VERSE
  3361. Movim is another social networking system based around the XMPP protocol.
  3362. You will need to have previously [[Install a Jabber/XMPP server][installed the Jabber/XMPP server]].
  3363. 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:
  3364. #+BEGIN_SRC: bash
  3365. editor /etc/apache2/sites-available/mydomainname.com
  3366. #+END_SRC
  3367. Within the section which begins with *<VirtualHost *:80>* add the following:
  3368. #+BEGIN_SRC: bash
  3369. <Directory /var/www/mydomainname.com/htdocs/movim>
  3370. deny from all
  3371. </Directory>
  3372. #+END_SRC
  3373. Within the section which begins with *<VirtualHost *:443>* add the following:
  3374. #+BEGIN_SRC: bash
  3375. <Directory /var/www/mydomainname.com/htdocs/movim>
  3376. Options Indexes FollowSymLinks MultiViews
  3377. AllowOverride All
  3378. Order allow,deny
  3379. allow from all
  3380. </Directory>
  3381. #+END_SRC
  3382. Save and exit, then restart the apache server.
  3383. #+BEGIN_SRC: bash
  3384. service apache2 restart
  3385. #+END_SRC
  3386. Download the source.
  3387. #+BEGIN_SRC: bash
  3388. mkdir ~/build
  3389. cd ~/build
  3390. wget http://freedombone.uk.to/movim.tar.gz
  3391. #+END_SRC
  3392. Verify it.
  3393. #+BEGIN_SRC: bash
  3394. sha256sum movim.tar.gz
  3395. 2740ddbedf6cefcc2934759374376643b6cdea4fb7f944ec25098a6868cb499e movim.tar.gz
  3396. #+END_SRC
  3397. Install it.
  3398. #+BEGIN_SRC: bash
  3399. tar -xzvf movim.tar.gz
  3400. export HOSTNAME=mydomainname.com
  3401. cp -r movim-* /var/www/$HOSTNAME/htdocs/movim
  3402. chmod 755 /var/www/$HOSTNAME/htdocs/movim
  3403. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/movim
  3404. #+END_SRC
  3405. Install some MySql prerequisites.
  3406. #+BEGIN_SRC: bash
  3407. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  3408. #+END_SRC
  3409. If necessary, enter an admin password for MySQL.
  3410. Reduce the memory use of mysql by using the "small" configuration.
  3411. #+BEGIN_SRC: bash
  3412. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3413. #+END_SRC
  3414. Create a mysql database.
  3415. #+BEGIN_SRC: bash
  3416. mysql -u root -p
  3417. create database movim;
  3418. CREATE USER 'movimadmin'@'localhost' IDENTIFIED BY 'movimadminpassword';
  3419. GRANT ALL PRIVILEGES ON movim.* TO 'movimadmin'@'localhost';
  3420. quit
  3421. #+END_SRC
  3422. With a web browser navigate to:
  3423. https://mydomainname.com/movim/admin
  3424. Enter /admin/ as the username and /password/ as the password.
  3425. 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).
  3426. Change the /Environment/ from /Development/ to /Production/.
  3427. 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?)
  3428. Click /Submit/ followed by /Resend/.
  3429. Click on /Database Settings/ and alter the MySql movim database username to /movimadmin/ and password to the password you specified in the previous step.
  3430. 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".
  3431. 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).
  3432. *** Red Matrix
  3433. **** Introduction
  3434. 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.
  3435. **** Prerequisites
  3436. 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.
  3437. 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.
  3438. **** Installation
  3439. 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.
  3440. 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:
  3441. #+BEGIN_SRC: bash
  3442. editor /etc/apache2/sites-available/mydomainname.com
  3443. #+END_SRC
  3444. Replace the section which begins with *<VirtualHost *:80>* with the following:
  3445. #+BEGIN_SRC: bash
  3446. <VirtualHost *:80>
  3447. ServerAdmin myusername@mydomainname.com
  3448. ServerName myredmatrixdomainname.com
  3449. RewriteEngine On
  3450. RewriteCond %{HTTPS} off
  3451. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3452. </VirtualHost>
  3453. #+END_SRC
  3454. Save and exit, then restart the apache server.
  3455. #+BEGIN_SRC: bash
  3456. service apache2 restart
  3457. #+END_SRC
  3458. Now install some dependencies.
  3459. #+BEGIN_SRC: bash
  3460. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  3461. #+END_SRC
  3462. Enter an admin password for MySQL.
  3463. Reduce the memory use of mysql by using the "small" configuration.
  3464. #+BEGIN_SRC: bash
  3465. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3466. #+END_SRC
  3467. Create a mysql database.
  3468. #+BEGIN_SRC: bash
  3469. mysql -u root -p
  3470. create database redmatrix;
  3471. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'password';
  3472. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  3473. quit
  3474. #+END_SRC
  3475. You may need to fix Git SSL problems.
  3476. #+BEGIN_SRC: bash
  3477. git config --global http.sslVerify true
  3478. apt-get install ca-certificates
  3479. cd ~/
  3480. editor .gitconfig
  3481. #+END_SRC
  3482. The .gitconfig file should look something like this:
  3483. #+BEGIN_SRC: bash
  3484. [http]
  3485. sslVerify = true
  3486. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  3487. [user]
  3488. email = myusername@mydomainname.com
  3489. name = yourname
  3490. #+END_SRC
  3491. Get the source code.
  3492. #+BEGIN_SRC: bash
  3493. export HOSTNAME=mydomainname.com
  3494. mkdir /var/www/$HOSTNAME
  3495. cd /var/www/$HOSTNAME
  3496. rm -rf htdocs
  3497. git clone https://github.com/friendica/red.git htdocs
  3498. chmod -R 755 htdocs
  3499. chown -R www-data:www-data htdocs
  3500. mkdir htdocs/view/tpl/smarty3
  3501. mkdir htdocs/store/[data]
  3502. mkdir htdocs/store/[data]/smarty3
  3503. chmod 777 htdocs/view/tpl
  3504. chmod 777 htdocs/view/tpl/smarty3
  3505. chmod 777 htdocs/store/[data]/smarty3
  3506. git clone https://github.com/friendica/red-addons.git htdocs/addon
  3507. #+END_SRC
  3508. 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.
  3509. Install the poller.
  3510. #+BEGIN_SRC
  3511. editor /etc/crontab
  3512. #+END_SRC
  3513. and append the following, changing mydomainname.com to whatever your domain is.
  3514. #+BEGIN_SRC
  3515. 12,22,32,42,52 * * * * root cd /var/www/apespace.org/htdocs; /usr/bin/timeout 240 /usr/bin/php include/poller.php
  3516. #+END_SRC
  3517. Save and exit, then restart cron.
  3518. #+BEGIN_SRC: bash
  3519. service cron restart
  3520. #+END_SRC
  3521. **** Backups
  3522. 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.
  3523. #+BEGIN_SRC: bash
  3524. editor /etc/cron.daily/backup
  3525. #+END_SRC
  3526. Uncomment the lines for Red Matrix, then save and exit. If you didn't install Friendica earlier then see the backup section within the Friendica install instructions.
  3527. #+BEGIN_SRC: bash
  3528. chmod 600 /etc/cron.daily/backup
  3529. chmod +x /etc/cron.daily/backup
  3530. editor /etc/cron.weekly/backup
  3531. #+END_SRC
  3532. 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:
  3533. #+BEGIN_SRC: bash
  3534. #!/bin/sh
  3535. umask 0077
  3536. # Friendica
  3537. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_2weekly.sql
  3538. cp -f /var/backups/friendica_daily.sql /var/backups/friendica_weekly.sql
  3539. # Red Matrix
  3540. cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_2weekly.sql
  3541. cp -f /var/backups/redmatrix_daily.sql /var/backups/redmatrix_weekly.sql
  3542. #+END_SRC
  3543. Save and exit.
  3544. #+BEGIN_SRC: bash
  3545. chmod 600 /etc/cron.weekly/backup
  3546. chmod +x /etc/cron.weekly/backup
  3547. editor /etc/cron.monthly/backup
  3548. #+END_SRC
  3549. 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:
  3550. #+BEGIN_SRC: bash
  3551. #!/bin/sh
  3552. # Friendica
  3553. cp -f /var/backups/friendica_monthly.sql /var/backups/friendica_2monthly.sql
  3554. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_monthly.sql
  3555. # Red Matrix
  3556. cp -f /var/backups/redmatrix_monthly.sql /var/backups/redmatrix_2monthly.sql
  3557. cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_monthly.sql
  3558. #+END_SRC
  3559. Save and exit.
  3560. #+BEGIN_SRC: bash
  3561. chmod 600 /etc/cron.monthly/backup
  3562. chmod +x /etc/cron.monthly/backup
  3563. #+END_SRC
  3564. **** To access from an Android device
  3565. ***** App
  3566. 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.
  3567. 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.
  3568. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  3569. *** pump.io
  3570. :PROPERTIES:
  3571. :ORDERED: t
  3572. :END:
  3573. 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.
  3574. 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.
  3575. #+BEGIN_SRC: bash
  3576. apt-get update
  3577. apt-get install build-essential openssl libssl-dev redis-server imagemagick graphicsmagick git-core screen
  3578. #+END_SRC
  3579. Download nodejs
  3580. #+BEGIN_SRC: bash
  3581. mkdir ~/build
  3582. cd ~/build
  3583. wget http://freedombone.uk.to/node_0.10.28-1_armhf.deb
  3584. #+END_SRC
  3585. Verify it.
  3586. #+BEGIN_SRC: bash
  3587. sha256sum node_0.10.28-1_armhf.deb
  3588. 42000a475d3397f295fe76998e79af999eebb8324ac9bb4981e931fabd9297aa
  3589. #+END_SRC
  3590. Install it.
  3591. #+BEGIN_SRC: bash
  3592. dpkg -i node_0.10.28-1_armhf.deb
  3593. #+END_SRC
  3594. Install pump.io
  3595. #+BEGIN_SRC: bash
  3596. cd /opt
  3597. git clone https://github.com/e14n/pump.io.git
  3598. cd /opt/pump.io
  3599. npm install
  3600. npm install databank-redis
  3601. echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
  3602. sysctl vm.overcommit_memory=1
  3603. #+END_SRC
  3604. Now edit the configuration file.
  3605. #+BEGIN_SRC: bash
  3606. editor /etc/pump.io.json
  3607. #+END_SRC
  3608. Add the following, replacing /mypumpiodomainname.com/ with your domain name.
  3609. #+BEGIN_SRC: bash
  3610. {
  3611. "driver": "redis",
  3612. "params": {"host":"localhost","port":6379},
  3613. "secret": "A long random string",
  3614. "noweb": false,
  3615. "site": "Name of my pump.io site",
  3616. "owner": "My name or organisation",
  3617. "ownerURL": "https://mypumpiodomainname.com/",
  3618. "port": 7270,
  3619. "urlPort": 443,
  3620. "hostname": "mypumpiodomainname.com",
  3621. "address": "localhost",
  3622. "nologger": true,
  3623. "serverUser": "pumpio",
  3624. "rejectUnauthorized": false,
  3625. "key": "/var/local/pump.io/keys/mypumpiodomainname.com.key",
  3626. "cert": "/var/local/pump.io/keys/mypumpiodomainname.com.crt",
  3627. "uploaddir": "/var/local/pump.io/uploads",
  3628. "debugClient": false,
  3629. "firehose": "ofirehose.example",
  3630. "logfile": "/var/local/pump.io/pump.log",
  3631. "disableRegistration": false
  3632. }
  3633. #+END_SRC
  3634. Save and exit.
  3635. #+BEGIN_SRC: bash
  3636. export HOSTNAME=mypumpiodomainname.com
  3637. mkdir /var/local/pump.io
  3638. mkdir /var/local/pump.io/uploads
  3639. mkdir /var/local/pump.io/keys
  3640. cp /etc/ssl/private/$HOSTNAME.key /var/local/pump.io/keys
  3641. cp /etc/ssl/certs/$HOSTNAME.crt /var/local/pump.io/keys
  3642. useradd -s /bin/bash -d /var/local/pump.io pumpio
  3643. chown -R pumpio:pumpio /var/local/pump.io
  3644. chmod 400 /var/local/pump.io/keys/*
  3645. chmod -R 777 /opt
  3646. #+END_SRC
  3647. Patch the version of Apache.
  3648. #+BEGIN_SRC: bash
  3649. mkdir ~/build
  3650. mkdir ~/build/apache2
  3651. cd ~/build/apache2
  3652. apt-get build-dep apache2
  3653. apt-get install autoconf
  3654. apt-get source apache2
  3655. cd apache2-*
  3656. wget http://freedombone.uk.to/apache-2.2-wstunnel.patch
  3657. sha256sum apache-2.2-wstunnel.patch
  3658. cfc4866da2688a8eb76e0300cf16b52539ef4e525053a3851d4b6bba9a77e439
  3659. patch -p1 -i apache-2.2-wstunnel.patch
  3660. autoconf
  3661. ./configure --enable-so --enable-proxy=shared --enable-proxy-wstunnel=shared
  3662. make
  3663. make install
  3664. cp modules/proxy/.libs/mod_proxy_wstunnel.so /usr/lib/apache2/modules/
  3665. cd /etc/apache2/mods-enabled
  3666. ln -s /usr/lib/apache2/modules/mod_proxy_wstunnel.so ../mods-available/proxy_wstunnel.load
  3667. #+END_SRC
  3668. Within the section of your Apache site configuration:
  3669. #+BEGIN_SRC: bash
  3670. editor /etc/apache2/sites-available/mypumpiodomainname.com
  3671. #+END_SRC
  3672. 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.
  3673. #+BEGIN_SRC: bash
  3674. <VirtualHost *:80>
  3675. ServerAdmin myusername@mydomainname.com
  3676. ServerName mypumpiodomainname.com
  3677. RewriteEngine On
  3678. RewriteCond %{HTTPS} off
  3679. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3680. </VirtualHost>
  3681. #+END_SRC
  3682. Add the following in the section which begins with *<VirtualHost *:443>*.
  3683. #+BEGIN_SRC: bash
  3684. ProxyVia On
  3685. ProxyPreserveHost On
  3686. ProxyRequests Off
  3687. SSLProxyEngine On
  3688. ProxyPass / https://localhost:7270/
  3689. ProxyPassReverse / https://localhost:7270/
  3690. #+END_SRC
  3691. Save and exit.
  3692. #+BEGIN_SRC: bash
  3693. a2enmod ssl
  3694. a2enmod cache
  3695. a2enmod disk_cache
  3696. a2enmod expires
  3697. a2enmod proxy
  3698. a2enmod proxy_connect
  3699. a2enmod proxy_http
  3700. apachectl configtest
  3701. service apache2 restart
  3702. npm install forever -g
  3703. #+END_SRC
  3704. Now create the daemon.
  3705. #+BEGIN_SRC: bash
  3706. editor /etc/init.d/pumpio
  3707. #+END_SRC
  3708. Add the following text:
  3709. #+BEGIN_SRC: bash
  3710. #!/bin/bash
  3711. # /etc/init.d/pumpio
  3712. ### BEGIN INIT INFO
  3713. # Provides: pump.io
  3714. # Required-Start: $remote_fs $syslog
  3715. # Required-Stop: $remote_fs $syslog
  3716. # Default-Start: 2 3 4 5
  3717. # Default-Stop: 0 1 6
  3718. # Short-Description: starts pump.io as a background daemon
  3719. # Description: Starts pump.io on boot
  3720. ### END INIT INFO
  3721. # Author: Bob Mottram <bob@robotics.uk.to>
  3722. #Settings
  3723. SERVICE='pumpio'
  3724. COMMAND="forever /opt/pump.io/bin/pump > /var/local/pump.io/daemon.log"
  3725. USERNAME='pumpio'
  3726. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system OAresources
  3727. HISTORY=1024
  3728. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  3729. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/var/local/pump.io'
  3730. pumpio_start() {
  3731. echo "Starting $SERVICE..."
  3732. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  3733. }
  3734. pumpio_stop() {
  3735. echo "Stopping $SERVICE"
  3736. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  3737. }
  3738. #Start-Stop here
  3739. case "$1" in
  3740. start)
  3741. pumpio_start
  3742. ;;
  3743. stop)
  3744. pumpio_stop
  3745. ;;
  3746. restart)
  3747. pumpio_stop
  3748. sleep 10s
  3749. pumpio_start
  3750. ;;
  3751. *)
  3752. echo "Usage: $0 {start|stop|restart}"
  3753. exit 1
  3754. ;;
  3755. esac
  3756. exit 0
  3757. #+END_SRC
  3758. Save and exit. Then enable the daemon and run it.
  3759. #+BEGIN_SRC: bash
  3760. chmod +x /etc/init.d/pumpio
  3761. update-rc.d pumpio defaults
  3762. service pumpio start
  3763. #+END_SRC
  3764. Now visit your pump.io site by navigating to:
  3765. https://mypumpiodomainname.com
  3766. 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*.
  3767. 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.
  3768. 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).
  3769. Ensure that data data gets backed up with:
  3770. #+BEGIN_SRC: bash
  3771. printf "\n\n# Redis backup" >> /etc/cron.daily/backup
  3772. printf "\ntar -czvf /var/backups/redis_daily.tar.gz /var/lib/redis/dump.rdb" >> /etc/cron.daily/backup
  3773. printf "\n\n# Redis backup" >> /etc/cron.weekly/backup
  3774. printf "\ncp -f /var/backups/redis_weekly.tar.gz /var/backups/redis_weekly2.tar.gz" >> /etc/cron.weekly/backup
  3775. printf "\ncp -f /var/backups/redis_daily.tar.gz /var/backups/redis_weekly.tar.gz" >> /etc/cron.weekly/backup
  3776. printf "\n\n# Redis backup" >> /etc/cron.monthly/backup
  3777. printf "\ncp -f /var/backups/redis_monthly.tar.gz /var/backups/redis_monthly2.tar.gz" >> /etc/cron.monthly/backup
  3778. printf "\ncp -f /var/backups/redis_weekly.tar.gz /var/backups/redis_monthly.tar.gz" >> /etc/cron.monthly/backup
  3779. printf "\n\n# Pump.io backup" >> /etc/cron.daily/backup
  3780. printf "\ntar -czvf /var/backups/pumpio_daily.tar.gz /var/local/pump.io --exclude /var/local/pump.io/.forever" >> /etc/cron.daily/backup
  3781. printf "\n\n# Pump.io backup" >> /etc/cron.weekly/backup
  3782. printf "\ncp -f /var/backups/pumpio_weekly.tar.gz /var/backups/pumpio_weekly2.tar.gz" >> /etc/cron.weekly/backup
  3783. printf "\ncp -f /var/backups/pumpio_daily.tar.gz /var/backups/pumpio_weekly.tar.gz" >> /etc/cron.weekly/backup
  3784. printf "\n\n# Pump.io backup" >> /etc/cron.monthly/backup
  3785. printf "\ncp -f /var/backups/pumpio_monthly.tar.gz /var/backups/pumpio_monthly2.tar.gz" >> /etc/cron.monthly/backup
  3786. printf "\ncp -f /var/backups/pumpio_weekly.tar.gz /var/backups/pumpio_monthly.tar.gz" >> /etc/cron.monthly/backup
  3787. #+END_SRC
  3788. 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).
  3789. ** Install Gopher
  3790. *** Server setup
  3791. 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.
  3792. To set up a gopher server:
  3793. #+BEGIN_SRC: bash
  3794. apt-get install build-essential
  3795. mkdir ~/build
  3796. cd ~/build
  3797. wget http://freedombone.uk.to/geomyidae-current.tgz
  3798. #+END_SRC
  3799. Verify the download:
  3800. #+BEGIN_SRC: bash
  3801. sha256sum geomyidae-current.tgz
  3802. 162f55ab059ab0a9be8e840497795293bbd51c34b1f4564dcdf3f0ddd5c0db31 geomyidae-current.tgz
  3803. #+END_SRC
  3804. Then extract and install it.
  3805. #+BEGIN_SRC: bash
  3806. tar -xzvf geomyidae-current.tgz
  3807. cd geomyidae-*
  3808. make
  3809. make install
  3810. mkdir -p /var/gopher
  3811. #+END_SRC
  3812. 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.
  3813. #+BEGIN_SRC: bash
  3814. editor /etc/init.d/gopher
  3815. #+END_SRC
  3816. Enter the following:
  3817. #+BEGIN_SRC: bash
  3818. #! /bin/sh
  3819. ### BEGIN INIT INFO
  3820. # Provides: gopher
  3821. # Required-Start: $remote_fs $syslog
  3822. # Required-Stop: $remote_fs $syslog
  3823. # Default-Start: 2 3 4 5
  3824. # Default-Stop: 0 1 6
  3825. # Short-Description: Gopher daemon
  3826. # Description: Gopher daemon
  3827. ### END INIT INFO
  3828. # Do NOT "set -e"
  3829. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  3830. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  3831. DESC="Gopher daemon"
  3832. NAME=geomyidae
  3833. DAEMON=/usr/bin/$NAME
  3834. DAEMON_ARGS="-l /var/log/geomyidae.log -b /var/gopher -p 70"
  3835. PIDFILE=/var/run/$NAME.pid
  3836. SCRIPTNAME=/etc/init.d/$NAME
  3837. # Exit if the package is not installed
  3838. [ -x "$DAEMON" ] || exit 0
  3839. # Read configuration variable file if it is present
  3840. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  3841. # Load the VERBOSE setting and other rcS variables
  3842. . /lib/init/vars.sh
  3843. # Define LSB log_* functions.
  3844. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  3845. # and status_of_proc is working.
  3846. . /lib/lsb/init-functions
  3847. #
  3848. # Function that starts the daemon/service
  3849. #
  3850. do_start()
  3851. {
  3852. # Return
  3853. # 0 if daemon has been started
  3854. # 1 if daemon was already running
  3855. # 2 if daemon could not be started
  3856. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  3857. || return 1
  3858. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  3859. $DAEMON_ARGS \
  3860. || return 2
  3861. # Add code here, if necessary, that waits for the process to be ready
  3862. # to handle requests from services started subsequently which depend
  3863. # on this one. As a last resort, sleep for some time.
  3864. }
  3865. #
  3866. # Function that stops the daemon/service
  3867. #
  3868. do_stop()
  3869. {
  3870. # Return
  3871. # 0 if daemon has been stopped
  3872. # 1 if daemon was already stopped
  3873. # 2 if daemon could not be stopped
  3874. # other if a failure occurred
  3875. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  3876. RETVAL="$?"
  3877. [ "$RETVAL" = 2 ] && return 2
  3878. # Wait for children to finish too if this is a daemon that forks
  3879. # and if the daemon is only ever run from this initscript.
  3880. # If the above conditions are not satisfied then add some other code
  3881. # that waits for the process to drop all resources that could be
  3882. # needed by services started subsequently. A last resort is to
  3883. # sleep for some time.
  3884. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  3885. [ "$?" = 2 ] && return 2
  3886. # Many daemons don't delete their pidfiles when they exit.
  3887. rm -f $PIDFILE
  3888. return "$RETVAL"
  3889. }
  3890. #
  3891. # Function that sends a SIGHUP to the daemon/service
  3892. #
  3893. do_reload() {
  3894. #
  3895. # If the daemon can reload its configuration without
  3896. # restarting (for example, when it is sent a SIGHUP),
  3897. # then implement that here.
  3898. #
  3899. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  3900. return 0
  3901. }
  3902. case "$1" in
  3903. start)
  3904. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  3905. do_start
  3906. case "$?" in
  3907. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  3908. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  3909. esac
  3910. ;;
  3911. stop)
  3912. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  3913. do_stop
  3914. case "$?" in
  3915. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  3916. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  3917. esac
  3918. ;;
  3919. status)
  3920. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  3921. ;;
  3922. #reload|force-reload)
  3923. #
  3924. # If do_reload() is not implemented then leave this commented out
  3925. # and leave 'force-reload' as an alias for 'restart'.
  3926. #
  3927. #log_daemon_msg "Reloading $DESC" "$NAME"
  3928. #do_reload
  3929. #log_end_msg $?
  3930. #;;
  3931. restart|force-reload)
  3932. #
  3933. # If the "reload" option is implemented then remove the
  3934. # 'force-reload' alias
  3935. #
  3936. log_daemon_msg "Restarting $DESC" "$NAME"
  3937. do_stop
  3938. case "$?" in
  3939. 0|1)
  3940. do_start
  3941. case "$?" in
  3942. 0) log_end_msg 0 ;;
  3943. 1) log_end_msg 1 ;; # Old process is still running
  3944. *) log_end_msg 1 ;; # Failed to start
  3945. esac
  3946. ;;
  3947. *)
  3948. # Failed to stop
  3949. log_end_msg 1
  3950. ;;
  3951. esac
  3952. ;;
  3953. *)
  3954. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  3955. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  3956. exit 3
  3957. ;;
  3958. esac
  3959. :
  3960. #+END_SRC
  3961. Save and exit. Then start the gopher service.
  3962. #+BEGIN_SRC: bash
  3963. chmod +x /etc/init.d/gopher
  3964. update-rc.d gopher defaults
  3965. service gopher start
  3966. #+END_SRC
  3967. 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:
  3968. #+BEGIN_SRC: bash
  3969. gopher://mydomainname.com
  3970. #+END_SRC
  3971. There is a browser addon for Gopher called "overbite". Installing that should enable you to view your site.
  3972. *** A phlogging script
  3973. A phlog is the gopher equivalent of a blog on the web. You can create a script which makes phlogging easy.
  3974. #+BEGIN_SRC: bash
  3975. editor /usr/bin/mkphlog
  3976. #+END_SRC
  3977. Add the following:
  3978. #+BEGIN_SRC: bash
  3979. #!/bin/sh
  3980. # mkphlog - a utility to ease the creation of phlogs.
  3981. # Organizes phlog posts in separate directories.
  3982. # Created by octotep; anyone can distribute, modify, and
  3983. # share this file however they please.
  3984. #
  3985. # Version 0.3
  3986. #
  3987. # Modified by Bob Mottram
  3988. #
  3989. # Please note, all date strings are in the form of mm/dd/yy(yy)
  3990. # The base of the entire gopher site.
  3991. gopherRoot="/var/gopher"
  3992. # The name of the phlog directory (contained in $gopherHome)
  3993. phlogDirName="phlog"
  3994. # Default editor, unless the user has one specified in env
  3995. editor=${EDITOR:-emacs}
  3996. # Default timezone, unless the user has one specified in env
  3997. TZ=${TZ:-UTC}
  3998. # Tells the script how many lines the title of the main page spans.
  3999. # Used to insert the newest post at the top.
  4000. # Titles created by mkphlog are 3 lines.
  4001. # Isn't used if $addTitleToMain is false
  4002. titleLineCount=3
  4003. entryDate=`date +%Y-%m-%d`
  4004. # Creates the phlog directory if it dosen't already exist.
  4005. CreatePhlogDir() {
  4006. mkdir $phlogDirName
  4007. chmod 755 $phlogDirName
  4008. cd $phlogDirName
  4009. echo "Phlog directory created."
  4010. }
  4011. # Updates the main phlog listing
  4012. UpdatePhlogListing() {
  4013. # Just in case the user didn't specify a title
  4014. if [ "$postTitleAns" = "" ] ; then
  4015. echo -n "Do you want to create a blank post? (y/n) "
  4016. read blankPostAns
  4017. case $blankPostAns in
  4018. y* | Y* ) $postTitleAns="New Post" ;;
  4019. n* | N* ) echo "Goodbye, then." ; exit 1 ;;
  4020. * ) exit 1 ;;
  4021. esac
  4022. fi
  4023. cd $gopherRoot/$phlogDirName/
  4024. title2=$(echo "${postTitleAns}" | tr " " _)
  4025. postfilename="${entryDate}_${title2}.txt"
  4026. touch ${postfilename}
  4027. echo $postTitleAns >> ${postfilename}
  4028. date "+%A %b %e %l:%M:%S %Y" >> ${postfilename}
  4029. echo "------------------------------" >> ${postfilename}
  4030. echo >> ${postfilename}
  4031. }
  4032. if [ -d $gopherRoot ] ; then
  4033. cd $gopherRoot
  4034. else
  4035. echo "You don't have a gopherspace set-up. Please run the gopher server setup instructions."
  4036. exit 1
  4037. fi
  4038. if [ -d $phlogDirName ] ; then
  4039. cd $phlogDirName
  4040. else
  4041. echo -n "Do you want to create a phlog directory? (y/n) "
  4042. read phlogDirAns
  4043. case $phlogDirAns in
  4044. y* | Y* ) CreatePhlogDir ;;
  4045. n* | N* ) exit 1 ;;
  4046. * ) exit 1 ;;
  4047. esac
  4048. fi
  4049. echo -n "Would you like to create a phlog entry for today? (y/n) "
  4050. read phlogAns
  4051. case $phlogAns in
  4052. y* | Y* ) echo "Creating today's phlog entry..." ;;
  4053. n* | N* ) exit 0 ;;
  4054. * ) exit 1 ;;
  4055. esac
  4056. # Make sure there isn't a post for that day, lest we overwrite it.
  4057. if [ ! -d $entryDate ]; then
  4058. echo -n "Title: "
  4059. read postTitleAns
  4060. title2=$(echo "${postTitleAns}" | tr " " _)
  4061. postfilename="${entryDate}_${title2}.txt"
  4062. touch ${postfilename}
  4063. chmod 644 ${postfilename}
  4064. UpdatePhlogListing
  4065. echo -n "Would you like to edit the post with $editor? (y/n) "
  4066. read editorAns
  4067. case $editorAns in
  4068. y* | Y* ) $editor $gopherRoot/$phlogDirName/${postfilename} ;;
  4069. n* | N* ) exit 0 ;;
  4070. * ) exit 0 ;;
  4071. esac
  4072. rm $gopherRoot/$phlogDirName/${postfilename}~
  4073. else
  4074. echo "There is already a post for today."
  4075. echo -n "Would you like to edit the post with $editor? (y/n) "
  4076. read editorAns
  4077. case $editorAns in
  4078. y* | Y* ) $editor $gopherRoot/$phlogDirName/$entryDate*.txt ;;
  4079. n* | N* ) exit 0 ;;
  4080. * ) exit 1 ;;
  4081. esac
  4082. rm $gopherRoot/$phlogDirName/${postfilename}.txt~
  4083. fi
  4084. exit 0
  4085. #+END_SRC
  4086. Save and exit.
  4087. #+BEGIN_SRC: bash
  4088. chmod +x /usr/bin/mkphlog
  4089. #+END_SRC
  4090. Now entering the command /mkphlog/ will allow you to create a phlog entry.
  4091. ** Install Owncloud
  4092. #+BEGIN_VERSE
  4093. /It's not water vapour/
  4094. -- Larry Ellison
  4095. #+END_VERSE
  4096. 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.
  4097. *** Server Installation
  4098. Install some dependencies:
  4099. #+BEGIN_SRC: bash
  4100. apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
  4101. apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
  4102. #+END_SRC
  4103. 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.
  4104. #+BEGIN_SRC: bash
  4105. a2dismod php5filter
  4106. apt-get install libapache2-mod-php5
  4107. #+END_SRC
  4108. Ensure that the size of files which may be uploaded or downloaded is large enough.
  4109. #+BEGIN_SRC: bash
  4110. editor /etc/php5/apache2/php.ini
  4111. #+END_SRC
  4112. Set the following:
  4113. #+BEGIN_SRC: bash
  4114. upload_max_filesize = 512M
  4115. post_max_size = 512M
  4116. #+END_SRC
  4117. Save and exit, then edit your Apache configuration.
  4118. #+BEGIN_SRC: bash
  4119. export HOSTNAME=mydomainname.com
  4120. editor /etc/apache2/sites-available/$HOSTNAME
  4121. #+END_SRC
  4122. 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.
  4123. #+BEGIN_SRC: bash
  4124. <Directory /var/www/mydomainname.com/htdocs/owncloud>
  4125. Options Indexes FollowSymLinks MultiViews
  4126. AllowOverride All
  4127. Order allow,deny
  4128. allow from all
  4129. LimitRequestBody 536870912
  4130. </Directory>
  4131. #+END_SRC
  4132. To ensure that nobody logs in insecurely add the following to the 80 VirtualHost section.
  4133. #+BEGIN_SRC: bash
  4134. <Directory /var/www/mydomainname.com/htdocs/owncloud>
  4135. deny from all
  4136. </Directory>
  4137. #+END_SRC
  4138. Save and exit, then restart apache.
  4139. #+BEGIN_SRC: bash
  4140. service apache2 restart
  4141. #+END_SRC
  4142. Download owncloud.
  4143. #+BEGIN_SRC: bash
  4144. mkdir ~/build
  4145. cd ~/build
  4146. wget http://freedombone.uk.to/owncloud.tar.bz2
  4147. #+END_SRC
  4148. Verify the download:
  4149. #+BEGIN_SRC: bash
  4150. sha256sum owncloud.tar.bz2
  4151. 9aca2aa0a0cd7b052e881c30ad6de25d135ec3f88a3920274f1be223b4cabedf
  4152. #+END_SRC
  4153. Extract the archive. This may take a couple of minutes, so don't be alarmed that the system has crashed.
  4154. #+BEGIN_SRC: bash
  4155. export HOSTNAME=mydomainname.com
  4156. tar -xjf owncloud.tar.bz2
  4157. #+END_SRC
  4158. The extraction will take a few minutes. Move the extracted files to your site and set file permissions.
  4159. #+BEGIN_SRC: bash
  4160. cp -r owncloud /var/www/$HOSTNAME/htdocs
  4161. #+END_SRC
  4162. The copying also takes a few minutes. Then change the file permissions.
  4163. #+BEGIN_SRC: bash
  4164. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/apps
  4165. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/config
  4166. chown www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud
  4167. #+END_SRC
  4168. Edit the htaccess file for Owncloud.
  4169. #+BEGIN_SRC: bash
  4170. editor /var/www/$HOSTNAME/htdocs/owncloud/.htaccess
  4171. #+END_SRC
  4172. Set the following.
  4173. #+BEGIN_SRC: bash
  4174. php_value upload_max_filesize 512M
  4175. php_value post_max_size 512M
  4176. php_value memory_limit 32M
  4177. #+END_SRC
  4178. Save and exit.
  4179. With a web browser visit your domain (mydomainname.com/owncloud) and enter an administrator username and password.
  4180. For extra security you may also wish to create an ordinary owncloud user with limited privileges. To do that click on the *settings* dropdown menu (top right) then *users* then enter a *Login Name* and *password* and click on *create*. Under *quota* select a size which is suitable for the remaining space on your microSD card, then select the settings menu from the top right and select *log out*. You can now log back in as your new user.
  4181. *** Owncloud on Android
  4182. 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.
  4183. ** Install a Wiki
  4184. #+BEGIN_VERSE
  4185. /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./
  4186. -- Tom Barbalet
  4187. #+END_VERSE
  4188. Dokuwiki is based upon flat files, and so is easy to move from one server to another without a lot of database complications.
  4189. Download the wiki.
  4190. #+BEGIN_SRC: bash
  4191. mkdir ~/build
  4192. cd ~/build
  4193. wget http://freedombone.uk.to/dokuwiki.tgz
  4194. #+END_SRC
  4195. Verify it.
  4196. #+BEGIN_SRC: bash
  4197. sha256sum dokuwiki.tgz
  4198. 6b126f90979463d9ddaa74acc6f96aa230cfdc789946f241c3646086d9574be8 dokuwiki.tgz
  4199. #+END_SRC
  4200. Then extract and install it.
  4201. #+BEGIN_SRC: bash
  4202. export HOSTNAME=mywikidomainname.com
  4203. tar -xzvf dokuwiki.tgz
  4204. mv /var/www/$HOSTNAME/htdocs /var/www/$HOSTNAME/htdocs_old
  4205. mv dokuwiki /var/www/$HOSTNAME/htdocs
  4206. #+END_SRC
  4207. Edit the Apache configuration for your wiki site.
  4208. #+BEGIN_SRC: bash
  4209. editor /etc/apache2/sites-available/$HOSTNAME
  4210. #+END_SRC
  4211. The settings should look something like the following. Replace /mywikidomainname.com/ with your wiki domain name.
  4212. #+BEGIN_SRC: bash
  4213. <VirtualHost *:80>
  4214. ServerAdmin myusername@mywikidomainname.com
  4215. ServerName mydomainname.com
  4216. DocumentRoot /var/www/mywikidomainname.com/htdocs
  4217. <Directory /var/www/mywikidomainname.com/htdocs>
  4218. order deny,allow
  4219. allow from all
  4220. </Directory>
  4221. <LocationMatch "/(data|conf|bin|inc)/">
  4222. order allow,deny
  4223. deny from all
  4224. satisfy all
  4225. </LocationMatch>
  4226. <Directory />
  4227. Options FollowSymLinks
  4228. AllowOverride All
  4229. </Directory>
  4230. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  4231. <Directory "/usr/lib/cgi-bin">
  4232. AllowOverride All
  4233. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  4234. Order allow,deny
  4235. Allow from all
  4236. </Directory>
  4237. ErrorLog ${APACHE_LOG_DIR}/error.log
  4238. # Possible values include: debug, info, notice, warn, error, crit,
  4239. # alert, emerg.
  4240. LogLevel error
  4241. CustomLog ${APACHE_LOG_DIR}/access.log combined
  4242. </VirtualHost>
  4243. <IfModule mod_ssl.c>
  4244. <VirtualHost *:443>
  4245. ServerAdmin myusername@mywikidomainname.com
  4246. ServerName mywikidomainname.com
  4247. DocumentRoot /var/www/mywikidomainname.com/htdocs
  4248. <Directory /var/www/mywikidomainname.com/htdocs>
  4249. order deny,allow
  4250. allow from all
  4251. </Directory>
  4252. <LocationMatch "/(data|conf|bin|inc)/">
  4253. order allow,deny
  4254. deny from all
  4255. satisfy all
  4256. </LocationMatch>
  4257. <Directory />
  4258. Options FollowSymLinks
  4259. AllowOverride All
  4260. </Directory>
  4261. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  4262. <Directory "/usr/lib/cgi-bin">
  4263. AllowOverride All
  4264. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  4265. Order allow,deny
  4266. Allow from all
  4267. </Directory>
  4268. ErrorLog ${APACHE_LOG_DIR}/error.log
  4269. # Possible values include: debug, info, notice, warn, error, crit,
  4270. # alert, emerg.
  4271. LogLevel error
  4272. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  4273. # SSL Engine Switch:
  4274. # Enable/Disable SSL for this virtual host.
  4275. SSLEngine on
  4276. # A self-signed certificate
  4277. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  4278. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  4279. # Options based on bettercrypto.org
  4280. SSLProtocol All -SSLv2 -SSLv3
  4281. SSLHonorCipherOrder On
  4282. SSLCompression off
  4283. 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
  4284. # SSL Engine Options:
  4285. # Set various options for the SSL engine.
  4286. # o FakeBasicAuth:
  4287. # Translate the client X.509 into a Basic Authorisation. This means that
  4288. # the standard Auth/DBMAuth methods can be used for access control. The
  4289. # user name is the `one line' version of the client's X.509 certificate.
  4290. # Note that no password is obtained from the user. Every entry in the user
  4291. # file needs this password: `xxj31ZMTZzkVA'.
  4292. # o ExportCertData:
  4293. # This exports two additional environment variables: SSL_CLIENT_CERT and
  4294. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  4295. # server (always existing) and the client (only existing when client
  4296. # authentication is used). This can be used to import the certificates
  4297. # into CGI scripts.
  4298. # o StdEnvVars:
  4299. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  4300. # Per default this exportation is switched off for performance reasons,
  4301. # because the extraction step is an expensive operation and is usually
  4302. # useless for serving static content. So one usually enables the
  4303. # exportation for CGI and SSI requests only.
  4304. # o StrictRequire:
  4305. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  4306. # under a "Satisfy any" situation, i.e. when it applies access is denied
  4307. # and no other module can change it.
  4308. # o OptRenegotiate:
  4309. # This enables optimized SSL connection renegotiation handling when SSL
  4310. # directives are used in per-directory context.
  4311. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  4312. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  4313. SSLOptions +StdEnvVars
  4314. </FilesMatch>
  4315. <Directory /usr/lib/cgi-bin>
  4316. SSLOptions +StdEnvVars
  4317. </Directory>
  4318. # SSL Protocol Adjustments:
  4319. # The safe and default but still SSL/TLS standard compliant shutdown
  4320. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  4321. # the close notify alert from client. When you need a different shutdown
  4322. # approach you can use one of the following variables:
  4323. # o ssl-unclean-shutdown:
  4324. # This forces an unclean shutdown when the connection is closed, i.e. no
  4325. # SSL close notify alert is send or allowed to received. This violates
  4326. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  4327. # this when you receive I/O errors because of the standard approach where
  4328. # mod_ssl sends the close notify alert.
  4329. # o ssl-accurate-shutdown:
  4330. # This forces an accurate shutdown when the connection is closed, i.e. a
  4331. # SSL close notify alert is send and mod_ssl waits for the close notify
  4332. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  4333. # practice often causes hanging connections with brain-dead browsers. Use
  4334. # this only for browsers where you know that their SSL implementation
  4335. # works correctly.
  4336. # Notice: Most problems of broken clients are also related to the HTTP
  4337. # keep-alive facility, so you usually additionally want to disable
  4338. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  4339. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  4340. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  4341. # "force-response-1.0" for this.
  4342. BrowserMatch "MSIE [2-6]" \
  4343. nokeepalive ssl-unclean-shutdown \
  4344. downgrade-1.0 force-response-1.0
  4345. # MSIE 7 and newer should be able to use keepalive
  4346. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  4347. </VirtualHost>
  4348. </IfModule>
  4349. #+END_SRC
  4350. Enable your site with:
  4351. #+BEGIN_SRC: bash
  4352. a2ensite
  4353. #+END_SRC
  4354. then select the domain name and reload.
  4355. #+BEGIN_SRC: bash
  4356. service apache2 reload
  4357. #+END_SRC
  4358. and alter permissions:
  4359. #+BEGIN_SRC: bash
  4360. chmod -R 755 /var/www/$HOSTNAME/htdocs
  4361. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs
  4362. #+END_SRC
  4363. Open a browser and visit http://$HOSTNAME/install.php, then fill out the details. Once everything has been accepted without errors:
  4364. #+BEGIN_SRC: bash
  4365. rm /var/www/$HOSTNAME/htdocs/install.php
  4366. #+END_SRC
  4367. Add a few extra mime types:
  4368. #+BEGIN_SRC: bash
  4369. editor /var/www/$HOSTNAME/htdocs/conf/mime.conf
  4370. #+END_SRC
  4371. Append the following:
  4372. #+BEGIN_SRC: bash
  4373. ogv video/ogg
  4374. mp4 video/mp4
  4375. webm video/webm
  4376. #+END_SRC
  4377. Save and exit.
  4378. 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*.
  4379. Now you can visit your wiki and begin editing.
  4380. ** Install Bitmessage
  4381. #+BEGIN_VERSE
  4382. /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/
  4383. -- Edward J. Snowden, testimony to the EU parliament
  4384. #+END_VERSE
  4385. *** A new kind of Email
  4386. [[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.
  4387. 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.
  4388. Installing Bitmessage as a daemon will increase the size of the network, and therefore the level of security for all users.
  4389. *** The Daemon
  4390. Install from the current source code.
  4391. #+BEGIN_SRC: bash
  4392. apt-get install python screen
  4393. mkdir ~/build
  4394. cd ~/build
  4395. git clone https://github.com/bashrc/PyBitmessage.git
  4396. cd PyBitmessage
  4397. make install
  4398. #+END_SRC
  4399. Now create the daemon.
  4400. #+BEGIN_SRC: bash
  4401. editor /etc/init.d/pybitmessage
  4402. #+END_SRC
  4403. Add the following text:
  4404. #+BEGIN_SRC: bash
  4405. #!/bin/bash
  4406. # /etc/init.d/bitmessage
  4407. ### BEGIN INIT INFO
  4408. # Provides: pybitmessage
  4409. # Required-Start: $remote_fs $syslog
  4410. # Required-Stop: $remote_fs $syslog
  4411. # Default-Start: 2 3 4 5
  4412. # Default-Stop: 0 1 6
  4413. # Short-Description: starts bitmessage as a background daemon, suitable for servers
  4414. # Description: This file should be used to construct scripts to be
  4415. # placed in /etc/init.d.
  4416. ### END INIT INFO
  4417. # Author: Super-Nathan <BM-Gu2k3Wy2hpTMYBxSoM2937SPcuU6xzEj>
  4418. #Settings
  4419. SERVICE='pybitmessage'
  4420. LOGFILE='/dev/null' # this disables logging
  4421. # LOGFILE='/var/log/bitmessage.log' # comment out the above line and un-comment this line to save a log
  4422. COMMAND="python bitmessagemain.py > $LOGFILE"
  4423. USERNAME='bitmsg'
  4424. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  4425. HISTORY=1024
  4426. PBM_LOCATION="/usr/local/share/pybitmessage"
  4427. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4428. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin:/usr/local/share/pybitmessage'
  4429. bm_start() {
  4430. echo "Starting $SERVICE..."
  4431. cd ${PBM_LOCATION}
  4432. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4433. }
  4434. bm_stop() {
  4435. echo "Stopping $SERVICE"
  4436. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  4437. }
  4438. #Start-Stop here
  4439. case "$1" in
  4440. start)
  4441. bm_start
  4442. ;;
  4443. stop)
  4444. bm_stop
  4445. ;;
  4446. restart)
  4447. bm_stop
  4448. sleep 60s
  4449. bm_start
  4450. ;;
  4451. *)
  4452. echo "Usage: $0 {start|stop|restart}"
  4453. exit 1
  4454. ;;
  4455. esac
  4456. exit 0
  4457. #+END_SRC
  4458. Save and exit.
  4459. 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.
  4460. #+BEGIN_SRC: bash
  4461. adduser bitmsg
  4462. #+END_SRC
  4463. Create a /keys.dat/ file which is used to configure Bitmessage.
  4464. #+BEGIN_SRC: bash
  4465. mkdir /home/bitmsg/.config
  4466. mkdir /home/bitmsg/.config/PyBitmessage
  4467. editor /home/bitmsg/.config/PyBitmessage/keys.dat
  4468. #+END_SRC
  4469. Add the following, changing /apipassword/ to some long random string:
  4470. #+BEGIN_SRC: bash
  4471. [bitmessagesettings]
  4472. settingsversion = 8
  4473. port = 8444
  4474. timeformat = %%a, %%d %%b %%Y %%I:%%M %%p
  4475. blackwhitelist = black
  4476. startonlogon = False
  4477. minimizetotray = False
  4478. showtraynotifications = True
  4479. startintray = False
  4480. socksproxytype = none
  4481. sockshostname = localhost
  4482. socksport = 9050
  4483. socksauthentication = False
  4484. sockslisten = False
  4485. socksusername =
  4486. sockspassword =
  4487. keysencrypted = false
  4488. messagesencrypted = false
  4489. defaultnoncetrialsperbyte = 640
  4490. defaultpayloadlengthextrabytes = 14000
  4491. minimizeonclose = false
  4492. maxacceptablenoncetrialsperbyte = 0
  4493. maxacceptablepayloadlengthextrabytes = 0
  4494. userlocale = system
  4495. useidenticons = True
  4496. identiconsuffix = re9E9UtSEaWD
  4497. replybelow = False
  4498. stopresendingafterxdays = 4
  4499. stopresendingafterxmonths =
  4500. namecoinrpctype = namecoind
  4501. namecoinrpchost = localhost
  4502. namecoinrpcuser =
  4503. namecoinrpcpassword =
  4504. namecoinrpcport = 8336
  4505. sendoutgoingconnections = True
  4506. willinglysendtomobile = False
  4507. maxpayloadlengthkb = 256
  4508. daemon = true
  4509. apienabled = true
  4510. apiport = 8442
  4511. apiinterface = 127.0.0.1
  4512. apiusername = bitmsg
  4513. maxpayloadlengthkb = 256
  4514. apipassword = change_this_password
  4515. #+END_SRC
  4516. Save and exit. Then enable the daemon and run it.
  4517. #+BEGIN_SRC: bash
  4518. rm -f /tmp/-usr-local-share-pybitmessage-*.lock
  4519. chown -R bitmsg:bitmsg /home/bitmsg
  4520. chmod +x /etc/init.d/pybitmessage
  4521. update-rc.d pybitmessage defaults
  4522. service pybitmessage start
  4523. #+END_SRC
  4524. Now open port 8444 on your internet router or firewall and direct it to the BBB.
  4525. *** Using Bitmessage
  4526. 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.
  4527. 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:
  4528. #+BEGIN_SRC: bash
  4529. mkdir ~/build
  4530. cd ~/build
  4531. git clone https://github.com/Bitmessage/PyBitmessage.git
  4532. cd PyBitmessage
  4533. make install
  4534. pybitmessage
  4535. #+END_SRC
  4536. *** Connect Bitmessage to Email
  4537. It may be convenient to have any Bitmessages addressed to you which arrive at the BBB to be transfered to your email, so that you can check for messages on mobile devices or on computers where installing a Bitmessage client isn't an available option. This transference will take place on the BBB itself, so will not involve transmitting any plaintext over the local network or internet. To do this first you'll need to set up a receiving Bitmessage address by editing:
  4538. #+BEGIN_SRC: bash
  4539. /home/bitmsg/.config/PyBitmessage/keys.dat
  4540. #+END_SRC
  4541. and adding the details for your address, which could be coppied from another machine (such as a laptop running a Bitmessage client).
  4542. It will look something like:
  4543. #+BEGIN_SRC: bash
  4544. [BM-address]
  4545. label = myusername@mydomainname.com
  4546. enabled = true
  4547. decoy = false
  4548. noncetrialsperbyte = 640
  4549. payloadlengthextrabytes = 14000
  4550. privsigningkey = ...
  4551. privencryptionkey = ...
  4552. lastpubkeysendtime = ...
  4553. #+END_SRC
  4554. Note that it's particularly important that /label/ be set to your email address. This is how the system will know that when a bitmessage arrives which account to transfer it to.
  4555. You should also make sure that /apipassword/ is set to some long random string.
  4556. Save and close /keys.dat/, then restart the Bitmessage daemon.
  4557. #+BEGIN_SRC: bash
  4558. service pybitmessage restart
  4559. #+END_SRC
  4560. The restart will take 30 seconds or so. Next install the Bitmessage to email gateway.
  4561. #+BEGIN_SRC: bash
  4562. cd /usr/share
  4563. git clone https://github.com/bashrc/bitmessage-email-gateway
  4564. chown -R bitmsg:bitmsg bitmessage-email-gateway
  4565. cd bitmessage-email-gateway
  4566. mkdir /home/bitmsg/Maildir
  4567. mkdir /home/bitmsg/Maildir/new
  4568. chown -R bitmsg:bitmsg /home/bitmsg
  4569. #+END_SRC
  4570. Substitute /your_domain_name/ for your domain name (the main one used for email).
  4571. #+BEGIN_SRC: bash
  4572. sed 's/mydomainname.com/your_domain_name/g' bitmessage-gateway.py > bitmessage-gateway.py
  4573. #+END_SRC
  4574. Find out what the API password is:
  4575. #+BEGIN_SRC: bash
  4576. grep "apipassword" /home/bitmsg/.config/PyBitmessage/keys.dat | awk -F ' ' '{print $3}'
  4577. #+END_SRC
  4578. Then change it with:
  4579. #+BEGIN_SRC: bash
  4580. sed "s/'password' : ''/'password' : 'bitmessage_api_password'/g" bitmessage-gateway.py > bitmessage-gateway.py
  4581. #+END_SRC
  4582. Now create the daemon.
  4583. #+BEGIN_SRC: bash
  4584. editor /etc/init.d/bitmessage-gateway
  4585. #+END_SRC
  4586. Add the following text:
  4587. #+BEGIN_SRC: bash
  4588. #!/bin/bash
  4589. # /etc/init.d/bitmessage-gateway
  4590. ### BEGIN INIT INFO
  4591. # Provides: bitmessage-gateway
  4592. # Required-Start: $remote_fs $syslog
  4593. # Required-Stop: $remote_fs $syslog
  4594. # Default-Start: 2 3 4 5
  4595. # Default-Stop: 0 1 6
  4596. # Short-Description: starts a gateway between bitmessage and email
  4597. # Description:
  4598. ### END INIT INFO
  4599. # Author: Bob Mottram <bob@robotics.uk.to>
  4600. #Settings
  4601. SERVICE='bitmessage-gateway'
  4602. LOGFILE='/dev/null'
  4603. COMMAND="python bitmessage-gateway.py > $LOGFILE"
  4604. USERNAME='bitmsg'
  4605. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  4606. HISTORY=1024
  4607. BMG_LOCATION="/usr/share/bitmessage-email-gateway"
  4608. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4609. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/usr/share/bitmessage-email-gateway'
  4610. bmg_start() {
  4611. echo "Starting $SERVICE..."
  4612. cd ${BMG_LOCATION}
  4613. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4614. }
  4615. bmg_stop() {
  4616. echo "Stopping $SERVICE"
  4617. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  4618. }
  4619. #Start-Stop here
  4620. case "$1" in
  4621. start)
  4622. bmg_start
  4623. ;;
  4624. stop)
  4625. bmg_stop
  4626. ;;
  4627. restart)
  4628. bmg_stop
  4629. sleep 5s
  4630. bmg_start
  4631. ;;
  4632. *)
  4633. echo "Usage: $0 {start|stop|restart}"
  4634. exit 1
  4635. ;;
  4636. esac
  4637. exit 0
  4638. #+END_SRC
  4639. Save and exit.
  4640. #+BEGIN_SRC: bash
  4641. chmod +x /etc/init.d/bitmessage-gateway
  4642. update-rc.d bitmessage-gateway defaults
  4643. service bitmessage-gateway start
  4644. #+END_SRC
  4645. From a Bitmessage client you should now be able to send a message to your Bitmessage address and have it eventually appear as an email in your inbox.
  4646. ** Overcome restrictive environments
  4647. #+BEGIN_VERSE
  4648. /Censorship reflects a society's lack of confidence in itself. It is a hallmark of an authoritarian regime./
  4649. -- Potter Stewart
  4650. #+END_VERSE
  4651. 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.
  4652. 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.
  4653. #+BEGIN_SRC: bash
  4654. apt-get install shellinabox libapache2-mod-proxy-html
  4655. #+END_SRC
  4656. Update your Apache configuration.
  4657. #+BEGIN_SRC: bash
  4658. export HOSTNAME=mydomainname.com
  4659. editor /etc/apache2/sites-available/$HOSTNAME
  4660. #+END_SRC
  4661. Within the section which begins with *<VirtualHost *:443>* add the following, replacing /mydomainname.com/ with your domain name and /myusername/ with your username.
  4662. #+BEGIN_SRC: bash
  4663. <Location /shell>
  4664. ProxyPass http://localhost:4200/
  4665. Order allow,deny
  4666. Allow from all
  4667. AuthName "Authentication for shellinabox"
  4668. AuthUserFile /home/mydomainname.com/public_html/.htpasswd
  4669. AuthGroupFile /home/mydomainname.com/public_html/.htgroup
  4670. AuthType Basic
  4671. Require group shellinabox
  4672. Require user myusername
  4673. </Location>
  4674. #+END_SRC
  4675. 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.
  4676. #+BEGIN_SRC: bash
  4677. mkdir /home/$HOSTNAME
  4678. mkdir /home/$HOSTNAME/public_html
  4679. htpasswd -c /home/$HOSTNAME/public_html/.htpasswd myusername
  4680. #+END_SRC
  4681. Create a user group.
  4682. #+BEGIN_SRC: bash
  4683. editor /home/$HOSTNAME/public_html/.htgroup
  4684. #+END_SRC
  4685. Add the following:
  4686. #+BEGIN_SRC: bash
  4687. shellinabox: myusername
  4688. #+END_SRC
  4689. Save and exit, then restart Apache.
  4690. #+BEGIN_SRC: bash
  4691. a2enmod proxy_http
  4692. service apache2 restart
  4693. #+END_SRC
  4694. Now with a web browser navigate to https://mydomainname.com/shell and log in.
  4695. 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/.
  4696. ** Set up a mailing list
  4697. #+BEGIN_VERSE
  4698. /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./
  4699. -- Jono Bacon
  4700. #+END_VERSE
  4701. *** Public mailing list
  4702. 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.
  4703. **** Installation
  4704. #+BEGIN_SRC: bash
  4705. export HOSTNAME=mydomainname.com
  4706. apt-get install mailman
  4707. newlist mailman
  4708. #+END_SRC
  4709. Enter an email address for the list administrator and a password.
  4710. #+BEGIN_SRC: bash
  4711. editor /etc/mailman/mm_cfg.py
  4712. #+END_SRC
  4713. Set *MTA=None* and change *http:* to *https:*, then save and exit.
  4714. Add some settings.
  4715. #+BEGIN_SRC: bash
  4716. editor /etc/exim4/conf.d/main/04_mailman_options
  4717. #+END_SRC
  4718. Add the following, replacing /mydomainname.com/ with your domain name.
  4719. #+BEGIN_SRC: bash
  4720. # Mailman macro definitions
  4721. # Home dir for the Mailman installation
  4722. MM_HOME=/var/lib/mailman
  4723. # User and group for Mailman
  4724. MM_UID=list
  4725. MM_GID=list
  4726. #
  4727. # Domains that your lists are in - colon separated list
  4728. # you may wish to add these into local_domains as well
  4729. domainlist mm_domains=mydomainname.com
  4730. # The path of the Mailman mail wrapper script
  4731. MM_WRAP=MM_HOME/mail/mailman
  4732. #
  4733. # The path of the list config file (used as a required file when
  4734. # verifying list addresses)
  4735. MM_LISTCHK=MM_HOME/lists/${lc::$local_part}/config.pck
  4736. #+END_SRC
  4737. Save and exit.
  4738. #+BEGIN_SRC: bash
  4739. editor /etc/exim4/conf.d/main/000_localmacros
  4740. #+END_SRC
  4741. Append the following:
  4742. #+BEGIN_SRC: bash
  4743. SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe
  4744. SYSTEM_ALIASES_USER = list
  4745. SYSTEM_ALIASES_GROUP = list
  4746. #+END_SRC
  4747. Save and exit.
  4748. #+BEGIN_SRC: bash
  4749. editor /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
  4750. #+END_SRC
  4751. Append the following, before the final /accept/:
  4752. #+BEGIN_SRC: bash
  4753. # Do callback verification unless Mailman incoming bounce
  4754. deny !local_parts = *-bounces : *-bounces+*
  4755. !verify = sender/callout=30s,defer_ok
  4756. #+END_SRC
  4757. Save and exit.
  4758. #+BEGIN_SRC: bash
  4759. editor
  4760. /etc/exim4/conf.d/router/450_exim4-config_mailman_aliases
  4761. #+END_SRC
  4762. Add the following:
  4763. #+BEGIN_SRC: bash
  4764. mailman:
  4765. driver = accept
  4766. domains = +mm_domains
  4767. require_files = MM_LISTCHK
  4768. local_part_suffix_optional
  4769. local_part_suffix = -admin : \
  4770. -bounces : -bounces+* : \
  4771. -confirm : -confirm+* : \
  4772. -join : -leave : \
  4773. -owner : -request : \
  4774. -subscribe : -unsubscribe
  4775. transport = mailman_transport
  4776. #+END_SRC
  4777. Save and exit.
  4778. #+BEGIN_SRC: bash
  4779. editor /etc/exim4/conf.d/transport/40_exim4-config_mailman_pipe
  4780. #+END_SRC
  4781. Add the following:
  4782. #+BEGIN_SRC: bash
  4783. mailman_transport:
  4784. driver = pipe
  4785. command = MM_WRAP \
  4786. '${if def:local_part_suffix \
  4787. {${sg{$local_part_suffix}{-(\\w+)(\\+.*)?}{\$1}}} \
  4788. {post}}' \
  4789. $local_part
  4790. current_directory = MM_HOME
  4791. home_directory = MM_HOME
  4792. user = MM_UID
  4793. group = MM_GID
  4794. #+END_SRC
  4795. Save and exit.
  4796. #+BEGIN_SRC: bash
  4797. chown root:list /var/lib/mailman/mail/mailman
  4798. update-exim4.conf.template -r
  4799. update-exim4.conf
  4800. service exim4 restart
  4801. editor /etc/apache2/conf.d/mailman
  4802. #+END_SRC
  4803. Add the following:
  4804. #+BEGIN_SRC: bash
  4805. Alias /pipermail /var/lib/mailman/archives/public
  4806. Alias /images/mailman /usr/share/images/mailman
  4807. <directory /var/lib/mailman/archives/public>
  4808. DirectoryIndex index.html
  4809. </directory>
  4810. #+END_SRC
  4811. Save and exit.
  4812. #+BEGIN_SRC: bash
  4813. editor /etc/apache2/sites-available/$HOSTNAME
  4814. #+END_SRC
  4815. Add the following to the 443 section.
  4816. #+BEGIN_SRC: bash
  4817. <Location /mailman>
  4818. Options Indexes FollowSymLinks MultiViews
  4819. Order allow,deny
  4820. Allow from all
  4821. RedirectMatch ^/$ /cgi-bin/mailman/listinfo
  4822. </Location>
  4823. #+END_SRC
  4824. Save and exit.
  4825. #+BEGIN_SRC: bash
  4826. service apache2 restart
  4827. #+END_SRC
  4828. Now add your mailing list. The list name should not include any spaces.
  4829. #+BEGIN_SRC: bash
  4830. newlist mymailinglistname
  4831. #+END_SRC
  4832. With a browser visit https://$HOSTNAME/cgi-bin/mailman/admin/mymailinglistname to configure the mailing list.
  4833. Under *General Options* add an email address for a moderator (could be the same as the administrator) and click *Submit your changes*.
  4834. Under *Privacy Options* set steps required for subscription to *Confirm and approve* and click *Submit your changes*.
  4835. Also change these settings for the account within https://$HOSTNAME/cgi-bin/mailman/admin/mailman
  4836. Then to test that the mailing list works:
  4837. #+BEGIN_SRC: bash
  4838. exim -d+route -bt mymailinglistname@$HOSTNAME
  4839. #+END_SRC
  4840. If everything is working then this shouldn't show any problems.
  4841. **** Using the mailing list
  4842. Direct subscribers towards:
  4843. #+BEGIN_SRC: bash
  4844. https://mydomainname.com/cgi-bin/mailman/listinfo/mymailinglistname
  4845. #+END_SRC
  4846. To administrate the list visit:
  4847. #+BEGIN_SRC: bash
  4848. https://mydomainname.com/cgi-bin/mailman/admin/mymailinglistname
  4849. #+END_SRC
  4850. To add another mailing list:
  4851. #+BEGIN_SRC: bash
  4852. newlist mymailinglistname
  4853. #+END_SRC
  4854. To delete a mailing list:
  4855. #+BEGIN_SRC: bash
  4856. rmlist -a mymailinglistname
  4857. #+END_SRC
  4858. *** Private (encrypted) mailing list
  4859. 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.
  4860. 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.
  4861. **** Installation
  4862. #+BEGIN_SRC: bash
  4863. apt-get install schleuder
  4864. #+END_SRC
  4865. Edit the configuration:
  4866. #+BEGIN_SRC: bash
  4867. editor /etc/schleuder/schleuder.conf
  4868. #+END_SRC
  4869. Set the following parameters, replacing /mydomainname.com/ with your domain name:
  4870. #+BEGIN_SRC: bash
  4871. smtp_port: 465
  4872. superadminaddr: root@mydomainname.com
  4873. #+END_SRC
  4874. Save and exit.
  4875. Get your GPG public key, replacing /myGPGkeyID/ with your GPG key ID:
  4876. #+BEGIN_SRC: bash
  4877. export MYKEYID=myGPGkeyID
  4878. gpg --search-keys $MYKEYID
  4879. gpg --output /tmp/mypublickey.txt --armor --export $MYKEYID
  4880. #+END_SRC
  4881. 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.
  4882. #+BEGIN_SRC: bash
  4883. export MAILINGLISTNAME=mailinglistname
  4884. export MYUSERNAME=myusername
  4885. export HOSTNAME=mydomainname.com
  4886. export EMAILADDRESS=$MYUSERNAME@$HOSTNAME
  4887. schleuder-newlist $MAILINGLISTNAME@$HOSTNAME -realname "mailing list name" -adminaddress $EMAILADDRESS -initmember $EMAILADDRESS -initmemberkey /tmp/mypublickey.txt -nointeractive
  4888. #+END_SRC
  4889. Now add a mailing list rule:
  4890. #+BEGIN_SRC: bash
  4891. emailrule $MYUSERNAME $MAILINGLISTNAME@$HOSTNAME $MAILINGLISTNAME
  4892. #+END_SRC
  4893. Edit your Mutt configuration.
  4894. #+BEGIN_SRC: bash
  4895. editor /home/$MYUSERNAME/.muttrc
  4896. #+END_SRC
  4897. Search for the /mailboxes/ parameter and add "=mailinglistname". For example:
  4898. #+BEGIN_SRC: bash
  4899. mailboxes = =Sent =Drafts =mailinglistname
  4900. #+END_SRC
  4901. Save and exit.
  4902. Update Exim routing.
  4903. #+BEGIN_SRC: bash
  4904. editor /etc/exim4/conf.d/router/550_exim4-config_schleuder
  4905. #+END_SRC
  4906. Add the following:
  4907. #+BEGIN_SRC: bash
  4908. schleuder:
  4909. debug_print = "R: schleuder for $local_part@$domain"
  4910. driver = accept
  4911. local_part_suffix_optional
  4912. local_part_suffix = +* : -bounce : -sendkey
  4913. domains = +local_domains
  4914. user = schleuder
  4915. group = schleuder
  4916. require_files = schleuder:+/var/lib/schleuder/$domain/${local_part}
  4917. transport = schleuder_transport
  4918. #+END_SRC
  4919. Save and exit.
  4920. #+BEGIN_SRC: bash
  4921. editor /etc/exim4/conf.d/transport/30_exim4-config_schleuder
  4922. #+END_SRC
  4923. Add the following.
  4924. #+BEGIN_SRC: bash
  4925. schleuder_transport:
  4926. debug_print = "T: schleuder_transport for $local_part@$domain"
  4927. driver = pipe
  4928. home_directory = "/var/lib/schleuder/$domain/$local_part"
  4929. command = "/usr/bin/schleuder $local_part@$domain"
  4930. #+END_SRC
  4931. Save and exit.
  4932. #+BEGIN_SRC: bash
  4933. chown -R schleuder:schleuder /var/lib/schleuder
  4934. update-exim4.conf.template -r
  4935. update-exim4.conf
  4936. service exim4 restart
  4937. useradd -d /var/schleuderlists -s /bin/false schleuder
  4938. adduser Debian-exim schleuder
  4939. usermod -a -G mail schleuder
  4940. #+END_SRC
  4941. Test the routing.
  4942. #+BEGIN_SRC: bash
  4943. exim -d -bt mailinglistname@mydomainname.com
  4944. #+END_SRC
  4945. **** Importing the public key of the mailing list
  4946. 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.
  4947. ***** Using Mutt
  4948. Send an email to /mailinglistname-sendkey@mydomainname.com/ to have the list public key emailed to you.
  4949. When you receive the email open it and press *CTRL-k* to import it.
  4950. ***** Using Thunderbird
  4951. Send an email to /mailinglistname-sendkey@mydomainname.com/ to have the list public key emailed to you.
  4952. When you receive the email open it, select all the text with *CTRL-a* then *CTRL-c*.
  4953. On the menu select *OpenPGP* followed by *Key Management*.
  4954. You will now see a new menu bar. Select *Edit* followed by *Import keys from clipboard*.
  4955. Click on *Import* followed by *Ok*.
  4956. **** Using the list
  4957. To obtain the public keys of list members send an email to /mailinglistname-request@mydomainname.com/ containing *X-LIST-KEYS* in the message body.
  4958. To add a member: *X-ADD-MEMBER: othermember@otherdomain.net*
  4959. An example of adding a public key to the list:
  4960. #+BEGIN_SRC: bash
  4961. X-ADD-KEY:
  4962. -----BEGIN PGP PUBLIC KEY BLOCK-----
  4963. Version: GnuPG v1.4.9 (GNU/Linux)
  4964. mQGiBEjVO7oRBADQvT6wtD2IzzIiK0NbrcilCKCp4MWb8cYXTXguwPQI6y0Nerz4
  4965. dsK6J0X1Vgeo02tqA4xd3EDK8rdqL2yZfl/2egH8+85R3gDk+kqkfEp4pwCgp6VO
  4966. [...]
  4967. pNlF/qkaWwRb048h+iMrW21EkouLKTDPFkdFbapV2X5KJZIcfhO1zEbwc1ZKF3Ju
  4968. Q9X5GRmY62hz9SCZnsC0jeYAni8OUQV9NXfXlS/vePBUnOL08NQB
  4969. =xTv3
  4970. -----END PGP PUBLIC KEY BLOCK-----
  4971. #+END_SRC
  4972. To get details for a member: *X-GET-MEMBER: othermember@otherdomain.net*
  4973. To delete a member: *X-DELETE-MEMBER: othermember@otherdomain.net*
  4974. To delete a public key: *X-DELETE-KEY: keyID*
  4975. You can unsubscribe from the list with *X-UNSUBSCRIBE* in the message body.
  4976. *** Decentralised mailing list
  4977. 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.
  4978. 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/".
  4979. 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.
  4980. On a Debian based system:
  4981. #+BEGIN_SRC: bash
  4982. sudo apt-get install makepasswd
  4983. #+END_SRC
  4984. or on an RPM based system:
  4985. #+BEGIN_SRC: bash
  4986. sudo yum install makepasswd
  4987. #+END_SRC
  4988. Create a name for your mailing list. This will be a random string.
  4989. #+BEGIN_SRC: bash
  4990. makepasswd -c 40
  4991. #+END_SRC
  4992. Keep a note of this.
  4993. Run the Bitmessage client and on the menu select *File/Join-Create Chan/Create new chan*
  4994. 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.
  4995. 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.
  4996. 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.
  4997. 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.
  4998. ** Install a microblog
  4999. #+BEGIN_VERSE
  5000. /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/
  5001. -- Jason Self
  5002. #+END_VERSE
  5003. 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.
  5004. Install some dependencies:
  5005. #+BEGIN_SRC: bash
  5006. apt-get install php5-xcache php-gettext php5-curl php5-gd php5-mysql
  5007. #+END_SRC
  5008. Download GNU Social
  5009. #+BEGIN_SRC: bash
  5010. mkdir ~/build
  5011. cd ~/build
  5012. wget http://freedombone.uk.to/gnu-social.tar.gz
  5013. #+END_SRC
  5014. Verify it.
  5015. #+BEGIN_SRC: bash
  5016. sha256sum gnu-social.tar.gz
  5017. 1f886241c7f1a175e7be3cccbcb944ab6c03617fb75aefa4d62d37abed87d2b4
  5018. #+END_SRC
  5019. Extract the files and set permissions on them, where /mydomainname.com/ is your domain name.
  5020. #+BEGIN_SRC: bash
  5021. export HOSTNAME=mydomainname.com
  5022. tar zxf gnu-social.tar.gz
  5023. rm -rf /var/www/$HOSTNAME/htdocs
  5024. mv statusnet-gnu-social /var/www/$HOSTNAME/htdocs
  5025. chmod a+w /var/www/$HOSTNAME/htdocs
  5026. chown www-data:www-data /var/www/$HOSTNAME/htdocs
  5027. chmod a+w /var/www/$HOSTNAME/htdocs/avatar
  5028. chmod a+w /var/www/$HOSTNAME/htdocs/background
  5029. chmod a+w /var/www/$HOSTNAME/htdocs/file
  5030. chmod +x /var/www/$HOSTNAME/htdocs/scripts/maildaemon.php
  5031. #+END_SRC
  5032. Edit the Apache access settings.
  5033. #+BEGIN_SRC: bash
  5034. editor /var/www/$HOSTNAME/htdocs/.htaccess
  5035. #+END_SRC
  5036. Add the following:
  5037. #+BEGIN_SRC: bash
  5038. <IfModule mod_rewrite.c>
  5039. RewriteEngine On
  5040. RewriteBase /
  5041. ## Uncomment these if having trouble with API authentication
  5042. ## when PHP is running in CGI or FastCGI mode.
  5043. #
  5044. #RewriteCond %{HTTP:Authorization} ^(.*)
  5045. #RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
  5046. RewriteCond %{REQUEST_FILENAME} !-f
  5047. RewriteCond %{REQUEST_FILENAME} !-d
  5048. RewriteRule (.*) index.php?p=$1 [L,QSA]
  5049. </IfModule>
  5050. <FilesMatch "\.(ini)">
  5051. Order allow,deny
  5052. </FilesMatch>
  5053. #+END_SRC
  5054. Save and exit, then create a database.
  5055. #+BEGIN_SRC: bash
  5056. mysql -u root -p
  5057. create database gnusocial;
  5058. CREATE USER 'gnusocialadmin'@'localhost' IDENTIFIED BY 'gnusocialpassword';
  5059. GRANT ALL PRIVILEGES ON gnusocial.* TO 'gnusocialadmin'@'localhost';
  5060. quit
  5061. #+END_SRC
  5062. Add the mailer script to the aliases file:
  5063. #+BEGIN_SRC: bash
  5064. editor /etc/aliases
  5065. #+END_SRC
  5066. Add the following, replacing /mydomainname.com/ with your domain name.
  5067. #+BEGIN_SRC: bash
  5068. www-data: root
  5069. *: /var/www/mydomainname.com/htdocs/scripts/maildaemon.php
  5070. #+END_SRC
  5071. Save and exit. Update the aliases by typing:
  5072. #+BEGIN_SRC: bash
  5073. newaliases
  5074. #+END_SRC
  5075. Then with a web browser navigate to:
  5076. https://$HOSTNAME/install.php
  5077. Set a name for the site.
  5078. Server SSL: enable
  5079. Hostname: localhost
  5080. Type: MySql
  5081. Name: gnusocial
  5082. DB username: gnusocialadmin
  5083. DB Password; your gnu social admin password goes here
  5084. Administrator nickname: myusername
  5085. Administrator password: mylongrandompassword
  5086. Subscribe to announcements: ticked
  5087. Site profile: Community
  5088. 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.
  5089. 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:
  5090. Under the *Site* settings:
  5091. Text limit: 140
  5092. Dupe Limit: 60000
  5093. Under the *User* settings:
  5094. Bio limit: 1000
  5095. Under the *Access* settings:
  5096. /Invite only/ ticked
  5097. 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.
  5098. 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.
  5099. Edit the config file.
  5100. #+BEGIN_SRC: bash
  5101. editor /var/www/$HOSTNAME/htdocs/config.php
  5102. #+END_SRC
  5103. Change the ssl setting from *always* to *sometimes*, hten save and exit.
  5104. 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/
  5105. When following other GNU Social users enter the URL of your profile. For example, https://mygnusocialdomain/myusername
  5106. ** Install Mediagoblin
  5107. #+BEGIN_VERSE
  5108. /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./
  5109. #+END_VERSE
  5110. 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/.
  5111. 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.
  5112. Install some dependencies.
  5113. #+BEGIN_SRC: bash
  5114. aptitude 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
  5115. #+END_SRC
  5116. Create a user, replacing /mymediagoblindomain/ with the domain name for your mediagoblin site.
  5117. #+BEGIN_SRC: bash
  5118. export HOSTNAME=mymediagoblindomain
  5119. adduser mediagoblin
  5120. #+END_SRC
  5121. Give the user a long random password.
  5122. #+BEGIN_SRC: bash
  5123. mkdir -p /srv/$HOSTNAME
  5124. chown -hR mediagoblin:mediagoblin /srv/$HOSTNAME
  5125. su - mediagoblin
  5126. export HOSTNAME=mymediagoblindomain
  5127. cd /srv/$HOSTNAME
  5128. git clone git://gitorious.org/mediagoblin/mediagoblin.git
  5129. cd mediagoblin
  5130. git submodule init
  5131. git submodule update
  5132. virtualenv --system-site-packages .
  5133. ./bin/python setup.py develop
  5134. ./bin/easy_install flup
  5135. cp mediagoblin.ini mediagoblin_local.ini
  5136. cp paste.ini paste_local.ini
  5137. editor mediagoblin_local.ini
  5138. #+END_SRC
  5139. 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.
  5140. #+BEGIN_SRC: bash
  5141. [[mediagoblin.media_types.audio]]
  5142. [[mediagoblin.media_types.video]]
  5143. [[mediagoblin.media_types.stl]]
  5144. #+END_SRC
  5145. Then save and exit.
  5146. #+BEGIN_SRC: bash
  5147. ./bin/pip install scikits.audiolab
  5148. ./bin/gmg dbupdate
  5149. exit # to go back to the root user
  5150. editor /etc/init.d/mediagoblin
  5151. #+END_SRC
  5152. Add the following, replacing /mymediagoblindomain/ with the domain name for your mediagoblin site.
  5153. #+BEGIN_SRC: bash
  5154. #!/bin/bash
  5155. # /etc/init.d/mediagoblin
  5156. ### BEGIN INIT INFO
  5157. # Provides: mediagoblin
  5158. # Required-Start: $remote_fs $syslog
  5159. # Required-Stop: $remote_fs $syslog
  5160. # Default-Start: 2 3 4 5
  5161. # Default-Stop: 0 1 6
  5162. # Short-Description: starts mediagoblin
  5163. # Description: Other methods may work, but I found this the easiest
  5164. ### END INIT INFO
  5165. # Author: Bob Mottram <bob@robotics.uk.to>
  5166. #Settings
  5167. SERVICE='mediagoblin'
  5168. LOGFILE='/srv/mymediagoblindomain/mediagoblin.log'
  5169. COMMAND="./lazyserver.sh > $LOGFILE"
  5170. USERNAME='mediagoblin'
  5171. NICELEVEL=15 # from 0-19 the bigger the number, the less the impact on system resources
  5172. HISTORY=1024
  5173. MG_LOCATION="/srv/mymediagoblindomain/mediagoblin"
  5174. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  5175. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin'
  5176. mg_start() {
  5177. echo "Starting $SERVICE..."
  5178. cd ${MG_LOCATION}
  5179. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  5180. }
  5181. mg_stop() {
  5182. echo "Stopping $SERVICE"
  5183. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  5184. }
  5185. #Start-Stop here
  5186. case "$1" in
  5187. start)
  5188. mg_start
  5189. ;;
  5190. stop)
  5191. mg_stop
  5192. ;;
  5193. restart)
  5194. mg_stop
  5195. sleep 10s
  5196. mg_start
  5197. ;;
  5198. *)
  5199. echo "Usage: $0 {start|stop|restart}"
  5200. exit 1
  5201. ;;
  5202. esac
  5203. exit 0
  5204. #+END_SRC
  5205. Save and exit.
  5206. #+BEGIN_SRC: bash
  5207. chmod +x /etc/init.d/mediagoblin
  5208. update-rc.d mediagoblin defaults
  5209. service mediagoblin start
  5210. #+END_SRC
  5211. Edit the Apache configuration for your mediagoblin site.
  5212. #+BEGIN_SRC: bash
  5213. editor /etc/apache2/sites-available/mymediagoblindomain
  5214. #+END_SRC
  5215. 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.
  5216. #+BEGIN_SRC: bash
  5217. <VirtualHost *:80>
  5218. ServerAdmin myusername@mydomainname.com
  5219. DocumentRoot /srv/mymediagoblindomain/mediagoblin
  5220. ServerName mymediagoblindomain
  5221. <Directory />
  5222. Options FollowSymLinks
  5223. AllowOverride None
  5224. </Directory>
  5225. <Directory /srv/mymediagoblindomain/mediagoblin/>
  5226. Options Indexes FollowSymLinks MultiViews
  5227. AllowOverride All
  5228. Order allow,deny
  5229. allow from all
  5230. LimitRequestBody 536870912
  5231. </Directory>
  5232. LogLevel warn
  5233. ProxyVia On
  5234. ProxyRequests off
  5235. ProxyPreserveHost on
  5236. ProxyPass / http://localhost:6543/
  5237. ErrorLog "/var/log/apache2/error.log"
  5238. CustomLog "/var/log/apache2/access.log" combined
  5239. RewriteEngine On
  5240. RewriteOptions Inherit
  5241. </VirtualHost>
  5242. #+END_SRC
  5243. Save and exit.
  5244. 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.
  5245. #+BEGIN_SRC: bash
  5246. editor /srv/mymediagoblindomain/mediagoblin/mediagoblin_local.ini
  5247. #+END_SRC
  5248. Then set:
  5249. #+BEGIN_SRC: bash
  5250. allow_registration = false
  5251. #+END_SRC
  5252. Save and exit.
  5253. ** Run a pastebin service
  5254. 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.
  5255. 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]].
  5256. #+BEGIN_SRC: bash
  5257. adduser --disabled-login zerobin
  5258. mkdir ~/build
  5259. cd ~/build
  5260. git clone https://github.com/sametmax/0bin.git
  5261. cd 0bin
  5262. python setup.py install
  5263. chown -R zerobin:zerobin /usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static
  5264. #+END_SRC
  5265. For the /chown/ command you may need to change the directory name within /dist-packages/, depending upon the version number of [[https://github.com/sametmax/0bin][0bin]].
  5266. Now create the daemon.
  5267. #+BEGIN_SRC: bash
  5268. editor /etc/init.d/zerobin
  5269. #+END_SRC
  5270. Add the following text:
  5271. #+BEGIN_SRC: bash
  5272. #!/bin/bash
  5273. # /etc/init.d/zerobin
  5274. ### BEGIN INIT INFO
  5275. # Provides: zerobin
  5276. # Required-Start: $remote_fs $syslog
  5277. # Required-Stop: $remote_fs $syslog
  5278. # Default-Start: 2 3 4 5
  5279. # Default-Stop: 0 1 6
  5280. # Short-Description: starts zerobin as a background daemon
  5281. # Description: starts zerobin as a background daemon
  5282. ### END INIT INFO
  5283. # Author: Bob Mottram <bob@robotics.uk.to>
  5284. #Settings
  5285. SERVICE='zerobin'
  5286. LOGFILE='/home/zerobin/zerobin.log'
  5287. COMMAND="zerobin > $LOGFILE"
  5288. USERNAME='zerobin'
  5289. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  5290. HISTORY=1024
  5291. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  5292. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  5293. zerobin_start() {
  5294. echo "Starting $SERVICE..."
  5295. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  5296. }
  5297. zerobin_stop() {
  5298. echo "Stopping $SERVICE"
  5299. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  5300. }
  5301. #Start-Stop here
  5302. case "$1" in
  5303. start)
  5304. zerobin_start
  5305. ;;
  5306. stop)
  5307. zerobin_stop
  5308. ;;
  5309. restart)
  5310. zerobin_stop
  5311. sleep 2s
  5312. zerobin_start
  5313. ;;
  5314. *)
  5315. echo "Usage: $0 {start|stop|restart}"
  5316. exit 1
  5317. ;;
  5318. esac
  5319. exit 0
  5320. #+END_SRC
  5321. Save and exit.
  5322. #+BEGIN_SRC: bash
  5323. chmod +x /etc/init.d/zerobin
  5324. update-rc.d zerobin defaults
  5325. service zerobin start
  5326. #+END_SRC
  5327. 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:
  5328. #+BEGIN_SRC: bash
  5329. <VirtualHost *:80>
  5330. ServerAdmin username@mydomainname.com
  5331. ServerName mypastedomainname.com
  5332. <Location />
  5333. ProxyPass http://localhost:8000/
  5334. Order allow,deny
  5335. Allow from all
  5336. LimitRequestBody 256000
  5337. </Location>
  5338. ErrorLog ${APACHE_LOG_DIR}/paste_error.log
  5339. # Possible values include: debug, info, notice, warn, error, crit,
  5340. # alert, emerg.
  5341. LogLevel error
  5342. CustomLog ${APACHE_LOG_DIR}/paste.log combined
  5343. </VirtualHost>
  5344. #+END_SRC
  5345. Save and exit.
  5346. 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.
  5347. #+BEGIN_SRC: bash
  5348. service apache2 restart
  5349. #+END_SRC
  5350. 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. You can further limit the maximum amount of storage space by doing the following:
  5351. #+BEGIN_SRC: bash
  5352. editor /usr/bin/zerobinupdate
  5353. #+END_SRC
  5354. Add the following:
  5355. #+BEGIN_SRC: bash
  5356. #!/bin/bash
  5357. CONTENT=/usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static/content
  5358. # Exit if there is no content directory
  5359. if [[ ! -d $CONTENT ]]; then
  5360. exit
  5361. fi
  5362. LOG=/home/zerobin/zerobin.log
  5363. CHECK=`du -hs $CONTENT`
  5364. regex="([0-9]+)G"
  5365. if [[ $CHECK =~ $regex && ${BASH_REMATCH[1]} -gt 1 ]]; then
  5366. echo "Directory size limit exceeded - removing zerobin content" >> $LOG
  5367. rm -rf $CONTENT/*
  5368. fi
  5369. #+END_SRC
  5370. Save and exit.
  5371. #+BEGIN_SRC: bash
  5372. chmod +x /usr/bin/zerobinupdate
  5373. echo "*/5 * * * * root /usr/bin/timeout 120 /usr/bin/zerobinupdate" >> /etc/crontab
  5374. #+END_SRC
  5375. Additionally to ensure that the service is being used as intended and not as a permanent data store:
  5376. #+BEGIN_SRC: bash
  5377. editor /usr/bin/zerobinclear
  5378. #+END_SRC
  5379. Add the following:
  5380. #+BEGIN_SRC: bash
  5381. #!/bin/bash
  5382. CONTENT=/usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static/content
  5383. # Exit if there is no content directory
  5384. if [[ ! -d $CONTENT ]]; then
  5385. exit
  5386. fi
  5387. rm -rf $CONTENT
  5388. #+END_SRC
  5389. Save and exit.
  5390. #+BEGIN_SRC: bash
  5391. chmod +x /usr/bin/zerobinclear
  5392. echo "35 3 * * * root /usr/bin/zerobinclear" >> /etc/crontab
  5393. service cron restart
  5394. #+END_SRC
  5395. This will delete all pasted content once per day.
  5396. ** Database maintenance
  5397. #+BEGIN_VERSE
  5398. /To be ready to fail is to be prepared for success./
  5399. -- Jose Bergamin
  5400. #+END_VERSE
  5401. Ideally the system should be as close to "/install and forget/" as possible, but sometimes mysql databases can become corrupted. To handle that situation we can set up a script to monitor the databases and automatically try to repair them, and if the repair fails then to roll back to the previous day's backup, so that at most you may have lost one day of social media updates, rather than losing everything.
  5402. #+BEGIN_SRC: bash
  5403. editor /usr/bin/repairdatabase
  5404. #+END_SRC
  5405. Add the following, using your mysql root password and entering your email address.
  5406. #+BEGIN_SRC: bash
  5407. #!/bin/bash
  5408. DATABASE=$1
  5409. EMAIL=myusername@mydomainname.com
  5410. MYSQL_ROOT_PASSWORD=mysqlrootpassword
  5411. TEMPFILE=/tmp/repairdatabase_$DATABASE
  5412. umask 0077
  5413. # check the database
  5414. mysqlcheck -c -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE > $TEMPFILE
  5415. # Attempt to repair the database if it contains errors
  5416. if grep -q "Error" "$TEMPFILE"; then
  5417. mysqlcheck -u root --password=$MYSQL_ROOT_PASSWORD --auto-repair $DATABASE
  5418. else
  5419. # No errors were found, so exit
  5420. rm -f $TEMPFILE
  5421. exit 0
  5422. fi
  5423. rm -f $TEMPFILE
  5424. # Check the database again
  5425. mysqlcheck -c -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE > $TEMPFILE
  5426. # If it still contains errors then restore from backup
  5427. if grep -q "Error" "$TEMPFILE"; then
  5428. mysql -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE -o < /var/backups/${DATABASE}_daily.sql
  5429. # Send a warning email
  5430. echo "$DATABASE database corruption could not be repaired. Restored from backup." | mail -s "Freedombone database maintenance" $EMAIL
  5431. rm -f $TEMPFILE
  5432. exit 1
  5433. fi
  5434. rm -f $TEMPFILE
  5435. exit 0
  5436. #+END_SRC
  5437. Save and exit.
  5438. #+BEGIN_SRC: bash
  5439. chmod 600 /usr/bin/repairdatabase
  5440. editor /etc/cron.hourly/repair
  5441. #+END_SRC
  5442. Add the following. If you're using Red Matrix then uncomment that line.
  5443. #+BEGIN_SRC: bash
  5444. #!/bin/bash
  5445. repairdatabase friendica
  5446. #repairdatabase redmatrix
  5447. repairdatabase roundcubemail
  5448. #+END_SRC
  5449. Save and exit.
  5450. #+BEGIN_SRC: bash
  5451. chmod +x /etc/cron.hourly/repair
  5452. #+END_SRC
  5453. ** Install Tripwire
  5454. #+BEGIN_VERSE
  5455. /...by the time you get done with all of that, we have a freedom box/
  5456. -- Eben Moglen
  5457. #+END_VERSE
  5458. 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.
  5459. #+BEGIN_SRC: bash
  5460. apt-get install tripwire
  5461. export HOSTNAME=mydomainname.com
  5462. cd /etc/tripwire
  5463. cp arm-local.key $HOSTNAME-local.key
  5464. cp site.key $HOSTNAME-site.key
  5465. tripwire --init
  5466. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  5467. tripwire --check --interactive
  5468. #+END_SRC
  5469. you will be asked for two passphrases ("site" and "local"). Make a note of these.
  5470. Turn off reporting of changes to system logs.
  5471. #+BEGIN_SRC: bash
  5472. editor /etc/tripwire/twcfg.txt
  5473. #+END_SRC
  5474. Set *SYSLOGREPORTING* to false and comment out the line, then save and exit.
  5475. #+BEGIN_SRC: bash
  5476. editor /etc/tripwire/twpol.txt
  5477. #+END_SRC
  5478. Edit the "Root config files" section so that it looks like this:
  5479. #+BEGIN_SRC: bash
  5480. # These files change the behavior of the root account
  5481. (
  5482. rulename = "Root config files",
  5483. severity = 100
  5484. )
  5485. {
  5486. /root -> $(SEC_CRIT) ; # Catch all additions to /root
  5487. /root/.bashrc -> $(SEC_CONFIG) ;
  5488. /root/.bash_history -> $(SEC_CONFIG) ;
  5489. }
  5490. #+END_SRC
  5491. Then save and exit.
  5492. #+BEGIN_SRC: bash
  5493. editor /usr/bin/reset-tripwire
  5494. #+END_SRC
  5495. Add the following:
  5496. #+BEGIN_SRC: bash
  5497. #!/bin/sh
  5498. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  5499. #+END_SRC
  5500. Save and exit.
  5501. #+BEGIN_SRC: bash
  5502. chmod +x /usr/bin/reset-tripwire
  5503. #+END_SRC
  5504. If you subsequently install any more packages or make configuration changes then update the policy again with:
  5505. #+BEGIN_SRC: bash
  5506. reset-tripwire
  5507. #+END_SRC
  5508. Also, to look for any rootkits.
  5509. #+BEGIN_SRC: bash
  5510. apt-get install rkhunter
  5511. #+END_SRC
  5512. * Router/Firewall ports
  5513. The following ports on your internet router/firewall should be forwarded to the BBB.
  5514. | Protocol | Port/s |
  5515. |---------------+------------|
  5516. | Gopher | 70 |
  5517. | HTTP | 80 |
  5518. | HTTPS | 443 |
  5519. | IMAP | 143 |
  5520. | IRC SSL | 6697 |
  5521. | SIP | 5060..5061 |
  5522. | SMTP | 25,587 |
  5523. | SMTPS | 465 |
  5524. | SSH | 22 |
  5525. | XMPP | 5222..5223 |
  5526. | XMPP (server) | 5269 |
  5527. | XMPP (BOSH) | 5280..5281 |
  5528. | Bitmessage | 8444 |
  5529. | Convergence | 8432..8433 |
  5530. * Hints and Tips
  5531. ** Example software sources
  5532. 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*
  5533. *** Beaglebone Black
  5534. #+BEGIN_SRC: bash
  5535. deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5536. deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5537. deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5538. deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5539. deb http://security.debian.org/ wheezy/updates main contrib non-free
  5540. deb-src http://security.debian.org/ wheezy/updates main contrib non-free
  5541. deb http://ftp.us.debian.org/debian wheezy-backports main contrib non-free
  5542. #+END_SRC
  5543. *** Cubieboard
  5544. #+BEGIN_SRC: bash
  5545. deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5546. deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5547. deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5548. deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5549. deb http://security.debian.org/ wheezy/updates main contrib non-free
  5550. deb-src http://security.debian.org/ wheezy/updates main contrib non-free
  5551. deb http://ftp.us.debian.org/debian wheezy-backports main contrib non-free
  5552. deb http://mirrors.sohu.com/debian/ wheezy main contrib non-free
  5553. deb-src http://mirrors.sohu.com/debian/ wheezy main contrib non-free
  5554. deb http://packages.cubian.org/ wheezy main non-free
  5555. deb http://repo.ajenti.org/debian main main debian
  5556. #+END_SRC
  5557. ** Messaging security
  5558. 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.
  5559. ** Moving Domains
  5560. 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:
  5561. #+BEGIN_SRC: bash
  5562. find /var/www/mynewdomain/htdocs -type f -exec sed -i 's@myolddomain@mynewdomain@g' {} \;
  5563. #+END_SRC
  5564. If you're moving the blog to a new domain then you will need to delete the lock file:
  5565. #+BEGIN_SRC: bash
  5566. rm /var/www/myblogdomainname.com/htdocs/fp-content/%%setup.lock
  5567. #+END_SRC
  5568. 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.
  5569. 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*.
  5570. ** MySql foo
  5571. *** Reset the root password
  5572. To reset the root password, or if mysql forgets its root password.
  5573. #+BEGIN_SRC: bash
  5574. /etc/init.d/mysql stop
  5575. mysqld_safe --skip-grant-tables &
  5576. mysql -u root
  5577. use mysql;
  5578. update user set password=PASSWORD("mynewpassword") where User='root';
  5579. flush privileges;
  5580. quit
  5581. /etc/init.d/mysql stop
  5582. /etc/init.d/mysql start
  5583. #+END_SRC
  5584. *** Repair and optimize databases
  5585. To check, repair and optimize the databases.
  5586. #+BEGIN_SRC: bash
  5587. mysqlcheck -c -u root -p --all-databases
  5588. mysqlcheck -u root -p --auto-repair --all-databases
  5589. mysqlcheck -u root -p -o --all-databases
  5590. #+END_SRC
  5591. *** Backup all databases
  5592. To back up all mysql databases:
  5593. #+BEGIN_SRC: bash
  5594. mysqldump -u root -p --all-databases --events > /var/backups/databasebackup.sql
  5595. #+END_SRC
  5596. *** Restoring a particular mysql database
  5597. To restore yesterday's friendica backup:
  5598. #+BEGIN_SRC: bash
  5599. mysql -u root -p friendica -o < /var/backups/friendica_daily.sql
  5600. #+END_SRC
  5601. To restore the webmail database:
  5602. #+BEGIN_SRC: bash
  5603. mysql -u root -p roundcubemail -o < /var/backups/roundcubemail_daily.sql
  5604. #+END_SRC
  5605. To restore yesterday's Red Matrix backup:
  5606. #+BEGIN_SRC: bash
  5607. mysql -u root -p redmatrix -o < /var/backups/redmatrix_daily.sql
  5608. #+END_SRC
  5609. *** Removing and reinstalling mysql server
  5610. Sometimes the mysql database may get completely messed up, and running /service mysql start/ may always fail with nothing reported in the logs. So if you manage to get into that unfortinate situation then you can fully remove mysql and reinstall it as follows:
  5611. #+BEGIN_SRC: bash
  5612. ps aux | grep mysql
  5613. #+END_SRC
  5614. and use /kill -9 <pid>/ to kill all mysql processes.
  5615. #+BEGIN_SRC: bash
  5616. apt-get remove --purge mysql\*
  5617. rm -rf /etc/mysql
  5618. rm -rf /var/lib/mysql
  5619. apt-get clean
  5620. updatedb
  5621. #+END_SRC
  5622. Reinstall mysql:
  5623. #+BEGIN_SRC: bash
  5624. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt php5-fpm php5-cgi php-apc
  5625. #+END_SRC
  5626. Then to recreate the Friendica and webmail databases:
  5627. #+BEGIN_SRC: bash
  5628. mysql -p
  5629. create database friendica;
  5630. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'myfriendicapassword';
  5631. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  5632. create database roundcubemail;
  5633. CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'roundcubepassword';
  5634. GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
  5635. quit
  5636. mysql -u root -p friendica -o < /var/backups/friendica_daily.sql
  5637. mysql -u root -p roundcubemail -o < /var/backups/roundcubemail_daily.sql
  5638. #+END_SRC
  5639. And if you previously had Red Matrix installed:
  5640. #+BEGIN_SRC: bash
  5641. mysql -p
  5642. create database redmatrix;
  5643. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'myredmatrixpassword';
  5644. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  5645. quit
  5646. mysql -u root -p redmatrix -o < /var/backups/redmatrix_daily.sql
  5647. #+END_SRC
  5648. Since IMAP seems entangled with mysql it may also be necessary to reinstall Exim and Dovecot.
  5649. #+BEGIN_SRC: bash
  5650. apt-get remove --purge exim4\*
  5651. #+END_SRC
  5652. Then follow the instructions in [[Install Email]], [[Spam filtering]] and [[Install Dovecot]].
  5653. ** Regenerating SSL certificates
  5654. 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:
  5655. Obtain the latest updates:
  5656. #+BEGIN_SRC: bash
  5657. apt-get update
  5658. apt-get upgrade
  5659. #+END_SRC
  5660. Run *makecert <domain>* for each of your sites.
  5661. Recreate the XMPP certificate:
  5662. #+BEGIN_SRC: bash
  5663. openssl genrsa -out /etc/ssl/private/xmpp.key 4096
  5664. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  5665. chmod 600 /etc/ssl/private/xmpp.key
  5666. chmod 600 /etc/ssl/certs/xmpp.crt
  5667. chown prosody:prosody /etc/ssl/private/xmpp.key
  5668. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  5669. #+END_SRC
  5670. And regenerate the IRC server keys:
  5671. #+BEGIN_SRC: bash
  5672. openssl genrsa -out /etc/ircd-hybrid/key/ircd.key 4096
  5673. openssl req -new -x509 -key /etc/ircd-hybrid/key/ircd.key -out /etc/ircd-hybrid/key/ircd.pem -days 3650
  5674. chmod 600 /etc/ircd-hybrid/key/ircd.key
  5675. chmod 600 /etc/ircd-hybrid/key/ircd.pem
  5676. #+END_SRC
  5677. Regenerate email certificate.
  5678. #+BEGIN_SRC: bash
  5679. exim-gencert --force
  5680. #+END_SRC
  5681. As an added precaution you may wish to regenerate your ssh host keys:
  5682. #+BEGIN_SRC: bash
  5683. rm /etc/ssh/ssh_host_*
  5684. dpkg-reconfigure openssh-server
  5685. #+END_SRC
  5686. Then reboot the server with:
  5687. #+BEGIN_SRC: bash
  5688. reboot
  5689. #+END_SRC
  5690. ** Example crontab file
  5691. 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.
  5692. #+BEGIN_SRC: bash
  5693. # /etc/crontab: system-wide crontab
  5694. # Unlike any other crontab you don't have to run the `crontab'
  5695. # command to install the new version when you edit this file
  5696. # and files in /etc/cron.d. These files also have username fields,
  5697. # that none of the other crontabs do.
  5698. SHELL=/bin/sh
  5699. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  5700. # m h dom mon dow user command
  5701. 10,20,30,40,50 * * * * root /usr/bin/timeout 120 /usr/bin/dynamicdns && /usr/bin/spamfilter myusername
  5702. 15,35,55 * * * * root cd /var/www/mydomainname/htdocs; /usr/bin/timeout 240 /usr/bin/php include/poller.php
  5703. 17 * * * * root cd / && run-parts --report /etc/cron.hourly
  5704. 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
  5705. 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
  5706. 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
  5707. #+END_SRC
  5708. ** Using your own domain
  5709. Suppose that you have bought a domain name (rather than using a free subdomain on freedns) and you want to use that instead.
  5710. Remove any existing nameservers for your domain (or select "custom" nameservers), then add:
  5711. #+BEGIN_SRC: bash
  5712. NS1.AFRAID.ORG
  5713. NS2.AFRAID.ORG
  5714. NS3.AFRAID.ORG
  5715. NS4.AFRAID.ORG
  5716. #+END_SRC
  5717. 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".
  5718. 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*.
  5719. To route email to one of your freedns domains:
  5720. #+BEGIN_SRC: bash
  5721. editor /etc/mailname
  5722. #+END_SRC
  5723. Add any extra domains which you own, then save and exit.
  5724. #+BEGIN_SRC: bash
  5725. editor /etc/exim4/update-exim4.conf.conf
  5726. #+END_SRC
  5727. Within dc_other_hostnames add your extra domain names, separated by a colon ':' character.
  5728. Save and exit, then restart exim.
  5729. #+BEGIN_SRC: bash
  5730. update-exim4.conf.template -r
  5731. update-exim4.conf
  5732. service exim4 restart
  5733. #+END_SRC
  5734. You should now be able to send an email from /postmaster@mynewdomainname/ and it should arrive in your inbox.
  5735. ** Obtaining an "official" SSL certificate
  5736. 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).
  5737. 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.
  5738. Firstly you should have an Apache web site configutaion ready to go. See [[Setting up a web site]] for details.
  5739. Within StartSSL under the validations wizard validate your domain, which means sending an email to it and confirming a code.
  5740. Now we can generate the certificate request as follows.
  5741. #+BEGIN_SRC: bash
  5742. export HOSTNAME=mydomainname.com
  5743. openssl genrsa -out /etc/ssl/private/$HOSTNAME.key 2048
  5744. chown root:ssl-cert /etc/ssl/private/$HOSTNAME.key
  5745. chmod 440 /etc/ssl/private/$HOSTNAME.key
  5746. mkdir /etc/ssl/requests
  5747. #+END_SRC
  5748. Now make a certificate request as follows. You should copy and paste the whole of this, not just line by line.
  5749. #+BEGIN_SRC: bash
  5750. openssl req -new -key /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/requests/$HOSTNAME.csr
  5751. #+END_SRC
  5752. For the email address it's a good idea to use postmaster@mydomainname.
  5753. Use a random 20 character password, and keep a note of it. We'll remove this later.
  5754. View the request with:
  5755. #+BEGIN_SRC: bash
  5756. cat /etc/ssl/requests/$HOSTNAME.csr
  5757. #+END_SRC
  5758. 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.
  5759. Log into your StartSSL account and select *Retrieve Certificate* from the *Tool Box* tab. Copy the text.
  5760. #+BEGIN_SRC: bash
  5761. editor /etc/ssl/certs/$HOSTNAME.crt
  5762. #+END_SRC
  5763. Paste the public key, then save and exit. Then on the BBB.
  5764. #+BEGIN_SRC: bash
  5765. mkdir /etc/ssl/roots
  5766. mkdir /etc/ssl/chains
  5767. wget "http://www.startssl.com/certs/ca.pem" --output-document="/etc/ssl/roots/startssl-root.ca"
  5768. wget "http://www.startssl.com/certs/sub.class1.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class1.server.ca.pem"
  5769. wget "http://www.startssl.com/certs/sub.class2.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class2.server.ca.pem"
  5770. wget "http://www.startssl.com/certs/sub.class3.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class3.server.ca.pem"
  5771. ln -s "/etc/ssl/roots/startssl-root.ca" "/etc/ssl/roots/$HOSTNAME-root.ca"
  5772. ln -s "/etc/ssl/chains/startssl-sub.class1.server.ca.pem" "/etc/ssl/chains/$HOSTNAME.ca"
  5773. cp "/etc/ssl/certs/$HOSTNAME.crt" "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5774. test -e "/etc/ssl/chains/$HOSTNAME.ca" && cat "/etc/ssl/chains/$HOSTNAME.ca" >> "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5775. test -e "/etc/ssl/roots/$HOSTNAME-root.ca" && cat "/etc/ssl/roots/$HOSTNAME-root.ca" >> "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5776. #+END_SRC
  5777. To avoid any possibility of the certificates being accidentally overwritten by self-signed ones at a later date you can create backups.
  5778. #+BEGIN_SRC: bash
  5779. mkdir /etc/ssl/backups
  5780. mkdir /etc/ssl/backups/certs
  5781. mkdir /etc/ssl/backups/private
  5782. cp /etc/ssl/certs/$HOSTNAME* /etc/ssl/backups/certs/
  5783. cp /etc/ssl/private/$HOSTNAME* /etc/ssl/backups/private/
  5784. chmod -R 400 /etc/ssl/backups/certs/*
  5785. chmod -R 400 /etc/ssl/backups/private/*
  5786. #+END_SRC
  5787. 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.
  5788. #+BEGIN_SRC: bash
  5789. openssl rsa -in /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/private/$HOSTNAME.new.key
  5790. cp /etc/ssl/private/$HOSTNAME.new.key /etc/ssl/private/$HOSTNAME.key
  5791. shred -zu /etc/ssl/private/$HOSTNAME.new.key
  5792. #+END_SRC
  5793. Edit your Apache configuration file.
  5794. #+BEGIN_SRC: bash
  5795. editor /etc/apache2/sites-available/$HOSTNAME
  5796. #+END_SRC
  5797. Add the following to the section which starts with *<VirtualHost *:443>*
  5798. #+BEGIN_SRC: bash
  5799. SSLCertificateChainFile /etc/ssl/chains/startssl-sub.class1.server.ca.pem
  5800. #+END_SRC
  5801. Save and exit, then restart apache.
  5802. #+BEGIN_SRC: bash
  5803. service apache2 restart
  5804. #+END_SRC
  5805. 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]].
  5806. * Deprecated
  5807. The following items have been deprecated until such time as a successful installation is achieved.
  5808. ** Gitlab
  5809. Install some dependencies:
  5810. #+BEGIN_SRC: bash
  5811. apt-get update -y
  5812. apt-get upgrade -y
  5813. apt-get install sudo -y
  5814. 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
  5815. #+END_SRC
  5816. Install bundler
  5817. #+BEGIN_SRC: bash
  5818. gem install bundler --no-ri --no-rdoc
  5819. #+END_SRC
  5820. Create a user for running Gitlab.
  5821. #+BEGIN_SRC: bash
  5822. adduser --disabled-login --gecos 'GitLab' git
  5823. #+END_SRC
  5824. Install mysql (it may already be installed).
  5825. #+BEGIN_SRC: bash
  5826. apt-get install -y mysql-server mysql-client libmysqlclient-dev
  5827. mysql_secure_installation
  5828. mysql -u root -p
  5829. #+END_SRC
  5830. Enter the following commands, substituting /gitlabpassword/ with a password to be used for the Gitlab installation.
  5831. #+BEGIN_SRC: bash
  5832. CREATE USER 'git'@'localhost' IDENTIFIED BY 'gitlabpassword';
  5833. SET storage_engine=INNODB;
  5834. CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  5835. GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
  5836. quit
  5837. #+END_SRC
  5838. Obtain the code and install it.
  5839. #+BEGIN_SRC: bash
  5840. cd /home/git
  5841. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-8-stable gitlab
  5842. cd /home/git/gitlab
  5843. sudo -u git -H cp /home/git/gitlab/config/gitlab.yml.example /home/git/gitlab/config/gitlab.yml
  5844. sudo -u git -H editor /home/git/gitlab/config/gitlab.yml
  5845. #+END_SRC
  5846. Set /host/ to your gitlab domain name, /port/ to 443 and /https/ to true, then save and exit.
  5847. #+BEGIN_SRC: bash
  5848. chown -R git /home/git/gitlab/log/
  5849. chown -R git /home/git/gitlab/tmp/
  5850. chmod -R u+rwX /home/git/gitlab/log/
  5851. chmod -R u+rwX /home/git/gitlab/tmp/
  5852. sudo -u git -H mkdir /home/git/gitlab-satellites
  5853. chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites
  5854. chmod -R u+rwX /home/git/gitlab/tmp/pids/
  5855. chmod -R u+rwX /home/git/gitlab/tmp/sockets/
  5856. chmod -R u+rwX /home/git/gitlab/public/uploads
  5857. sudo -u git -H cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb
  5858. #sudo -u git -H editor /home/git/gitlab/config/unicorn.rb
  5859. sudo -u git -H cp /home/git/gitlab/config/initializers/rack_attack.rb.example /home/git/gitlab/config/initializers/rack_attack.rb
  5860. sudo -u git -H git config --global user.name "GitLab"
  5861. sudo -u git -H git config --global user.email "gitlab@localhost"
  5862. sudo -u git -H git config --global core.autocrlf input
  5863. sudo -u git cp /home/git/gitlab/config/database.yml.mysql /home/git/gitlab/config/database.yml
  5864. sudo -u git -H chmod o-rwx /home/git/gitlab/config/database.yml
  5865. sudo -u git -H bundle install --deployment --without development test postgres aws
  5866. #+END_SRC
  5867. Fails here with:
  5868. /Could not find libv8-3.16.14.3 in any of the sources/
  5869. /Run `bundle install` to install missing gems./
  5870. #+BEGIN_SRC: bash
  5871. sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  5872. sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.3] REDIS_URL=redis://localhost:6379
  5873. sudo -u git -H editor /home/git/gitlab-shell/config.yml
  5874. cp lib/support/init.d/gitlab /etc/init.d/gitlab
  5875. update-rc.d gitlab defaults 21
  5876. cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
  5877. sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
  5878. sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
  5879. service gitlab start
  5880. #+END_SRC
  5881. Set up the Apache configuration.
  5882. #+BEGIN_SRC: bash
  5883. cp lib/support/apache/gitlab /etc/apache2/sites-available/mygitlabdomain
  5884. editor /etc/apache2/sites-available/mygitlabdomain
  5885. #+END_SRC
  5886. Set your domain name and email accordingly.
  5887. #+BEGIN_SRC: bash
  5888. a2ensite mygitlabdomain
  5889. #+END_SRC
  5890. ** Monkeysphere
  5891. #+BEGIN_SRC: bash
  5892. aptitude install monkeysphere
  5893. aptitude install msva-perl
  5894. aptitude install xul-ext-monkeysphere
  5895. export HOSTNAME=mydomainname.com
  5896. monkeysphere-host import-key /etc/ssh/ssh_host_rsa_key ssh://$HOSTNAME
  5897. monkeysphere-host publish-key
  5898. #+END_SRC
  5899. ** Diaspora
  5900. First install some dependencies:
  5901. #+BEGIN_SRC: bash
  5902. 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 gawk libreadline6-dev libyaml-dev sqlite3 libgdbm-dev libffi-dev
  5903. #+END_SRC
  5904. If there is trouble with dependencies select 'n' then 'y' to the solution.
  5905. Create a diaspora user.
  5906. #+BEGIN_SRC: bash
  5907. adduser --disabled-login diaspora
  5908. su diaspora
  5909. cd ~/
  5910. curl -L dspr.tk/1t | bash
  5911. echo "[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"" >> ~/.bashrc
  5912. . ~/.bashrc
  5913. rvm autolibs read-only
  5914. rvm install ruby-2.0.0-p481
  5915. git clone https://github.com/diaspora/diaspora.git
  5916. cd diaspora
  5917. #+END_SRC
  5918. Select 'y' to trust /home/diaspora/diaspora/.rvmrc
  5919. #+BEGIN_SRC: bash
  5920. cp config/diaspora.yml.example config/diaspora.yml
  5921. editor config/diaspora.yml
  5922. #+END_SRC
  5923. Set *url* to https://mydiasporadomainname.com/
  5924. Set *certificate_authorities* to */etc/ssl/certs/ca-certificates.crt*
  5925. Set *require_ssl* to *true*
  5926. Set *single_process_mode* to *false*
  5927. Set *port* to 3001
  5928. Set *rails_environment* to 'production'.
  5929. Set *pod_name* to the name of your pod.
  5930. Set *enable_registrations* to *true*.
  5931. Set *autofollow_on_join* to *false*
  5932. Under *captcha* set *enable* to *false*
  5933. Under *invitations* set *open* to *true*
  5934. Set *bitcoin_address* if you wish to accept donations.
  5935. Under *mail* set *enable* to *true*
  5936. Set *sender_address* to no-reply@mydiasporadomainname.com
  5937. Set *method* to *sendmail*
  5938. Set *exim_fix* to true.
  5939. Under *admins* set *account* to your username
  5940. Under *admins* set *podmin_email* to your email address
  5941. Save and exit.
  5942. #+BEGIN_SRC: bash
  5943. RAILS_ENV=production bundle install --without test development
  5944. #+END_SRC
  5945. This will take quite a while to install.
  5946. #+BEGIN_SRC: bash
  5947. RAILS_ENV=production bundle exec rake db:create db:schema:load
  5948. bundle exec rake assets:precompile
  5949. #+END_SRC
  5950. Alter the Apache configuration.
  5951. #+BEGIN_SRC: bash
  5952. exit
  5953. export HOSTNAME=mydiasporadomainname.com
  5954. editor /etc/apache2/sites-available/$HOSTNAME
  5955. #+END_SRC
  5956. Delete anything which already exists and add the following:
  5957. #+BEGIN_SRC: bash
  5958. <VirtualHost *:80>
  5959. ServerName mydiasporadomainname.com
  5960. ServerAlias www.mydiasporadomainname.com
  5961. RedirectPermanent / https://mydiasporadomainname.com/
  5962. </VirtualHost>
  5963. <VirtualHost *:443>
  5964. ServerName mydiasporadomainname.com
  5965. ServerAlias www.mydiasporadomainname.com
  5966. DocumentRoot /home/diaspora/diaspora/public
  5967. RewriteEngine On
  5968. RewriteCond %{HTTP_HOST} !^mydiasporadomainname\.com [NC]
  5969. RewriteRule ^/(.*)$ https://mydiasporadomainname\.com/$1 [L,R,QSA]
  5970. RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  5971. RewriteRule ^/(.*)$ balancer://upstream%{REQUEST_URI} [P,QSA,L]
  5972. <Proxy balancer://upstream>
  5973. BalancerMember http://127.0.0.1:3001
  5974. </Proxy>
  5975. ProxyRequests Off
  5976. ProxyVia On
  5977. ProxyPreserveHost On
  5978. RequestHeader set X_FORWARDED_PROTO https
  5979. <Proxy *>
  5980. # Apache < 2.4
  5981. Order allow,deny
  5982. Allow from all
  5983. # Apache >= 2.4
  5984. #Require all granted
  5985. </Proxy>
  5986. <Directory /home/diaspora/diaspora/public>
  5987. Options -MultiViews
  5988. # Apache < 2.4
  5989. Allow from all
  5990. AllowOverride all
  5991. # Apache >= 2.4
  5992. #Require all granted
  5993. </Directory>
  5994. SSLEngine On
  5995. SSLCertificateFile /etc/ssl/certs/mydiasporadomainname.com.crt
  5996. SSLCertificateKeyFile /etc/ssl/private/mydiasporadomainname.com.key
  5997. # maybe not needed, need for example for startssl to point to a local
  5998. # copy of http://www.startssl.com/certs/sub.class1.server.ca.pem
  5999. SSLCertificateChainFile /etc/ssl/chains/startssl-sub.class1.server.ca.pem
  6000. # Based on https://wiki.mozilla.org/Security/Server_Side_TLS - consider as global configuration
  6001. SSLProtocol all -SSLv2
  6002. 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
  6003. SSLHonorCipherOrder on
  6004. SSLCompression off
  6005. </VirtualHost>
  6006. #+END_SRC
  6007. Save and exit.
  6008. #+BEGIN_SRC: bash
  6009. editor /usr/bin/rundiaspora
  6010. #+END_SRC
  6011. Add the following.
  6012. #+BEGIN_SRC: bash
  6013. #!/bin/sh
  6014. USERNAME=diaspora
  6015. COMMAND="cd /home/$USERNAME/diaspora; /bin/sh /home/$USERNAME/diaspora/script/server > /home/$USERNAME/diaspora.log"
  6016. su -l $USERNAME -c '$COMMAND'
  6017. #+END_SRC
  6018. Save and exit.
  6019. Create an init script:
  6020. #+BEGIN_SRC: bash
  6021. chmod +x /usr/bin/rundiaspora
  6022. editor /etc/init.d/diaspora
  6023. #+END_SRC
  6024. Add the following.
  6025. #+BEGIN_SRC: bash
  6026. #!/bin/bash
  6027. # /etc/init.d/diaspora
  6028. ### BEGIN INIT INFO
  6029. # Provides: diaspora
  6030. # Required-Start: $remote_fs $syslog
  6031. # Required-Stop: $remote_fs $syslog
  6032. # Default-Start: 2 3 4 5
  6033. # Default-Stop: 0 1 6
  6034. # Short-Description: starts diaspora
  6035. # Description: Starts Diaspora.
  6036. ### END INIT INFO
  6037. # Author: Bob Mottram <bob@robotics.uk.to>
  6038. #Settings
  6039. SERVICE='diaspora'
  6040. HISTORY=1024
  6041. USERNAME='diaspora'
  6042. COMMAND="rundiaspora"
  6043. NICELEVEL=19 # from 0-19
  6044. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  6045. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  6046. diaspora_start() {
  6047. echo -n $"Starting $SERVICE service"
  6048. screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}
  6049. # su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  6050. # su -l $USERNAME -c "$COMMAND"
  6051. # RETVAL=$?
  6052. echo
  6053. }
  6054. diaspora_stop() {
  6055. echo -n $"Stopping $SERVICE service"
  6056. screen -p 0 -S ${SERVICE} -X stuff "'^C'"
  6057. # su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  6058. # su -l $USERNAME -c "/home/$USERNAME/diaspora/script/server"
  6059. # RETVAL=$?
  6060. echo
  6061. }
  6062. #Start-Stop here
  6063. case "$1" in
  6064. start)
  6065. diaspora_start
  6066. ;;
  6067. stop)
  6068. diaspora_stop
  6069. ;;
  6070. restart)
  6071. diaspora_stop
  6072. diaspora_start
  6073. ;;
  6074. *)
  6075. echo "Usage: $0 {start|stop|restart}"
  6076. exit 1
  6077. ;;
  6078. esac
  6079. exit 0
  6080. #+END_SRC
  6081. Save and exit.
  6082. #+BEGIN_SRC: bash
  6083. chmod +x /etc/init.d/diaspora
  6084. update-rc.d diaspora defaults
  6085. service diaspora start
  6086. #+END_SRC
  6087. Now enable the site:
  6088. #+BEGIN_SRC: bash
  6089. a2enmod ssl
  6090. a2enmod rewrite
  6091. a2enmod headers
  6092. a2enmod proxy
  6093. a2enmod proxy_connect
  6094. a2enmod proxy_http
  6095. a2enmod proxy_balancer
  6096. a2ensite $HOSTNAME
  6097. service apache2 restart
  6098. #+END_SRC
  6099. * Related projects
  6100. * [[https://freedomboxfoundation.org/][Freedombox]]
  6101. * [[https://arkos.io/][ArkOS]]
  6102. * [[https://github.com/JoshData/mailinabox][Mail-in-a-Box]]
  6103. * [[https://github.com/sandstorm-io/sandstorm][Sandstorm]]