beaglebone.txt 259KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078
  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. First install some dependencies.
  2501. #+BEGIN_SRC: bash
  2502. apt-get update
  2503. apt-get install build-essential openssl libssl-dev debhelper dpatch docbook-to-man flex bison libpcre3-dev screen
  2504. #+END_SRC
  2505. Then get the source code for ircd-hybrid.
  2506. #+BEGIN_SRC: bash
  2507. mkdir ~/build
  2508. cd ~/build
  2509. wget http://freedombone.uk.to/ircd-hybrid-8.1.17.tgz
  2510. #+END_SRC
  2511. verify it.
  2512. #+BEGIN_SRC: bash
  2513. sha256sum ircd-hybrid-8.1.17.tgz
  2514. 440c9d86ba6bc930efef9cdaaec547b425c35cad3f08bed8df69e55788c1268a
  2515. #+END_SRC
  2516. Install it.
  2517. #+BEGIN_SRC: bash
  2518. tar -xzvf ircd-hybrid-8.1.17.tgz
  2519. cd ircd-hybrid-8.1.17
  2520. ./configure --prefix=/usr/local/ircd --enable-openssl
  2521. make
  2522. make install
  2523. #+END_SRC
  2524. Customise the configuration to your system, giving it a name and description. In this example 192.168.1.60 is the static IP address on the BBB on the local network, so change that if necessary.
  2525. #+BEGIN_SRC: bash
  2526. chown -R irc:irc /usr/local/ircd
  2527. cp /usr/local/ircd/etc/reference.conf /usr/local/ircd/etc/ircd.conf
  2528. editor /usr/local/ircd/etc/ircd.conf
  2529. #+END_SRC
  2530. Set *name* to the domain name of your server, and set a description.
  2531. Set a *network_name* and *network_desc*. The network name should not contain any spaces.
  2532. Set max_clients to 20, or however many you expect that you'll typically need.
  2533. Within the admin section set your *name* and *email*.
  2534. Within the *listen* section set host to your fixed IP address (in the earlier
  2535. sections it was 192.168.1.60).
  2536. Within the *auth* section set user = "*@192.168.1.60" - or whatever the fixed IP address of the BBB is on your network - and password to the desired password for the IRC server. If you don't wish to use a password then remove need_password from the flags.
  2537. Within the *connect* section set *host* and *vhost* to your fixed IP address (in the earlier
  2538. sections it was 192.168.1.60) and *name* to your domain name. Also set the *send/accept passwords* to your IRC login password.
  2539. Within the *operator* section change *name* to the username/nick which you will user to irc@192.168.1.60
  2540. Change *ssl_connection_required* to *yes*.
  2541. Save and exit, then restart the IRC server. Open port 6697 on your internet router and forward it to the BBB. Note that although ports 6665 to 6669 are active within the configuration file in practice we will only use the encrypted port.
  2542. Ensure that the configuration is only readable by the root user.
  2543. #+BEGIN_SRC: bash
  2544. chmod 600 /usr/local/ircd/etc/ircd.conf
  2545. #+END_SRC
  2546. Now create an init script.
  2547. #+BEGIN_SRC: bash
  2548. adduser irc
  2549. #+END_SRC
  2550. Make the password some long random string.
  2551. #+BEGIN_SRC: bash
  2552. editor /usr/bin/runircd
  2553. #+END_SRC
  2554. Add the following:
  2555. #+BEGIN_SRC: bash
  2556. #!/bin/sh
  2557. USERNAME=irc
  2558. COMMAND="cd /usr/local/ircd/bin; ircd > /usr/local/ircd/ircd.log"
  2559. su -l $USERNAME -c '$COMMAND'
  2560. #+END_SRC
  2561. Save and exit.
  2562. #+BEGIN_SRC: bash
  2563. chmod +x /usr/bin/runircd
  2564. editor /etc/init.d/ircd-hybrid
  2565. #+END_SRC
  2566. Add the following:
  2567. #+BEGIN_SRC: bash
  2568. #!/bin/bash
  2569. # /etc/init.d/ircd-hybrid
  2570. ### BEGIN INIT INFO
  2571. # Provides: ircd-hybrid
  2572. # Required-Start: $remote_fs $syslog
  2573. # Required-Stop: $remote_fs $syslog
  2574. # Default-Start: 2 3 4 5
  2575. # Default-Stop: 0 1 6
  2576. # Short-Description: starts irc server
  2577. # Description: starts irc server
  2578. ### END INIT INFO
  2579. # Author: Bob Mottram <bob@robotics.uk.to>
  2580. #Settings
  2581. SERVICE='ircd-hybrid'
  2582. COMMAND="runircd"
  2583. USER='irc'
  2584. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  2585. HISTORY=1024
  2586. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  2587. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin'
  2588. irc_start() {
  2589. echo "Starting $SERVICE..."
  2590. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USER
  2591. }
  2592. irc_stop() {
  2593. echo "Stopping $SERVICE"
  2594. pkill ${COMMAND}
  2595. }
  2596. #Start-Stop here
  2597. case "$1" in
  2598. start)
  2599. irc_start
  2600. ;;
  2601. stop)
  2602. irc_stop
  2603. ;;
  2604. restart)
  2605. irc_stop
  2606. sleep 10s
  2607. irc_start
  2608. ;;
  2609. *)
  2610. echo "Usage: $0 {start|stop|restart}"
  2611. exit 1
  2612. ;;
  2613. esac
  2614. exit 0
  2615. #+END_SRC
  2616. Save and exit, then start the daemon.
  2617. #+BEGIN_SRC: bash
  2618. chmod +x /etc/init.d/ircd-hybrid
  2619. update-rc.d ircd-hybrid defaults
  2620. service ircd-hybrid start
  2621. #+END_SRC
  2622. *** Channel management
  2623. To to install channel management tools.
  2624. #+BEGIN_SRC: bash
  2625. mkdir ~/build
  2626. cd ~/build
  2627. wget http://freedombone.uk.to/hybserv_1.9.4-1_armhf.deb
  2628. #+END_SRC
  2629. Verify it.
  2630. #+BEGIN_SRC: bash
  2631. sha256sum hybserv_1.9.4-1_armhf.deb
  2632. 41bf4eb6e24c87610a80bc14db1103a57484835510eea7e4ba9709c523318615 hybserv_1.9.4-1_armhf.deb
  2633. #+END_SRC
  2634. Install it.
  2635. #+BEGIN_SRC: bash
  2636. dpkg -i hybserv_1.9.4-1_armhf.deb
  2637. #+END_SRC
  2638. Make a md5 version of the password for the IRC server operator.
  2639. #+BEGIN_SRC: bash
  2640. /usr/bin/mkpasswd <myoperatorpassword>
  2641. #+END_SRC
  2642. Edit the ircd-hybrid configuration.
  2643. #+BEGIN_SRC: bash
  2644. editor /etc/ircd-hybrid/ircd.conf
  2645. #+END_SRC
  2646. Enter the md5 password which you previously created within the /operator/ section. Also change /user/ to:
  2647. #+BEGIN_SRC: bash
  2648. user = "*@*";
  2649. #+END_SRC
  2650. Then save and exit.
  2651. #+BEGIN_SRC: bash
  2652. editor /etc/hybserv/hybserv.conf
  2653. #+END_SRC
  2654. 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/.
  2655. #+BEGIN_SRC: bash
  2656. A:mynickname <myemailaddress>
  2657. N:irc.mydomainname.com:Hybrid services
  2658. O:*@*:#MD5 PASSWORD HERE#:root:segj (comment out other Q: lines)
  2659. S:mysendacceptpassword:192.168.1.60:6697 (remove the other two services)
  2660. #+END_SRC
  2661. Also remove the line *#NOT-EDITED#*, then save and exit.
  2662. Now we need to restart the ircd and hybrid server to make things work:
  2663. #+BEGIN_SRC: bash
  2664. service ircd-hybrid restart
  2665. service hybserv start
  2666. #+END_SRC
  2667. *** Usage with Irssi
  2668. On another computer (not the BBB).
  2669. #+BEGIN_SRC: bash
  2670. sudo apt-get install irssi irssi-plugin-otr irssi-plugin-xmpp
  2671. irssi
  2672. #+END_SRC
  2673. 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".
  2674. #+BEGIN_SRC: bash
  2675. /network add -nick mynick mynetwork
  2676. /channel add -auto #mychannel mynetwork channelpassword
  2677. /server add -auto -network mynetwork -ssl mydonainname.com 6697 mysendacceptpassword
  2678. /connect mydomainname.com
  2679. /join #mychannel
  2680. /msg -servername chanserv REGISTER #mychannel channelpassword
  2681. /msg -servername chanserv set #mychannel mlock +k channelpassword
  2682. /set paste_join_multiline OFF
  2683. #+END_SRC
  2684. If you edit the irssi config file:
  2685. #+BEGIN_SRC: bash
  2686. editor ~/.irssi/config
  2687. #+END_SRC
  2688. It should look something like this:
  2689. #+BEGIN_SRC: bash
  2690. {
  2691. address = "mydomainname.com";
  2692. chatnet = "mynetwork";
  2693. port = "6697";
  2694. password = "mysendacceptpassword";
  2695. use_ssl = "yes";
  2696. ssl_verify = "no";
  2697. autoconnect = "yes";
  2698. },
  2699. #+END_SRC
  2700. If you're not using a self-signed certificate (self-signed is the default) then you can set *ssl_verify* to "yes".
  2701. By default irssi will use UTC time. An example of setting to some other time zone is as follows:
  2702. #+BEGIN_SRC: bash
  2703. echo "load perl" >> ~/.irssi/startup
  2704. echo "script exec $ENV{'TZ'}='Europe/London';" >> ~/.irssi/startup
  2705. #+END_SRC
  2706. Also enable /Off The Record/ (OTR) messaging.
  2707. #+BEGIN_SRC: bash
  2708. echo "load otr" >> ~/.irssi/startup
  2709. #+END_SRC
  2710. By default Irssi does not look especially attractive. To improve it's looks:
  2711. #+BEGIN_SRC: bash
  2712. cd ~/.irssi
  2713. wget http://freedombone.uk.to/irssi/xchat.theme
  2714. mkdir ~/.irssi/scripts
  2715. mkdir ~/.irssi/scripts/autorun
  2716. cd ~/.irssi/scripts/autorun
  2717. wget http://freedombone.uk.to/irssi/xchatnickcolor.pl
  2718. wget http://freedombone.uk.to/irssi/adv_windowlist.pl
  2719. #+END_SRC
  2720. Verify the files:
  2721. #+BEGIN_SRC: bash
  2722. sha256sum ~/.irssi/xchat.theme
  2723. 7a84130ad55aabd0b043a03b013628438e6c7f82a58e15267633bc7eb443e60b
  2724. sha256sum ~/.irssi/scripts/autorun/xchatnickcolor.pl
  2725. 8293e867a22d42ce5a28cd755237509b6f3587fd2b21d7d20af4a832081610ca
  2726. sha256sum ~/.irssi/scripts/autorun/adv_windowlist.pl
  2727. e4dd8f6d384bf4f2d0ab5ccf06df06e4a69d2647b08d37c8fc6cfd9326688395
  2728. #+END_SRC
  2729. Then run Irssi and enter the commands:
  2730. #+BEGIN_SRC: bash
  2731. /set theme xchat
  2732. /statusbar window remove act
  2733. /set awl
  2734. /set awl_block -14
  2735. /set awl_display_key $Q%K|$N%n $H$C$S
  2736. /set awl_display_key_active $Q%K|$N%n $H%U$C%n$S
  2737. /set awl_display_nokey [$N]$H$C$S
  2738. /run autorun/adv_windowlist.pl
  2739. /set awl_viewer off
  2740. /save
  2741. #+END_SRC
  2742. *** Using irssi with Off The Record messaging (OTR)
  2743. Once you're running irssi then you can enable OTR with:
  2744. #+BEGIN_SRC: bash
  2745. /statusbar window add otr
  2746. /otr genkey mynick@network (for example mynick@irc.freenode.net)
  2747. #+END_SRC
  2748. Then to see your OTR fingerprint:
  2749. #+BEGIN_SRC: bash
  2750. /otr info
  2751. #+END_SRC
  2752. And to trust or distrust someone else's fingerprint.
  2753. #+BEGIN_SRC: bash
  2754. /otr trust [fingerprint]
  2755. /otr distrust [fingerprint]
  2756. #+END_SRC
  2757. *** Usage with XChat
  2758. Within the network list click, *Add* and enter your domain name then click *Edit*.
  2759. Select the entry within the servers box, then enter *mydomainname.com/6697* and press *Enter*.
  2760. Uncheck *use global user information*.
  2761. Enter first and second nicknames and check *auto connect to this network on startup*.
  2762. Check *use SSL* and *accept invalid SSL certificate*.
  2763. Enter some favourite channels and within *server password* enter /mysendacceptpassword/ which you defined earlier when setting up the server.
  2764. Click *close* and then *connect*.
  2765. *** Install Irssi as a daemon
  2766. 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.
  2767. First install some prerequisites.
  2768. #+BEGIN_SRC: bash
  2769. apt-get install irssi irssi-plugin-otr irssi-plugin-xmpp screen
  2770. #+END_SRC
  2771. Create an initialisation script.
  2772. #+BEGIN_SRC: bash
  2773. editor /etc/init.d/irssid
  2774. #+END_SRC
  2775. Add the following:
  2776. #+BEGIN_SRC: bash
  2777. #!/bin/bash
  2778. ### BEGIN INIT INFO
  2779. # Provides: irssid
  2780. # Required-Start: $network
  2781. # Required-Stop: $network
  2782. # Default-Start: 2 3 4 5
  2783. # Default-Stop: 0 1 6
  2784. # Short-Description: Start irssi daemon within screen session at boot time
  2785. # Description: This init script will start an irssi session under screen using the settings provided in /etc/irssid.conf
  2786. ### END INIT INFO
  2787. # Include the LSB library functions
  2788. . /lib/lsb/init-functions
  2789. # Setup static variables
  2790. configFile='/etc/irssid.conf'
  2791. daemonExec='/usr/bin/screen'
  2792. daemonArgs='-D -m'
  2793. daemonName="$(basename "$daemonExec")"
  2794. pidFile='/var/run/irssid.pid'
  2795. #
  2796. # Checks if the environment is capable of running the script (such as
  2797. # availability of programs etc).
  2798. #
  2799. # Return: 0 if the environmnt is properly setup for execution of init script, 1
  2800. # if not all conditions have been met.
  2801. #
  2802. function checkEnvironment() {
  2803. # Verify that the necessary binaries are available for execution.
  2804. local binaries=(irssi screen)
  2805. for bin in "${binaries[@]}"; do
  2806. if ! which "$bin" > /dev/null; then
  2807. log_failure_msg "Binary '$bin' is not available. Please install \
  2808. package containing it."
  2809. exit 5
  2810. fi
  2811. done
  2812. }
  2813. #
  2814. # Checks if the configuration files are available and properly setup.
  2815. #
  2816. # Return: 0 if irssid if properly configured, 1 otherwise.
  2817. #
  2818. function checkConfig() {
  2819. # Make sure the configuration file has been created
  2820. if ! [[ -f $configFile ]]; then
  2821. log_failure_msg "Please populate the configuration file '$configFile' \
  2822. before running."
  2823. exit 6
  2824. fi
  2825. # Make sure the required options have been set
  2826. local reqOptions=(user group session)
  2827. for option in "${reqOptions[@]}"; do
  2828. if ! grep -q -e "^[[:blank:]]*$option=" "$configFile"; then
  2829. log_failure_msg "Mandatory option '$option' was not specified in \
  2830. '$configFile'"
  2831. exit 6
  2832. fi
  2833. done
  2834. }
  2835. #
  2836. # Loads the configuration file and performs any additional configuration steps.
  2837. #
  2838. function configure() {
  2839. . "$configFile"
  2840. daemonArgs="$daemonArgs -S $session irssi"
  2841. [[ -n $args ]] && daemonArgs="$daemonArgs $args"
  2842. daemonCommand="$daemonExec $daemonArgs"
  2843. }
  2844. #
  2845. # Starts the daemon.
  2846. #
  2847. # Return: LSB-compliant code.
  2848. #
  2849. function start() {
  2850. 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
  2851. }
  2852. #
  2853. # Stops the daemon.
  2854. #
  2855. # Return: LSB-compliant code.
  2856. #
  2857. function stop() {
  2858. start-stop-daemon --stop -x /bin/su -p /tmp/irssi.screen.session -q
  2859. }
  2860. checkEnvironment
  2861. checkConfig
  2862. configure
  2863. case "$1" in
  2864. start)
  2865. log_daemon_msg "Starting daemon" "irssid"
  2866. start && log_end_msg 0 || log_end_msg $?
  2867. ;;
  2868. stop)
  2869. log_daemon_msg "Stopping daemon" "irssid"
  2870. stop && log_end_msg 0 || log_end_msg $?
  2871. ;;
  2872. restart)
  2873. log_daemon_msg "Restarting daemon" "irssid"
  2874. stop
  2875. start && log_end_msg 0 || log_end_msg $?
  2876. ;;
  2877. force-reload)
  2878. log_daemon_msg "Restarting daemon" "irssid"
  2879. stop
  2880. start && log_end_msg 0 || log_end_msg $?
  2881. ;;
  2882. status)
  2883. status_of_proc -p "$pidFile" "$daemonExec" screen && exit 0 || exit $?
  2884. ;;
  2885. *)
  2886. echo "irssid (start|stop|restart|force-reload|status|help)"
  2887. ;;
  2888. esac
  2889. #+END_SRC
  2890. Save and exit.
  2891. #+BEGIN_SRC: bash
  2892. chmod +x /etc/init.d/irssid
  2893. #+END_SRC
  2894. Create a configuration file, replacing /myusername/ with your username.
  2895. #+BEGIN_SRC: bash
  2896. editor /etc/irssid.conf
  2897. #+END_SRC
  2898. #+BEGIN_SRC: bash
  2899. #
  2900. # Configuration file for irssid init script
  2901. #
  2902. # Mandatory options:
  2903. #
  2904. # user - Specify user for running irssi.
  2905. # group - Specify group for running irssi.
  2906. # session - Specify screen session name to be used for irssi.
  2907. #
  2908. # Non-mandatory options:
  2909. #
  2910. # args - Pass additional arguments to irssi.
  2911. #
  2912. user='myusername'
  2913. group='irssi'
  2914. session='irssi'
  2915. args='--config /home/myusername/.irssi/config'
  2916. #+END_SRC
  2917. Save and exit. Then add your user to the irssi group and start the daemon.
  2918. #+BEGIN_SRC: bash
  2919. groupadd irssi
  2920. usermod -aG irssi myusername
  2921. update-rc.d irssid defaults
  2922. chown -R myusername:irssi /home/myusername/.irssi
  2923. service irssid start
  2924. #+END_SRC
  2925. Create a script to make running IRC on the server easier.
  2926. #+BEGIN_SRC: bash
  2927. editor /usr/bin/irc
  2928. #+END_SRC
  2929. Add the following:
  2930. #+BEGIN_SRC: bash
  2931. #!/bin/bash
  2932. screen -r irssi
  2933. #+END_SRC
  2934. Save and exit.
  2935. #+BEGIN_SRC: bash
  2936. chmod +x /usr/bin/irc
  2937. chown myusername:myusername /usr/bin/irc
  2938. #+END_SRC
  2939. Then to subsequently access irssi log into the BBB using ssh and type:
  2940. #+BEGIN_SRC: bash
  2941. irc
  2942. #+END_SRC
  2943. To set UK time within Irssi:
  2944. #+BEGIN_SRC: bash
  2945. /script exec $ENV{'TZ'}='Europe/London';
  2946. /save
  2947. #+END_SRC
  2948. ** Install a Jabber/XMPP server
  2949. #+BEGIN_VERSE
  2950. /Well heck, it isn’t that hard to write an instant messaging system./
  2951. --Jeremie Miller
  2952. #+END_VERSE
  2953. *** The Server
  2954. Generate a SSL certificate.
  2955. #+BEGIN_SRC: bash
  2956. openssl genrsa -out /etc/ssl/private/xmpp.key 4096
  2957. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  2958. #+END_SRC
  2959. Change permissions.
  2960. #+BEGIN_SRC: bash
  2961. chmod 600 /etc/ssl/private/xmpp.key
  2962. chmod 600 /etc/ssl/certs/xmpp.crt
  2963. #+END_SRC
  2964. Install Prosody.
  2965. #+BEGIN_SRC: bash
  2966. apt-get install prosody
  2967. chown prosody:prosody /etc/ssl/private/xmpp.key
  2968. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  2969. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  2970. editor /etc/prosody/conf.avail/xmpp.cfg.lua
  2971. #+END_SRC
  2972. Change the *VirtualHost* name to your domain name and remove the line below it.
  2973. Set the ssl section to:
  2974. #+BEGIN_SRC: bash
  2975. ssl = {
  2976. key = "/etc/ssl/private/xmpp.key";
  2977. certificate = "/etc/ssl/certs/xmpp.crt";
  2978. }
  2979. #+END_SRC
  2980. And also append the following:
  2981. #+BEGIN_SRC: bash
  2982. modules_enabled = {
  2983. "bosh"; -- Enable mod_bosh
  2984. "tls"; -- Enable mod_tls
  2985. }
  2986. c2s_require_encryption = true
  2987. s2s_require_encryption = true
  2988. #+END_SRC
  2989. Save and exit. Create a symbolic link.
  2990. #+BEGIN_SRC: bash
  2991. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  2992. editor /etc/prosody/prosody.cfg.lua
  2993. #+END_SRC
  2994. Within the *ssl* section set:
  2995. #+BEGIN_SRC: bash
  2996. ssl = {
  2997. key = "/etc/ssl/private/xmpp.key";
  2998. certificate = "/etc/ssl/certs/xmpp.crt";
  2999. }
  3000. #+END_SRC
  3001. Uncomment and set the following to *true*
  3002. #+BEGIN_SRC: bash
  3003. c2s_require_encryption = true
  3004. s2s_require_encryption = true
  3005. #+END_SRC
  3006. Within the *modules_enabled* section uncomment *bosh*, then save and exit.
  3007. 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).
  3008. #+BEGIN_SRC: bash
  3009. prosodyctl adduser myusername@mydomainname.com
  3010. #+END_SRC
  3011. Restart the server
  3012. #+BEGIN_SRC: bash
  3013. service prosody restart
  3014. #+END_SRC
  3015. On your internet router/firewall open ports 5222, 5223, 5269, 5280 and 5281 and forward them to the BBB.
  3016. 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.
  3017. *** Managing users
  3018. To add a user:
  3019. #+BEGIN_SRC: bash
  3020. prosodyctl adduser myusername@mydomainname.com
  3021. #+END_SRC
  3022. To change a user password:
  3023. #+BEGIN_SRC: bash
  3024. prosodyctl passwd myusername@mydomainname.com
  3025. #+END_SRC
  3026. To remove a user:
  3027. #+BEGIN_SRC: bash
  3028. prosodyctl deluser myusername@mydomainname.com
  3029. #+END_SRC
  3030. Report the status of the XMPP server:
  3031. #+BEGIN_SRC: bash
  3032. prosodyctl status
  3033. #+END_SRC
  3034. *** Using with Jitsi
  3035. 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.
  3036. Jitsi can be downloaded from https://jitsi.org/
  3037. On your desktop/laptop open Jitsi and select *Options* from the *Tools* menu.
  3038. 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).
  3039. 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.
  3040. 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.
  3041. You can also [[https://www.youtube.com/watch?v=vgx7VSrDGjk][see this video]] as an example of using OTR.
  3042. *** Using with Ubuntu
  3043. 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.
  3044. Open *System Settings* and select *Online Accounts*, *Add account* and then *Jabber*.
  3045. Enter your username (myusername@mydomainname.com) and password.
  3046. 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*.
  3047. *** Using with Android
  3048. There are a few XMPP clients available on Android. Ideally choose ones which support off-the-record messaging. Here are some examples.
  3049. **** Xabber
  3050. Install [[https://f-droid.org/][F-Droid]]
  3051. Search for and install Xabber.
  3052. Add an account and enter your Jabber/XMPP ID and password.
  3053. From the menu select *Settings* then *Security* then *OTR mode*. Set the mode to *Required*.
  3054. Make sure that *Check server certificate* is not checked.
  3055. 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.
  3056. **** Gibberbot
  3057. Install [[https://f-droid.org/][F-Droid]]
  3058. Search for and install Gibberbot, otherwise known as ChatSecure.
  3059. From the menu open *Accounts*
  3060. Select *Add account*
  3061. Change the server port from 0 to 5222
  3062. Done
  3063. Accept unknown certificate? Select *Always*
  3064. Go back to the initial screen and then using the menu you can add contacts and begin chatting.
  3065. ** Social Networking
  3066. #+BEGIN_VERSE
  3067. /Facebook is not your friend, it is a surveillance engine./
  3068. -- Richard Stallman, Free Software Foundation
  3069. #+END_VERSE
  3070. *** Friendica
  3071. **** Installation
  3072. 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.
  3073. 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:
  3074. #+BEGIN_SRC: bash
  3075. editor /etc/apache2/sites-available/myfriendicadomainname.com
  3076. #+END_SRC
  3077. 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:
  3078. #+BEGIN_SRC: bash
  3079. <VirtualHost *:80>
  3080. ServerAdmin myusername@mydomainname.com
  3081. ServerName myfriendicadomainname.com
  3082. RewriteEngine On
  3083. RewriteCond %{HTTPS} off
  3084. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3085. </VirtualHost>
  3086. #+END_SRC
  3087. Save and exit, then restart the apache server.
  3088. #+BEGIN_SRC: bash
  3089. service apache2 restart
  3090. #+END_SRC
  3091. Now install some dependencies.
  3092. #+BEGIN_SRC: bash
  3093. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt php5-fpm php5-cgi php-apc
  3094. #+END_SRC
  3095. Enter an admin password for MySQL.
  3096. Reduce the memory use of mysql by using the "small" configuration.
  3097. #+BEGIN_SRC: bash
  3098. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3099. #+END_SRC
  3100. Create a mysql database, replacing /myfriendicapassword/ with a password used to administer the friendica database.
  3101. #+BEGIN_SRC: bash
  3102. mysql -u root -p
  3103. create database friendica;
  3104. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'myfriendicapassword';
  3105. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  3106. quit
  3107. #+END_SRC
  3108. You may need to fix Git SSL problems.
  3109. #+BEGIN_SRC: bash
  3110. git config --global http.sslVerify true
  3111. apt-get install ca-certificates
  3112. cd ~/
  3113. editor .gitconfig
  3114. #+END_SRC
  3115. The .gitconfig file should look something like this:
  3116. #+BEGIN_SRC: bash
  3117. [user]
  3118. name = yourname
  3119. email = myusername@mydomainname.com
  3120. [http]
  3121. sslVerify = true
  3122. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  3123. #+END_SRC
  3124. Get the source code.
  3125. #+BEGIN_SRC: bash
  3126. export HOSTNAME=myfriendicadomainname.com
  3127. cd /var/www/$HOSTNAME
  3128. rm -rf htdocs
  3129. git clone https://github.com/friendica/friendica.git htdocs
  3130. chmod -R 755 htdocs
  3131. chown -R www-data:www-data htdocs
  3132. chown -R www-data:www-data htdocs/view/smarty3
  3133. git clone https://github.com/friendica/friendica-addons.git htdocs/addon
  3134. #+END_SRC
  3135. Now visit the URL of your site and you should be taken through the rest of the installation procedure.
  3136. | Database Server Name | localhost |
  3137. | Database login name | friendicaadmin |
  3138. | Database Login Password | myfriendicapassword |
  3139. | Database Name | friendica |
  3140. 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.
  3141. 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.
  3142. Install the poller.
  3143. #+BEGIN_SRC: bash
  3144. editor /etc/crontab
  3145. #+END_SRC
  3146. and append the following, changing /myfriendicadomainname.com/ to whatever your Friendica domain is.
  3147. #+BEGIN_SRC: bash
  3148. */10 * * * * root cd /var/www/myfriendicadomainname.com/htdocs; /usr/bin/timeout 120 /usr/bin/php include/poller.php
  3149. #+END_SRC
  3150. Save and exit, then restart cron.
  3151. #+BEGIN_SRC: bash
  3152. service cron restart
  3153. #+END_SRC
  3154. You can improve the speed of Friendica database searches by adding the following indexes:
  3155. #+BEGIN_SRC: bash
  3156. mysql -u root -p
  3157. use friendica;
  3158. CREATE INDEX `uri_received` ON item(`uri`, `received`);
  3159. CREATE INDEX `received_uri` ON item(`received`, `uri`);
  3160. CREATE INDEX `contact-id_created` ON item(`contact-id`, created);
  3161. CREATE INDEX `uid_network_received` ON item(`uid`, `network`, `received`);
  3162. CREATE INDEX `uid_parent` ON item(`uid`, `parent`);
  3163. CREATE INDEX `uid_received` ON item(`uid`, `received`);
  3164. CREATE INDEX `uid_network_commented` ON item(`uid`, `network`, `commented`);
  3165. CREATE INDEX `uid_title` ON item(uid, `title`);
  3166. CREATE INDEX `created_contact-id` ON item(`created`, `contact-id`);
  3167. quit
  3168. #+END_SRC
  3169. Make sure that Friendica doesn't use too much memory.
  3170. #+BEGIN_SRC: bash
  3171. editor /var/www/$HOSTNAME/htdocs/.htaccess
  3172. #+END_SRC
  3173. Append the following:
  3174. #+BEGIN_SRC: bash
  3175. php_value memory_limit 32M
  3176. #+END_SRC
  3177. The save ane exit.
  3178. **** Backups
  3179. 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.
  3180. #+BEGIN_SRC: bash
  3181. editor /etc/cron.daily/backup
  3182. #+END_SRC
  3183. Enter the following, replacing /myusername@mydomainname.com/ with your email address and the mysql root password as appropriate.
  3184. #+BEGIN_SRC: bash
  3185. #!/bin/sh
  3186. EMAIL=myusername@mydomainname.com
  3187. MYSQL_PASSWORD=<mysql root password>
  3188. umask 0077
  3189. # stop the web server to avoid any changes to the databases during backup
  3190. service apache2 stop
  3191. # Save to a temporary file first so that it can be checked for non-zero size
  3192. TEMPFILE=/tmp/friendicared.sql
  3193. # Backup the Friendica database
  3194. DAILYFILE=/var/backups/friendica_daily.sql
  3195. mysqldump --password=$MYSQL_PASSWORD friendica > $TEMPFILE
  3196. FILESIZE=$(stat -c%s $TEMPFILE)
  3197. if [ "$FILESIZE" -eq "0" ]; then
  3198. if [ -f $DAILYFILE ]; then
  3199. cp $DAILYFILE $TEMPFILE
  3200. # try to restore yesterday's database
  3201. mysql -u root --password=$MYSQL_PASSWORD friendica -o < $DAILYFILE
  3202. # Send a warning email
  3203. echo "Unable to create a backup of the Friendica database. Attempted to restore from yesterday's backup." | mail -s "Friendica backup" $EMAIL
  3204. else
  3205. # Send a warning email
  3206. echo "Unable to create a backup of the Friendica database." | mail -s "Friendica backup" $EMAIL
  3207. fi
  3208. else
  3209. chmod 600 $TEMPFILE
  3210. mv $TEMPFILE $DAILYFILE
  3211. # Make the backup readable only by root
  3212. chmod 600 $DAILYFILE
  3213. fi
  3214. # Backup the Roundcube database
  3215. DAILYFILE=/var/backups/roundcubemail_daily.sql
  3216. mysqldump --password=$MYSQL_PASSWORD roundcubemail > $TEMPFILE
  3217. FILESIZE=$(stat -c%s $TEMPFILE)
  3218. if [ "$FILESIZE" -eq "0" ]; then
  3219. if [ -f $DAILYFILE ]; then
  3220. cp $DAILYFILE $TEMPFILE
  3221. # try to restore yesterday's database
  3222. mysql -u root --password=$MYSQL_PASSWORD roundcubemail -o < $DAILYFILE
  3223. # Send a warning email
  3224. echo "Unable to create a backup of the Roundcube database. Attempted to restore from yesterday's backup" | mail -s "Roundcube backup" $EMAIL
  3225. else
  3226. # Send a warning email
  3227. echo "Unable to create a backup of the Roundcube database." | mail -s "Roundcube backup" $EMAIL
  3228. fi
  3229. else
  3230. chmod 600 $TEMPFILE
  3231. mv $TEMPFILE $DAILYFILE
  3232. # Make the backup readable only by root
  3233. chmod 600 $DAILYFILE
  3234. fi
  3235. # Backup the Red Matrix database
  3236. DAILYFILE=/var/backups/redmatrix_daily.sql
  3237. #mysqldump --password=$MYSQL_PASSWORD redmatrix > $TEMPFILE
  3238. #FILESIZE=$(stat -c%s $TEMPFILE)
  3239. #if [ "$FILESIZE" -eq "0" ]; then
  3240. # if [ -f $DAILYFILE ]; then
  3241. # cp $DAILYFILE $TEMPFILE
  3242. # # try to restore yesterday's database
  3243. # mysql -u root --password=$MYSQL_PASSWORD redmatrix -o < $DAILYFILE
  3244. # # Send a warning email
  3245. # echo "Unable to create a backup of the Red Matrix database. Attempted to restore from yesterday's backup" | mail -s "Red Matrix backup" $EMAIL
  3246. # else
  3247. # # Send a warning email
  3248. # echo "Unable to create a backup of the Red Matrix database." | mail -s "Red Matrix backup" $EMAIL
  3249. # fi
  3250. #else
  3251. # chmod 600 $TEMPFILE
  3252. # mv $TEMPFILE $DAILYFILE
  3253. # # Make the backup readable only by root
  3254. # chmod 600 $DAILYFILE
  3255. #fi
  3256. # restart the web server
  3257. service apache2 start
  3258. exit 0
  3259. #+END_SRC
  3260. Save and exit.
  3261. #+BEGIN_SRC: bash
  3262. chmod 600 /etc/cron.daily/backup
  3263. chmod +x /etc/cron.daily/backup
  3264. editor /etc/cron.weekly/backup
  3265. #+END_SRC
  3266. Enter the following
  3267. #+BEGIN_SRC: bash
  3268. #!/bin/sh
  3269. umask 0077
  3270. # Friendica
  3271. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_2weekly.sql
  3272. cp -f /var/backups/friendica_daily.sql /var/backups/friendica_weekly.sql
  3273. # Roundcube
  3274. cp -f /var/backups/roundcubemail_weekly.sql /var/backups/roundcubemail_2weekly.sql
  3275. cp -f /var/backups/roundcubemail_daily.sql /var/backups/roundcubemail_weekly.sql
  3276. # Red Matrix
  3277. #cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_2weekly.sql
  3278. #cp -f /var/backups/redmatrix_daily.sql /var/backups/redmatrix_weekly.sql
  3279. #+END_SRC
  3280. Save and exit.
  3281. #+BEGIN_SRC: bash
  3282. chmod 600 /etc/cron.weekly/backup
  3283. chmod +x /etc/cron.weekly/backup
  3284. editor /etc/cron.monthly/backup
  3285. #+END_SRC
  3286. Enter the following
  3287. #+BEGIN_SRC: bash
  3288. #!/bin/sh
  3289. # Friendica
  3290. cp -f /var/backups/friendica_monthly.sql /var/backups/friendica_2monthly.sql
  3291. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_monthly.sql
  3292. # Roundcube
  3293. cp -f /var/backups/roundcubemail_monthly.sql /var/backups/roundcubemail_2monthly.sql
  3294. cp -f /var/backups/roundcubemail_weekly.sql /var/backups/roundcubemail_monthly.sql
  3295. # Red Matrix
  3296. #cp -f /var/backups/redmatrix_monthly.sql /var/backups/redmatrix_2monthly.sql
  3297. #cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_monthly.sql
  3298. #+END_SRC
  3299. Save and exit.
  3300. #+BEGIN_SRC: bash
  3301. chmod 600 /etc/cron.monthly/backup
  3302. chmod +x /etc/cron.monthly/backup
  3303. #+END_SRC
  3304. **** Recommended configuration
  3305. ***** Admin
  3306. 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.
  3307. 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.
  3308. Under the *themes* section select a few themes, including mobile themes which are suitable for phones or tablets.
  3309. 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.
  3310. If you also wish to publish your public posts to a Diaspora node then within the *site* settings select *enable Diaspora support*.
  3311. 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]].
  3312. ***** Settings
  3313. Each user has their own customisable settings, typically available either via an icon or by an entry on a drop down menu.
  3314. Under *additional features* enable "/richtext editor/", "/post preview/", "/group filter/", "/network filter/", "/edit sent posts/" and "/dislike posts/".
  3315. Under *display settings* select your desktop and mobile themes.
  3316. 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.
  3317. **** To access from an Android device
  3318. ***** App
  3319. 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.
  3320. 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.
  3321. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  3322. ***** Mobile Theme
  3323. 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.
  3324. *** Movim
  3325. #+BEGIN_VERSE
  3326. /The way we communicate with others and with ourselves ultimately determines the quality of our lives/
  3327. -- Anthony Robbins
  3328. #+END_VERSE
  3329. Movim is another social networking system based around the XMPP protocol.
  3330. You will need to have previously [[Install a Jabber/XMPP server][installed the Jabber/XMPP server]].
  3331. 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:
  3332. #+BEGIN_SRC: bash
  3333. editor /etc/apache2/sites-available/mydomainname.com
  3334. #+END_SRC
  3335. Within the section which begins with *<VirtualHost *:80>* add the following:
  3336. #+BEGIN_SRC: bash
  3337. <Directory /var/www/mydomainname.com/htdocs/movim>
  3338. deny from all
  3339. </Directory>
  3340. #+END_SRC
  3341. Within the section which begins with *<VirtualHost *:443>* add the following:
  3342. #+BEGIN_SRC: bash
  3343. <Directory /var/www/mydomainname.com/htdocs/movim>
  3344. Options Indexes FollowSymLinks MultiViews
  3345. AllowOverride All
  3346. Order allow,deny
  3347. allow from all
  3348. </Directory>
  3349. #+END_SRC
  3350. Save and exit, then restart the apache server.
  3351. #+BEGIN_SRC: bash
  3352. service apache2 restart
  3353. #+END_SRC
  3354. Download the source.
  3355. #+BEGIN_SRC: bash
  3356. mkdir ~/build
  3357. cd ~/build
  3358. wget http://freedombone.uk.to/movim.tar.gz
  3359. #+END_SRC
  3360. Verify it.
  3361. #+BEGIN_SRC: bash
  3362. sha256sum movim.tar.gz
  3363. 2740ddbedf6cefcc2934759374376643b6cdea4fb7f944ec25098a6868cb499e movim.tar.gz
  3364. #+END_SRC
  3365. Install it.
  3366. #+BEGIN_SRC: bash
  3367. tar -xzvf movim.tar.gz
  3368. export HOSTNAME=mydomainname.com
  3369. cp -r movim-* /var/www/$HOSTNAME/htdocs/movim
  3370. chmod 755 /var/www/$HOSTNAME/htdocs/movim
  3371. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/movim
  3372. #+END_SRC
  3373. Install some MySql prerequisites.
  3374. #+BEGIN_SRC: bash
  3375. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  3376. #+END_SRC
  3377. If necessary, enter an admin password for MySQL.
  3378. Reduce the memory use of mysql by using the "small" configuration.
  3379. #+BEGIN_SRC: bash
  3380. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3381. #+END_SRC
  3382. Create a mysql database.
  3383. #+BEGIN_SRC: bash
  3384. mysql -u root -p
  3385. create database movim;
  3386. CREATE USER 'movimadmin'@'localhost' IDENTIFIED BY 'movimadminpassword';
  3387. GRANT ALL PRIVILEGES ON movim.* TO 'movimadmin'@'localhost';
  3388. quit
  3389. #+END_SRC
  3390. With a web browser navigate to:
  3391. https://mydomainname.com/movim/admin
  3392. Enter /admin/ as the username and /password/ as the password.
  3393. 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).
  3394. Change the /Environment/ from /Development/ to /Production/.
  3395. 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?)
  3396. Click /Submit/ followed by /Resend/.
  3397. Click on /Database Settings/ and alter the MySql movim database username to /movimadmin/ and password to the password you specified in the previous step.
  3398. 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".
  3399. 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).
  3400. *** Red Matrix
  3401. **** Introduction
  3402. 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.
  3403. **** Prerequisites
  3404. 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.
  3405. 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.
  3406. **** Installation
  3407. 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.
  3408. 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:
  3409. #+BEGIN_SRC: bash
  3410. editor /etc/apache2/sites-available/mydomainname.com
  3411. #+END_SRC
  3412. Replace the section which begins with *<VirtualHost *:80>* with the following:
  3413. #+BEGIN_SRC: bash
  3414. <VirtualHost *:80>
  3415. ServerAdmin myusername@mydomainname.com
  3416. ServerName myredmatrixdomainname.com
  3417. RewriteEngine On
  3418. RewriteCond %{HTTPS} off
  3419. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3420. </VirtualHost>
  3421. #+END_SRC
  3422. Save and exit, then restart the apache server.
  3423. #+BEGIN_SRC: bash
  3424. service apache2 restart
  3425. #+END_SRC
  3426. Now install some dependencies.
  3427. #+BEGIN_SRC: bash
  3428. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt
  3429. #+END_SRC
  3430. Enter an admin password for MySQL.
  3431. Reduce the memory use of mysql by using the "small" configuration.
  3432. #+BEGIN_SRC: bash
  3433. cp /usr/share/doc/mysql-server-5.5/examples/my-small.cnf /etc/mysql/my.cnf
  3434. #+END_SRC
  3435. Create a mysql database.
  3436. #+BEGIN_SRC: bash
  3437. mysql -u root -p
  3438. create database redmatrix;
  3439. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'password';
  3440. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  3441. quit
  3442. #+END_SRC
  3443. You may need to fix Git SSL problems.
  3444. #+BEGIN_SRC: bash
  3445. git config --global http.sslVerify true
  3446. apt-get install ca-certificates
  3447. cd ~/
  3448. editor .gitconfig
  3449. #+END_SRC
  3450. The .gitconfig file should look something like this:
  3451. #+BEGIN_SRC: bash
  3452. [http]
  3453. sslVerify = true
  3454. sslCAinfo = /etc/ssl/certs/ca-certificates.crt
  3455. [user]
  3456. email = myusername@mydomainname.com
  3457. name = yourname
  3458. #+END_SRC
  3459. Get the source code.
  3460. #+BEGIN_SRC: bash
  3461. export HOSTNAME=mydomainname.com
  3462. mkdir /var/www/$HOSTNAME
  3463. cd /var/www/$HOSTNAME
  3464. rm -rf htdocs
  3465. git clone https://github.com/friendica/red.git htdocs
  3466. chmod -R 755 htdocs
  3467. chown -R www-data:www-data htdocs
  3468. mkdir htdocs/view/tpl/smarty3
  3469. mkdir htdocs/store/[data]
  3470. mkdir htdocs/store/[data]/smarty3
  3471. chmod 777 htdocs/view/tpl
  3472. chmod 777 htdocs/view/tpl/smarty3
  3473. chmod 777 htdocs/store/[data]/smarty3
  3474. git clone https://github.com/friendica/red-addons.git htdocs/addon
  3475. #+END_SRC
  3476. 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.
  3477. Install the poller.
  3478. #+BEGIN_SRC
  3479. editor /etc/crontab
  3480. #+END_SRC
  3481. and append the following, changing mydomainname.com to whatever your domain is.
  3482. #+BEGIN_SRC
  3483. 12,22,32,42,52 * * * * root cd /var/www/apespace.org/htdocs; /usr/bin/timeout 240 /usr/bin/php include/poller.php
  3484. #+END_SRC
  3485. Save and exit, then restart cron.
  3486. #+BEGIN_SRC: bash
  3487. service cron restart
  3488. #+END_SRC
  3489. **** Backups
  3490. 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.
  3491. #+BEGIN_SRC: bash
  3492. editor /etc/cron.daily/backup
  3493. #+END_SRC
  3494. 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.
  3495. #+BEGIN_SRC: bash
  3496. chmod 600 /etc/cron.daily/backup
  3497. chmod +x /etc/cron.daily/backup
  3498. editor /etc/cron.weekly/backup
  3499. #+END_SRC
  3500. 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:
  3501. #+BEGIN_SRC: bash
  3502. #!/bin/sh
  3503. umask 0077
  3504. # Friendica
  3505. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_2weekly.sql
  3506. cp -f /var/backups/friendica_daily.sql /var/backups/friendica_weekly.sql
  3507. # Red Matrix
  3508. cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_2weekly.sql
  3509. cp -f /var/backups/redmatrix_daily.sql /var/backups/redmatrix_weekly.sql
  3510. #+END_SRC
  3511. Save and exit.
  3512. #+BEGIN_SRC: bash
  3513. chmod 600 /etc/cron.weekly/backup
  3514. chmod +x /etc/cron.weekly/backup
  3515. editor /etc/cron.monthly/backup
  3516. #+END_SRC
  3517. 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:
  3518. #+BEGIN_SRC: bash
  3519. #!/bin/sh
  3520. # Friendica
  3521. cp -f /var/backups/friendica_monthly.sql /var/backups/friendica_2monthly.sql
  3522. cp -f /var/backups/friendica_weekly.sql /var/backups/friendica_monthly.sql
  3523. # Red Matrix
  3524. cp -f /var/backups/redmatrix_monthly.sql /var/backups/redmatrix_2monthly.sql
  3525. cp -f /var/backups/redmatrix_weekly.sql /var/backups/redmatrix_monthly.sql
  3526. #+END_SRC
  3527. Save and exit.
  3528. #+BEGIN_SRC: bash
  3529. chmod 600 /etc/cron.monthly/backup
  3530. chmod +x /etc/cron.monthly/backup
  3531. #+END_SRC
  3532. **** To access from an Android device
  3533. ***** App
  3534. 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.
  3535. 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.
  3536. More information about the Friendica app can be found on http://friendica-for-android.wiki-lab.net/
  3537. *** pump.io
  3538. :PROPERTIES:
  3539. :ORDERED: t
  3540. :END:
  3541. 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.
  3542. 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.
  3543. #+BEGIN_SRC: bash
  3544. apt-get update
  3545. apt-get install build-essential openssl libssl-dev redis-server imagemagick graphicsmagick git-core screen
  3546. #+END_SRC
  3547. Download nodejs
  3548. #+BEGIN_SRC: bash
  3549. mkdir ~/build
  3550. cd ~/build
  3551. wget http://freedombone.uk.to/node_0.10.28-1_armhf.deb
  3552. #+END_SRC
  3553. Verify it.
  3554. #+BEGIN_SRC: bash
  3555. sha256sum node_0.10.28-1_armhf.deb
  3556. 42000a475d3397f295fe76998e79af999eebb8324ac9bb4981e931fabd9297aa
  3557. #+END_SRC
  3558. Install it.
  3559. #+BEGIN_SRC: bash
  3560. dpkg -i node_0.10.28-1_armhf.deb
  3561. #+END_SRC
  3562. Install pump.io
  3563. #+BEGIN_SRC: bash
  3564. cd /opt
  3565. git clone https://github.com/e14n/pump.io.git
  3566. cd /opt/pump.io
  3567. npm install
  3568. npm install databank-redis
  3569. echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
  3570. sysctl vm.overcommit_memory=1
  3571. #+END_SRC
  3572. Now edit the configuration file.
  3573. #+BEGIN_SRC: bash
  3574. editor /etc/pump.io.json
  3575. #+END_SRC
  3576. Add the following, replacing /mypumpiodomainname.com/ with your domain name.
  3577. #+BEGIN_SRC: bash
  3578. {
  3579. "driver": "redis",
  3580. "params": {"host":"localhost","port":6379},
  3581. "secret": "A long random string",
  3582. "noweb": false,
  3583. "site": "Name of my pump.io site",
  3584. "owner": "My name or organisation",
  3585. "ownerURL": "https://mypumpiodomainname.com/",
  3586. "port": 7270,
  3587. "urlPort": 443,
  3588. "hostname": "mypumpiodomainname.com",
  3589. "address": "localhost",
  3590. "nologger": true,
  3591. "serverUser": "pumpio",
  3592. "rejectUnauthorized": false,
  3593. "key": "/var/local/pump.io/keys/mypumpiodomainname.com.key",
  3594. "cert": "/var/local/pump.io/keys/mypumpiodomainname.com.crt",
  3595. "uploaddir": "/var/local/pump.io/uploads",
  3596. "debugClient": false,
  3597. "firehose": "ofirehose.example",
  3598. "logfile": "/var/local/pump.io/pump.log",
  3599. "disableRegistration": false
  3600. }
  3601. #+END_SRC
  3602. Save and exit.
  3603. #+BEGIN_SRC: bash
  3604. export HOSTNAME=mypumpiodomainname.com
  3605. mkdir /var/local/pump.io
  3606. mkdir /var/local/pump.io/uploads
  3607. mkdir /var/local/pump.io/keys
  3608. cp /etc/ssl/private/$HOSTNAME.key /var/local/pump.io/keys
  3609. cp /etc/ssl/certs/$HOSTNAME.crt /var/local/pump.io/keys
  3610. useradd -s /bin/bash -d /var/local/pump.io pumpio
  3611. chown -R pumpio:pumpio /var/local/pump.io
  3612. chmod 400 /var/local/pump.io/keys/*
  3613. chmod -R 777 /opt
  3614. #+END_SRC
  3615. Patch the version of Apache.
  3616. #+BEGIN_SRC: bash
  3617. mkdir ~/build
  3618. mkdir ~/build/apache2
  3619. cd ~/build/apache2
  3620. apt-get build-dep apache2
  3621. apt-get install autoconf
  3622. apt-get source apache2
  3623. cd apache2-*
  3624. wget http://freedombone.uk.to/apache-2.2-wstunnel.patch
  3625. sha256sum apache-2.2-wstunnel.patch
  3626. cfc4866da2688a8eb76e0300cf16b52539ef4e525053a3851d4b6bba9a77e439
  3627. patch -p1 -i apache-2.2-wstunnel.patch
  3628. autoconf
  3629. ./configure --enable-so --enable-proxy=shared --enable-proxy-wstunnel=shared
  3630. make
  3631. make install
  3632. cp modules/proxy/.libs/mod_proxy_wstunnel.so /usr/lib/apache2/modules/
  3633. cd /etc/apache2/mods-enabled
  3634. ln -s /usr/lib/apache2/modules/mod_proxy_wstunnel.so ../mods-available/proxy_wstunnel.load
  3635. #+END_SRC
  3636. Within the section of your Apache site configuration:
  3637. #+BEGIN_SRC: bash
  3638. editor /etc/apache2/sites-available/mypumpiodomainname.com
  3639. #+END_SRC
  3640. 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.
  3641. #+BEGIN_SRC: bash
  3642. <VirtualHost *:80>
  3643. ServerAdmin myusername@mydomainname.com
  3644. ServerName mypumpiodomainname.com
  3645. RewriteEngine On
  3646. RewriteCond %{HTTPS} off
  3647. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  3648. </VirtualHost>
  3649. #+END_SRC
  3650. Add the following in the section which begins with *<VirtualHost *:443>*.
  3651. #+BEGIN_SRC: bash
  3652. ProxyVia On
  3653. ProxyPreserveHost On
  3654. ProxyRequests Off
  3655. SSLProxyEngine On
  3656. ProxyPass / https://localhost:7270/
  3657. ProxyPassReverse / https://localhost:7270/
  3658. #+END_SRC
  3659. Save and exit.
  3660. #+BEGIN_SRC: bash
  3661. a2enmod ssl
  3662. a2enmod cache
  3663. a2enmod disk_cache
  3664. a2enmod expires
  3665. a2enmod proxy
  3666. a2enmod proxy_connect
  3667. a2enmod proxy_http
  3668. apachectl configtest
  3669. service apache2 restart
  3670. npm install forever -g
  3671. #+END_SRC
  3672. Now create the daemon.
  3673. #+BEGIN_SRC: bash
  3674. editor /etc/init.d/pumpio
  3675. #+END_SRC
  3676. Add the following text:
  3677. #+BEGIN_SRC: bash
  3678. #!/bin/bash
  3679. # /etc/init.d/pumpio
  3680. ### BEGIN INIT INFO
  3681. # Provides: pump.io
  3682. # Required-Start: $remote_fs $syslog
  3683. # Required-Stop: $remote_fs $syslog
  3684. # Default-Start: 2 3 4 5
  3685. # Default-Stop: 0 1 6
  3686. # Short-Description: starts pump.io as a background daemon
  3687. # Description: Starts pump.io on boot
  3688. ### END INIT INFO
  3689. # Author: Bob Mottram <bob@robotics.uk.to>
  3690. #Settings
  3691. SERVICE='pumpio'
  3692. COMMAND="forever /opt/pump.io/bin/pump > /var/local/pump.io/daemon.log"
  3693. USERNAME='pumpio'
  3694. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system OAresources
  3695. HISTORY=1024
  3696. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  3697. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/var/local/pump.io'
  3698. pumpio_start() {
  3699. echo "Starting $SERVICE..."
  3700. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  3701. }
  3702. pumpio_stop() {
  3703. echo "Stopping $SERVICE"
  3704. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  3705. }
  3706. #Start-Stop here
  3707. case "$1" in
  3708. start)
  3709. pumpio_start
  3710. ;;
  3711. stop)
  3712. pumpio_stop
  3713. ;;
  3714. restart)
  3715. pumpio_stop
  3716. sleep 10s
  3717. pumpio_start
  3718. ;;
  3719. *)
  3720. echo "Usage: $0 {start|stop|restart}"
  3721. exit 1
  3722. ;;
  3723. esac
  3724. exit 0
  3725. #+END_SRC
  3726. Save and exit. Then enable the daemon and run it.
  3727. #+BEGIN_SRC: bash
  3728. chmod +x /etc/init.d/pumpio
  3729. update-rc.d pumpio defaults
  3730. service pumpio start
  3731. #+END_SRC
  3732. Now visit your pump.io site by navigating to:
  3733. https://mypumpiodomainname.com
  3734. 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*.
  3735. 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.
  3736. 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).
  3737. Ensure that data data gets backed up with:
  3738. #+BEGIN_SRC: bash
  3739. printf "\n\n# Redis backup" >> /etc/cron.daily/backup
  3740. printf "\ntar -czvf /var/backups/redis_daily.tar.gz /var/lib/redis/dump.rdb" >> /etc/cron.daily/backup
  3741. printf "\n\n# Redis backup" >> /etc/cron.weekly/backup
  3742. printf "\ncp -f /var/backups/redis_weekly.tar.gz /var/backups/redis_weekly2.tar.gz" >> /etc/cron.weekly/backup
  3743. printf "\ncp -f /var/backups/redis_daily.tar.gz /var/backups/redis_weekly.tar.gz" >> /etc/cron.weekly/backup
  3744. printf "\n\n# Redis backup" >> /etc/cron.monthly/backup
  3745. printf "\ncp -f /var/backups/redis_monthly.tar.gz /var/backups/redis_monthly2.tar.gz" >> /etc/cron.monthly/backup
  3746. printf "\ncp -f /var/backups/redis_weekly.tar.gz /var/backups/redis_monthly.tar.gz" >> /etc/cron.monthly/backup
  3747. printf "\n\n# Pump.io backup" >> /etc/cron.daily/backup
  3748. printf "\ntar -czvf /var/backups/pumpio_daily.tar.gz /var/local/pump.io --exclude /var/local/pump.io/.forever" >> /etc/cron.daily/backup
  3749. printf "\n\n# Pump.io backup" >> /etc/cron.weekly/backup
  3750. printf "\ncp -f /var/backups/pumpio_weekly.tar.gz /var/backups/pumpio_weekly2.tar.gz" >> /etc/cron.weekly/backup
  3751. printf "\ncp -f /var/backups/pumpio_daily.tar.gz /var/backups/pumpio_weekly.tar.gz" >> /etc/cron.weekly/backup
  3752. printf "\n\n# Pump.io backup" >> /etc/cron.monthly/backup
  3753. printf "\ncp -f /var/backups/pumpio_monthly.tar.gz /var/backups/pumpio_monthly2.tar.gz" >> /etc/cron.monthly/backup
  3754. printf "\ncp -f /var/backups/pumpio_weekly.tar.gz /var/backups/pumpio_monthly.tar.gz" >> /etc/cron.monthly/backup
  3755. #+END_SRC
  3756. 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).
  3757. ** Install Gopher
  3758. *** Server setup
  3759. 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.
  3760. To set up a gopher server:
  3761. #+BEGIN_SRC: bash
  3762. apt-get install build-essential
  3763. mkdir ~/build
  3764. cd ~/build
  3765. wget http://freedombone.uk.to/geomyidae-current.tgz
  3766. #+END_SRC
  3767. Verify the download:
  3768. #+BEGIN_SRC: bash
  3769. sha256sum geomyidae-current.tgz
  3770. 162f55ab059ab0a9be8e840497795293bbd51c34b1f4564dcdf3f0ddd5c0db31 geomyidae-current.tgz
  3771. #+END_SRC
  3772. Then extract and install it.
  3773. #+BEGIN_SRC: bash
  3774. tar -xzvf geomyidae-current.tgz
  3775. cd geomyidae-*
  3776. make
  3777. make install
  3778. mkdir -p /var/gopher
  3779. #+END_SRC
  3780. 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.
  3781. #+BEGIN_SRC: bash
  3782. editor /etc/init.d/gopher
  3783. #+END_SRC
  3784. Enter the following:
  3785. #+BEGIN_SRC: bash
  3786. #! /bin/sh
  3787. ### BEGIN INIT INFO
  3788. # Provides: gopher
  3789. # Required-Start: $remote_fs $syslog
  3790. # Required-Stop: $remote_fs $syslog
  3791. # Default-Start: 2 3 4 5
  3792. # Default-Stop: 0 1 6
  3793. # Short-Description: Gopher daemon
  3794. # Description: Gopher daemon
  3795. ### END INIT INFO
  3796. # Do NOT "set -e"
  3797. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  3798. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  3799. DESC="Gopher daemon"
  3800. NAME=geomyidae
  3801. DAEMON=/usr/bin/$NAME
  3802. DAEMON_ARGS="-l /var/log/geomyidae.log -b /var/gopher -p 70"
  3803. PIDFILE=/var/run/$NAME.pid
  3804. SCRIPTNAME=/etc/init.d/$NAME
  3805. # Exit if the package is not installed
  3806. [ -x "$DAEMON" ] || exit 0
  3807. # Read configuration variable file if it is present
  3808. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  3809. # Load the VERBOSE setting and other rcS variables
  3810. . /lib/init/vars.sh
  3811. # Define LSB log_* functions.
  3812. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
  3813. # and status_of_proc is working.
  3814. . /lib/lsb/init-functions
  3815. #
  3816. # Function that starts the daemon/service
  3817. #
  3818. do_start()
  3819. {
  3820. # Return
  3821. # 0 if daemon has been started
  3822. # 1 if daemon was already running
  3823. # 2 if daemon could not be started
  3824. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
  3825. || return 1
  3826. start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
  3827. $DAEMON_ARGS \
  3828. || return 2
  3829. # Add code here, if necessary, that waits for the process to be ready
  3830. # to handle requests from services started subsequently which depend
  3831. # on this one. As a last resort, sleep for some time.
  3832. }
  3833. #
  3834. # Function that stops the daemon/service
  3835. #
  3836. do_stop()
  3837. {
  3838. # Return
  3839. # 0 if daemon has been stopped
  3840. # 1 if daemon was already stopped
  3841. # 2 if daemon could not be stopped
  3842. # other if a failure occurred
  3843. start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
  3844. RETVAL="$?"
  3845. [ "$RETVAL" = 2 ] && return 2
  3846. # Wait for children to finish too if this is a daemon that forks
  3847. # and if the daemon is only ever run from this initscript.
  3848. # If the above conditions are not satisfied then add some other code
  3849. # that waits for the process to drop all resources that could be
  3850. # needed by services started subsequently. A last resort is to
  3851. # sleep for some time.
  3852. start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
  3853. [ "$?" = 2 ] && return 2
  3854. # Many daemons don't delete their pidfiles when they exit.
  3855. rm -f $PIDFILE
  3856. return "$RETVAL"
  3857. }
  3858. #
  3859. # Function that sends a SIGHUP to the daemon/service
  3860. #
  3861. do_reload() {
  3862. #
  3863. # If the daemon can reload its configuration without
  3864. # restarting (for example, when it is sent a SIGHUP),
  3865. # then implement that here.
  3866. #
  3867. start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
  3868. return 0
  3869. }
  3870. case "$1" in
  3871. start)
  3872. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  3873. do_start
  3874. case "$?" in
  3875. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  3876. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  3877. esac
  3878. ;;
  3879. stop)
  3880. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  3881. do_stop
  3882. case "$?" in
  3883. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  3884. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  3885. esac
  3886. ;;
  3887. status)
  3888. status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
  3889. ;;
  3890. #reload|force-reload)
  3891. #
  3892. # If do_reload() is not implemented then leave this commented out
  3893. # and leave 'force-reload' as an alias for 'restart'.
  3894. #
  3895. #log_daemon_msg "Reloading $DESC" "$NAME"
  3896. #do_reload
  3897. #log_end_msg $?
  3898. #;;
  3899. restart|force-reload)
  3900. #
  3901. # If the "reload" option is implemented then remove the
  3902. # 'force-reload' alias
  3903. #
  3904. log_daemon_msg "Restarting $DESC" "$NAME"
  3905. do_stop
  3906. case "$?" in
  3907. 0|1)
  3908. do_start
  3909. case "$?" in
  3910. 0) log_end_msg 0 ;;
  3911. 1) log_end_msg 1 ;; # Old process is still running
  3912. *) log_end_msg 1 ;; # Failed to start
  3913. esac
  3914. ;;
  3915. *)
  3916. # Failed to stop
  3917. log_end_msg 1
  3918. ;;
  3919. esac
  3920. ;;
  3921. *)
  3922. #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
  3923. echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
  3924. exit 3
  3925. ;;
  3926. esac
  3927. :
  3928. #+END_SRC
  3929. Save and exit. Then start the gopher service.
  3930. #+BEGIN_SRC: bash
  3931. chmod +x /etc/init.d/gopher
  3932. update-rc.d gopher defaults
  3933. service gopher start
  3934. #+END_SRC
  3935. 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:
  3936. #+BEGIN_SRC: bash
  3937. gopher://mydomainname.com
  3938. #+END_SRC
  3939. There is a browser addon for Gopher called "overbite". Installing that should enable you to view your site.
  3940. *** A phlogging script
  3941. A phlog is the gopher equivalent of a blog on the web. You can create a script which makes phlogging easy.
  3942. #+BEGIN_SRC: bash
  3943. editor /usr/bin/mkphlog
  3944. #+END_SRC
  3945. Add the following:
  3946. #+BEGIN_SRC: bash
  3947. #!/bin/sh
  3948. # mkphlog - a utility to ease the creation of phlogs.
  3949. # Organizes phlog posts in separate directories.
  3950. # Created by octotep; anyone can distribute, modify, and
  3951. # share this file however they please.
  3952. #
  3953. # Version 0.3
  3954. #
  3955. # Modified by Bob Mottram
  3956. #
  3957. # Please note, all date strings are in the form of mm/dd/yy(yy)
  3958. # The base of the entire gopher site.
  3959. gopherRoot="/var/gopher"
  3960. # The name of the phlog directory (contained in $gopherHome)
  3961. phlogDirName="phlog"
  3962. # Default editor, unless the user has one specified in env
  3963. editor=${EDITOR:-emacs}
  3964. # Default timezone, unless the user has one specified in env
  3965. TZ=${TZ:-UTC}
  3966. # Tells the script how many lines the title of the main page spans.
  3967. # Used to insert the newest post at the top.
  3968. # Titles created by mkphlog are 3 lines.
  3969. # Isn't used if $addTitleToMain is false
  3970. titleLineCount=3
  3971. entryDate=`date +%Y-%m-%d`
  3972. # Creates the phlog directory if it dosen't already exist.
  3973. CreatePhlogDir() {
  3974. mkdir $phlogDirName
  3975. chmod 755 $phlogDirName
  3976. cd $phlogDirName
  3977. echo "Phlog directory created."
  3978. }
  3979. # Updates the main phlog listing
  3980. UpdatePhlogListing() {
  3981. # Just in case the user didn't specify a title
  3982. if [ "$postTitleAns" = "" ] ; then
  3983. echo -n "Do you want to create a blank post? (y/n) "
  3984. read blankPostAns
  3985. case $blankPostAns in
  3986. y* | Y* ) $postTitleAns="New Post" ;;
  3987. n* | N* ) echo "Goodbye, then." ; exit 1 ;;
  3988. * ) exit 1 ;;
  3989. esac
  3990. fi
  3991. cd $gopherRoot/$phlogDirName/
  3992. title2=$(echo "${postTitleAns}" | tr " " _)
  3993. postfilename="${entryDate}_${title2}.txt"
  3994. touch ${postfilename}
  3995. echo $postTitleAns >> ${postfilename}
  3996. date "+%A %b %e %l:%M:%S %Y" >> ${postfilename}
  3997. echo "------------------------------" >> ${postfilename}
  3998. echo >> ${postfilename}
  3999. }
  4000. if [ -d $gopherRoot ] ; then
  4001. cd $gopherRoot
  4002. else
  4003. echo "You don't have a gopherspace set-up. Please run the gopher server setup instructions."
  4004. exit 1
  4005. fi
  4006. if [ -d $phlogDirName ] ; then
  4007. cd $phlogDirName
  4008. else
  4009. echo -n "Do you want to create a phlog directory? (y/n) "
  4010. read phlogDirAns
  4011. case $phlogDirAns in
  4012. y* | Y* ) CreatePhlogDir ;;
  4013. n* | N* ) exit 1 ;;
  4014. * ) exit 1 ;;
  4015. esac
  4016. fi
  4017. echo -n "Would you like to create a phlog entry for today? (y/n) "
  4018. read phlogAns
  4019. case $phlogAns in
  4020. y* | Y* ) echo "Creating today's phlog entry..." ;;
  4021. n* | N* ) exit 0 ;;
  4022. * ) exit 1 ;;
  4023. esac
  4024. # Make sure there isn't a post for that day, lest we overwrite it.
  4025. if [ ! -d $entryDate ]; then
  4026. echo -n "Title: "
  4027. read postTitleAns
  4028. title2=$(echo "${postTitleAns}" | tr " " _)
  4029. postfilename="${entryDate}_${title2}.txt"
  4030. touch ${postfilename}
  4031. chmod 644 ${postfilename}
  4032. UpdatePhlogListing
  4033. echo -n "Would you like to edit the post with $editor? (y/n) "
  4034. read editorAns
  4035. case $editorAns in
  4036. y* | Y* ) $editor $gopherRoot/$phlogDirName/${postfilename} ;;
  4037. n* | N* ) exit 0 ;;
  4038. * ) exit 0 ;;
  4039. esac
  4040. rm $gopherRoot/$phlogDirName/${postfilename}~
  4041. else
  4042. echo "There is already a post for today."
  4043. echo -n "Would you like to edit the post with $editor? (y/n) "
  4044. read editorAns
  4045. case $editorAns in
  4046. y* | Y* ) $editor $gopherRoot/$phlogDirName/$entryDate*.txt ;;
  4047. n* | N* ) exit 0 ;;
  4048. * ) exit 1 ;;
  4049. esac
  4050. rm $gopherRoot/$phlogDirName/${postfilename}.txt~
  4051. fi
  4052. exit 0
  4053. #+END_SRC
  4054. Save and exit.
  4055. #+BEGIN_SRC: bash
  4056. chmod +x /usr/bin/mkphlog
  4057. #+END_SRC
  4058. Now entering the command /mkphlog/ will allow you to create a phlog entry.
  4059. ** Install Owncloud
  4060. #+BEGIN_VERSE
  4061. /It's not water vapour/
  4062. -- Larry Ellison
  4063. #+END_VERSE
  4064. 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.
  4065. *** Server Installation
  4066. Install some dependencies:
  4067. #+BEGIN_SRC: bash
  4068. apt-get install apache2 php5 php5-gd php-xml-parser php5-intl
  4069. apt-get install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl
  4070. #+END_SRC
  4071. 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.
  4072. #+BEGIN_SRC: bash
  4073. a2dismod php5filter
  4074. apt-get install libapache2-mod-php5
  4075. #+END_SRC
  4076. Ensure that the size of files which may be uploaded or downloaded is large enough.
  4077. #+BEGIN_SRC: bash
  4078. editor /etc/php5/apache2/php.ini
  4079. #+END_SRC
  4080. Set the following:
  4081. #+BEGIN_SRC: bash
  4082. upload_max_filesize = 512M
  4083. post_max_size = 512M
  4084. #+END_SRC
  4085. Save and exit, then edit your Apache configuration.
  4086. #+BEGIN_SRC: bash
  4087. export HOSTNAME=mydomainname.com
  4088. editor /etc/apache2/sites-available/$HOSTNAME
  4089. #+END_SRC
  4090. 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.
  4091. #+BEGIN_SRC: bash
  4092. <Directory /var/www/mydomainname.com/htdocs/owncloud>
  4093. Options Indexes FollowSymLinks MultiViews
  4094. AllowOverride All
  4095. Order allow,deny
  4096. allow from all
  4097. LimitRequestBody 536870912
  4098. </Directory>
  4099. #+END_SRC
  4100. To ensure that nobody logs in insecurely add the following to the 80 VirtualHost section.
  4101. #+BEGIN_SRC: bash
  4102. <Directory /var/www/mydomainname.com/htdocs/owncloud>
  4103. deny from all
  4104. </Directory>
  4105. #+END_SRC
  4106. Save and exit, then restart apache.
  4107. #+BEGIN_SRC: bash
  4108. service apache2 restart
  4109. #+END_SRC
  4110. Download owncloud.
  4111. #+BEGIN_SRC: bash
  4112. mkdir ~/build
  4113. cd ~/build
  4114. wget http://freedombone.uk.to/owncloud.tar.bz2
  4115. #+END_SRC
  4116. Verify the download:
  4117. #+BEGIN_SRC: bash
  4118. sha256sum owncloud.tar.bz2
  4119. 9aca2aa0a0cd7b052e881c30ad6de25d135ec3f88a3920274f1be223b4cabedf
  4120. #+END_SRC
  4121. Extract the archive. This may take a couple of minutes, so don't be alarmed that the system has crashed.
  4122. #+BEGIN_SRC: bash
  4123. export HOSTNAME=mydomainname.com
  4124. tar -xjf owncloud.tar.bz2
  4125. #+END_SRC
  4126. The extraction will take a few minutes. Move the extracted files to your site and set file permissions.
  4127. #+BEGIN_SRC: bash
  4128. cp -r owncloud /var/www/$HOSTNAME/htdocs
  4129. #+END_SRC
  4130. The copying also takes a few minutes. Then change the file permissions.
  4131. #+BEGIN_SRC: bash
  4132. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/apps
  4133. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud/config
  4134. chown www-data:www-data /var/www/$HOSTNAME/htdocs/owncloud
  4135. #+END_SRC
  4136. Edit the htaccess file for Owncloud.
  4137. #+BEGIN_SRC: bash
  4138. editor /var/www/$HOSTNAME/htdocs/owncloud/.htaccess
  4139. #+END_SRC
  4140. Set the following.
  4141. #+BEGIN_SRC: bash
  4142. php_value upload_max_filesize 512M
  4143. php_value post_max_size 512M
  4144. php_value memory_limit 32M
  4145. #+END_SRC
  4146. Save and exit.
  4147. With a web browser visit your domain (mydomainname.com/owncloud) and enter an administrator username and password.
  4148. 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.
  4149. *** Owncloud on Android
  4150. 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.
  4151. ** Install a Wiki
  4152. #+BEGIN_VERSE
  4153. /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./
  4154. -- Tom Barbalet
  4155. #+END_VERSE
  4156. Dokuwiki is based upon flat files, and so is easy to move from one server to another without a lot of database complications.
  4157. Download the wiki.
  4158. #+BEGIN_SRC: bash
  4159. mkdir ~/build
  4160. cd ~/build
  4161. wget http://freedombone.uk.to/dokuwiki.tgz
  4162. #+END_SRC
  4163. Verify it.
  4164. #+BEGIN_SRC: bash
  4165. sha256sum dokuwiki.tgz
  4166. 6b126f90979463d9ddaa74acc6f96aa230cfdc789946f241c3646086d9574be8 dokuwiki.tgz
  4167. #+END_SRC
  4168. Then extract and install it.
  4169. #+BEGIN_SRC: bash
  4170. export HOSTNAME=mywikidomainname.com
  4171. tar -xzvf dokuwiki.tgz
  4172. mv /var/www/$HOSTNAME/htdocs /var/www/$HOSTNAME/htdocs_old
  4173. mv dokuwiki /var/www/$HOSTNAME/htdocs
  4174. #+END_SRC
  4175. Edit the Apache configuration for your wiki site.
  4176. #+BEGIN_SRC: bash
  4177. editor /etc/apache2/sites-available/$HOSTNAME
  4178. #+END_SRC
  4179. The settings should look something like the following. Replace /mywikidomainname.com/ with your wiki domain name.
  4180. #+BEGIN_SRC: bash
  4181. <VirtualHost *:80>
  4182. ServerAdmin myusername@mywikidomainname.com
  4183. ServerName mydomainname.com
  4184. DocumentRoot /var/www/mywikidomainname.com/htdocs
  4185. <Directory /var/www/mywikidomainname.com/htdocs>
  4186. order deny,allow
  4187. allow from all
  4188. </Directory>
  4189. <LocationMatch "/(data|conf|bin|inc)/">
  4190. order allow,deny
  4191. deny from all
  4192. satisfy all
  4193. </LocationMatch>
  4194. <Directory />
  4195. Options FollowSymLinks
  4196. AllowOverride All
  4197. </Directory>
  4198. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  4199. <Directory "/usr/lib/cgi-bin">
  4200. AllowOverride All
  4201. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  4202. Order allow,deny
  4203. Allow from all
  4204. </Directory>
  4205. ErrorLog ${APACHE_LOG_DIR}/error.log
  4206. # Possible values include: debug, info, notice, warn, error, crit,
  4207. # alert, emerg.
  4208. LogLevel error
  4209. CustomLog ${APACHE_LOG_DIR}/access.log combined
  4210. </VirtualHost>
  4211. <IfModule mod_ssl.c>
  4212. <VirtualHost *:443>
  4213. ServerAdmin myusername@mywikidomainname.com
  4214. ServerName mywikidomainname.com
  4215. DocumentRoot /var/www/mywikidomainname.com/htdocs
  4216. <Directory /var/www/mywikidomainname.com/htdocs>
  4217. order deny,allow
  4218. allow from all
  4219. </Directory>
  4220. <LocationMatch "/(data|conf|bin|inc)/">
  4221. order allow,deny
  4222. deny from all
  4223. satisfy all
  4224. </LocationMatch>
  4225. <Directory />
  4226. Options FollowSymLinks
  4227. AllowOverride All
  4228. </Directory>
  4229. ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  4230. <Directory "/usr/lib/cgi-bin">
  4231. AllowOverride All
  4232. Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  4233. Order allow,deny
  4234. Allow from all
  4235. </Directory>
  4236. ErrorLog ${APACHE_LOG_DIR}/error.log
  4237. # Possible values include: debug, info, notice, warn, error, crit,
  4238. # alert, emerg.
  4239. LogLevel error
  4240. CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
  4241. # SSL Engine Switch:
  4242. # Enable/Disable SSL for this virtual host.
  4243. SSLEngine on
  4244. # A self-signed certificate
  4245. SSLCertificateFile /etc/ssl/certs/mydomainname.com.crt
  4246. SSLCertificateKeyFile /etc/ssl/private/mydomainname.com.key
  4247. # Options based on bettercrypto.org
  4248. SSLProtocol All -SSLv2 -SSLv3
  4249. SSLHonorCipherOrder On
  4250. SSLCompression off
  4251. 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
  4252. # SSL Engine Options:
  4253. # Set various options for the SSL engine.
  4254. # o FakeBasicAuth:
  4255. # Translate the client X.509 into a Basic Authorisation. This means that
  4256. # the standard Auth/DBMAuth methods can be used for access control. The
  4257. # user name is the `one line' version of the client's X.509 certificate.
  4258. # Note that no password is obtained from the user. Every entry in the user
  4259. # file needs this password: `xxj31ZMTZzkVA'.
  4260. # o ExportCertData:
  4261. # This exports two additional environment variables: SSL_CLIENT_CERT and
  4262. # SSL_SERVER_CERT. These contain the PEM-encoded certificates of the
  4263. # server (always existing) and the client (only existing when client
  4264. # authentication is used). This can be used to import the certificates
  4265. # into CGI scripts.
  4266. # o StdEnvVars:
  4267. # This exports the standard SSL/TLS related `SSL_*' environment variables.
  4268. # Per default this exportation is switched off for performance reasons,
  4269. # because the extraction step is an expensive operation and is usually
  4270. # useless for serving static content. So one usually enables the
  4271. # exportation for CGI and SSI requests only.
  4272. # o StrictRequire:
  4273. # This denies access when "SSLRequireSSL" or "SSLRequire" applied even
  4274. # under a "Satisfy any" situation, i.e. when it applies access is denied
  4275. # and no other module can change it.
  4276. # o OptRenegotiate:
  4277. # This enables optimized SSL connection renegotiation handling when SSL
  4278. # directives are used in per-directory context.
  4279. #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
  4280. <FilesMatch "\.(cgi|shtml|phtml|php)$">
  4281. SSLOptions +StdEnvVars
  4282. </FilesMatch>
  4283. <Directory /usr/lib/cgi-bin>
  4284. SSLOptions +StdEnvVars
  4285. </Directory>
  4286. # SSL Protocol Adjustments:
  4287. # The safe and default but still SSL/TLS standard compliant shutdown
  4288. # approach is that mod_ssl sends the close notify alert but doesn't wait for
  4289. # the close notify alert from client. When you need a different shutdown
  4290. # approach you can use one of the following variables:
  4291. # o ssl-unclean-shutdown:
  4292. # This forces an unclean shutdown when the connection is closed, i.e. no
  4293. # SSL close notify alert is send or allowed to received. This violates
  4294. # the SSL/TLS standard but is needed for some brain-dead browsers. Use
  4295. # this when you receive I/O errors because of the standard approach where
  4296. # mod_ssl sends the close notify alert.
  4297. # o ssl-accurate-shutdown:
  4298. # This forces an accurate shutdown when the connection is closed, i.e. a
  4299. # SSL close notify alert is send and mod_ssl waits for the close notify
  4300. # alert of the client. This is 100% SSL/TLS standard compliant, but in
  4301. # practice often causes hanging connections with brain-dead browsers. Use
  4302. # this only for browsers where you know that their SSL implementation
  4303. # works correctly.
  4304. # Notice: Most problems of broken clients are also related to the HTTP
  4305. # keep-alive facility, so you usually additionally want to disable
  4306. # keep-alive for those clients, too. Use variable "nokeepalive" for this.
  4307. # Similarly, one has to force some clients to use HTTP/1.0 to workaround
  4308. # their broken HTTP/1.1 implementation. Use variables "downgrade-1.0" and
  4309. # "force-response-1.0" for this.
  4310. BrowserMatch "MSIE [2-6]" \
  4311. nokeepalive ssl-unclean-shutdown \
  4312. downgrade-1.0 force-response-1.0
  4313. # MSIE 7 and newer should be able to use keepalive
  4314. BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  4315. </VirtualHost>
  4316. </IfModule>
  4317. #+END_SRC
  4318. Enable your site with:
  4319. #+BEGIN_SRC: bash
  4320. a2ensite
  4321. #+END_SRC
  4322. then select the domain name and reload.
  4323. #+BEGIN_SRC: bash
  4324. service apache2 reload
  4325. #+END_SRC
  4326. and alter permissions:
  4327. #+BEGIN_SRC: bash
  4328. chmod -R 755 /var/www/$HOSTNAME/htdocs
  4329. chown -R www-data:www-data /var/www/$HOSTNAME/htdocs
  4330. #+END_SRC
  4331. Open a browser and visit http://$HOSTNAME/install.php, then fill out the details. Once everything has been accepted without errors:
  4332. #+BEGIN_SRC: bash
  4333. rm /var/www/$HOSTNAME/htdocs/install.php
  4334. #+END_SRC
  4335. Add a few extra mime types:
  4336. #+BEGIN_SRC: bash
  4337. editor /var/www/$HOSTNAME/htdocs/conf/mime.conf
  4338. #+END_SRC
  4339. Append the following:
  4340. #+BEGIN_SRC: bash
  4341. ogv video/ogg
  4342. mp4 video/mp4
  4343. webm video/webm
  4344. #+END_SRC
  4345. Save and exit.
  4346. 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*.
  4347. Now you can visit your wiki and begin editing.
  4348. ** Install Bitmessage
  4349. #+BEGIN_VERSE
  4350. /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/
  4351. -- Edward J. Snowden, testimony to the EU parliament
  4352. #+END_VERSE
  4353. *** A new kind of Email
  4354. [[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.
  4355. 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.
  4356. Installing Bitmessage as a daemon will increase the size of the network, and therefore the level of security for all users.
  4357. *** The Daemon
  4358. Install from the current source code.
  4359. #+BEGIN_SRC: bash
  4360. apt-get install python screen
  4361. mkdir ~/build
  4362. cd ~/build
  4363. git clone https://github.com/bashrc/PyBitmessage.git
  4364. cd PyBitmessage
  4365. make install
  4366. #+END_SRC
  4367. Now create the daemon.
  4368. #+BEGIN_SRC: bash
  4369. editor /etc/init.d/pybitmessage
  4370. #+END_SRC
  4371. Add the following text:
  4372. #+BEGIN_SRC: bash
  4373. #!/bin/bash
  4374. # /etc/init.d/bitmessage
  4375. ### BEGIN INIT INFO
  4376. # Provides: pybitmessage
  4377. # Required-Start: $remote_fs $syslog
  4378. # Required-Stop: $remote_fs $syslog
  4379. # Default-Start: 2 3 4 5
  4380. # Default-Stop: 0 1 6
  4381. # Short-Description: starts bitmessage as a background daemon, suitable for servers
  4382. # Description: This file should be used to construct scripts to be
  4383. # placed in /etc/init.d.
  4384. ### END INIT INFO
  4385. # Author: Super-Nathan <BM-Gu2k3Wy2hpTMYBxSoM2937SPcuU6xzEj>
  4386. #Settings
  4387. SERVICE='pybitmessage'
  4388. LOGFILE='/dev/null' # this disables logging
  4389. # LOGFILE='/var/log/bitmessage.log' # comment out the above line and un-comment this line to save a log
  4390. COMMAND="python bitmessagemain.py > $LOGFILE"
  4391. USERNAME='bitmsg'
  4392. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  4393. HISTORY=1024
  4394. PBM_LOCATION="/usr/local/share/pybitmessage"
  4395. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4396. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin:/usr/local/share/pybitmessage'
  4397. bm_start() {
  4398. echo "Starting $SERVICE..."
  4399. cd ${PBM_LOCATION}
  4400. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4401. }
  4402. bm_stop() {
  4403. echo "Stopping $SERVICE"
  4404. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  4405. }
  4406. #Start-Stop here
  4407. case "$1" in
  4408. start)
  4409. bm_start
  4410. ;;
  4411. stop)
  4412. bm_stop
  4413. ;;
  4414. restart)
  4415. bm_stop
  4416. sleep 60s
  4417. bm_start
  4418. ;;
  4419. *)
  4420. echo "Usage: $0 {start|stop|restart}"
  4421. exit 1
  4422. ;;
  4423. esac
  4424. exit 0
  4425. #+END_SRC
  4426. Save and exit.
  4427. 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.
  4428. #+BEGIN_SRC: bash
  4429. adduser bitmsg
  4430. #+END_SRC
  4431. Create a /keys.dat/ file which is used to configure Bitmessage.
  4432. #+BEGIN_SRC: bash
  4433. mkdir /home/bitmsg/.config
  4434. mkdir /home/bitmsg/.config/PyBitmessage
  4435. editor /home/bitmsg/.config/PyBitmessage/keys.dat
  4436. #+END_SRC
  4437. Add the following, changing /apipassword/ to some long random string:
  4438. #+BEGIN_SRC: bash
  4439. [bitmessagesettings]
  4440. settingsversion = 8
  4441. port = 8444
  4442. timeformat = %%a, %%d %%b %%Y %%I:%%M %%p
  4443. blackwhitelist = black
  4444. startonlogon = False
  4445. minimizetotray = False
  4446. showtraynotifications = True
  4447. startintray = False
  4448. socksproxytype = none
  4449. sockshostname = localhost
  4450. socksport = 9050
  4451. socksauthentication = False
  4452. sockslisten = False
  4453. socksusername =
  4454. sockspassword =
  4455. keysencrypted = false
  4456. messagesencrypted = false
  4457. defaultnoncetrialsperbyte = 640
  4458. defaultpayloadlengthextrabytes = 14000
  4459. minimizeonclose = false
  4460. maxacceptablenoncetrialsperbyte = 0
  4461. maxacceptablepayloadlengthextrabytes = 0
  4462. userlocale = system
  4463. useidenticons = True
  4464. identiconsuffix = re9E9UtSEaWD
  4465. replybelow = False
  4466. stopresendingafterxdays = 4
  4467. stopresendingafterxmonths =
  4468. namecoinrpctype = namecoind
  4469. namecoinrpchost = localhost
  4470. namecoinrpcuser =
  4471. namecoinrpcpassword =
  4472. namecoinrpcport = 8336
  4473. sendoutgoingconnections = True
  4474. willinglysendtomobile = False
  4475. maxpayloadlengthkb = 256
  4476. daemon = true
  4477. apienabled = true
  4478. apiport = 8442
  4479. apiinterface = 127.0.0.1
  4480. apiusername = bitmsg
  4481. maxpayloadlengthkb = 256
  4482. apipassword = change_this_password
  4483. #+END_SRC
  4484. Save and exit. Then enable the daemon and run it.
  4485. #+BEGIN_SRC: bash
  4486. rm -f /tmp/-usr-local-share-pybitmessage-*.lock
  4487. chown -R bitmsg:bitmsg /home/bitmsg
  4488. chmod +x /etc/init.d/pybitmessage
  4489. update-rc.d pybitmessage defaults
  4490. service pybitmessage start
  4491. #+END_SRC
  4492. Now open port 8444 on your internet router or firewall and direct it to the BBB.
  4493. *** Using Bitmessage
  4494. 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.
  4495. 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:
  4496. #+BEGIN_SRC: bash
  4497. mkdir ~/build
  4498. cd ~/build
  4499. git clone https://github.com/Bitmessage/PyBitmessage.git
  4500. cd PyBitmessage
  4501. make install
  4502. pybitmessage
  4503. #+END_SRC
  4504. *** Connect Bitmessage to Email
  4505. 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:
  4506. #+BEGIN_SRC: bash
  4507. /home/bitmsg/.config/PyBitmessage/keys.dat
  4508. #+END_SRC
  4509. and adding the details for your address, which could be coppied from another machine (such as a laptop running a Bitmessage client).
  4510. It will look something like:
  4511. #+BEGIN_SRC: bash
  4512. [BM-address]
  4513. label = myusername@mydomainname.com
  4514. enabled = true
  4515. decoy = false
  4516. noncetrialsperbyte = 640
  4517. payloadlengthextrabytes = 14000
  4518. privsigningkey = ...
  4519. privencryptionkey = ...
  4520. lastpubkeysendtime = ...
  4521. #+END_SRC
  4522. 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.
  4523. You should also make sure that /apipassword/ is set to some long random string.
  4524. Save and close /keys.dat/, then restart the Bitmessage daemon.
  4525. #+BEGIN_SRC: bash
  4526. service pybitmessage restart
  4527. #+END_SRC
  4528. The restart will take 30 seconds or so. Next install the Bitmessage to email gateway.
  4529. #+BEGIN_SRC: bash
  4530. cd /usr/share
  4531. git clone https://github.com/bashrc/bitmessage-email-gateway
  4532. chown -R bitmsg:bitmsg bitmessage-email-gateway
  4533. cd bitmessage-email-gateway
  4534. mkdir /home/bitmsg/Maildir
  4535. mkdir /home/bitmsg/Maildir/new
  4536. chown -R bitmsg:bitmsg /home/bitmsg
  4537. #+END_SRC
  4538. Substitute /your_domain_name/ for your domain name (the main one used for email).
  4539. #+BEGIN_SRC: bash
  4540. sed 's/mydomainname.com/your_domain_name/g' bitmessage-gateway.py > bitmessage-gateway.py
  4541. #+END_SRC
  4542. Find out what the API password is:
  4543. #+BEGIN_SRC: bash
  4544. grep "apipassword" /home/bitmsg/.config/PyBitmessage/keys.dat | awk -F ' ' '{print $3}'
  4545. #+END_SRC
  4546. Then change it with:
  4547. #+BEGIN_SRC: bash
  4548. sed "s/'password' : ''/'password' : 'bitmessage_api_password'/g" bitmessage-gateway.py > bitmessage-gateway.py
  4549. #+END_SRC
  4550. Now create the daemon.
  4551. #+BEGIN_SRC: bash
  4552. editor /etc/init.d/bitmessage-gateway
  4553. #+END_SRC
  4554. Add the following text:
  4555. #+BEGIN_SRC: bash
  4556. #!/bin/bash
  4557. # /etc/init.d/bitmessage-gateway
  4558. ### BEGIN INIT INFO
  4559. # Provides: bitmessage-gateway
  4560. # Required-Start: $remote_fs $syslog
  4561. # Required-Stop: $remote_fs $syslog
  4562. # Default-Start: 2 3 4 5
  4563. # Default-Stop: 0 1 6
  4564. # Short-Description: starts a gateway between bitmessage and email
  4565. # Description:
  4566. ### END INIT INFO
  4567. # Author: Bob Mottram <bob@robotics.uk.to>
  4568. #Settings
  4569. SERVICE='bitmessage-gateway'
  4570. LOGFILE='/dev/null'
  4571. COMMAND="python bitmessage-gateway.py > $LOGFILE"
  4572. USERNAME='bitmsg'
  4573. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  4574. HISTORY=1024
  4575. BMG_LOCATION="/usr/share/bitmessage-email-gateway"
  4576. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  4577. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin:/usr/share/bitmessage-email-gateway'
  4578. bmg_start() {
  4579. echo "Starting $SERVICE..."
  4580. cd ${BMG_LOCATION}
  4581. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  4582. }
  4583. bmg_stop() {
  4584. echo "Stopping $SERVICE"
  4585. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  4586. }
  4587. #Start-Stop here
  4588. case "$1" in
  4589. start)
  4590. bmg_start
  4591. ;;
  4592. stop)
  4593. bmg_stop
  4594. ;;
  4595. restart)
  4596. bmg_stop
  4597. sleep 5s
  4598. bmg_start
  4599. ;;
  4600. *)
  4601. echo "Usage: $0 {start|stop|restart}"
  4602. exit 1
  4603. ;;
  4604. esac
  4605. exit 0
  4606. #+END_SRC
  4607. Save and exit.
  4608. #+BEGIN_SRC: bash
  4609. chmod +x /etc/init.d/bitmessage-gateway
  4610. update-rc.d bitmessage-gateway defaults
  4611. service bitmessage-gateway start
  4612. #+END_SRC
  4613. 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.
  4614. ** Overcome restrictive environments
  4615. #+BEGIN_VERSE
  4616. /Censorship reflects a society's lack of confidence in itself. It is a hallmark of an authoritarian regime./
  4617. -- Potter Stewart
  4618. #+END_VERSE
  4619. 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.
  4620. 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.
  4621. #+BEGIN_SRC: bash
  4622. apt-get install shellinabox libapache2-mod-proxy-html
  4623. #+END_SRC
  4624. Update your Apache configuration.
  4625. #+BEGIN_SRC: bash
  4626. export HOSTNAME=mydomainname.com
  4627. editor /etc/apache2/sites-available/$HOSTNAME
  4628. #+END_SRC
  4629. Within the section which begins with *<VirtualHost *:443>* add the following, replacing /mydomainname.com/ with your domain name and /myusername/ with your username.
  4630. #+BEGIN_SRC: bash
  4631. <Location /shell>
  4632. ProxyPass http://localhost:4200/
  4633. Order allow,deny
  4634. Allow from all
  4635. AuthName "Authentication for shellinabox"
  4636. AuthUserFile /home/mydomainname.com/public_html/.htpasswd
  4637. AuthGroupFile /home/mydomainname.com/public_html/.htgroup
  4638. AuthType Basic
  4639. Require group shellinabox
  4640. Require user myusername
  4641. </Location>
  4642. #+END_SRC
  4643. 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.
  4644. #+BEGIN_SRC: bash
  4645. mkdir /home/$HOSTNAME
  4646. mkdir /home/$HOSTNAME/public_html
  4647. htpasswd -c /home/$HOSTNAME/public_html/.htpasswd myusername
  4648. #+END_SRC
  4649. Create a user group.
  4650. #+BEGIN_SRC: bash
  4651. editor /home/$HOSTNAME/public_html/.htgroup
  4652. #+END_SRC
  4653. Add the following:
  4654. #+BEGIN_SRC: bash
  4655. shellinabox: myusername
  4656. #+END_SRC
  4657. Save and exit, then restart Apache.
  4658. #+BEGIN_SRC: bash
  4659. a2enmod proxy_http
  4660. service apache2 restart
  4661. #+END_SRC
  4662. Now with a web browser navigate to https://mydomainname.com/shell and log in.
  4663. 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/.
  4664. ** Set up a mailing list
  4665. #+BEGIN_VERSE
  4666. /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./
  4667. -- Jono Bacon
  4668. #+END_VERSE
  4669. *** Public mailing list
  4670. 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.
  4671. **** Installation
  4672. #+BEGIN_SRC: bash
  4673. export HOSTNAME=mydomainname.com
  4674. apt-get install mailman
  4675. newlist mailman
  4676. #+END_SRC
  4677. Enter an email address for the list administrator and a password.
  4678. #+BEGIN_SRC: bash
  4679. editor /etc/mailman/mm_cfg.py
  4680. #+END_SRC
  4681. Set *MTA=None* and change *http:* to *https:*, then save and exit.
  4682. Add some settings.
  4683. #+BEGIN_SRC: bash
  4684. editor /etc/exim4/conf.d/main/04_mailman_options
  4685. #+END_SRC
  4686. Add the following, replacing /mydomainname.com/ with your domain name.
  4687. #+BEGIN_SRC: bash
  4688. # Mailman macro definitions
  4689. # Home dir for the Mailman installation
  4690. MM_HOME=/var/lib/mailman
  4691. # User and group for Mailman
  4692. MM_UID=list
  4693. MM_GID=list
  4694. #
  4695. # Domains that your lists are in - colon separated list
  4696. # you may wish to add these into local_domains as well
  4697. domainlist mm_domains=mydomainname.com
  4698. # The path of the Mailman mail wrapper script
  4699. MM_WRAP=MM_HOME/mail/mailman
  4700. #
  4701. # The path of the list config file (used as a required file when
  4702. # verifying list addresses)
  4703. MM_LISTCHK=MM_HOME/lists/${lc::$local_part}/config.pck
  4704. #+END_SRC
  4705. Save and exit.
  4706. #+BEGIN_SRC: bash
  4707. editor /etc/exim4/conf.d/main/000_localmacros
  4708. #+END_SRC
  4709. Append the following:
  4710. #+BEGIN_SRC: bash
  4711. SYSTEM_ALIASES_PIPE_TRANSPORT = address_pipe
  4712. SYSTEM_ALIASES_USER = list
  4713. SYSTEM_ALIASES_GROUP = list
  4714. #+END_SRC
  4715. Save and exit.
  4716. #+BEGIN_SRC: bash
  4717. editor /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
  4718. #+END_SRC
  4719. Append the following, before the final /accept/:
  4720. #+BEGIN_SRC: bash
  4721. # Do callback verification unless Mailman incoming bounce
  4722. deny !local_parts = *-bounces : *-bounces+*
  4723. !verify = sender/callout=30s,defer_ok
  4724. #+END_SRC
  4725. Save and exit.
  4726. #+BEGIN_SRC: bash
  4727. editor
  4728. /etc/exim4/conf.d/router/450_exim4-config_mailman_aliases
  4729. #+END_SRC
  4730. Add the following:
  4731. #+BEGIN_SRC: bash
  4732. mailman:
  4733. driver = accept
  4734. domains = +mm_domains
  4735. require_files = MM_LISTCHK
  4736. local_part_suffix_optional
  4737. local_part_suffix = -admin : \
  4738. -bounces : -bounces+* : \
  4739. -confirm : -confirm+* : \
  4740. -join : -leave : \
  4741. -owner : -request : \
  4742. -subscribe : -unsubscribe
  4743. transport = mailman_transport
  4744. #+END_SRC
  4745. Save and exit.
  4746. #+BEGIN_SRC: bash
  4747. editor /etc/exim4/conf.d/transport/40_exim4-config_mailman_pipe
  4748. #+END_SRC
  4749. Add the following:
  4750. #+BEGIN_SRC: bash
  4751. mailman_transport:
  4752. driver = pipe
  4753. command = MM_WRAP \
  4754. '${if def:local_part_suffix \
  4755. {${sg{$local_part_suffix}{-(\\w+)(\\+.*)?}{\$1}}} \
  4756. {post}}' \
  4757. $local_part
  4758. current_directory = MM_HOME
  4759. home_directory = MM_HOME
  4760. user = MM_UID
  4761. group = MM_GID
  4762. #+END_SRC
  4763. Save and exit.
  4764. #+BEGIN_SRC: bash
  4765. chown root:list /var/lib/mailman/mail/mailman
  4766. update-exim4.conf.template -r
  4767. update-exim4.conf
  4768. service exim4 restart
  4769. editor /etc/apache2/conf.d/mailman
  4770. #+END_SRC
  4771. Add the following:
  4772. #+BEGIN_SRC: bash
  4773. Alias /pipermail /var/lib/mailman/archives/public
  4774. Alias /images/mailman /usr/share/images/mailman
  4775. <directory /var/lib/mailman/archives/public>
  4776. DirectoryIndex index.html
  4777. </directory>
  4778. #+END_SRC
  4779. Save and exit.
  4780. #+BEGIN_SRC: bash
  4781. editor /etc/apache2/sites-available/$HOSTNAME
  4782. #+END_SRC
  4783. Add the following to the 443 section.
  4784. #+BEGIN_SRC: bash
  4785. <Location /mailman>
  4786. Options Indexes FollowSymLinks MultiViews
  4787. Order allow,deny
  4788. Allow from all
  4789. RedirectMatch ^/$ /cgi-bin/mailman/listinfo
  4790. </Location>
  4791. #+END_SRC
  4792. Save and exit.
  4793. #+BEGIN_SRC: bash
  4794. service apache2 restart
  4795. #+END_SRC
  4796. Now add your mailing list. The list name should not include any spaces.
  4797. #+BEGIN_SRC: bash
  4798. newlist mymailinglistname
  4799. #+END_SRC
  4800. With a browser visit https://$HOSTNAME/cgi-bin/mailman/admin/mymailinglistname to configure the mailing list.
  4801. Under *General Options* add an email address for a moderator (could be the same as the administrator) and click *Submit your changes*.
  4802. Under *Privacy Options* set steps required for subscription to *Confirm and approve* and click *Submit your changes*.
  4803. Also change these settings for the account within https://$HOSTNAME/cgi-bin/mailman/admin/mailman
  4804. Then to test that the mailing list works:
  4805. #+BEGIN_SRC: bash
  4806. exim -d+route -bt mymailinglistname@$HOSTNAME
  4807. #+END_SRC
  4808. If everything is working then this shouldn't show any problems.
  4809. **** Using the mailing list
  4810. Direct subscribers towards:
  4811. #+BEGIN_SRC: bash
  4812. https://mydomainname.com/cgi-bin/mailman/listinfo/mymailinglistname
  4813. #+END_SRC
  4814. To administrate the list visit:
  4815. #+BEGIN_SRC: bash
  4816. https://mydomainname.com/cgi-bin/mailman/admin/mymailinglistname
  4817. #+END_SRC
  4818. To add another mailing list:
  4819. #+BEGIN_SRC: bash
  4820. newlist mymailinglistname
  4821. #+END_SRC
  4822. To delete a mailing list:
  4823. #+BEGIN_SRC: bash
  4824. rmlist -a mymailinglistname
  4825. #+END_SRC
  4826. *** Private (encrypted) mailing list
  4827. 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.
  4828. 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.
  4829. **** Installation
  4830. #+BEGIN_SRC: bash
  4831. apt-get install schleuder
  4832. #+END_SRC
  4833. Edit the configuration:
  4834. #+BEGIN_SRC: bash
  4835. editor /etc/schleuder/schleuder.conf
  4836. #+END_SRC
  4837. Set the following parameters, replacing /mydomainname.com/ with your domain name:
  4838. #+BEGIN_SRC: bash
  4839. smtp_port: 465
  4840. superadminaddr: root@mydomainname.com
  4841. #+END_SRC
  4842. Save and exit.
  4843. Get your GPG public key, replacing /myGPGkeyID/ with your GPG key ID:
  4844. #+BEGIN_SRC: bash
  4845. export MYKEYID=myGPGkeyID
  4846. gpg --search-keys $MYKEYID
  4847. gpg --output /tmp/mypublickey.txt --armor --export $MYKEYID
  4848. #+END_SRC
  4849. 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.
  4850. #+BEGIN_SRC: bash
  4851. export MAILINGLISTNAME=mailinglistname
  4852. export MYUSERNAME=myusername
  4853. export HOSTNAME=mydomainname.com
  4854. export EMAILADDRESS=$MYUSERNAME@$HOSTNAME
  4855. schleuder-newlist $MAILINGLISTNAME@$HOSTNAME -realname "mailing list name" -adminaddress $EMAILADDRESS -initmember $EMAILADDRESS -initmemberkey /tmp/mypublickey.txt -nointeractive
  4856. #+END_SRC
  4857. Now add a mailing list rule:
  4858. #+BEGIN_SRC: bash
  4859. emailrule $MYUSERNAME $MAILINGLISTNAME@$HOSTNAME $MAILINGLISTNAME
  4860. #+END_SRC
  4861. Edit your Mutt configuration.
  4862. #+BEGIN_SRC: bash
  4863. editor /home/$MYUSERNAME/.muttrc
  4864. #+END_SRC
  4865. Search for the /mailboxes/ parameter and add "=mailinglistname". For example:
  4866. #+BEGIN_SRC: bash
  4867. mailboxes = =Sent =Drafts =mailinglistname
  4868. #+END_SRC
  4869. Save and exit.
  4870. Update Exim routing.
  4871. #+BEGIN_SRC: bash
  4872. editor /etc/exim4/conf.d/router/550_exim4-config_schleuder
  4873. #+END_SRC
  4874. Add the following:
  4875. #+BEGIN_SRC: bash
  4876. schleuder:
  4877. debug_print = "R: schleuder for $local_part@$domain"
  4878. driver = accept
  4879. local_part_suffix_optional
  4880. local_part_suffix = +* : -bounce : -sendkey
  4881. domains = +local_domains
  4882. user = schleuder
  4883. group = schleuder
  4884. require_files = schleuder:+/var/lib/schleuder/$domain/${local_part}
  4885. transport = schleuder_transport
  4886. #+END_SRC
  4887. Save and exit.
  4888. #+BEGIN_SRC: bash
  4889. editor /etc/exim4/conf.d/transport/30_exim4-config_schleuder
  4890. #+END_SRC
  4891. Add the following.
  4892. #+BEGIN_SRC: bash
  4893. schleuder_transport:
  4894. debug_print = "T: schleuder_transport for $local_part@$domain"
  4895. driver = pipe
  4896. home_directory = "/var/lib/schleuder/$domain/$local_part"
  4897. command = "/usr/bin/schleuder $local_part@$domain"
  4898. #+END_SRC
  4899. Save and exit.
  4900. #+BEGIN_SRC: bash
  4901. chown -R schleuder:schleuder /var/lib/schleuder
  4902. update-exim4.conf.template -r
  4903. update-exim4.conf
  4904. service exim4 restart
  4905. useradd -d /var/schleuderlists -s /bin/false schleuder
  4906. adduser Debian-exim schleuder
  4907. usermod -a -G mail schleuder
  4908. #+END_SRC
  4909. Test the routing.
  4910. #+BEGIN_SRC: bash
  4911. exim -d -bt mailinglistname@mydomainname.com
  4912. #+END_SRC
  4913. **** Importing the public key of the mailing list
  4914. 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.
  4915. ***** Using Mutt
  4916. Send an email to /mailinglistname-sendkey@mydomainname.com/ to have the list public key emailed to you.
  4917. When you receive the email open it and press *CTRL-k* to import it.
  4918. ***** Using Thunderbird
  4919. Send an email to /mailinglistname-sendkey@mydomainname.com/ to have the list public key emailed to you.
  4920. When you receive the email open it, select all the text with *CTRL-a* then *CTRL-c*.
  4921. On the menu select *OpenPGP* followed by *Key Management*.
  4922. You will now see a new menu bar. Select *Edit* followed by *Import keys from clipboard*.
  4923. Click on *Import* followed by *Ok*.
  4924. **** Using the list
  4925. To obtain the public keys of list members send an email to /mailinglistname-request@mydomainname.com/ containing *X-LIST-KEYS* in the message body.
  4926. To add a member: *X-ADD-MEMBER: othermember@otherdomain.net*
  4927. An example of adding a public key to the list:
  4928. #+BEGIN_SRC: bash
  4929. X-ADD-KEY:
  4930. -----BEGIN PGP PUBLIC KEY BLOCK-----
  4931. Version: GnuPG v1.4.9 (GNU/Linux)
  4932. mQGiBEjVO7oRBADQvT6wtD2IzzIiK0NbrcilCKCp4MWb8cYXTXguwPQI6y0Nerz4
  4933. dsK6J0X1Vgeo02tqA4xd3EDK8rdqL2yZfl/2egH8+85R3gDk+kqkfEp4pwCgp6VO
  4934. [...]
  4935. pNlF/qkaWwRb048h+iMrW21EkouLKTDPFkdFbapV2X5KJZIcfhO1zEbwc1ZKF3Ju
  4936. Q9X5GRmY62hz9SCZnsC0jeYAni8OUQV9NXfXlS/vePBUnOL08NQB
  4937. =xTv3
  4938. -----END PGP PUBLIC KEY BLOCK-----
  4939. #+END_SRC
  4940. To get details for a member: *X-GET-MEMBER: othermember@otherdomain.net*
  4941. To delete a member: *X-DELETE-MEMBER: othermember@otherdomain.net*
  4942. To delete a public key: *X-DELETE-KEY: keyID*
  4943. You can unsubscribe from the list with *X-UNSUBSCRIBE* in the message body.
  4944. *** Decentralised mailing list
  4945. 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.
  4946. 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/".
  4947. 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.
  4948. On a Debian based system:
  4949. #+BEGIN_SRC: bash
  4950. sudo apt-get install makepasswd
  4951. #+END_SRC
  4952. or on an RPM based system:
  4953. #+BEGIN_SRC: bash
  4954. sudo yum install makepasswd
  4955. #+END_SRC
  4956. Create a name for your mailing list. This will be a random string.
  4957. #+BEGIN_SRC: bash
  4958. makepasswd -c 40
  4959. #+END_SRC
  4960. Keep a note of this.
  4961. Run the Bitmessage client and on the menu select *File/Join-Create Chan/Create new chan*
  4962. 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.
  4963. 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.
  4964. 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.
  4965. 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.
  4966. ** Install a microblog
  4967. #+BEGIN_VERSE
  4968. /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/
  4969. -- Jason Self
  4970. #+END_VERSE
  4971. 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.
  4972. Install some dependencies:
  4973. #+BEGIN_SRC: bash
  4974. apt-get install php5-xcache php-gettext php5-curl php5-gd php5-mysql
  4975. #+END_SRC
  4976. Download GNU Social
  4977. #+BEGIN_SRC: bash
  4978. mkdir ~/build
  4979. cd ~/build
  4980. wget http://freedombone.uk.to/gnu-social.tar.gz
  4981. #+END_SRC
  4982. Verify it.
  4983. #+BEGIN_SRC: bash
  4984. sha256sum gnu-social.tar.gz
  4985. 1f886241c7f1a175e7be3cccbcb944ab6c03617fb75aefa4d62d37abed87d2b4
  4986. #+END_SRC
  4987. Extract the files and set permissions on them, where /mydomainname.com/ is your domain name.
  4988. #+BEGIN_SRC: bash
  4989. export HOSTNAME=mydomainname.com
  4990. tar zxf gnu-social.tar.gz
  4991. rm -rf /var/www/$HOSTNAME/htdocs
  4992. mv statusnet-gnu-social /var/www/$HOSTNAME/htdocs
  4993. chmod a+w /var/www/$HOSTNAME/htdocs
  4994. chown www-data:www-data /var/www/$HOSTNAME/htdocs
  4995. chmod a+w /var/www/$HOSTNAME/htdocs/avatar
  4996. chmod a+w /var/www/$HOSTNAME/htdocs/background
  4997. chmod a+w /var/www/$HOSTNAME/htdocs/file
  4998. chmod +x /var/www/$HOSTNAME/htdocs/scripts/maildaemon.php
  4999. #+END_SRC
  5000. Edit the Apache access settings.
  5001. #+BEGIN_SRC: bash
  5002. editor /var/www/$HOSTNAME/htdocs/.htaccess
  5003. #+END_SRC
  5004. Add the following:
  5005. #+BEGIN_SRC: bash
  5006. <IfModule mod_rewrite.c>
  5007. RewriteEngine On
  5008. RewriteBase /
  5009. ## Uncomment these if having trouble with API authentication
  5010. ## when PHP is running in CGI or FastCGI mode.
  5011. #
  5012. #RewriteCond %{HTTP:Authorization} ^(.*)
  5013. #RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
  5014. RewriteCond %{REQUEST_FILENAME} !-f
  5015. RewriteCond %{REQUEST_FILENAME} !-d
  5016. RewriteRule (.*) index.php?p=$1 [L,QSA]
  5017. </IfModule>
  5018. <FilesMatch "\.(ini)">
  5019. Order allow,deny
  5020. </FilesMatch>
  5021. #+END_SRC
  5022. Save and exit, then create a database.
  5023. #+BEGIN_SRC: bash
  5024. mysql -u root -p
  5025. create database gnusocial;
  5026. CREATE USER 'gnusocialadmin'@'localhost' IDENTIFIED BY 'gnusocialpassword';
  5027. GRANT ALL PRIVILEGES ON gnusocial.* TO 'gnusocialadmin'@'localhost';
  5028. quit
  5029. #+END_SRC
  5030. Add the mailer script to the aliases file:
  5031. #+BEGIN_SRC: bash
  5032. editor /etc/aliases
  5033. #+END_SRC
  5034. Add the following, replacing /mydomainname.com/ with your domain name.
  5035. #+BEGIN_SRC: bash
  5036. www-data: root
  5037. *: /var/www/mydomainname.com/htdocs/scripts/maildaemon.php
  5038. #+END_SRC
  5039. Save and exit. Update the aliases by typing:
  5040. #+BEGIN_SRC: bash
  5041. newaliases
  5042. #+END_SRC
  5043. Then with a web browser navigate to:
  5044. https://$HOSTNAME/install.php
  5045. Set a name for the site.
  5046. Server SSL: enable
  5047. Hostname: localhost
  5048. Type: MySql
  5049. Name: gnusocial
  5050. DB username: gnusocialadmin
  5051. DB Password; your gnu social admin password goes here
  5052. Administrator nickname: myusername
  5053. Administrator password: mylongrandompassword
  5054. Subscribe to announcements: ticked
  5055. Site profile: Community
  5056. 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.
  5057. 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:
  5058. Under the *Site* settings:
  5059. Text limit: 140
  5060. Dupe Limit: 60000
  5061. Under the *User* settings:
  5062. Bio limit: 1000
  5063. Under the *Access* settings:
  5064. /Invite only/ ticked
  5065. 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.
  5066. 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.
  5067. Edit the config file.
  5068. #+BEGIN_SRC: bash
  5069. editor /var/www/$HOSTNAME/htdocs/config.php
  5070. #+END_SRC
  5071. Change the ssl setting from *always* to *sometimes*, hten save and exit.
  5072. 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/
  5073. When following other GNU Social users enter the URL of your profile. For example, https://mygnusocialdomain/myusername
  5074. ** Install Mediagoblin
  5075. #+BEGIN_VERSE
  5076. /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./
  5077. #+END_VERSE
  5078. 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/.
  5079. 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.
  5080. Install some dependencies.
  5081. #+BEGIN_SRC: bash
  5082. 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
  5083. #+END_SRC
  5084. Create a user, replacing /mymediagoblindomain/ with the domain name for your mediagoblin site.
  5085. #+BEGIN_SRC: bash
  5086. export HOSTNAME=mymediagoblindomain
  5087. adduser mediagoblin
  5088. #+END_SRC
  5089. Give the user a long random password.
  5090. #+BEGIN_SRC: bash
  5091. mkdir -p /srv/$HOSTNAME
  5092. chown -hR mediagoblin:mediagoblin /srv/$HOSTNAME
  5093. su - mediagoblin
  5094. export HOSTNAME=mymediagoblindomain
  5095. cd /srv/$HOSTNAME
  5096. git clone git://gitorious.org/mediagoblin/mediagoblin.git
  5097. cd mediagoblin
  5098. git submodule init
  5099. git submodule update
  5100. virtualenv --system-site-packages .
  5101. ./bin/python setup.py develop
  5102. ./bin/easy_install flup
  5103. cp mediagoblin.ini mediagoblin_local.ini
  5104. cp paste.ini paste_local.ini
  5105. editor mediagoblin_local.ini
  5106. #+END_SRC
  5107. 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.
  5108. #+BEGIN_SRC: bash
  5109. [[mediagoblin.media_types.audio]]
  5110. [[mediagoblin.media_types.video]]
  5111. [[mediagoblin.media_types.stl]]
  5112. #+END_SRC
  5113. Then save and exit.
  5114. #+BEGIN_SRC: bash
  5115. ./bin/pip install scikits.audiolab
  5116. ./bin/gmg dbupdate
  5117. exit # to go back to the root user
  5118. editor /etc/init.d/mediagoblin
  5119. #+END_SRC
  5120. Add the following, replacing /mymediagoblindomain/ with the domain name for your mediagoblin site.
  5121. #+BEGIN_SRC: bash
  5122. #!/bin/bash
  5123. # /etc/init.d/mediagoblin
  5124. ### BEGIN INIT INFO
  5125. # Provides: mediagoblin
  5126. # Required-Start: $remote_fs $syslog
  5127. # Required-Stop: $remote_fs $syslog
  5128. # Default-Start: 2 3 4 5
  5129. # Default-Stop: 0 1 6
  5130. # Short-Description: starts mediagoblin
  5131. # Description: Other methods may work, but I found this the easiest
  5132. ### END INIT INFO
  5133. # Author: Bob Mottram <bob@robotics.uk.to>
  5134. #Settings
  5135. SERVICE='mediagoblin'
  5136. LOGFILE='/srv/mymediagoblindomain/mediagoblin.log'
  5137. COMMAND="./lazyserver.sh > $LOGFILE"
  5138. USERNAME='mediagoblin'
  5139. NICELEVEL=15 # from 0-19 the bigger the number, the less the impact on system resources
  5140. HISTORY=1024
  5141. MG_LOCATION="/srv/mymediagoblindomain/mediagoblin"
  5142. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  5143. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/core_perl:/sbin:/usr/sbin:/bin'
  5144. mg_start() {
  5145. echo "Starting $SERVICE..."
  5146. cd ${MG_LOCATION}
  5147. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  5148. }
  5149. mg_stop() {
  5150. echo "Stopping $SERVICE"
  5151. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  5152. }
  5153. #Start-Stop here
  5154. case "$1" in
  5155. start)
  5156. mg_start
  5157. ;;
  5158. stop)
  5159. mg_stop
  5160. ;;
  5161. restart)
  5162. mg_stop
  5163. sleep 10s
  5164. mg_start
  5165. ;;
  5166. *)
  5167. echo "Usage: $0 {start|stop|restart}"
  5168. exit 1
  5169. ;;
  5170. esac
  5171. exit 0
  5172. #+END_SRC
  5173. Save and exit.
  5174. #+BEGIN_SRC: bash
  5175. chmod +x /etc/init.d/mediagoblin
  5176. update-rc.d mediagoblin defaults
  5177. service mediagoblin start
  5178. #+END_SRC
  5179. Edit the Apache configuration for your mediagoblin site.
  5180. #+BEGIN_SRC: bash
  5181. editor /etc/apache2/sites-available/mymediagoblindomain
  5182. #+END_SRC
  5183. 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.
  5184. #+BEGIN_SRC: bash
  5185. <VirtualHost *:80>
  5186. ServerAdmin myusername@mydomainname.com
  5187. DocumentRoot /srv/mymediagoblindomain/mediagoblin
  5188. ServerName mymediagoblindomain
  5189. <Directory />
  5190. Options FollowSymLinks
  5191. AllowOverride None
  5192. </Directory>
  5193. <Directory /srv/mymediagoblindomain/mediagoblin/>
  5194. Options Indexes FollowSymLinks MultiViews
  5195. AllowOverride All
  5196. Order allow,deny
  5197. allow from all
  5198. LimitRequestBody 536870912
  5199. </Directory>
  5200. LogLevel warn
  5201. ProxyVia On
  5202. ProxyRequests off
  5203. ProxyPreserveHost on
  5204. ProxyPass / http://localhost:6543/
  5205. ErrorLog "/var/log/apache2/error.log"
  5206. CustomLog "/var/log/apache2/access.log" combined
  5207. RewriteEngine On
  5208. RewriteOptions Inherit
  5209. </VirtualHost>
  5210. #+END_SRC
  5211. Save and exit.
  5212. 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.
  5213. #+BEGIN_SRC: bash
  5214. editor /srv/mymediagoblindomain/mediagoblin/mediagoblin_local.ini
  5215. #+END_SRC
  5216. Then set:
  5217. #+BEGIN_SRC: bash
  5218. allow_registration = false
  5219. #+END_SRC
  5220. Save and exit.
  5221. ** Run a pastebin service
  5222. 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.
  5223. 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]].
  5224. #+BEGIN_SRC: bash
  5225. adduser --disabled-login zerobin
  5226. mkdir ~/build
  5227. cd ~/build
  5228. git clone https://github.com/sametmax/0bin.git
  5229. cd 0bin
  5230. python setup.py install
  5231. chown -R zerobin:zerobin /usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static
  5232. #+END_SRC
  5233. 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]].
  5234. Now create the daemon.
  5235. #+BEGIN_SRC: bash
  5236. editor /etc/init.d/zerobin
  5237. #+END_SRC
  5238. Add the following text:
  5239. #+BEGIN_SRC: bash
  5240. #!/bin/bash
  5241. # /etc/init.d/zerobin
  5242. ### BEGIN INIT INFO
  5243. # Provides: zerobin
  5244. # Required-Start: $remote_fs $syslog
  5245. # Required-Stop: $remote_fs $syslog
  5246. # Default-Start: 2 3 4 5
  5247. # Default-Stop: 0 1 6
  5248. # Short-Description: starts zerobin as a background daemon
  5249. # Description: starts zerobin as a background daemon
  5250. ### END INIT INFO
  5251. # Author: Bob Mottram <bob@robotics.uk.to>
  5252. #Settings
  5253. SERVICE='zerobin'
  5254. LOGFILE='/home/zerobin/zerobin.log'
  5255. COMMAND="zerobin > $LOGFILE"
  5256. USERNAME='zerobin'
  5257. NICELEVEL=19 # from 0-19 the bigger the number, the less the impact on system resources
  5258. HISTORY=1024
  5259. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  5260. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  5261. zerobin_start() {
  5262. echo "Starting $SERVICE..."
  5263. su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  5264. }
  5265. zerobin_stop() {
  5266. echo "Stopping $SERVICE"
  5267. su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  5268. }
  5269. #Start-Stop here
  5270. case "$1" in
  5271. start)
  5272. zerobin_start
  5273. ;;
  5274. stop)
  5275. zerobin_stop
  5276. ;;
  5277. restart)
  5278. zerobin_stop
  5279. sleep 2s
  5280. zerobin_start
  5281. ;;
  5282. *)
  5283. echo "Usage: $0 {start|stop|restart}"
  5284. exit 1
  5285. ;;
  5286. esac
  5287. exit 0
  5288. #+END_SRC
  5289. Save and exit.
  5290. #+BEGIN_SRC: bash
  5291. chmod +x /etc/init.d/zerobin
  5292. update-rc.d zerobin defaults
  5293. service zerobin start
  5294. #+END_SRC
  5295. 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:
  5296. #+BEGIN_SRC: bash
  5297. <VirtualHost *:80>
  5298. ServerAdmin username@mydomainname.com
  5299. ServerName mypastedomainname.com
  5300. <Location />
  5301. ProxyPass http://localhost:8000/
  5302. Order allow,deny
  5303. Allow from all
  5304. LimitRequestBody 256000
  5305. </Location>
  5306. ErrorLog ${APACHE_LOG_DIR}/paste_error.log
  5307. # Possible values include: debug, info, notice, warn, error, crit,
  5308. # alert, emerg.
  5309. LogLevel error
  5310. CustomLog ${APACHE_LOG_DIR}/paste.log combined
  5311. </VirtualHost>
  5312. #+END_SRC
  5313. Save and exit.
  5314. 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.
  5315. #+BEGIN_SRC: bash
  5316. service apache2 restart
  5317. #+END_SRC
  5318. 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:
  5319. #+BEGIN_SRC: bash
  5320. editor /usr/bin/zerobinupdate
  5321. #+END_SRC
  5322. Add the following:
  5323. #+BEGIN_SRC: bash
  5324. #!/bin/bash
  5325. CONTENT=/usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static/content
  5326. # Exit if there is no content directory
  5327. if [[ ! -d $CONTENT ]]; then
  5328. exit
  5329. fi
  5330. LOG=/home/zerobin/zerobin.log
  5331. CHECK=`du -hs $CONTENT`
  5332. regex="([0-9]+)G"
  5333. if [[ $CHECK =~ $regex && ${BASH_REMATCH[1]} -gt 1 ]]; then
  5334. echo "Directory size limit exceeded - removing zerobin content" >> $LOG
  5335. rm -rf $CONTENT/*
  5336. fi
  5337. #+END_SRC
  5338. Save and exit.
  5339. #+BEGIN_SRC: bash
  5340. chmod +x /usr/bin/zerobinupdate
  5341. echo "*/5 * * * * root /usr/bin/timeout 120 /usr/bin/zerobinupdate" >> /etc/crontab
  5342. #+END_SRC
  5343. Additionally to ensure that the service is being used as intended and not as a permanent data store:
  5344. #+BEGIN_SRC: bash
  5345. editor /usr/bin/zerobinclear
  5346. #+END_SRC
  5347. Add the following:
  5348. #+BEGIN_SRC: bash
  5349. #!/bin/bash
  5350. CONTENT=/usr/local/lib/python2.7/dist-packages/zerobin-0.4.1-py2.7.egg/zerobin/static/content
  5351. # Exit if there is no content directory
  5352. if [[ ! -d $CONTENT ]]; then
  5353. exit
  5354. fi
  5355. rm -rf $CONTENT
  5356. #+END_SRC
  5357. Save and exit.
  5358. #+BEGIN_SRC: bash
  5359. chmod +x /usr/bin/zerobinclear
  5360. echo "35 3 * * * root /usr/bin/zerobinclear" >> /etc/crontab
  5361. service cron restart
  5362. #+END_SRC
  5363. This will delete all pasted content once per day.
  5364. ** Database maintenance
  5365. #+BEGIN_VERSE
  5366. /To be ready to fail is to be prepared for success./
  5367. -- Jose Bergamin
  5368. #+END_VERSE
  5369. 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.
  5370. #+BEGIN_SRC: bash
  5371. editor /usr/bin/repairdatabase
  5372. #+END_SRC
  5373. Add the following, using your mysql root password and entering your email address.
  5374. #+BEGIN_SRC: bash
  5375. #!/bin/bash
  5376. DATABASE=$1
  5377. EMAIL=myusername@mydomainname.com
  5378. MYSQL_ROOT_PASSWORD=mysqlrootpassword
  5379. TEMPFILE=/tmp/repairdatabase_$DATABASE
  5380. umask 0077
  5381. # check the database
  5382. mysqlcheck -c -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE > $TEMPFILE
  5383. # Attempt to repair the database if it contains errors
  5384. if grep -q "Error" "$TEMPFILE"; then
  5385. mysqlcheck -u root --password=$MYSQL_ROOT_PASSWORD --auto-repair $DATABASE
  5386. else
  5387. # No errors were found, so exit
  5388. rm -f $TEMPFILE
  5389. exit 0
  5390. fi
  5391. rm -f $TEMPFILE
  5392. # Check the database again
  5393. mysqlcheck -c -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE > $TEMPFILE
  5394. # If it still contains errors then restore from backup
  5395. if grep -q "Error" "$TEMPFILE"; then
  5396. mysql -u root --password=$MYSQL_ROOT_PASSWORD $DATABASE -o < /var/backups/$DATABASE_daily.sql
  5397. # Send a warning email
  5398. echo "$DATABASE database corruption within could not be repaired. Restored from backup." $EMAIL
  5399. rm -f $TEMPFILE
  5400. exit 1
  5401. fi
  5402. rm -f $TEMPFILE
  5403. exit 0
  5404. #+END_SRC
  5405. Save and exit.
  5406. #+BEGIN_SRC: bash
  5407. chmod 600 /usr/bin/repairdatabase
  5408. editor /etc/cron.hourly/repair
  5409. #+END_SRC
  5410. Add the following. If you're using Red Matrix then uncomment that line.
  5411. #+BEGIN_SRC: bash
  5412. #!/bin/bash
  5413. repairdatabase friendica
  5414. #repairdatabase redmatrix
  5415. repairdatabase roundcubemail
  5416. #+END_SRC
  5417. Save and exit.
  5418. #+BEGIN_SRC: bash
  5419. chmod +x /etc/cron.hourly/repair
  5420. #+END_SRC
  5421. ** Install Tripwire
  5422. #+BEGIN_VERSE
  5423. /...by the time you get done with all of that, we have a freedom box/
  5424. -- Eben Moglen
  5425. #+END_VERSE
  5426. 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.
  5427. #+BEGIN_SRC: bash
  5428. apt-get install tripwire
  5429. export HOSTNAME=mydomainname.com
  5430. cd /etc/tripwire
  5431. cp arm-local.key $HOSTNAME-local.key
  5432. cp site.key $HOSTNAME-site.key
  5433. tripwire --init
  5434. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  5435. tripwire --check --interactive
  5436. #+END_SRC
  5437. you will be asked for two passphrases ("site" and "local"). Make a note of these.
  5438. Turn off reporting of changes to system logs.
  5439. #+BEGIN_SRC: bash
  5440. editor /etc/tripwire/twcfg.txt
  5441. #+END_SRC
  5442. Set *SYSLOGREPORTING* to false and comment out the line, then save and exit.
  5443. #+BEGIN_SRC: bash
  5444. editor /etc/tripwire/twpol.txt
  5445. #+END_SRC
  5446. Edit the "Root config files" section so that it looks like this:
  5447. #+BEGIN_SRC: bash
  5448. # These files change the behavior of the root account
  5449. (
  5450. rulename = "Root config files",
  5451. severity = 100
  5452. )
  5453. {
  5454. /root -> $(SEC_CRIT) ; # Catch all additions to /root
  5455. /root/.bashrc -> $(SEC_CONFIG) ;
  5456. /root/.bash_history -> $(SEC_CONFIG) ;
  5457. }
  5458. #+END_SRC
  5459. Then save and exit.
  5460. #+BEGIN_SRC: bash
  5461. editor /usr/bin/reset-tripwire
  5462. #+END_SRC
  5463. Add the following:
  5464. #+BEGIN_SRC: bash
  5465. #!/bin/sh
  5466. tripwire --update-policy --secure-mode low /etc/tripwire/twpol.txt
  5467. #+END_SRC
  5468. Save and exit.
  5469. #+BEGIN_SRC: bash
  5470. chmod +x /usr/bin/reset-tripwire
  5471. #+END_SRC
  5472. If you subsequently install any more packages or make configuration changes then update the policy again with:
  5473. #+BEGIN_SRC: bash
  5474. reset-tripwire
  5475. #+END_SRC
  5476. Also, to look for any rootkits.
  5477. #+BEGIN_SRC: bash
  5478. apt-get install rkhunter
  5479. #+END_SRC
  5480. * Router/Firewall ports
  5481. The following ports on your internet router/firewall should be forwarded to the BBB.
  5482. | Protocol | Port/s |
  5483. |---------------+------------|
  5484. | Gopher | 70 |
  5485. | HTTP | 80 |
  5486. | HTTPS | 443 |
  5487. | IMAP | 143 |
  5488. | IRC SSL | 6697 |
  5489. | SIP | 5060..5061 |
  5490. | SMTP | 25,587 |
  5491. | SMTPS | 465 |
  5492. | SSH | 22 |
  5493. | XMPP | 5222..5223 |
  5494. | XMPP (server) | 5269 |
  5495. | XMPP (BOSH) | 5280..5281 |
  5496. | Bitmessage | 8444 |
  5497. | Convergence | 8432..8433 |
  5498. * Hints and Tips
  5499. ** Example software sources
  5500. 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*
  5501. *** Beaglebone Black
  5502. #+BEGIN_SRC: bash
  5503. deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5504. deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5505. deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5506. deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5507. deb http://security.debian.org/ wheezy/updates main contrib non-free
  5508. deb-src http://security.debian.org/ wheezy/updates main contrib non-free
  5509. deb http://ftp.us.debian.org/debian wheezy-backports main contrib non-free
  5510. #+END_SRC
  5511. *** Cubieboard
  5512. #+BEGIN_SRC: bash
  5513. deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5514. deb-src http://ftp.us.debian.org/debian/ wheezy main contrib non-free
  5515. deb http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5516. deb-src http://ftp.us.debian.org/debian/ wheezy-updates main contrib non-free
  5517. deb http://security.debian.org/ wheezy/updates main contrib non-free
  5518. deb-src http://security.debian.org/ wheezy/updates main contrib non-free
  5519. deb http://ftp.us.debian.org/debian wheezy-backports main contrib non-free
  5520. deb http://mirrors.sohu.com/debian/ wheezy main contrib non-free
  5521. deb-src http://mirrors.sohu.com/debian/ wheezy main contrib non-free
  5522. deb http://packages.cubian.org/ wheezy main non-free
  5523. deb http://repo.ajenti.org/debian main main debian
  5524. #+END_SRC
  5525. ** Messaging security
  5526. 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.
  5527. ** Moving Domains
  5528. 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:
  5529. #+BEGIN_SRC: bash
  5530. find /var/www/mynewdomain/htdocs -type f -exec sed -i 's@myolddomain@mynewdomain@g' {} \;
  5531. #+END_SRC
  5532. If you're moving the blog to a new domain then you will need to delete the lock file:
  5533. #+BEGIN_SRC: bash
  5534. rm /var/www/myblogdomainname.com/htdocs/fp-content/%%setup.lock
  5535. #+END_SRC
  5536. 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.
  5537. 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*.
  5538. ** MySql foo
  5539. *** Reset the root password
  5540. To reset the root password, or if mysql forgets its root password.
  5541. #+BEGIN_SRC: bash
  5542. /etc/init.d/mysql stop
  5543. mysqld_safe --skip-grant-tables &
  5544. mysql -u root
  5545. use mysql;
  5546. update user set password=PASSWORD("mynewpassword") where User='root';
  5547. flush privileges;
  5548. quit
  5549. /etc/init.d/mysql stop
  5550. /etc/init.d/mysql start
  5551. #+END_SRC
  5552. *** Repair and optimize databases
  5553. To check, repair and optimize the databases.
  5554. #+BEGIN_SRC: bash
  5555. mysqlcheck -c -u root -p --all-databases
  5556. mysqlcheck -u root -p --auto-repair --all-databases
  5557. mysqlcheck -u root -p -o --all-databases
  5558. #+END_SRC
  5559. *** Backup all databases
  5560. To back up all mysql databases:
  5561. #+BEGIN_SRC: bash
  5562. mysqldump -u root -p --all-databases --events > /var/backups/databasebackup.sql
  5563. #+END_SRC
  5564. *** Restoring a particular mysql database
  5565. To restore yesterday's friendica backup:
  5566. #+BEGIN_SRC: bash
  5567. mysql -u root -p friendica -o < /var/backups/friendica_daily.sql
  5568. #+END_SRC
  5569. To restore the webmail database:
  5570. #+BEGIN_SRC: bash
  5571. mysql -u root -p roundcubemail -o < /var/backups/roundcubemail_daily.sql
  5572. #+END_SRC
  5573. To restore yesterday's Red Matrix backup:
  5574. #+BEGIN_SRC: bash
  5575. mysql -u root -p redmatrix -o < /var/backups/redmatrix_daily.sql
  5576. #+END_SRC
  5577. *** Removing and reinstalling mysql server
  5578. 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:
  5579. #+BEGIN_SRC: bash
  5580. ps aux | grep mysql
  5581. #+END_SRC
  5582. and use /kill -9 <pid>/ to kill all mysql processes.
  5583. #+BEGIN_SRC: bash
  5584. apt-get remove --purge mysql\*
  5585. rm -rf /etc/mysql
  5586. rm -rf /var/lib/mysql
  5587. apt-get clean
  5588. updatedb
  5589. #+END_SRC
  5590. Reinstall mysql:
  5591. #+BEGIN_SRC: bash
  5592. apt-get install mysql-server php5-common php5-cli php5-curl php5-gd php5-mysql php5-mcrypt php5-fpm php5-cgi php-apc
  5593. #+END_SRC
  5594. Then to recreate the Friendica and webmail databases:
  5595. #+BEGIN_SRC: bash
  5596. mysql -p
  5597. create database friendica;
  5598. CREATE USER 'friendicaadmin'@'localhost' IDENTIFIED BY 'myfriendicapassword';
  5599. GRANT ALL PRIVILEGES ON friendica.* TO 'friendicaadmin'@'localhost';
  5600. create database roundcubemail;
  5601. CREATE USER 'roundcube'@'localhost' IDENTIFIED BY 'roundcubepassword';
  5602. GRANT ALL PRIVILEGES ON roundcubemail.* TO 'roundcube'@'localhost';
  5603. quit
  5604. mysql -u root -p friendica -o < /var/backups/friendica_daily.sql
  5605. mysql -u root -p roundcubemail -o < /var/backups/roundcubemail_daily.sql
  5606. #+END_SRC
  5607. And if you previously had Red Matrix installed:
  5608. #+BEGIN_SRC: bash
  5609. mysql -p
  5610. create database redmatrix;
  5611. CREATE USER 'redmatrixadmin'@'localhost' IDENTIFIED BY 'myredmatrixpassword';
  5612. GRANT ALL PRIVILEGES ON redmatrix.* TO 'redmatrixadmin'@'localhost';
  5613. quit
  5614. mysql -u root -p redmatrix -o < /var/backups/redmatrix_daily.sql
  5615. #+END_SRC
  5616. Since IMAP seems entangled with mysql it may also be necessary to reinstall Exim and Dovecot.
  5617. #+BEGIN_SRC: bash
  5618. apt-get remove --purge exim4\*
  5619. #+END_SRC
  5620. Then follow the instructions in [[Install Email]], [[Spam filtering]] and [[Install Dovecot]].
  5621. ** Regenerating SSL certificates
  5622. 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:
  5623. Obtain the latest updates:
  5624. #+BEGIN_SRC: bash
  5625. apt-get update
  5626. apt-get upgrade
  5627. #+END_SRC
  5628. Run *makecert <domain>* for each of your sites.
  5629. Recreate the XMPP certificate:
  5630. #+BEGIN_SRC: bash
  5631. openssl genrsa -out /etc/ssl/private/xmpp.key 4096
  5632. openssl req -new -x509 -key /etc/ssl/private/xmpp.key -out /etc/ssl/certs/xmpp.crt -days 3650
  5633. chmod 600 /etc/ssl/private/xmpp.key
  5634. chmod 600 /etc/ssl/certs/xmpp.crt
  5635. chown prosody:prosody /etc/ssl/private/xmpp.key
  5636. chown prosody:prosody /etc/ssl/certs/xmpp.crt
  5637. #+END_SRC
  5638. And regenerate the IRC server keys:
  5639. #+BEGIN_SRC: bash
  5640. openssl genrsa -out /etc/ircd-hybrid/key/ircd.key 4096
  5641. openssl req -new -x509 -key /etc/ircd-hybrid/key/ircd.key -out /etc/ircd-hybrid/key/ircd.pem -days 3650
  5642. chmod 600 /etc/ircd-hybrid/key/ircd.key
  5643. chmod 600 /etc/ircd-hybrid/key/ircd.pem
  5644. #+END_SRC
  5645. Regenerate email certificate.
  5646. #+BEGIN_SRC: bash
  5647. exim-gencert --force
  5648. #+END_SRC
  5649. As an added precaution you may wish to regenerate your ssh host keys:
  5650. #+BEGIN_SRC: bash
  5651. rm /etc/ssh/ssh_host_*
  5652. dpkg-reconfigure openssh-server
  5653. #+END_SRC
  5654. Then reboot the server with:
  5655. #+BEGIN_SRC: bash
  5656. reboot
  5657. #+END_SRC
  5658. ** Example crontab file
  5659. 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.
  5660. #+BEGIN_SRC: bash
  5661. # /etc/crontab: system-wide crontab
  5662. # Unlike any other crontab you don't have to run the `crontab'
  5663. # command to install the new version when you edit this file
  5664. # and files in /etc/cron.d. These files also have username fields,
  5665. # that none of the other crontabs do.
  5666. SHELL=/bin/sh
  5667. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  5668. # m h dom mon dow user command
  5669. 10,20,30,40,50 * * * * root /usr/bin/timeout 120 /usr/bin/dynamicdns && /usr/bin/spamfilter myusername
  5670. 15,35,55 * * * * root cd /var/www/mydomainname/htdocs; /usr/bin/timeout 240 /usr/bin/php include/poller.php
  5671. 17 * * * * root cd / && run-parts --report /etc/cron.hourly
  5672. 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
  5673. 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
  5674. 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
  5675. #+END_SRC
  5676. ** Using your own domain
  5677. Suppose that you have bought a domain name (rather than using a free subdomain on freedns) and you want to use that instead.
  5678. Remove any existing nameservers for your domain (or select "custom" nameservers), then add:
  5679. #+BEGIN_SRC: bash
  5680. NS1.AFRAID.ORG
  5681. NS2.AFRAID.ORG
  5682. NS3.AFRAID.ORG
  5683. NS4.AFRAID.ORG
  5684. #+END_SRC
  5685. 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".
  5686. 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*.
  5687. To route email to one of your freedns domains:
  5688. #+BEGIN_SRC: bash
  5689. editor /etc/mailname
  5690. #+END_SRC
  5691. Add any extra domains which you own, then save and exit.
  5692. #+BEGIN_SRC: bash
  5693. editor /etc/exim4/update-exim4.conf.conf
  5694. #+END_SRC
  5695. Within dc_other_hostnames add your extra domain names, separated by a colon ':' character.
  5696. Save and exit, then restart exim.
  5697. #+BEGIN_SRC: bash
  5698. update-exim4.conf.template -r
  5699. update-exim4.conf
  5700. service exim4 restart
  5701. #+END_SRC
  5702. You should now be able to send an email from /postmaster@mynewdomainname/ and it should arrive in your inbox.
  5703. ** Obtaining an "official" SSL certificate
  5704. 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).
  5705. 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.
  5706. Firstly you should have an Apache web site configutaion ready to go. See [[Setting up a web site]] for details.
  5707. Within StartSSL under the validations wizard validate your domain, which means sending an email to it and confirming a code.
  5708. Now we can generate the certificate request as follows.
  5709. #+BEGIN_SRC: bash
  5710. export HOSTNAME=mydomainname.com
  5711. openssl genrsa -out /etc/ssl/private/$HOSTNAME.key 2048
  5712. chown root:ssl-cert /etc/ssl/private/$HOSTNAME.key
  5713. chmod 440 /etc/ssl/private/$HOSTNAME.key
  5714. mkdir /etc/ssl/requests
  5715. #+END_SRC
  5716. Now make a certificate request as follows. You should copy and paste the whole of this, not just line by line.
  5717. #+BEGIN_SRC: bash
  5718. openssl req -new -key /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/requests/$HOSTNAME.csr
  5719. #+END_SRC
  5720. For the email address it's a good idea to use postmaster@mydomainname.
  5721. Use a random 20 character password, and keep a note of it. We'll remove this later.
  5722. View the request with:
  5723. #+BEGIN_SRC: bash
  5724. cat /etc/ssl/requests/$HOSTNAME.csr
  5725. #+END_SRC
  5726. 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.
  5727. Log into your StartSSL account and select *Retrieve Certificate* from the *Tool Box* tab. Copy the text.
  5728. #+BEGIN_SRC: bash
  5729. editor /etc/ssl/certs/$HOSTNAME.crt
  5730. #+END_SRC
  5731. Paste the public key, then save and exit. Then on the BBB.
  5732. #+BEGIN_SRC: bash
  5733. mkdir /etc/ssl/roots
  5734. mkdir /etc/ssl/chains
  5735. wget "http://www.startssl.com/certs/ca.pem" --output-document="/etc/ssl/roots/startssl-root.ca"
  5736. wget "http://www.startssl.com/certs/sub.class1.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class1.server.ca.pem"
  5737. wget "http://www.startssl.com/certs/sub.class2.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class2.server.ca.pem"
  5738. wget "http://www.startssl.com/certs/sub.class3.server.ca.pem" --output-document="/etc/ssl/chains/startssl-sub.class3.server.ca.pem"
  5739. ln -s "/etc/ssl/roots/startssl-root.ca" "/etc/ssl/roots/$HOSTNAME-root.ca"
  5740. ln -s "/etc/ssl/chains/startssl-sub.class1.server.ca.pem" "/etc/ssl/chains/$HOSTNAME.ca"
  5741. cp "/etc/ssl/certs/$HOSTNAME.crt" "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5742. test -e "/etc/ssl/chains/$HOSTNAME.ca" && cat "/etc/ssl/chains/$HOSTNAME.ca" >> "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5743. test -e "/etc/ssl/roots/$HOSTNAME-root.ca" && cat "/etc/ssl/roots/$HOSTNAME-root.ca" >> "/etc/ssl/certs/$HOSTNAME.crt+chain+root"
  5744. #+END_SRC
  5745. To avoid any possibility of the certificates being accidentally overwritten by self-signed ones at a later date you can create backups.
  5746. #+BEGIN_SRC: bash
  5747. mkdir /etc/ssl/backups
  5748. mkdir /etc/ssl/backups/certs
  5749. mkdir /etc/ssl/backups/private
  5750. cp /etc/ssl/certs/$HOSTNAME* /etc/ssl/backups/certs/
  5751. cp /etc/ssl/private/$HOSTNAME* /etc/ssl/backups/private/
  5752. chmod -R 400 /etc/ssl/backups/certs/*
  5753. chmod -R 400 /etc/ssl/backups/private/*
  5754. #+END_SRC
  5755. 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.
  5756. #+BEGIN_SRC: bash
  5757. openssl rsa -in /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/private/$HOSTNAME.new.key
  5758. cp /etc/ssl/private/$HOSTNAME.new.key /etc/ssl/private/$HOSTNAME.key
  5759. shred -zu /etc/ssl/private/$HOSTNAME.new.key
  5760. #+END_SRC
  5761. Edit your Apache configuration file.
  5762. #+BEGIN_SRC: bash
  5763. editor /etc/apache2/sites-available/$HOSTNAME
  5764. #+END_SRC
  5765. Add the following to the section which starts with *<VirtualHost *:443>*
  5766. #+BEGIN_SRC: bash
  5767. SSLCertificateChainFile /etc/ssl/chains/startssl-sub.class1.server.ca.pem
  5768. #+END_SRC
  5769. Save and exit, then restart apache.
  5770. #+BEGIN_SRC: bash
  5771. service apache2 restart
  5772. #+END_SRC
  5773. 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]].
  5774. * Deprecated
  5775. The following items have been deprecated until such time as a successful installation is achieved.
  5776. ** Gitlab
  5777. Install some dependencies:
  5778. #+BEGIN_SRC: bash
  5779. apt-get update -y
  5780. apt-get upgrade -y
  5781. apt-get install sudo -y
  5782. 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
  5783. #+END_SRC
  5784. Install bundler
  5785. #+BEGIN_SRC: bash
  5786. gem install bundler --no-ri --no-rdoc
  5787. #+END_SRC
  5788. Create a user for running Gitlab.
  5789. #+BEGIN_SRC: bash
  5790. adduser --disabled-login --gecos 'GitLab' git
  5791. #+END_SRC
  5792. Install mysql (it may already be installed).
  5793. #+BEGIN_SRC: bash
  5794. apt-get install -y mysql-server mysql-client libmysqlclient-dev
  5795. mysql_secure_installation
  5796. mysql -u root -p
  5797. #+END_SRC
  5798. Enter the following commands, substituting /gitlabpassword/ with a password to be used for the Gitlab installation.
  5799. #+BEGIN_SRC: bash
  5800. CREATE USER 'git'@'localhost' IDENTIFIED BY 'gitlabpassword';
  5801. SET storage_engine=INNODB;
  5802. CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  5803. GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
  5804. quit
  5805. #+END_SRC
  5806. Obtain the code and install it.
  5807. #+BEGIN_SRC: bash
  5808. cd /home/git
  5809. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-8-stable gitlab
  5810. cd /home/git/gitlab
  5811. sudo -u git -H cp /home/git/gitlab/config/gitlab.yml.example /home/git/gitlab/config/gitlab.yml
  5812. sudo -u git -H editor /home/git/gitlab/config/gitlab.yml
  5813. #+END_SRC
  5814. Set /host/ to your gitlab domain name, /port/ to 443 and /https/ to true, then save and exit.
  5815. #+BEGIN_SRC: bash
  5816. chown -R git /home/git/gitlab/log/
  5817. chown -R git /home/git/gitlab/tmp/
  5818. chmod -R u+rwX /home/git/gitlab/log/
  5819. chmod -R u+rwX /home/git/gitlab/tmp/
  5820. sudo -u git -H mkdir /home/git/gitlab-satellites
  5821. chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites
  5822. chmod -R u+rwX /home/git/gitlab/tmp/pids/
  5823. chmod -R u+rwX /home/git/gitlab/tmp/sockets/
  5824. chmod -R u+rwX /home/git/gitlab/public/uploads
  5825. sudo -u git -H cp /home/git/gitlab/config/unicorn.rb.example /home/git/gitlab/config/unicorn.rb
  5826. #sudo -u git -H editor /home/git/gitlab/config/unicorn.rb
  5827. sudo -u git -H cp /home/git/gitlab/config/initializers/rack_attack.rb.example /home/git/gitlab/config/initializers/rack_attack.rb
  5828. sudo -u git -H git config --global user.name "GitLab"
  5829. sudo -u git -H git config --global user.email "gitlab@localhost"
  5830. sudo -u git -H git config --global core.autocrlf input
  5831. sudo -u git cp /home/git/gitlab/config/database.yml.mysql /home/git/gitlab/config/database.yml
  5832. sudo -u git -H chmod o-rwx /home/git/gitlab/config/database.yml
  5833. sudo -u git -H bundle install --deployment --without development test postgres aws
  5834. #+END_SRC
  5835. Fails here with:
  5836. /Could not find libv8-3.16.14.3 in any of the sources/
  5837. /Run `bundle install` to install missing gems./
  5838. #+BEGIN_SRC: bash
  5839. sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  5840. sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.3] REDIS_URL=redis://localhost:6379
  5841. sudo -u git -H editor /home/git/gitlab-shell/config.yml
  5842. cp lib/support/init.d/gitlab /etc/init.d/gitlab
  5843. update-rc.d gitlab defaults 21
  5844. cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
  5845. sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
  5846. sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
  5847. service gitlab start
  5848. #+END_SRC
  5849. Set up the Apache configuration.
  5850. #+BEGIN_SRC: bash
  5851. cp lib/support/apache/gitlab /etc/apache2/sites-available/mygitlabdomain
  5852. editor /etc/apache2/sites-available/mygitlabdomain
  5853. #+END_SRC
  5854. Set your domain name and email accordingly.
  5855. #+BEGIN_SRC: bash
  5856. a2ensite mygitlabdomain
  5857. #+END_SRC
  5858. ** Monkeysphere
  5859. #+BEGIN_SRC: bash
  5860. aptitude install monkeysphere
  5861. aptitude install msva-perl
  5862. aptitude install xul-ext-monkeysphere
  5863. export HOSTNAME=mydomainname.com
  5864. monkeysphere-host import-key /etc/ssh/ssh_host_rsa_key ssh://$HOSTNAME
  5865. monkeysphere-host publish-key
  5866. #+END_SRC
  5867. ** Diaspora
  5868. First install some dependencies:
  5869. #+BEGIN_SRC: bash
  5870. 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
  5871. #+END_SRC
  5872. If there is trouble with dependencies select 'n' then 'y' to the solution.
  5873. Create a diaspora user.
  5874. #+BEGIN_SRC: bash
  5875. adduser --disabled-login diaspora
  5876. su diaspora
  5877. cd ~/
  5878. curl -L dspr.tk/1t | bash
  5879. echo "[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"" >> ~/.bashrc
  5880. . ~/.bashrc
  5881. rvm autolibs read-only
  5882. rvm install ruby-2.0.0-p481
  5883. git clone https://github.com/diaspora/diaspora.git
  5884. cd diaspora
  5885. #+END_SRC
  5886. Select 'y' to trust /home/diaspora/diaspora/.rvmrc
  5887. #+BEGIN_SRC: bash
  5888. cp config/diaspora.yml.example config/diaspora.yml
  5889. editor config/diaspora.yml
  5890. #+END_SRC
  5891. Set *url* to https://mydiasporadomainname.com/
  5892. Set *certificate_authorities* to */etc/ssl/certs/ca-certificates.crt*
  5893. Set *require_ssl* to *true*
  5894. Set *single_process_mode* to *false*
  5895. Set *port* to 3001
  5896. Set *rails_environment* to 'production'.
  5897. Set *pod_name* to the name of your pod.
  5898. Set *enable_registrations* to *true*.
  5899. Set *autofollow_on_join* to *false*
  5900. Under *captcha* set *enable* to *false*
  5901. Under *invitations* set *open* to *true*
  5902. Set *bitcoin_address* if you wish to accept donations.
  5903. Under *mail* set *enable* to *true*
  5904. Set *sender_address* to no-reply@mydiasporadomainname.com
  5905. Set *method* to *sendmail*
  5906. Set *exim_fix* to true.
  5907. Under *admins* set *account* to your username
  5908. Under *admins* set *podmin_email* to your email address
  5909. Save and exit.
  5910. #+BEGIN_SRC: bash
  5911. RAILS_ENV=production bundle install --without test development
  5912. #+END_SRC
  5913. This will take quite a while to install.
  5914. #+BEGIN_SRC: bash
  5915. RAILS_ENV=production bundle exec rake db:create db:schema:load
  5916. bundle exec rake assets:precompile
  5917. #+END_SRC
  5918. Alter the Apache configuration.
  5919. #+BEGIN_SRC: bash
  5920. exit
  5921. export HOSTNAME=mydiasporadomainname.com
  5922. editor /etc/apache2/sites-available/$HOSTNAME
  5923. #+END_SRC
  5924. Delete anything which already exists and add the following:
  5925. #+BEGIN_SRC: bash
  5926. <VirtualHost *:80>
  5927. ServerName mydiasporadomainname.com
  5928. ServerAlias www.mydiasporadomainname.com
  5929. RedirectPermanent / https://mydiasporadomainname.com/
  5930. </VirtualHost>
  5931. <VirtualHost *:443>
  5932. ServerName mydiasporadomainname.com
  5933. ServerAlias www.mydiasporadomainname.com
  5934. DocumentRoot /home/diaspora/diaspora/public
  5935. RewriteEngine On
  5936. RewriteCond %{HTTP_HOST} !^mydiasporadomainname\.com [NC]
  5937. RewriteRule ^/(.*)$ https://mydiasporadomainname\.com/$1 [L,R,QSA]
  5938. RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  5939. RewriteRule ^/(.*)$ balancer://upstream%{REQUEST_URI} [P,QSA,L]
  5940. <Proxy balancer://upstream>
  5941. BalancerMember http://127.0.0.1:3001
  5942. </Proxy>
  5943. ProxyRequests Off
  5944. ProxyVia On
  5945. ProxyPreserveHost On
  5946. RequestHeader set X_FORWARDED_PROTO https
  5947. <Proxy *>
  5948. # Apache < 2.4
  5949. Order allow,deny
  5950. Allow from all
  5951. # Apache >= 2.4
  5952. #Require all granted
  5953. </Proxy>
  5954. <Directory /home/diaspora/diaspora/public>
  5955. Options -MultiViews
  5956. # Apache < 2.4
  5957. Allow from all
  5958. AllowOverride all
  5959. # Apache >= 2.4
  5960. #Require all granted
  5961. </Directory>
  5962. SSLEngine On
  5963. SSLCertificateFile /etc/ssl/certs/mydiasporadomainname.com.crt
  5964. SSLCertificateKeyFile /etc/ssl/private/mydiasporadomainname.com.key
  5965. # maybe not needed, need for example for startssl to point to a local
  5966. # copy of http://www.startssl.com/certs/sub.class1.server.ca.pem
  5967. SSLCertificateChainFile /etc/ssl/chains/startssl-sub.class1.server.ca.pem
  5968. # Based on https://wiki.mozilla.org/Security/Server_Side_TLS - consider as global configuration
  5969. SSLProtocol all -SSLv2
  5970. 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
  5971. SSLHonorCipherOrder on
  5972. SSLCompression off
  5973. </VirtualHost>
  5974. #+END_SRC
  5975. Save and exit.
  5976. #+BEGIN_SRC: bash
  5977. editor /usr/bin/rundiaspora
  5978. #+END_SRC
  5979. Add the following.
  5980. #+BEGIN_SRC: bash
  5981. #!/bin/sh
  5982. USERNAME=diaspora
  5983. COMMAND="cd /home/$USERNAME/diaspora; /bin/sh /home/$USERNAME/diaspora/script/server > /home/$USERNAME/diaspora.log"
  5984. su -l $USERNAME -c '$COMMAND'
  5985. #+END_SRC
  5986. Save and exit.
  5987. Create an init script:
  5988. #+BEGIN_SRC: bash
  5989. chmod +x /usr/bin/rundiaspora
  5990. editor /etc/init.d/diaspora
  5991. #+END_SRC
  5992. Add the following.
  5993. #+BEGIN_SRC: bash
  5994. #!/bin/bash
  5995. # /etc/init.d/diaspora
  5996. ### BEGIN INIT INFO
  5997. # Provides: diaspora
  5998. # Required-Start: $remote_fs $syslog
  5999. # Required-Stop: $remote_fs $syslog
  6000. # Default-Start: 2 3 4 5
  6001. # Default-Stop: 0 1 6
  6002. # Short-Description: starts diaspora
  6003. # Description: Starts Diaspora.
  6004. ### END INIT INFO
  6005. # Author: Bob Mottram <bob@robotics.uk.to>
  6006. #Settings
  6007. SERVICE='diaspora'
  6008. HISTORY=1024
  6009. USERNAME='diaspora'
  6010. COMMAND="rundiaspora"
  6011. NICELEVEL=19 # from 0-19
  6012. INVOCATION="nice -n ${NICELEVEL} ${COMMAND}"
  6013. PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'
  6014. diaspora_start() {
  6015. echo -n $"Starting $SERVICE service"
  6016. screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}
  6017. # su --command "screen -h ${HISTORY} -dmS ${SERVICE} ${INVOCATION}" $USERNAME
  6018. # su -l $USERNAME -c "$COMMAND"
  6019. # RETVAL=$?
  6020. echo
  6021. }
  6022. diaspora_stop() {
  6023. echo -n $"Stopping $SERVICE service"
  6024. screen -p 0 -S ${SERVICE} -X stuff "'^C'"
  6025. # su --command "screen -p 0 -S ${SERVICE} -X stuff "'^C'"" $USERNAME
  6026. # su -l $USERNAME -c "/home/$USERNAME/diaspora/script/server"
  6027. # RETVAL=$?
  6028. echo
  6029. }
  6030. #Start-Stop here
  6031. case "$1" in
  6032. start)
  6033. diaspora_start
  6034. ;;
  6035. stop)
  6036. diaspora_stop
  6037. ;;
  6038. restart)
  6039. diaspora_stop
  6040. diaspora_start
  6041. ;;
  6042. *)
  6043. echo "Usage: $0 {start|stop|restart}"
  6044. exit 1
  6045. ;;
  6046. esac
  6047. exit 0
  6048. #+END_SRC
  6049. Save and exit.
  6050. #+BEGIN_SRC: bash
  6051. chmod +x /etc/init.d/diaspora
  6052. update-rc.d diaspora defaults
  6053. service diaspora start
  6054. #+END_SRC
  6055. Now enable the site:
  6056. #+BEGIN_SRC: bash
  6057. a2enmod ssl
  6058. a2enmod rewrite
  6059. a2enmod headers
  6060. a2enmod proxy
  6061. a2enmod proxy_connect
  6062. a2enmod proxy_http
  6063. a2enmod proxy_balancer
  6064. a2ensite $HOSTNAME
  6065. service apache2 restart
  6066. #+END_SRC
  6067. * Related projects
  6068. * [[https://freedomboxfoundation.org/][Freedombox]]
  6069. * [[https://arkos.io/][ArkOS]]
  6070. * [[https://github.com/JoshData/mailinabox][Mail-in-a-Box]]
  6071. * [[https://github.com/sandstorm-io/sandstorm][Sandstorm]]