├── .gitignore ├── LICENSE ├── cheat-sheets └── vim.md ├── configuration-files ├── .Xresources ├── .bashrc ├── .gitconfig ├── .inputrc ├── .lynx ├── .mailcap ├── .muttrc ├── .muttrc.fastmail ├── .muttrc.hotmail ├── .muttrc.tombstone ├── .shell-colors ├── .vimrc └── .xinitrc ├── hacking └── programming.md ├── linux-packages ├── acl.md ├── attr.md ├── autoconf.md ├── automake.md ├── awk.md ├── bc.md ├── bison.md ├── check.md ├── dbm.md ├── dejagnu.md ├── diff.md ├── expat.md ├── expect.md ├── findutils.md ├── flex.md ├── gdb.md ├── gettext.md ├── gmp.md ├── gperf.md ├── grep.md ├── groff.md ├── gzip.md ├── inetutils.md ├── intltool.md ├── iproute2.md ├── libcap.md ├── libpipeline.md ├── m4.md ├── make.md ├── mpc.md ├── mpfr.md ├── ncurses.md ├── patch.md ├── pkgconfig.md └── sed.md ├── procedures ├── configuring-i3.md ├── installing-freebsd-server.md ├── installing-gentoo-laptop-firewall.md ├── installing-gentoo-laptop-kernel.md ├── installing-gentoo-laptop-network.md ├── installing-gentoo-server-firewall.md ├── installing-gentoo-server-kernel.md ├── installing-gentoo-server-network.md ├── installing-gentoo.md ├── installing-openbsd-server.md ├── installing-salix-laptop.md ├── installing-salix-server.md ├── installing-salix-tombstone.md ├── installing-slackware-on-my-laptop.md ├── opting-out-from-tracking.md ├── self-hosting.md ├── writing-correct-c-function.md └── yubikey-pgp.md └── scripts ├── wireless-scan └── wireless-up /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Mathieu Desrochers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /cheat-sheets/vim.md: -------------------------------------------------------------------------------- 1 | Modes 2 | ----- 3 | 4 | i: insert mode (before current character) 5 | I: insert mode (before first non blank character) 6 | a: insert mode (after current character) 7 | A: insert mode (end of line) 8 | s: insert mode (deletes current character) 9 | S: insert mode (deletes current line) 10 | C: insert mode (deletes rest of line) 11 | 12 | C-o: insert normal mode (one off) 13 | 14 | R: replace mode 15 | 16 | v: visual mode 17 | V: visual mode (line) 18 | C-v: visual mode (block) 19 | gv: visual mode (last selection) 20 | 21 | :: command line mode 22 | 23 | Operators 24 | --------- 25 | 26 | c: change (uppercase to end of line) 27 | d: delete (uppercase to end of line) 28 | y: yank 29 | 30 | r: replace character 31 | g~: swap case 32 | gu: make lowercase 33 | gU: make uppercase 34 | 35 | >: shift right 36 | <: shift left 37 | =: autoindent 38 | 39 | !: filter through external program 40 | 41 | Motions 42 | ------- 43 | 44 | h: left one character 45 | j: down one line 46 | k: up one line 47 | l: right one character 48 | 49 | w: next word start (uppercase ignores punctuation) 50 | b: previous word start (uppercase ignores punctuation) 51 | e: next word end (uppercase ignores punctuation) 52 | 53 | 0: first character of the line 54 | ^: first non-blank character of the line 55 | $: last character of the line 56 | 57 | f: next occurrence of a character on the line 58 | F: previous occurrence of a character on the line 59 | t: until next occurrence of a character on the line 60 | T: until previous occurence of a character on the line 61 | ;: repeat last f, F, t or T in the same direction 62 | ,: repeat last f, F, t or T in the opposite direction 63 | 64 | gg: goto first line 65 | G: goto line, last by default 66 | 67 | /: search counts as a motion 68 | 69 | Grammar 70 | ------- 71 | 72 | syntax: count + operator + count + motion 73 | shotcut: count + operator + operator (current line) 74 | 75 | Text objects 76 | ------------ 77 | 78 | i: inside pending object 79 | a: around pending object 80 | 81 | w: word object 82 | p: paragraph object 83 | ": double quotes object 84 | ): parenthese object 85 | ]: square bracket object 86 | }: curly bracket object 87 | 88 | Navigation 89 | ---------- 90 | 91 | ctrl-b: up one screen 92 | ctrl-u: up one half-screen 93 | ctrl-d: down one half-screen 94 | ctrl-f: down one screen 95 | 96 | zz: center current line in the middle of screen 97 | 98 | {: start of current paragraph 99 | }: end of current paragraph 100 | 101 | %: matching (, [ or { 102 | 103 | C-o: jump previous location 104 | C-i: jump next location 105 | 106 | ma: sets mark a (uppercase letter cross buffers) 107 | `a: jump to mark a 108 | 109 | Normal mode 110 | ----------- 111 | 112 | @:: repeat last ex command 113 | 114 | Insert mode 115 | ----------- 116 | 117 | C-u: delete previous word 118 | C-w: delete to start of line 119 | 120 | C-r0: paste from of register 0 121 | C-r=: paste from expression register 122 | 123 | Visual mode 124 | ----------- 125 | 126 | I: insert before each line of block 127 | A: append after each line of block 128 | 129 | o: toggle end of block 130 | 131 | Command line grammar 132 | -------------------- 133 | 134 | range: 135 | address [offset] [, [address [offset]]] 136 | 137 | address: 138 | 1: line number 1 139 | .: current line 140 | 0: start of file 141 | $: end of file 142 | %: whole file 143 | /pattern/: search result location 144 | `m: mark m 145 | 146 | offset: 147 | {+|-}n 148 | 149 | Command line mode 150 | ----------------- 151 | 152 | [range] delete [x]: delete lines to register x 153 | [range] yank [x]: yank lines to register x 154 | [line] put x: put register x after line 155 | 156 | [range] copy address: copy lines 157 | [range] move address: move lines 158 | [range] normal x: run normal command x on every line 159 | [range] join: join lines 160 | 161 | read !x: put shell command x output 162 | [range] write !x: invoke shell command x with every line 163 | [range] !x: filters range through shell command x 164 | 165 | !x: execute shell command x 166 | !x %: current buffer name as parameter 167 | 168 | Tab: cycle through autocompleted commands 169 | C-d: suggest autocompleted commands 170 | 171 | C-r0: paste from of register 0 172 | C-r=: paste from expression register 173 | C-w: paste current word 174 | 175 | q:: open command line window from normal mode 176 | C-f: open command line window from command line mode 177 | Enter: execute command 178 | 179 | Buffers 180 | ------- 181 | 182 | :ls: list buffers (%visible, #alternate, +dirty) 183 | C-^: toggle between visible and alternate 184 | 185 | :bnext: next buffer 186 | :bprevious: previous buffer 187 | :bdelete N: delete buffer N 188 | 189 | Argument list 190 | ------------- 191 | 192 | :args: shows argument list ([active]) 193 | :args glob: load files in argument list 194 | :args `cat myfiles`: loat files by backtick expansion 195 | 196 | :next: next file in argument list 197 | :previous: previous file in argument list 198 | 199 | :argdo x: execute command x on every file in argument list 200 | 201 | Split windows 202 | ------------- 203 | 204 | C-ws: horizontal split 205 | C-wv: vertical split 206 | 207 | C-ww: cycle through windows 208 | C-w[h|j|k|l]: cycle to left|bottom|up|right window 209 | C-wT: move window to new tab page 210 | 211 | :close: close window 212 | :only: close other windows 213 | 214 | Tab pages 215 | --------- 216 | 217 | :tabedit: new tab page 218 | :tabedit file: edit file in new tab page 219 | 220 | gt: next tab page 221 | Ngt: tab page by number 222 | gT: previous tab page 223 | 224 | :tabclose: close tab page 225 | :tabonly: close other tab pages 226 | -------------------------------------------------------------------------------- /configuration-files/.Xresources: -------------------------------------------------------------------------------- 1 | UXTerm*renderFont: true 2 | UXTerm*faceName: xos4 Terminus 3 | UXTerm*faceSize: 14 4 | -------------------------------------------------------------------------------- /configuration-files/.bashrc: -------------------------------------------------------------------------------- 1 | export CLICOLOR="YES" 2 | ~/.shell-colors 3 | PS1="\[\033[32m\]\u@\h:\w\\$\[\033[0m\] " 4 | -------------------------------------------------------------------------------- /configuration-files/.gitconfig: -------------------------------------------------------------------------------- 1 | [user] 2 | email = mathieu@desrochers 3 | name = Mathieu Desrochers 4 | [core] 5 | pager = less -FXRS 6 | -------------------------------------------------------------------------------- /configuration-files/.inputrc: -------------------------------------------------------------------------------- 1 | "\e[1;5C": forward-word 2 | "\e[1;5D": backward-word 3 | -------------------------------------------------------------------------------- /configuration-files/.lynx: -------------------------------------------------------------------------------- 1 | INCLUDE:/etc/lynx.cfg 2 | 3 | AUTO_SESSION:FALSE 4 | SET_COOKIES:FALSE 5 | PERSISTENT_COOKIES:FALSE 6 | PREFERRED_LANGUAGE:en 7 | 8 | STARTFILE:https://www.google.ca 9 | -------------------------------------------------------------------------------- /configuration-files/.mailcap: -------------------------------------------------------------------------------- 1 | text/html; lynx -dump %s; nametemplate=%s.html; copiousoutput; 2 | -------------------------------------------------------------------------------- /configuration-files/.muttrc: -------------------------------------------------------------------------------- 1 | set ssl_force_tls = yes 2 | set imap_keepalive = 60 3 | 4 | set header_cache = "~/.mutt/cache/headers" 5 | set message_cachedir = "~/.mutt/cache/bodies" 6 | set certificate_file = "~/.mutt/certificates" 7 | 8 | set editor = vim 9 | 10 | set sort = reverse-date-received 11 | set move = no 12 | 13 | auto_view = text/html 14 | alternative_order = text/plain text/html 15 | 16 | source ~/.muttrc.hotmail 17 | folder-hook "imaps://imap-mail.outlook.com:993" 'source ~/.muttrc.hotmail' 18 | macro index 'imaps://imap-mail.outlook.com:993' 19 | 20 | source ~/.muttrc.tombstone 21 | folder-hook "imaps://mathieu-desrochers.com:993" 'source ~/.muttrc.tombstone' 22 | macro index 'imaps://mathieu-desrochers.com:993' 23 | -------------------------------------------------------------------------------- /configuration-files/.muttrc.fastmail: -------------------------------------------------------------------------------- 1 | set from = "*****@fastmail.com" 2 | set realname = "Mathieu Desrochers" 3 | 4 | set imap_user = "*****@fastmail.com" 5 | set imap_pass = "" 6 | set folder = "imaps://imap.fastmail.com:993" 7 | 8 | set spoolfile = "+INBOX" 9 | set postponed = "+Drafts" 10 | set record = "+Sent" 11 | -------------------------------------------------------------------------------- /configuration-files/.muttrc.hotmail: -------------------------------------------------------------------------------- 1 | set from = "*****@hotmail.com" 2 | set realname = "Mathieu Desrochers" 3 | 4 | set imap_user = "*****@hotmail.com" 5 | set imap_pass = "" 6 | set folder = "imaps://imap-mail.outlook.com:993" 7 | 8 | set spoolfile = "+INBOX" 9 | set postponed = "+Drafts" 10 | set record = "Sent" 11 | -------------------------------------------------------------------------------- /configuration-files/.muttrc.tombstone: -------------------------------------------------------------------------------- 1 | set from = "*****@matheu-desrochers.com" 2 | set realname = "Mathieu Desrochers" 3 | 4 | set imap_user = "*****" 5 | set imap_pass = "" 6 | set folder = "imaps://mathieu-desrochers.com:993" 7 | 8 | set smtp_url = "smtp://*****@mathieu-desrochers.com:587/" 9 | set smtp_pass = "" 10 | 11 | set spoolfile = "+INBOX" 12 | set postponed = "+drafts" 13 | set record = "+sent" 14 | -------------------------------------------------------------------------------- /configuration-files/.shell-colors: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # base16-shell (https://github.com/chriskempson/base16-shell) 3 | # Base16 Shell template by Chris Kempson (http://chriskempson.com) 4 | # Default Dark scheme by Chris Kempson (http://chriskempson.com) 5 | 6 | # This script doesn't support linux console (use 'vconsole' template instead) 7 | if [ "${TERM%%-*}" = 'linux' ]; then 8 | return 2>/dev/null || exit 0 9 | fi 10 | 11 | color00="18/18/18" # Base 00 - Black 12 | color01="ab/46/42" # Base 08 - Red 13 | color02="a1/b5/6c" # Base 0B - Green 14 | color03="f7/ca/88" # Base 0A - Yellow 15 | color04="7c/af/c2" # Base 0D - Blue 16 | color05="ba/8b/af" # Base 0E - Magenta 17 | color06="86/c1/b9" # Base 0C - Cyan 18 | color07="d8/d8/d8" # Base 05 - White 19 | color08="58/58/58" # Base 03 - Bright Black 20 | color09=$color01 # Base 08 - Bright Red 21 | color10=$color02 # Base 0B - Bright Green 22 | color11=$color03 # Base 0A - Bright Yellow 23 | color12=$color04 # Base 0D - Bright Blue 24 | color13=$color05 # Base 0E - Bright Magenta 25 | color14=$color06 # Base 0C - Bright Cyan 26 | color15="f8/f8/f8" # Base 07 - Bright White 27 | color16="dc/96/56" # Base 09 28 | color17="a1/69/46" # Base 0F 29 | color18="28/28/28" # Base 01 30 | color19="38/38/38" # Base 02 31 | color20="b8/b8/b8" # Base 04 32 | color21="e8/e8/e8" # Base 06 33 | color_foreground="d8/d8/d8" # Base 05 34 | color_background="18/18/18" # Base 00 35 | color_cursor="d8/d8/d8" # Base 05 36 | 37 | if [ -n "$TMUX" ]; then 38 | # Tell tmux to pass the escape sequences through 39 | # (Source: http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324) 40 | printf_template='\033Ptmux;\033\033]4;%d;rgb:%s\033\033\\\033\\' 41 | printf_template_var='\033Ptmux;\033\033]%d;rgb:%s\033\033\\\033\\' 42 | printf_template_custom='\033Ptmux;\033\033]%s%s\033\033\\\033\\' 43 | elif [ "${TERM%%-*}" = "screen" ]; then 44 | # GNU screen (screen, screen-256color, screen-256color-bce) 45 | printf_template='\033P\033]4;%d;rgb:%s\033\\' 46 | printf_template_var='\033P\033]%d;rgb:%s\033\\' 47 | printf_template_custom='\033P\033]%s%s\033\\' 48 | else 49 | printf_template='\033]4;%d;rgb:%s\033\\' 50 | printf_template_var='\033]%d;rgb:%s\033\\' 51 | printf_template_custom='\033]%s%s\033\\' 52 | fi 53 | 54 | # 16 color space 55 | printf $printf_template 0 $color00 56 | printf $printf_template 1 $color01 57 | printf $printf_template 2 $color02 58 | printf $printf_template 3 $color03 59 | printf $printf_template 4 $color04 60 | printf $printf_template 5 $color05 61 | printf $printf_template 6 $color06 62 | printf $printf_template 7 $color07 63 | printf $printf_template 8 $color08 64 | printf $printf_template 9 $color09 65 | printf $printf_template 10 $color10 66 | printf $printf_template 11 $color11 67 | printf $printf_template 12 $color12 68 | printf $printf_template 13 $color13 69 | printf $printf_template 14 $color14 70 | printf $printf_template 15 $color15 71 | 72 | # 256 color space 73 | printf $printf_template 16 $color16 74 | printf $printf_template 17 $color17 75 | printf $printf_template 18 $color18 76 | printf $printf_template 19 $color19 77 | printf $printf_template 20 $color20 78 | printf $printf_template 21 $color21 79 | 80 | # foreground / background / cursor color 81 | if [ -n "$ITERM_SESSION_ID" ]; then 82 | # iTerm2 proprietary escape codes 83 | printf $printf_template_custom Pg d8d8d8 # forground 84 | printf $printf_template_custom Ph 181818 # background 85 | printf $printf_template_custom Pi d8d8d8 # bold color 86 | printf $printf_template_custom Pj 383838 # selection color 87 | printf $printf_template_custom Pk d8d8d8 # selected text color 88 | printf $printf_template_custom Pl d8d8d8 # cursor 89 | printf $printf_template_custom Pm 181818 # cursor text 90 | else 91 | printf $printf_template_var 10 $color_foreground 92 | printf $printf_template_var 11 $color_background 93 | printf $printf_template_custom 12 ";7" # cursor (reverse video) 94 | fi 95 | 96 | # clean up 97 | unset printf_template 98 | unset printf_template_var 99 | unset color00 100 | unset color01 101 | unset color02 102 | unset color03 103 | unset color04 104 | unset color05 105 | unset color06 106 | unset color07 107 | unset color08 108 | unset color09 109 | unset color10 110 | unset color11 111 | unset color12 112 | unset color13 113 | unset color14 114 | unset color15 115 | unset color16 116 | unset color17 117 | unset color18 118 | unset color19 119 | unset color20 120 | unset color21 121 | unset color_foreground 122 | unset color_background 123 | unset color_cursor 124 | -------------------------------------------------------------------------------- /configuration-files/.vimrc: -------------------------------------------------------------------------------- 1 | set tabstop=2 2 | set softtabstop=2 3 | set shiftwidth=2 4 | set expandtab 5 | 6 | set encoding=utf-8 7 | set fileencoding=utf-8 8 | 9 | syntax enable 10 | 11 | set list 12 | set listchars=tab:··,trail:· 13 | 14 | set hlsearch 15 | nnoremap :noh 16 | 17 | set tags=./tags; 18 | 19 | set nobackup 20 | set noswapfile 21 | set noundofile 22 | 23 | set nocompatible 24 | filetype off 25 | set rtp+=~/.vim/bundle/Vundle.vim 26 | call vundle#begin() 27 | Plugin 'jeetsukumaran/vim-buffergator' 28 | Plugin 'kien/ctrlp.vim' 29 | Plugin 'mxw/vim-jsx' 30 | Plugin 'pangloss/vim-javascript' 31 | Plugin 'rking/ag.vim' 32 | Plugin 'vim-scripts/paredit.vim' 33 | Plugin 'VundleVim/Vundle.vim' 34 | Plugin 'rust-lang/rust.vim' 35 | call vundle#end() 36 | filetype plugin on 37 | 38 | let g:ctrlp_custom_ignore = {'file' : '\v\.(o)$' } 39 | let g:buffergator_viewport_split_policy="B" 40 | 41 | au BufRead,BufNewFile *.svelte set filetype=html 42 | -------------------------------------------------------------------------------- /configuration-files/.xinitrc: -------------------------------------------------------------------------------- 1 | xrandr --newmode "1280x720_60.00" 74.50 1280 1344 1472 1664 720 723 728 748 -hsync +vsync 2 | xrandr --addmode eDP-1 1280x720_60.00 3 | xrandr --output eDP-1 --mode 1280x720_60.00 4 | xrdb -merge ~/.Xresources 5 | exec i3 -c .i3 6 | -------------------------------------------------------------------------------- /hacking/programming.md: -------------------------------------------------------------------------------- 1 | Compiling a test program 2 | ------------------------ 3 | Run the following commands. 4 | 5 | $ cat > main.c << EOF 6 | #include 7 | 8 | int main() 9 | { 10 | int i; 11 | for (i = 0; i < 10; i++) 12 | { 13 | printf("Hello\n"); 14 | } 15 | return 0; 16 | } 17 | EOF 18 | 19 | $ gcc main.c -o main 20 | 21 | Realizing it's all assembly in the end 22 | -------------------------------------- 23 | Run the following command. 24 | 25 | $ objdump -M intel -d main 26 | ... 27 | 0000000000400628
: 28 | 400628: 55 push rbp 29 | 400629: 48 89 e5 mov rbp,rsp 30 | 40062c: 48 83 ec 10 sub rsp,0x10 31 | 400630: c7 45 fc 00 00 00 00 mov DWORD PTR [rbp-0x4],0x0 32 | 400637: eb 0e jmp 400647 33 | 400639: bf 2c 07 40 00 mov edi,0x40072c 34 | 40063e: e8 6d fe ff ff call 4004b0 35 | 400643: 83 45 fc 01 add DWORD PTR [rbp-0x4],0x1 36 | 400647: 83 7d fc 09 cmp DWORD PTR [rbp-0x4],0x9 37 | 40064b: 7e ec jle 400639 38 | 40064d: b8 00 00 00 00 mov eax,0x0 39 | 400652: c9 leave 40 | 400653: c3 ret 41 | ... 42 | 43 | This is only memory containing data, some of which may represent instructions. 44 | Add a processor to read/write that memory and execute these instructions, 45 | and there is your computer. 46 | 47 | Debugging assembly 48 | ------------------ 49 | Run the following commands. 50 | 51 | $ gdb ./main 52 | 53 | (gdb) set disassembly-flavor intel 54 | 55 | (gdb) break main 56 | Breakpoint 1 at 0x40062c 57 | 58 | (gdb) run 59 | Breakpoint 1, 0x000000000040062c in main () 60 | 61 | (gdb) disassemble main 62 | Dump of assembler code for function main: 63 | 0x0000000000400628 <+0>: push rbp 64 | 0x0000000000400629 <+1>: mov rbp,rsp 65 | => 0x000000000040062c <+4>: sub rsp,0x10 66 | 0x0000000000400630 <+8>: mov DWORD PTR [rbp-0x4],0x0 67 | 0x0000000000400637 <+15>: jmp 0x400647 68 | 0x0000000000400639 <+17>: mov edi,0x40072c 69 | 0x000000000040063e <+22>: call 0x4004b0 70 | 0x0000000000400643 <+27>: add DWORD PTR [rbp-0x4],0x1 71 | 0x0000000000400647 <+31>: cmp DWORD PTR [rbp-0x4],0x9 72 | 0x000000000040064b <+35>: jle 0x400639 73 | 0x000000000040064d <+37>: mov eax,0x0 74 | 0x0000000000400652 <+42>: leave 75 | 0x0000000000400653 <+43>: ret 76 | End of assembler dump. 77 | 78 | Note that instructions take the following form: 79 | 80 | operation , 81 | 82 | Inspecting memory 83 | ----------------- 84 | 85 | -------------------------------------------------------------------------------- /linux-packages/acl.md: -------------------------------------------------------------------------------- 1 | acl 2 | --- 3 | Access Control Lists are used to define more fine-grained discretionary access rights for files and directories. 4 | 5 | Enabling 6 | -------- 7 | Edit the following file as sudo: 8 | 9 | /etc/fstab 10 | 11 | Add the following mount option to the device: 12 | 13 | acl 14 | 15 | Remount the device by running the following command: 16 | 17 | $ sudo mount / -o remount 18 | 19 | Creating a test file 20 | -------------------- 21 | Run the following command: 22 | 23 | $ touch /tmp/file 24 | 25 | Creating test groups and users 26 | ------------------------------ 27 | Run the following commands: 28 | 29 | $ sudo groupadd sales 30 | 31 | $ sudo useradd alice 32 | $ sudo useradd bob 33 | 34 | $ sudo usermod -a -G sales alice 35 | $ sudo usermod -a -G sales bob 36 | 37 | Modifying permissions 38 | --------------------- 39 | Run the following commands: 40 | 41 | $ setfacl -m group:sales:rw- /tmp/file 42 | $ setfacl -m user:bob:r-- /tmp/file 43 | 44 | Listing permissions 45 | ------------------- 46 | Run the following commands: 47 | 48 | $ ll /tmp/file 49 | -rw-rw-r--+ 1 root root 0 Jan 1 11:11 /tmp/file 50 | 51 | $ getfacl /tmp/file 52 | user::rw- 53 | user:bob:r-- 54 | group::rw- 55 | group:sales:rw- 56 | other::r-- 57 | 58 | Demonstrating permissions 59 | ------------------------- 60 | Run the following commands: 61 | 62 | $ su - alice -c "touch /tmp/file" 63 | succeeds 64 | 65 | $ su - bob -c "touch /tmp/file" 66 | touch: cannot touch ‘/tmp/file’: Permission denied 67 | -------------------------------------------------------------------------------- /linux-packages/attr.md: -------------------------------------------------------------------------------- 1 | attr 2 | ---- 3 | Extended attributes implement the ability for a user to attach name:value pairs to objects within the XFS filesystem. 4 | 5 | Creating a test file 6 | -------------------- 7 | Run the following command: 8 | 9 | $ touch file 10 | 11 | Setting a file attribute 12 | ------------------------ 13 | Run the following command: 14 | 15 | $ attr -s color -V blue file 16 | Attribute "color" set to a 4 byte value for file: 17 | blue 18 | 19 | Listing a file attributes 20 | ------------------------- 21 | Run the following command: 22 | 23 | $ attr -l file 24 | Attribute "color" has a 4 byte value for file 25 | 26 | Getting a file attribute 27 | ------------------------ 28 | Run the following command: 29 | 30 | $ attr -g color file 31 | Attribute "color" had a 4 byte value for file: 32 | blue 33 | 34 | Removing a file attribute 35 | ------------------------- 36 | Run the following command: 37 | 38 | $ attr -r color file 39 | -------------------------------------------------------------------------------- /linux-packages/autoconf.md: -------------------------------------------------------------------------------- 1 | autoconf 2 | -------- 3 | Generate configuration scripts. 4 | 5 | Creating the autoconf script 6 | ---------------------------- 7 | Run the following command: 8 | 9 | $ cat > configure.ac << "EOF" 10 | AC_INIT(myconfig, version-0.1) 11 | 12 | echo "-----------------------------------------------" 13 | echo "Testing C compiler" 14 | echo "-----------------------------------------------" 15 | AC_PROG_CC 16 | 17 | echo "-----------------------------------------------" 18 | echo "Setting C compiler" 19 | echo "-----------------------------------------------" 20 | AC_LANG(C) 21 | 22 | echo "-----------------------------------------------" 23 | echo "Checking header file" 24 | echo "-----------------------------------------------" 25 | AC_CHECK_HEADERS(stdio.h) 26 | 27 | echo "-----------------------------------------------" 28 | echo "Checking library" 29 | echo "-----------------------------------------------" 30 | AC_CHECK_LIB(c, strlen) 31 | 32 | echo "-----------------------------------------------" 33 | echo "Setting output variables" 34 | echo "-----------------------------------------------" 35 | if test "$ac_cv_header_stdio_h" == yes 36 | then 37 | AC_SUBST(STDIO_PRESENT, "sure") 38 | else 39 | AC_SUBST(STDIO_PRESENT, "nope") 40 | fi 41 | 42 | if test "$ac_cv_lib_c_strlen" == yes 43 | then 44 | AC_SUBST(STRLEN_PRESENT, "sure") 45 | else 46 | AC_SUBST(STRLEN_PRESENT, "nope") 47 | fi 48 | 49 | echo "-----------------------------------------------" 50 | echo "Writing output variables" 51 | echo "-----------------------------------------------" 52 | AC_OUTPUT(result) 53 | EOF 54 | 55 | Creating the output template 56 | ---------------------------- 57 | Run the following command: 58 | 59 | $ cat > result.in << "EOF" 60 | c compiler: @CC@ 61 | stdio is present: @STDIO_PRESENT@ 62 | strlen is present: @STRLEN_PRESENT@ 63 | EOF 64 | 65 | Generating the configuration script 66 | ----------------------------------- 67 | Run the following command: 68 | 69 | $ autoconf configure.ac > configure 70 | 71 | Running the configuration script 72 | -------------------------------- 73 | Run the following commands: 74 | 75 | $ chmod u+x configure 76 | $ ./configure 77 | $ cat result 78 | -------------------------------------------------------------------------------- /linux-packages/automake.md: -------------------------------------------------------------------------------- 1 | automake 2 | -------- 3 | Generate Makefile.in for configure from Makefile.am. 4 | 5 | Creating the program to compile 6 | ------------------------------- 7 | Run the following command: 8 | 9 | $ cat > main.c << "EOF" 10 | #include 11 | 12 | int main (void) 13 | { 14 | puts("Test"); 15 | return 0; 16 | } 17 | EOF 18 | 19 | Creating the automake instructions 20 | ---------------------------------- 21 | Run the following command: 22 | 23 | $ cat > Makefile.am << "EOF" 24 | bin_PROGRAMS = test 25 | test_SOURCES = main.c 26 | EOF 27 | 28 | Creating the automake script 29 | ---------------------------- 30 | Run the following command: 31 | 32 | $ cat > configure.ac << "EOF" 33 | echo "-----------------------------------------------" 34 | echo "Initializing autoconf" 35 | echo "-----------------------------------------------" 36 | AC_INIT([test], [version-0.1]) 37 | 38 | echo "-----------------------------------------------" 39 | echo "Initializing automake" 40 | echo "-----------------------------------------------" 41 | AM_INIT_AUTOMAKE([-Wall -Werror foreign]) 42 | 43 | echo "-----------------------------------------------" 44 | echo "Setting C compiler" 45 | echo "-----------------------------------------------" 46 | AC_PROG_CC 47 | 48 | echo "-----------------------------------------------" 49 | echo "Declaring makefiles to generate" 50 | echo "-----------------------------------------------" 51 | AC_CONFIG_FILES([Makefile]) 52 | 53 | echo "-----------------------------------------------" 54 | echo "Writing makefiles" 55 | echo "-----------------------------------------------" 56 | AC_OUTPUT 57 | EOF 58 | 59 | Generating the configuration script 60 | ----------------------------------- 61 | Run the following command: 62 | 63 | $ autoreconf --install 64 | 65 | Compiling the program 66 | --------------------- 67 | Run the following commands: 68 | 69 | $ ./configure 70 | $ make 71 | $ ./test 72 | -------------------------------------------------------------------------------- /linux-packages/awk.md: -------------------------------------------------------------------------------- 1 | awk 2 | --- 3 | Pattern scanning and processing language. 4 | 5 | Creating the test file 6 | ---------------------- 7 | Run the following command: 8 | 9 | $ cat > order.txt << "EOF" 10 | Order number: 001 11 | Customer: ACME 12 | 13 | 1 Piano 15000 14 | 5 Dogs 895 15 | 12 Bananas 6 16 | 17 | Notes: Free shipping 18 | EOF 19 | 20 | Scanning lines 21 | -------------- 22 | Run the following commands: 23 | 24 | $ cat > script.awk << "EOF" 25 | # only lines starting with a number 26 | # print the second field 27 | /^[0-9]+/ { print $2; } 28 | EOF 29 | 30 | $ awk -f script.awk < order.txt 31 | Piano 32 | Dogs 33 | Bananas 34 | 35 | $ cat > script.awk << "EOF" 36 | # only expensive items 37 | # tidle means matching regex 38 | $1 ~ /[0-9]+/ && $3 > 100 { print $2; } 39 | EOF 40 | 41 | $ awk -f script.awk < order.txt 42 | Piano 43 | Dogs 44 | 45 | Processing lines 46 | ---------------- 47 | Run the following commands: 48 | 49 | $ cat > script.awk << "EOF" 50 | BEGIN { total = 0; } 51 | /^[0-9]+/ { total += $3 } 52 | END { print "Total: ", total; } 53 | EOF 54 | 55 | $ awk -f script.awk < order.txt 56 | Total: 15901 57 | -------------------------------------------------------------------------------- /linux-packages/bc.md: -------------------------------------------------------------------------------- 1 | bc 2 | -- 3 | An arbitrary precision calculator language. 4 | 5 | Launching the interpreter 6 | ------------------------- 7 | Run the following command: 8 | 9 | $ bc 10 | 11 | Setting the scale 12 | ----------------- 13 | Type the following commands: 14 | 15 | 22 / 7 16 | 3 17 | 18 | scale = 5 19 | 20 | 22 / 7 21 | 3.14285 22 | 23 | Setting the bases 24 | ----------------- 25 | Type the following commands: 26 | 27 | ibase = 10 28 | obase = 2 29 | 30 | 42 31 | 101010 32 | 33 | Defining functions 34 | ------------------ 35 | Type the following commands: 36 | 37 | define fact(x) { 38 | if (x <= 1) return (1); 39 | return (fact(x-1) * x); 40 | } 41 | 42 | fact(50) 43 | 30414093201713378043612608166064768844377641568960512000000000000 44 | -------------------------------------------------------------------------------- /linux-packages/bison.md: -------------------------------------------------------------------------------- 1 | bison 2 | ----- 3 | An LALR(3) parser generator. 4 | 5 | Defining the lex tokens 6 | ----------------------- 7 | Run the following command: 8 | 9 | $ cat > calc.lex << "EOF" 10 | %{ 11 | #include 12 | #include "calc.tab.h" 13 | %} 14 | 15 | %% 16 | 17 | [0-9]+ { yylval = atoi(yytext); return INTEGER; } 18 | [\+\-\n] { yylval = *yytext; return *yytext; } 19 | [ ] { ; } 20 | 21 | %% 22 | 23 | int yywrap(void) { 24 | return 1; 25 | } 26 | EOF 27 | 28 | Defining the yacc syntax 29 | ------------------------ 30 | Run the following command: 31 | 32 | $ cat > calc.y << "EOF" 33 | %{ 34 | #include 35 | void yyerror(char *); 36 | %} 37 | 38 | %token INTEGER 39 | 40 | %% 41 | 42 | program: 43 | program expr '\n' { printf("%d\n", $2); } 44 | | 45 | ; 46 | 47 | expr: 48 | INTEGER { $$ = $1; } 49 | | expr '+' INTEGER { $$ = $1 + $3; } 50 | | expr '-' INTEGER { $$ = $1 - $3; } 51 | ; 52 | 53 | %% 54 | 55 | void yyerror(char *s) { 56 | fprintf(stderr, "%s\n", s); 57 | } 58 | 59 | int main(void) { 60 | yyparse(); 61 | return 0; 62 | } 63 | EOF 64 | 65 | Compiling the program 66 | --------------------- 67 | Run the following commands: 68 | 69 | $ lex --outfile=calc.yy.c calc.lex 70 | $ yacc -d --file-prefix=calc calc.y 71 | $ cc calc.yy.c calc.tab.c -o calc 72 | 73 | Running the program 74 | ------------------- 75 | Run the following command: 76 | 77 | $ ./calc 78 | 1 + 2 79 | 3 80 | -------------------------------------------------------------------------------- /linux-packages/check.md: -------------------------------------------------------------------------------- 1 | check 2 | ----- 3 | A unit testing framework for C. 4 | 5 | Defining a test 6 | --------------- 7 | Run the following command: 8 | 9 | $ cat > test.c << "EOF" 10 | #include 11 | 12 | START_TEST(addition_test) 13 | { 14 | int result = 1 + 2; 15 | ck_assert_int_eq(result, 3); 16 | } 17 | END_TEST 18 | EOF 19 | 20 | Creating a test suite 21 | --------------------- 22 | Run the following command: 23 | 24 | $ cat >> test.c << "EOF" 25 | Suite* create_suite(void) 26 | { 27 | TCase* operators_case = tcase_create("operators"); 28 | tcase_add_test(operators_case, addition_test); 29 | 30 | Suite* integer_suite = suite_create("integer"); 31 | suite_add_tcase(integer_suite, operators_case); 32 | 33 | return integer_suite; 34 | } 35 | EOF 36 | 37 | Invoking the tests 38 | ------------------ 39 | Run the following command: 40 | 41 | $ cat >> test.c << "EOF" 42 | int main(void) 43 | { 44 | Suite* suite = create_suite(); 45 | SRunner* runner = srunner_create(suite); 46 | 47 | srunner_run_all(runner, CK_NORMAL); 48 | 49 | int number_failed = srunner_ntests_failed(runner); 50 | 51 | srunner_free(runner); 52 | 53 | return (number_failed == 0) ? 0 : -1; 54 | } 55 | EOF 56 | 57 | Compiling the program 58 | --------------------- 59 | Run the following command: 60 | 61 | $ gcc test.c `pkg-config --cflags --libs check` -o test 62 | 63 | Running the program 64 | ------------------- 65 | Run the following command: 66 | 67 | $ ./test 68 | Running suite(s): integer 69 | 100%: Checks: 1, Failures: 0, Errors: 0 70 | -------------------------------------------------------------------------------- /linux-packages/dbm.md: -------------------------------------------------------------------------------- 1 | dbm 2 | --- 3 | The GNU database manager. 4 | 5 | Creating the test program 6 | ------------------------- 7 | Run the following command: 8 | 9 | $ cat > test.c << "EOF" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | void demonstrate_write(); 16 | void demonstrate_read(); 17 | 18 | int main(void) 19 | { 20 | demonstrate_write(); 21 | demonstrate_read(); 22 | return 0; 23 | } 24 | EOF 25 | 26 | Demonstrating writes 27 | -------------------- 28 | Run the following command: 29 | 30 | $ cat >> test.c << "EOF" 31 | void demonstrate_write() 32 | { 33 | GDBM_FILE dbf = gdbm_open( 34 | "test.db", 35 | 0, 36 | GDBM_WRCREAT, 37 | S_IRUSR | S_IWUSR, 38 | NULL); 39 | 40 | datum key; 41 | key.dptr = "KEY-1"; 42 | key.dsize = strlen("KEY-1") + 1; 43 | 44 | datum content; 45 | content.dptr = "VALUE-1"; 46 | content.dsize = strlen("VALUE-1") + 1; 47 | 48 | gdbm_store( 49 | dbf, 50 | key, 51 | content, 52 | GDBM_REPLACE); 53 | 54 | gdbm_close(dbf); 55 | } 56 | EOF 57 | 58 | Demonstrating reads 59 | ------------------- 60 | Run the following command: 61 | 62 | $ cat >> test.c << "EOF" 63 | void demonstrate_read() 64 | { 65 | GDBM_FILE dbf = gdbm_open( 66 | "test.db", 67 | 0, 68 | GDBM_READER, 69 | 0, 70 | NULL); 71 | 72 | datum key; 73 | key.dptr = "KEY-1"; 74 | key.dsize = strlen("KEY-1") + 1; 75 | 76 | datum content = gdbm_fetch( 77 | dbf, 78 | key); 79 | 80 | puts(content.dptr); 81 | 82 | gdbm_close(dbf); 83 | } 84 | EOF 85 | 86 | Building and running the program 87 | -------------------------------- 88 | Run the following commands: 89 | 90 | $ gcc test.c -l gdbm -o test 91 | $ ./test 92 | VALUE-1 93 | -------------------------------------------------------------------------------- /linux-packages/dejagnu.md: -------------------------------------------------------------------------------- 1 | dejagnu 2 | ------- 3 | DejaGnu is a framework for testing other programs. 4 | 5 | Creating the script 6 | ------------------- 7 | Run the following command: 8 | 9 | $ cat > script.exp << "EOF" 10 | set could_login 0 11 | 12 | spawn ftp ftp.mozilla.org 13 | expect { 14 | "Name" { 15 | send "anonymous\n" 16 | expect { 17 | "Password" { 18 | send "\n" 19 | expect { 20 | "ftp>" { set could_login 1 } 21 | } 22 | } 23 | } 24 | } 25 | } 26 | 27 | if { $could_login == 1 } { 28 | pass "Could login" 29 | } else { 30 | fail "Could NOT login" 31 | } 32 | EOF 33 | 34 | Running the script 35 | ------------------ 36 | Run the following command: 37 | 38 | $ runtest script.exp 39 | # of expected passes 1 40 | -------------------------------------------------------------------------------- /linux-packages/diff.md: -------------------------------------------------------------------------------- 1 | diff 2 | ---- 3 | Compare files line by line. 4 | 5 | Demonstrating cmp 6 | ----------------- 7 | Run the following commands: 8 | 9 | $ cat > a << "EOF" 10 | * 1 carton milk 11 | * 2 loafs of bread 12 | * 6 bananas 13 | EOF 14 | 15 | $ cat > b << "EOF" 16 | * 1 carton milk 17 | * 2 loafs of white bread 18 | * 6 bananas 19 | EOF 20 | 21 | $ cmp a b 22 | a b differ: byte 30, line 2 23 | 24 | Demonstrating diff 25 | ------------------ 26 | Run the following commands: 27 | 28 | $ diff a b 29 | 2c2 30 | < * 2 loafs of bread 31 | --- 32 | > * 2 loafs of white bread 33 | 34 | $ diff a b --context 35 | *** a 2015-02-09 10:38:39.780000000 -0500 36 | --- b 2015-02-09 10:38:46.832000000 -0500 37 | *************** 38 | *** 1,3 **** 39 | * 1 carton milk 40 | ! * 2 loafs of bread 41 | * 6 bananas 42 | --- 1,3 ---- 43 | * 1 carton milk 44 | ! * 2 loafs of white bread 45 | * 6 bananas 46 | 47 | $ diff a b --unified 48 | --- a 2015-02-09 10:38:39.780000000 -0500 49 | +++ b 2015-02-09 10:38:46.832000000 -0500 50 | @@ -1,3 +1,3 @@ 51 | * 1 carton milk 52 | -* 2 loafs of bread 53 | +* 2 loafs of white bread 54 | * 6 bananas 55 | 56 | $ diff a b --side-by-side 57 | * 1 carton milk * 1 carton milk 58 | * 2 loafs of bread | * 2 loafs of white bread 59 | * 6 bananas * 6 bananas 60 | 61 | Demonstrating sdiff 62 | ------------------- 63 | Run the following commands: 64 | 65 | $ export EDITOR=vim 66 | 67 | $ sdiff a b -o ab 68 | * 1 carton milk * 1 carton milk 69 | * 2 loafs of bread | * 2 loafs of white bread 70 | %el 71 | :normal A (white if possible) 72 | :wq 73 | * 6 bananas * 6 bananas 74 | 75 | $ cat ab 76 | * 1 carton milk 77 | * 2 loafs of bread (white if possible) 78 | * 6 bananas 79 | 80 | Demonstrating diff3 81 | ------------------- 82 | Run the following commands: 83 | 84 | $ cat > c << "EOF" 85 | * 1 carton milk 86 | * 2 loafs of whole grain bread 87 | * 6 bananas 88 | EOF 89 | 90 | $ diff3 b a c 91 | ==== 92 | 1:2c 93 | * 2 loafs of white bread 94 | 2:2c 95 | * 2 loafs of bread 96 | 3:2c 97 | * 2 loafs of whole grain bread 98 | 99 | Demonstrating merge 100 | ------------------- 101 | Run the following commands: 102 | 103 | $ merge -A b a c 104 | merge: warning: conflicts during merge 105 | 106 | $ cat b 107 | * 1 carton milk 108 | <<<<<<< b 109 | * 2 loafs of white bread 110 | ||||||| a 111 | * 2 loafs of bread 112 | ======= 113 | * 2 loafs of whole grain bread 114 | >>>>>>> c 115 | * 6 bananas 116 | -------------------------------------------------------------------------------- /linux-packages/expat.md: -------------------------------------------------------------------------------- 1 | expat 2 | ----- 3 | Expat is an XML parser library written in C. 4 | 5 | Creating the program 6 | -------------------- 7 | Run the following command: 8 | 9 | $ cat > expat.c << "EOF" 10 | #include 11 | #include 12 | #include "expat.h" 13 | 14 | void start_element_handler(void *user_data, const char *name, const char **attributes) 15 | { 16 | if (strncmp(name, "scroll", strlen("scroll") + 1) == 0) 17 | { 18 | puts(attributes[1]); 19 | } 20 | } 21 | 22 | void end_element_handler(void *user_data, const char *name) 23 | { 24 | } 25 | 26 | int main() 27 | { 28 | XML_Parser parser = XML_ParserCreate(NULL); 29 | if (parser == NULL) 30 | { 31 | puts("Life sucks..."); 32 | exit(-1); 33 | } 34 | 35 | XML_SetElementHandler( 36 | parser, 37 | start_element_handler, 38 | end_element_handler); 39 | 40 | char* xml = "" 41 | "" 42 | " " 43 | " " 44 | " " 45 | ""; 46 | 47 | XML_Parse( 48 | parser, 49 | xml, 50 | strlen(xml), 51 | 1); 52 | 53 | return 0; 54 | } 55 | EOF 56 | 57 | Building and running the program 58 | -------------------------------- 59 | Run the following commands: 60 | 61 | $ gcc expat.c -lexpat -o expat 62 | $ ./expat 63 | HACKEM MUCHE 64 | LEP GEX VEN ZEA 65 | READ ME 66 | -------------------------------------------------------------------------------- /linux-packages/expect.md: -------------------------------------------------------------------------------- 1 | expect 2 | ------ 3 | A program to automate interactions with programs that expose a text terminal interface. 4 | 5 | Creating the script 6 | ------------------- 7 | Run the following command: 8 | 9 | $ cat > script.exp << "EOF" 10 | spawn ftp ftp.mozilla.org 11 | expect "Name" 12 | send "anonymous\n" 13 | expect "Password" 14 | send "\n" 15 | expect "ftp>" 16 | send "close\n" 17 | expect "ftp>" 18 | send "bye\n" 19 | expect eof 20 | EOF 21 | 22 | Running the script 23 | ------------------ 24 | Run the following command: 25 | 26 | $ expect script.exp 27 | -------------------------------------------------------------------------------- /linux-packages/findutils.md: -------------------------------------------------------------------------------- 1 | findutils 2 | --------- 3 | The basic directory searching utilities of the GNU operating system. 4 | 5 | find 6 | ---- 7 | Searches for files in a directory hierarchy. 8 | Run the following commands: 9 | 10 | $ mkdir directory/ 11 | $ touch directory/a.txt 12 | $ touch directory/b.txt 13 | 14 | $ mkdir directory/sub-directory/ 15 | $ touch directory/sub-directory/a.txt 16 | $ touch directory/sub-directory/b.txt 17 | 18 | $ find -name a.txt 19 | ./directory/a.txt 20 | ./directory/sub-directory/a.txt 21 | 22 | xargs 23 | ----- 24 | Builds and execute command lines from standard input. 25 | Run the following commands: 26 | 27 | $ find -name a.txt | xargs -t touch 28 | touch ./directory/a.txt ./directory/sub-directory/a.txt 29 | 30 | $ find -name a.txt | xargs -t -i cp {} {}.bak 31 | cp ./directory/a.txt ./directory/a.txt.bak 32 | cp ./directory/sub-directory/a.txt ./directory/sub-directory/a.txt.bak 33 | 34 | updatedb 35 | -------- 36 | Updates a file name database. 37 | Run the following commands: 38 | 39 | $ sudo updatedb 40 | 41 | locate 42 | ------ 43 | Lists files in databases that match a pattern. 44 | Run the following commands: 45 | 46 | $ locate vim 47 | /etc/vim 48 | /etc/alternatives/rvim 49 | /etc/alternatives/vimdiff 50 | /etc/vim/vimrc 51 | ... 52 | 53 | $ locate -r ".*/vim$" 54 | /etc/vim 55 | -------------------------------------------------------------------------------- /linux-packages/flex.md: -------------------------------------------------------------------------------- 1 | flex 2 | ---- 3 | Fast lexical analyser generator. 4 | 5 | Creating the script 6 | ------------------- 7 | Run the following command: 8 | 9 | $ cat > words.lex << "EOF" 10 | int small_words_count = 0; 11 | int big_words_count = 0; 12 | 13 | %% 14 | 15 | [a-zA-Z]{1,4} { small_words_count++; } 16 | [a-zA-Z]{5,} { big_words_count++; } 17 | . { ; } 18 | 19 | %% 20 | 21 | int yywrap() 22 | { 23 | return 1; 24 | } 25 | 26 | int main() 27 | { 28 | yylex(); 29 | 30 | printf("Small words count: %d\n", small_words_count); 31 | printf("Big words count: %d\n", big_words_count); 32 | 33 | return 0; 34 | } 35 | EOF 36 | 37 | Compiling the program 38 | --------------------- 39 | Run the following commands: 40 | 41 | $ lex --outfile=words.yy.c words.lex 42 | $ cc words.yy.c -o words 43 | 44 | Running the program 45 | ------------------- 46 | Run the following command: 47 | 48 | $ ./words 49 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore 50 | CTRL+D 51 | Small words count: 6 52 | Big words count: 9 53 | -------------------------------------------------------------------------------- /linux-packages/gdb.md: -------------------------------------------------------------------------------- 1 | gdb 2 | --- 3 | The GNU Debugger. 4 | 5 | Compiling the test program 6 | -------------------------- 7 | Run the following commands: 8 | 9 | $ cat > test.c << "EOF" 10 | int main(void) 11 | { 12 | int a = 10; 13 | int b = 5; 14 | int sum_of_squares = (a * a) + (b * b); 15 | return 0; 16 | } 17 | EOF 18 | 19 | $ gcc -g test.c -o test 20 | 21 | Launching the program inside the debugger 22 | ----------------------------------------- 23 | Run the following commands: 24 | 25 | $ gdb test 26 | (gdb) run 27 | tarting program: /tmp/test 28 | [Inferior 1 (process 5264) exited normally] 29 | 30 | Setting breakpoints 31 | ------------------- 32 | Run the following commands: 33 | 34 | (gdb) break test.c:main 35 | Breakpoint 1 at 0x4004f1: file test.c, line 3. 36 | 37 | (gdb) break test.c:5 38 | Breakpoint 2 at 0x4004ff: file test.c, line 5. 39 | 40 | (gdb) info breakpoint 41 | Num Type Disp Enb Address What 42 | 1 breakpoint keep y 0x00000000004004f1 in main at test.c:3 43 | 2 breakpoint keep y 0x00000000004004ff in main at test.c:5 44 | 45 | (gdb) disable 2 46 | 47 | (gdb) clear test.c:5 48 | Deleted breakpoint 2 49 | 50 | Stepping through the program 51 | ---------------------------- 52 | Run the following commands: 53 | 54 | (gdb) run 55 | Breakpoint 1, main () at test.c:3 56 | 3 int a = 10; 57 | 58 | (gdb) n 59 | 4 int b = 5; 60 | 61 | (gdb) c 62 | Continuing. 63 | [Inferior 1 (process 8808) exited normally] 64 | 65 | Use s to step into. 66 | Use n to step over. 67 | 68 | Inspecting and assigning variables 69 | ---------------------------------- 70 | Run the following commands: 71 | 72 | (gdb) run 73 | Breakpoint 1, main () at test.c:3 74 | 3 int a = 10; 75 | 76 | (gdb) n 77 | 78 | (gdb) print a 79 | $1 = 10 80 | 81 | (gdb) set variable b = 2 82 | 83 | (gdb) print b 84 | $2 = 2 85 | 86 | Displaying the stack 87 | -------------------- 88 | Run the following command: 89 | 90 | (gdb) bt 91 | #0 main () at test.c:4 92 | -------------------------------------------------------------------------------- /linux-packages/gettext.md: -------------------------------------------------------------------------------- 1 | gettext 2 | ------- 3 | Translates a natural language message into the user's language. 4 | 5 | Creating the localizable program 6 | -------------------------------- 7 | Run the following commands: 8 | 9 | $ cat > localizable.c << "EOF" 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | setlocale(LC_MESSAGES, ""); 17 | 18 | bindtextdomain("localizable", "/usr/local/share/locale"); 19 | textdomain("localizable"); 20 | 21 | printf(gettext("Hello world\n")); 22 | 23 | return 0; 24 | } 25 | EOF 26 | 27 | Compiling the localizable program 28 | --------------------------------- 29 | Run the following commands: 30 | 31 | $ gcc localizable.c -o localizable 32 | 33 | Extracting the localizable strings 34 | ---------------------------------- 35 | Run the following commands: 36 | 37 | $ mkdir po 38 | $ xgettext -d localizable -o po/localizable.pot localizable.c 39 | 40 | Localizing the strings 41 | ---------------------- 42 | Run the following commands: 43 | 44 | $ mkdir -p po/fr_FR 45 | $ cp po/localizable.pot po/fr_FR/localizable.po 46 | $ vim po/fr_FR/localizable.po 47 | 48 | The CHARSET placeholder shoud be replaced. 49 | The default for french is ISO-8859-1. 50 | 51 | Translations for each msgid line should be found on the next msgstr line. 52 | 53 | Compiling the localized strings 54 | ------------------------------- 55 | Run the following command: 56 | 57 | $ msgfmt po/fr_FR/localizable.po -o po/fr_FR/localizable.mo 58 | 59 | Deploying the localized strings 60 | ------------------------------- 61 | Run the following command: 62 | 63 | $ sudo mkdir -p /usr/local/share/locale/fr_FR/LC_MESSAGES 64 | $ sudo cp po/fr_FR/localizable.mo /usr/local/share/locale/fr_FR/LC_MESSAGES/ 65 | 66 | Demonstrating the localization 67 | ------------------------------ 68 | Run the following commands: 69 | 70 | $ ./localizable 71 | Hello world 72 | 73 | $ LANGUAGE=fr_FR 74 | $ ./localizable 75 | Bonjour monde 76 | -------------------------------------------------------------------------------- /linux-packages/gmp.md: -------------------------------------------------------------------------------- 1 | gmp 2 | --- 3 | Multiple precision arithmetic library. 4 | 5 | Creating the demonstration program 6 | ---------------------------------- 7 | Run the following command: 8 | 9 | $ cat > demo.c << "EOF" 10 | #include 11 | 12 | int main() 13 | { 14 | mpz_t first_integer; 15 | mpz_t second_integer; 16 | mpz_t greatest_common_divisor; 17 | 18 | mpz_init_set_str(first_integer, "116368671786395", 10); 19 | mpz_init_set_str(second_integer, "2819445786714176106", 10); 20 | 21 | mpz_init(greatest_common_divisor); 22 | 23 | mpz_gcd(greatest_common_divisor, first_integer, second_integer); 24 | 25 | gmp_printf("%Zd\n", greatest_common_divisor); 26 | 27 | mpz_clear(first_integer); 28 | mpz_clear(second_integer); 29 | mpz_clear(greatest_common_divisor); 30 | 31 | return 0; 32 | } 33 | EOF 34 | 35 | Compiling and running the demonstration program 36 | ----------------------------------------------- 37 | Run the following commands: 38 | 39 | $ gcc demo.c -lgmp -o demo 40 | $ ./demo 41 | 17 42 | -------------------------------------------------------------------------------- /linux-packages/gperf.md: -------------------------------------------------------------------------------- 1 | gperf 2 | ----- 3 | Perfect hash function generator. 4 | 5 | Creating the keywords list 6 | -------------------------- 7 | Run the following command: 8 | 9 | $ cat > keywords.gperf << "EOF" 10 | struct scroll_t 11 | { 12 | char* name; 13 | int id; 14 | }; 15 | %% 16 | HACKEM MUCHE, 1 17 | VELOX NEB, 2 18 | FOOBIE BLETCH, 3 19 | TEMOV, 4 20 | GARVEN DEH, 5 21 | READ ME, 6 22 | EOF 23 | 24 | Generating the has functions 25 | ---------------------------- 26 | Run the following command: 27 | 28 | $ gperf -t keywords.gperf > keywords.c 29 | 30 | Using the hash functions 31 | ------------------------ 32 | Run the following commands: 33 | 34 | $ cat > test.c << "EOF" 35 | #include 36 | #include 37 | 38 | #include "keywords.c" 39 | 40 | int main() 41 | { 42 | struct scroll_t* scroll = in_word_set("GARVEN DEH", strlen("GARVEN DEH")); 43 | printf("%d\n", scroll->id); 44 | return 0; 45 | } 46 | EOF 47 | 48 | $ gcc test.c -o test 49 | $ ./test 50 | 5 51 | -------------------------------------------------------------------------------- /linux-packages/grep.md: -------------------------------------------------------------------------------- 1 | grep 2 | ---- 3 | Print lines matching a pattern. 4 | 5 | Creating the test files 6 | ----------------------- 7 | Run the following commands: 8 | 9 | $ cat > potions << "EOF" 10 | ruby 11 | pink 12 | orange 13 | EOF 14 | 15 | $ mkdir folder 16 | $ cat > folder/wands << "EOF" 17 | glass 18 | balsa 19 | crystal 20 | EOF 21 | 22 | Demonstration 23 | ------------- 24 | Searching within a file: 25 | 26 | $ grep '[aeiouy]n' potions 27 | pink 28 | orange 29 | 30 | Printing the matching line numbers: 31 | 32 | $ grep -n 'pink' potions 33 | 2:pink 34 | 35 | Inverting the matching lines: 36 | 37 | $ grep -v 'pink' potions 38 | ruby 39 | orange 40 | 41 | Printing only the number of matching lines: 42 | 43 | $ grep -c '[aeiouy]n' potions 44 | 2 45 | 46 | Printing only the name of matching files: 47 | 48 | $ grep -l 'pink' * 49 | potions 50 | 51 | Searching recursively: 52 | 53 | $ grep -r 'a' * 54 | folder/wands:glass 55 | folder/wands:balsa 56 | folder/wands:crystal 57 | potions:orange 58 | -------------------------------------------------------------------------------- /linux-packages/groff.md: -------------------------------------------------------------------------------- 1 | groff 2 | ----- 3 | Document formatting system. 4 | 5 | Creating a man page 6 | ------------------- 7 | Run the following commands: 8 | 9 | $ cat > dance.man << EOF 10 | .TH DANCE 1 "2015-03-12" "1.0" "User commands" 11 | .SH NAME 12 | dance \- Makes you dance 13 | .SH SYNOPSIS 14 | \fBdance\fR [ -f | -l ] 15 | .SH DESCRIPTION 16 | dance is a rarely used command that makes programmers move in strange ways. 17 | .SH OPTIONS 18 | .TP 19 | \fB-f\fR makes you dance fast 20 | .TP 21 | \fB-l\fR makes you dance languorously (use with caution) 22 | .SH AUTHOR 23 | Your's Truly (alias@server.com) 24 | EOF 25 | 26 | Summary of the macros used: 27 | 28 | - .TH: Manual header 29 | - .SH: Section header 30 | - .TP: Bulleted paragraph 31 | - /fB: Bold font 32 | - /fR: Roman font 33 | 34 | Displaying the man page 35 | ----------------------- 36 | Run the following commands: 37 | 38 | $ man ./dance.man 39 | 40 | Installing the man page 41 | ----------------------- 42 | Run the following commands: 43 | 44 | $ sudo cp dance.man /usr/share/man/man1/dance.1 45 | $ sudo gzip /usr/share/man/man1/dance.1 46 | $ man dance 47 | -------------------------------------------------------------------------------- /linux-packages/gzip.md: -------------------------------------------------------------------------------- 1 | gzip 2 | ---- 3 | Compress or expand files. 4 | 5 | Creating a test file 6 | -------------------- 7 | Run the following commands: 8 | 9 | $ echo "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " > test 10 | $ echo "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, " >> test 11 | $ echo "quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. " >> test 12 | $ echo "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu " >> test 13 | $ echo "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, " >> test 14 | $ echo "sunt in culpa qui officia deserunt mollit anim id est laborum." >> test 15 | 16 | $ ll -h test* 17 | -rw-rw-r-- 1 root root 451 Apr 15 18:03 test 18 | 19 | Compressing a file 20 | ------------------ 21 | Run the following commands: 22 | 23 | $ gzip test 24 | 25 | $ ll test* 26 | -rw-rw-r-- 1 root root 294 Apr 15 18:03 test.gz 27 | 28 | Listing an archive 29 | ------------------ 30 | Run the following commands: 31 | 32 | $ gzip -l test.gz 33 | compressed uncompressed ratio uncompressed_name 34 | 294 451 39.9% test 35 | 36 | Viewing the content of an archive 37 | --------------------------------- 38 | Run the following commands: 39 | 40 | $ zcat test.gz 41 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 42 | ... 43 | 44 | Decompressing a file 45 | -------------------- 46 | Run the following commands: 47 | 48 | $ gunzip test.gz 49 | 50 | $ ll test* 51 | -rw-rw-r-- 1 root root 451 Apr 15 18:03 test 52 | -------------------------------------------------------------------------------- /linux-packages/inetutils.md: -------------------------------------------------------------------------------- 1 | inetutils 2 | --------- 3 | Network utilities. 4 | 5 | hostname 6 | -------- 7 | Run the following command: 8 | 9 | $ hostname 10 | apollo 11 | 12 | ping 13 | ---- 14 | Run the following command: 15 | 16 | $ ping www.google.com 17 | PING www.google.com (74.125.226.116) 56(84) bytes of data. 18 | 64 bytes from yyz08s13-in-f20.1e100.net (74.125.226.116): icmp_seq=1 ttl=128 time=7.85 ms 19 | 20 | traceroute 21 | ---------- 22 | Run the following command: 23 | 24 | $ traceroute www.google.com 25 | traceroute to www.google.com (74.125.136.104), 30 hops max, 60 byte packets 26 | 1 router2-nac.linode.com (207.99.1.14) 0.421 ms 0.543 ms 0.718 ms 27 | 2 207.99.53.45 (207.99.53.45) 0.978 ms 1.036 ms 1.108 ms 28 | 3 0.e1-2.tbr2.ewr.nac.net (209.123.10.113) 0.927 ms 0.905 ms 1.015 ms 29 | 4 core1-0-0-8.lga.net.google.com (198.32.118.39) 1.348 ms 1.365 ms 1.350 ms 30 | ... 31 | 12 ea-in-f104.1e100.net (74.125.136.104) 87.037 ms 86.909 ms 86.949 ms 32 | 33 | whois 34 | ----- 35 | Run the following command: 36 | 37 | $ whois google.com 38 | Domain Name: google.com 39 | ... 40 | Registrant Organization: Google Inc. 41 | Registrant Street: Please contact contact-admin@google.com, 1600 Amphitheatre Parkway 42 | Registrant City: Mountain View 43 | Registrant State/Province: CA 44 | Registrant Postal Code: 94043 45 | Registrant Country: US 46 | ... 47 | -------------------------------------------------------------------------------- /linux-packages/intltool.md: -------------------------------------------------------------------------------- 1 | intltool 2 | -------- 3 | Tools to centralize translation of many different file formats using GNU gettext-compatible PO files. 4 | 5 | Creating the XML file with translatable elements 6 | ------------------------------------------------ 7 | Run the following commands: 8 | 9 | $ cat > test.xml << EOF 10 | 11 | 1000 12 | <_title>Big trouble 13 | <_description>Ran out of chocolate bars. 14 | 15 | EOF 16 | 17 | Marking the XML file as translatable 18 | ------------------------------------ 19 | Run the following commands: 20 | 21 | $ mkdir po 22 | 23 | $ cat > po/POTFILES.in << EOF 24 | test.xml 25 | EOF 26 | 27 | Extracting the localizable strings 28 | ---------------------------------- 29 | Run the following commands: 30 | 31 | $ cd po 32 | $ intltool-update --pot -g template 33 | $ cd .. 34 | 35 | Localizing the strings 36 | ---------------------- 37 | Run the following commands: 38 | 39 | $ mkdir -p po/fr_FR 40 | $ cp po/template.pot po/fr_FR/fr_FR.po 41 | $ vim po/fr_FR/fr_FR.po 42 | 43 | The CHARSET placeholder shoud be replaced. 44 | UTF-8 is always a good choice. 45 | 46 | Translations for each msgid line should be found on the next msgstr line. 47 | 48 | Merging back the localized strings 49 | ---------------------------------- 50 | Run the following commands: 51 | 52 | $ intltool-merge -x po/fr_FR test.xml test.xml.fr 53 | 54 | $ cat test.xml.fr 55 | 56 | 57 | 1000 58 | Big trouble 59 | Gros problèmes 60 | Ran out of chocolate bars. 61 | Nous sommes en rupture de chocolats. 62 | 63 | -------------------------------------------------------------------------------- /linux-packages/iproute2.md: -------------------------------------------------------------------------------- 1 | iproute2 2 | -------- 3 | Shows / manipulates routing, devices, policy routing and tunnels. 4 | 5 | Listing the links 6 | ----------------- 7 | Run the following command: 8 | 9 | $ ip link list 10 | 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default 11 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 12 | 2: eth1: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 13 | link/ether 00:1c:42:e6:59:5a brd ff:ff:ff:ff:ff:ff 14 | 15 | This shows the following network interfaces: 16 | 17 | - The loopback link (with no MAC address) 18 | - The ethernet link (with MAC address 00:1c:42:e6:59:5a) 19 | 20 | Listing the addresses 21 | --------------------- 22 | Run the following command: 23 | 24 | $ ip address show 25 | 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default 26 | link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 27 | inet 127.0.0.1/8 scope host lo 28 | ... 29 | 2: eth1: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 30 | link/ether 00:1c:42:e6:59:5a brd ff:ff:ff:ff:ff:ff 31 | inet 10.211.55.6/24 brd 10.211.55.255 scope global eth1 32 | ... 33 | 34 | This shows us the following IP address bindings: 35 | 36 | - 127.0.0.1 is bound to the loopback link 37 | - 10.211.55.6 is bound to the ethernet link 38 | 39 | Furthermore we get shown that for the 10.211.55.6 address: 40 | 41 | - The first 24 bits identify the network (10.211.55.*) 42 | - The remaining 8 bits are specifically assigned to us (0.0.0.6) 43 | 44 | Listing the routes 45 | ------------------ 46 | Run the following command: 47 | 48 | $ ip route show 49 | 10.211.55.0/24 dev eth1 proto kernel scope link src 10.211.55.6 metric 1 50 | default via 10.211.55.1 dev eth1 proto static 51 | 52 | This shows us that: 53 | 54 | - Packets addressed to 10.211.55.* should be sent directly on the ethernet link 55 | - Any other packet shoud be sent via the 10.211.55.1 gateway on the ethernet link 56 | 57 | Listing the address resolutions 58 | ------------------------------- 59 | Run the following commands: 60 | 61 | $ ping 10.211.55.1 62 | 63 | $ ip neigh show 64 | 10.211.55.1 dev eth1 lladdr 00:1c:42:00:00:18 REACHABLE 65 | ... 66 | 67 | This shows us that: 68 | 69 | - The IP address 10.211.55.1 was resolved to MAC address 00:1c:42:00:00:18 70 | -------------------------------------------------------------------------------- /linux-packages/libcap.md: -------------------------------------------------------------------------------- 1 | libcap 2 | ------ 3 | Capabilities library. 4 | 5 | Testing for capabilities 6 | ------------------------ 7 | Run the following commands: 8 | 9 | $ cat > test.c << "EOF" 10 | #include 11 | 12 | void main() 13 | { 14 | cap_t capabilities = cap_get_proc(); 15 | 16 | cap_flag_value_t flag_value; 17 | cap_get_flag(capabilities, CAP_CHOWN, CAP_EFFECTIVE, &flag_value); 18 | 19 | if (flag_value == CAP_SET) 20 | { 21 | puts("I can change the owners!"); 22 | } 23 | else 24 | { 25 | puts("I cannot change the owners..."); 26 | } 27 | 28 | cap_free(capabilities); 29 | } 30 | EOF 31 | 32 | $ gcc test.c -lcap -o test 33 | 34 | $ ./test 35 | I cannot change the owners... 36 | 37 | $ sudo ./test 38 | I can change the owners! 39 | 40 | Being safe and declining unrequired capabalities 41 | ------------------------------------------------ 42 | Run the following commands: 43 | 44 | $ touch file 45 | 46 | $ cat > test.c << "EOF" 47 | #include 48 | #include 49 | 50 | void main() 51 | { 52 | int chown_result = chown("./file", 0, 0); 53 | 54 | printf("chown_result: %d\n", chown_result); 55 | 56 | cap_t capabilities = cap_get_proc(); 57 | 58 | cap_clear(capabilities); 59 | cap_set_proc(capabilities); 60 | 61 | cap_free(capabilities); 62 | 63 | chown_result = chown("./file", 1, 1); 64 | 65 | printf("chown_result: %d\n", chown_result); 66 | } 67 | EOF 68 | 69 | $ gcc test.c -lcap -o test 70 | 71 | $ sudo ./test 72 | chown_result: 0 73 | chown_result: -1 74 | 75 | Granting capabalities in order to avoid sudo 76 | -------------------------------------------- 77 | Run the following commands: 78 | 79 | $ touch file2 80 | 81 | $ cat > test.c << "EOF" 82 | #include 83 | 84 | void main() 85 | { 86 | int chown_result = chown("./file2", 0, 0); 87 | printf("chown_result: %d\n", chown_result); 88 | } 89 | EOF 90 | 91 | $ gcc test.c -lcap -o test 92 | 93 | $ ./test 94 | chown_result: -1 95 | 96 | $ sudo setcap 'cap_chown+ep' ./test 97 | 98 | $ ./test 99 | chown_result: 0 100 | -------------------------------------------------------------------------------- /linux-packages/libpipeline.md: -------------------------------------------------------------------------------- 1 | libpipeline 2 | ----------- 3 | Pipeline manipulation library. 4 | 5 | Invoking a command 6 | ------------------ 7 | Run the following commands: 8 | 9 | $ touch file 10 | 11 | $ cat > test.c << "EOF" 12 | #include 13 | 14 | int main() 15 | { 16 | pipeline *p = pipeline_new_command_args("cp", "file", "file-copy", NULL); 17 | pipeline_run(p); 18 | 19 | return 0; 20 | } 21 | EOF 22 | 23 | $ gcc test.c -lpipeline -o test 24 | 25 | $ ./test 26 | 27 | $ ls file-copy 28 | file-copy 29 | 30 | Piping commands 31 | --------------- 32 | Run the following commands: 33 | 34 | $ touch file 35 | 36 | $ cat > test.c << "EOF" 37 | #include 38 | 39 | int main() 40 | { 41 | pipeline *p = pipeline_new(); 42 | pipeline_command_args(p, "ls", "-l", "file", NULL); 43 | pipeline_command_args(p, "cut", "-d", " ", "-f", "8", NULL); 44 | pipeline_run(p); 45 | 46 | return 0; 47 | } 48 | EOF 49 | 50 | $ gcc test.c -lpipeline -o test 51 | 52 | $ ./test 53 | 11:07 54 | 55 | Capturing the pipeline output 56 | ----------------------------- 57 | Run the following commands: 58 | 59 | $ touch file 60 | 61 | $ cat > test.c << "EOF" 62 | #include 63 | 64 | int main() 65 | { 66 | pipeline *p = pipeline_new(); 67 | pipeline_command_args(p, "ls", "-l", "file", NULL); 68 | pipeline_want_out(p, -1); 69 | pipeline_start(p); 70 | 71 | const char *line = NULL; 72 | 73 | while (line = pipeline_readline(p)) 74 | { 75 | printf("%s", line); 76 | } 77 | 78 | pipeline_free(p); 79 | 80 | return 0; 81 | } 82 | EOF 83 | 84 | $ gcc test.c -lpipeline -o test 85 | 86 | $ ./test 87 | -rw-rw-r-- 1 root root 0 May 12 11:07 file 88 | -------------------------------------------------------------------------------- /linux-packages/m4.md: -------------------------------------------------------------------------------- 1 | m4 2 | -- 3 | General-purpose macro processor. 4 | 5 | Defining a macro 6 | ---------------- 7 | Run the following commands: 8 | 9 | $ cat > template << "EOF" 10 | define(NAME, Mathieu) 11 | Hello NAME. 12 | EOF 13 | 14 | $ m4 template 15 | 16 | Hello Mathieu. 17 | 18 | Suppressing white space 19 | ----------------------- 20 | Run the following commands: 21 | 22 | $ cat > template << "EOF" 23 | define(NAME, Mathieu)dnl 24 | Hello NAME. 25 | EOF 26 | 27 | $ m4 template 28 | Hello Mathieu 29 | 30 | Run the following commands: 31 | 32 | $ cat > template << "EOF" 33 | divert(-1) 34 | define(MACRO1, you) 35 | define(MACRO2, macro) 36 | define(MACRO3, master) 37 | divert(0)dnl 38 | Hello MACRO1 MACRO2 MACRO3. 39 | EOF 40 | 41 | $ m4 template 42 | Hello you macro master. 43 | 44 | Defining macros at the command line 45 | ----------------------------------- 46 | Run the following commands: 47 | 48 | $ cat > template << "EOF" 49 | Hello NAME. 50 | EOF 51 | 52 | $ m4 -DNAME=Mathieu template 53 | Hello Mathieu. 54 | 55 | Using conditional statements 56 | ---------------------------- 57 | Run the following commands: 58 | 59 | $ cat > template << "EOF" 60 | Hello ifelse(NAME, Mathieu, grand master, mister) NAME. 61 | EOF 62 | 63 | $ m4 -DNAME=Mathieu template 64 | Hello grand master Mathieu. 65 | 66 | $ m4 -DNAME=Bob template 67 | Hello mister Bob. 68 | 69 | Using parameters 70 | ---------------- 71 | Run the following commands: 72 | 73 | $ cat > template << "EOF" 74 | define(SAY_HI, Hello $1.)dnl 75 | SAY_HI(Mathieu) 76 | EOF 77 | 78 | $ m4 template 79 | Hello Mathieu. 80 | 81 | Using recursion 82 | --------------- 83 | Run the following commands: 84 | 85 | $ cat > template << "EOF" 86 | define(SAY_HI, `ifelse($1, 0, , Hello `SAY_HI(decr($1))')')dnl 87 | SAY_HI(2) 88 | EOF 89 | 90 | $ m4 template 91 | Hello Hello 92 | 93 | It is instructive to visualize how macros are expanded one set of `' at a time: 94 | 95 | - SAY_HI(2) 96 | - ifelse(2, 0, , Hello `SAY_HI(decr(2))') 97 | - ifelse(2, 0, , Hello ifelse(1, 0, , Hello `SAY_HI(decr(1))')) 98 | - ifelse(2, 0, , Hello ifelse(1, 0, , Hello ifelse(0, 0, , Hello `SAY_HI(decr(0))'))) 99 | -------------------------------------------------------------------------------- /linux-packages/make.md: -------------------------------------------------------------------------------- 1 | make 2 | ---- 3 | Maintain program dependencies. 4 | 5 | Preparing the demonstration files 6 | --------------------------------- 7 | Run the following commands: 8 | 9 | $ cat > part1.txt << EOF 10 | ZELGO MER 11 | JUYED AWK YACC 12 | NR 9 13 | EOF 14 | 15 | $ cat > part2.txt << EOF 16 | XIXAXA XOXAXA XUXAXA 17 | PRATYAVAYAH 18 | EOF 19 | 20 | Defining how to make a file 21 | --------------------------- 22 | Run the following commands: 23 | 24 | $ TAB="$(printf '\t')" 25 | 26 | $ cat > makefile << EOF 27 | whole.txt: part1.txt part2.txt 28 | ${TAB}cat part1.txt part2.txt > whole.txt 29 | EOF 30 | 31 | What is defined above: 32 | 33 | - whole.txt is made from part1.txt and part2.txt 34 | - the command to make whole.txt is cat 35 | 36 | Run the following commands: 37 | 38 | $ make whole.txt 39 | cat part1.txt part2.txt > whole.txt 40 | 41 | $ cat whole.txt 42 | ZELGO MER 43 | JUYED AWK YACC 44 | NR 9 45 | XIXAXA XOXAXA XUXAXA 46 | PRATYAVAYAH 47 | 48 | Demonstrating dependency tracking 49 | --------------------------------- 50 | Run the following command a second time: 51 | 52 | $ make whole.txt 53 | make: `whole.txt' is up to date. 54 | 55 | Make compares the timestamps of whole.txt, part1.txt and part2.txt. 56 | Since whole.txt is older than all of its dependencies, there is no need to make it again. 57 | 58 | Run the following commands: 59 | 60 | $ touch part1.txt 61 | 62 | $ make whole.txt 63 | cat part1.txt part2.txt > whole.txt 64 | 65 | Demonstrating hierarchical dependencies 66 | --------------------------------------- 67 | Run the following commands: 68 | 69 | $ TAB="$(printf '\t')" 70 | 71 | $ cat > makefile << EOF 72 | whole.txt.gz: whole.txt 73 | ${TAB}gzip -k whole.txt 74 | 75 | whole.txt: part1.txt part2.txt 76 | ${TAB}cat part1.txt part2.txt > whole.txt 77 | EOF 78 | 79 | A made file may itself be a dependency to another file. 80 | 81 | Run the following commands: 82 | 83 | $ touch part1.txt 84 | 85 | $ make whole.txt.gz 86 | cat part1.txt part2.txt > whole.txt 87 | gzip -k whole.txt 88 | 89 | Defining lists of files 90 | ----------------------- 91 | Run the following commands: 92 | 93 | $ TAB="$(printf '\t')" 94 | $ DOLLAR="$(printf '$')" 95 | 96 | $ cat > makefile << EOF 97 | PARTS = part1.txt part2.txt 98 | 99 | whole.txt: ${DOLLAR}(PARTS) 100 | ${TAB}cat ${DOLLAR}(PARTS) > whole.txt 101 | EOF 102 | 103 | Then run the following commands: 104 | 105 | $ touch part1.txt 106 | 107 | $ make whole.txt 108 | cat part1.txt part2.txt > whole.txt 109 | 110 | Defining generic rules 111 | ---------------------- 112 | Run the following commands: 113 | 114 | $ TAB="$(printf '\t')" 115 | $ DOLLAR="$(printf '$')" 116 | 117 | $ cat > makefile << EOF 118 | all: part1.gz part2.gz 119 | 120 | %.gz: %.txt 121 | ${TAB}gzip -k ${DOLLAR}< > ${DOLLAR}@ 122 | EOF 123 | 124 | What is defined above: 125 | 126 | - making all means making part1.gz and part2.gz 127 | - the command to make a gz file from its txt file is gzip 128 | - the $< construct is replaced by the dependent file 129 | - the $@ construct is replaced by the made file 130 | 131 | Run the following command: 132 | 133 | $ make all 134 | gzip -k part1.txt > part1.gz 135 | gzip -k part2.txt > part2.gz 136 | -------------------------------------------------------------------------------- /linux-packages/mpc.md: -------------------------------------------------------------------------------- 1 | mpc 2 | --- 3 | C library for the arithmetic of complex numbers. 4 | 5 | Creating the demonstration program 6 | ---------------------------------- 7 | Run the following command: 8 | 9 | $ cat > demo.c << "EOF" 10 | #include 11 | 12 | int main() 13 | { 14 | mpc_t x; 15 | mpc_t y; 16 | 17 | mpc_init2(x, 256); 18 | mpc_init2(y, 256); 19 | 20 | mpc_set_d_d(x, 0, 2, MPC_RNDNN); 21 | 22 | mpc_sqrt(y, x, MPC_RNDNN); 23 | 24 | char *y_string = mpc_get_str(10, 5, y, MPC_RNDNN); 25 | 26 | puts(y_string); 27 | 28 | mpc_free_str(y_string); 29 | 30 | mpc_clear(x); 31 | mpc_clear(y); 32 | 33 | return 0; 34 | } 35 | EOF 36 | 37 | Compiling and running the demonstration program 38 | ----------------------------------------------- 39 | Run the following commands: 40 | 41 | $ gcc demo.c -lmpc -o demo 42 | $ ./demo 43 | (1.0000 1.0000) 44 | -------------------------------------------------------------------------------- /linux-packages/mpfr.md: -------------------------------------------------------------------------------- 1 | mpfr 2 | ---- 3 | C library for multiple-precision floating-point computations. 4 | 5 | Creating the demonstration program 6 | ---------------------------------- 7 | Run the following command: 8 | 9 | $ cat > demo.c << "EOF" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | int main() 16 | { 17 | mpfr_t x; 18 | mpfr_t y; 19 | mpfr_t z; 20 | 21 | mpfr_init2(x, 256); 22 | mpfr_init2(y, 256); 23 | mpfr_init2(z, 256); 24 | 25 | mpfr_set_d(x, 1, MPFR_RNDN); 26 | mpfr_set_d(y, 3, MPFR_RNDN); 27 | 28 | mpfr_div(z, x, y, MPFR_RNDN); 29 | 30 | mpfr_exp_t e; 31 | 32 | char *z_string = mpfr_get_str(NULL, &e, 10, 0, z, MPFR_RNDN); 33 | 34 | printf("0.%s * 10^%d\n", z_string, (int)e); 35 | 36 | mpfr_free_str(z_string); 37 | 38 | mpfr_clear(x); 39 | mpfr_clear(y); 40 | mpfr_clear(z); 41 | 42 | return 0; 43 | } 44 | EOF 45 | 46 | Compiling and running the demonstration program 47 | ----------------------------------------------- 48 | Run the following commands: 49 | 50 | $ gcc demo.c -lmpfr -o demo 51 | $ ./demo 52 | 0.3333333333333333333333333333333333333333333333333333333333333333333333333333348 * 10^0 53 | -------------------------------------------------------------------------------- /linux-packages/ncurses.md: -------------------------------------------------------------------------------- 1 | ncurses 2 | ------- 3 | The ncurses library routines give the user a terminal-independent method of updating character screens. 4 | 5 | Creating the program 6 | -------------------- 7 | Run the following command: 8 | 9 | $ cat > test.c << "EOF" 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | initscr(); 17 | 18 | cbreak(); 19 | nonl(); 20 | noecho(); 21 | 22 | FIELD **fields = malloc(sizeof(FIELD *) * 3); 23 | fields[0] = new_field(1, 20, 1, 18, 0, 0); 24 | fields[1] = new_field(1, 20, 2, 18, 0, 0); 25 | fields[2] = NULL; 26 | 27 | set_field_back(fields[0], A_UNDERLINE); 28 | set_field_back(fields[1], A_UNDERLINE); 29 | 30 | set_field_type(fields[1], TYPE_INTEGER, 0, 0, 0); 31 | 32 | FORM *form = new_form(fields); 33 | post_form(form); 34 | refresh(); 35 | 36 | mvprintw(1, 2, "Full name:"); 37 | mvprintw(2, 2, "Age (numeric):"); 38 | move(1, 18); 39 | 40 | set_current_field(form, fields[0]); 41 | refresh(); 42 | 43 | int enter_pressed = 0; 44 | 45 | while (enter_pressed == 0) 46 | { 47 | int character = getch(); 48 | 49 | switch (character) 50 | { 51 | case 9: 52 | form_driver(form, REQ_NEXT_FIELD); 53 | form_driver(form, REQ_END_LINE); 54 | break; 55 | 56 | case 13: 57 | enter_pressed = 1; 58 | break; 59 | 60 | case 127: 61 | form_driver(form, REQ_DEL_PREV); 62 | break; 63 | 64 | default: 65 | form_driver(form, character); 66 | break; 67 | } 68 | } 69 | 70 | form_driver(form, REQ_VALIDATION); 71 | 72 | char *full_name = field_buffer(fields[0], 0); 73 | 74 | mvprintw(4, 2, "Welcome "); 75 | mvprintw(4, 10, full_name); 76 | move(5, 2); 77 | 78 | refresh(); 79 | getch(); 80 | 81 | unpost_form(form); 82 | 83 | free_form(form); 84 | free_field(fields[0]); 85 | free_field(fields[1]); 86 | 87 | free(fields); 88 | 89 | endwin(); 90 | 91 | return 0; 92 | } 93 | EOF 94 | 95 | Building and running the program 96 | -------------------------------- 97 | Run the following commands: 98 | 99 | $ gcc test.c -lform -lncurses -o test 100 | $ ./test 101 | 102 | Full name: Mathieu_____________ 103 | Age (numeric): 99__________________ 104 | 105 | Welcome Mathieu 106 | -------------------------------------------------------------------------------- /linux-packages/patch.md: -------------------------------------------------------------------------------- 1 | patch 2 | ----- 3 | Apply a diff file to an original. 4 | 5 | Creating a patch for a file 6 | --------------------------- 7 | Run the following commands: 8 | 9 | $ cat > original << "EOF" 10 | * 1 carton milk 11 | * 2 loafs of bread 12 | * 6 bananas 13 | EOF 14 | 15 | $ cat > modified << "EOF" 16 | * 1 carton milk 17 | * 2 loafs of white bread 18 | * 6 bananas 19 | EOF 20 | 21 | $ diff -u original modified > original.patch 22 | 23 | $ rm modified 24 | 25 | Applying a patch to a file 26 | -------------------------- 27 | Run the following commands: 28 | 29 | $ patch < original.patch 30 | patching file original 31 | 32 | $ cat original 33 | * 1 carton milk 34 | * 2 loafs of white bread 35 | * 6 bananas 36 | 37 | Creating a patch for a directory 38 | -------------------------------- 39 | Run the following commands: 40 | 41 | $ mkdir sources 42 | $ cat > sources/main.c << "EOF" 43 | int main() 44 | { 45 | } 46 | EOF 47 | 48 | $ mkdir sources.modified 49 | $ cat > sources.modified/main.c << "EOF" 50 | int main() 51 | { 52 | return 0; 53 | } 54 | EOF 55 | 56 | $ diff -u -r sources/ sources.modified/ > sources.patch 57 | 58 | $ rm -r sources.modified 59 | 60 | Applying a patch to a directory 61 | ------------------------------- 62 | Run the following commands: 63 | 64 | $ cd sources 65 | $ patch -p1 < ../sources.patch 66 | patching file main.c 67 | 68 | $ cat main.c 69 | int main() 70 | { 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /linux-packages/pkgconfig.md: -------------------------------------------------------------------------------- 1 | pkg-config 2 | ---------- 3 | Retrieves information about installed libraries in the system. 4 | 5 | Creating the configuration file 6 | ------------------------------- 7 | Run the following command: 8 | 9 | $ cat > librestaurant.pc << "EOF" 10 | prefix=/usr 11 | includedir=${prefix}/include 12 | libdir=${prefix}/lib 13 | 14 | Name: librestaurant 15 | Description: Event driven restaurant library 16 | Version: 0.1.0 17 | Cflags: -I${includedir}/librestaurant 18 | Libs: -L${libdir} -lrestaurant 19 | Requires: libevent >= 2.0.0 20 | EOF 21 | 22 | Deploy the configuration file as part of the library package, 23 | inside the following directory: 24 | 25 | /usr/lib/pkgconfig 26 | 27 | Generating the required compilation flags 28 | ----------------------------------------- 29 | Run the following commands: 30 | 31 | $ pkg-config --cflag librestaurant 32 | -I/usr/include/librestaurant 33 | 34 | $ pkg-config --libs librestaurant 35 | -L/usr/lib -lrestaurant -levent 36 | 37 | Using the required compilation flags 38 | ------------------------------------ 39 | Run the following commands: 40 | 41 | $ echo `pkg-config --cflags --libs librestaurant` 42 | -I/usr/include/librestaurant -L/usr/lib -lrestaurant -levent 43 | 44 | $ gcc `pkg-config --cflags --libs librestaurant` main.c -o main 45 | 46 | Checking dependencies 47 | --------------------- 48 | Run the following command: 49 | 50 | $ pkg-config --libs "libevent >= 1000" 51 | Requested 'libevent >= 1000' but version of libevent is 2.0.22-stable 52 | -------------------------------------------------------------------------------- /linux-packages/sed.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mathieu-Desrochers/Linux-Notebook/d9cbd827936a4e348ea8397c9ce49db603562225/linux-packages/sed.md -------------------------------------------------------------------------------- /procedures/configuring-i3.md: -------------------------------------------------------------------------------- 1 | Modifications to the wizard generated configuration 2 | --------------------------------------------------- 3 | Edit the following file. 4 | 5 | ~/.i3/config 6 | 7 | Apply the following changes. 8 | 9 | ---- bindsym $mod+Return exec i3-sensible-terminal 10 | ++++ bindsym $mod+Return exec uxterm 11 | 12 | ---- bindsym Left resize shrink width 10 px or 10 ppt 13 | ---- bindsym Down resize grow height 10 px or 10 ppt 14 | ---- bindsym Up resize shrink height 10 px or 10 ppt 15 | ---- bindsym Right resize grow width 10 px or 10 ppt 16 | 17 | ++++ bindsym Left resize shrink width 1 px or 1 ppt 18 | ++++ bindsym Down resize grow height 1 px or 1 ppt 19 | ++++ bindsym Up resize shrink height 1 px or 1 ppt 20 | ++++ bindsym Right resize grow width 1 px or 1 ppt 21 | 22 | Run the following command. 23 | 24 | cp /etc/i3status.conf ~/.i3status.conf 25 | 26 | Edit the following file. 27 | 28 | ~/.i3status.conf 29 | 30 | Apply the following change. 31 | 32 | ---- run_watch VPN { 33 | ---- pidfile = "/var/run/vpnc/pid" 34 | ---- } 35 | 36 | ++++ run_watch VPN { 37 | ++++ pidfile = "/var/run/openvpn.pid" 38 | ++++ } 39 | -------------------------------------------------------------------------------- /procedures/installing-freebsd-server.md: -------------------------------------------------------------------------------- 1 | FreeBSD installation 2 | -------------------- 3 | Select the following options. 4 | 5 | - Boot Multi User 6 | - Install 7 | - Continue with default keymap 8 | - Optional system components: lib32, ports 9 | - Partitioning: Shell 10 | 11 | Encrypted partitions 12 | -------------------- 13 | Create the GTP boot partition. 14 | 15 | # gpart create -s GPT vtbd0 16 | # gpart add -t freebsd-boot -s 512K vtbd0 17 | # gpart bootcode -b /boot/pmbr -p /boot/gptboot -i 1 vtbd0 18 | 19 | Create the boot partition. 20 | 21 | # gpart add -t freebsd-ufs -s 2G vtbd0 22 | # newfs -U /dev/vtbd0p2 23 | 24 | Create the encrypted root partition. 25 | 26 | # gpart add -t freebsd-ufs -s 100G vtbd0 27 | # geli init -b -s 4096 /dev/vtbd0p3 28 | # geli attach /dev/vtbd0p3 29 | # newfs -U /dev/vtbd0p3.eli 30 | 31 | Create the encrypted swap partition. 32 | 33 | # gpart add -t freebsd-swap -s 1G vtbd0 34 | 35 | Mount the encrypted partitions. 36 | This is where the installer will copy files. 37 | 38 | # mount /dev/vtbd0p3.eli /mnt 39 | 40 | Mount the boot partition. 41 | This is where the installer will copy the boot files. 42 | 43 | # mkdir /tmp/vtbd0p2 44 | # mount /dev/vtbd0p2 /tmp/vtbd0p2 45 | # mkdir /tmp/vtbd0p2/boot 46 | # ln -s /tmp/vtbd0p2/boot /mnt/boot 47 | 48 | Create the final mount point. 49 | 50 | # mkdir -p /mnt/mnt/vtbd0p2 51 | 52 | Create the following file. 53 | 54 | /tmp/bsdinstall_boot/loader.conf 55 | 56 | With the following content. 57 | 58 | geom_eli_load="YES" 59 | vfs.root.mountfrom="ufs:vtbd0p3.eli" 60 | 61 | Create the following file. 62 | 63 | /tmp/bsdinstall_etc/fstab 64 | 65 | With the following content. 66 | 67 | /dev/vtbd0p2 /mnt/vtbd0p2 ufs rw 0 2 68 | /dev/vtbd0p3.eli / ufs rw 0 1 69 | /dev/vtbd0p4.eli none swap sw 0 0 70 | 71 | Network Configuration 72 | --------------------- 73 | Cancel. 74 | 75 | Date and Time 76 | ------------- 77 | Select the following options. 78 | 79 | - America - Canada - Eastern ON, QC - EDT 80 | - Set date and time: Skip 81 | 82 | System Configuration 83 | -------------------- 84 | Unselect all the services. 85 | 86 | System Hardening 87 | ---------------- 88 | Select all the options. 89 | 90 | First boot 91 | ---------- 92 | Remove the CD, reboot and select Boot Single User. 93 | Fix the boot link. 94 | 95 | # rm /boot 96 | # mount /dev/vtbd0p2 /mnt/vtbd0p2 97 | # ln -s /mnt/vtbd0p2/boot /boot 98 | 99 | Securely joining the network 100 | ---------------------------- 101 | Run the following commands. 102 | 103 | # sysrc pf_enable=YES 104 | # sysrc blacklistd_enable=YES 105 | 106 | Create the following file. 107 | 108 | /etc/pf.conf 109 | 110 | With the following content. 111 | 112 | set skip on lo0 113 | scrub in 114 | 115 | anchor "blacklistd/*" in 116 | 117 | block in 118 | pass out 119 | 120 | pass in proto tcp from any to port 22 121 | 122 | Create the following file. 123 | 124 | /etc/blacklistd.conf 125 | 126 | With the following content. 127 | 128 | [local] 129 | ssh * * * * 3 24h 130 | 131 | Edit the following file. 132 | 133 | /etc/rc.conf 134 | 135 | Add the following line. 136 | 137 | ifconfig_vtnet0="DHCP" 138 | 139 | Reboot. 140 | 141 | Enabling remote access 142 | ---------------------- 143 | Edit the following file. 144 | 145 | /etc/ssh/sshd_config 146 | 147 | Set the following options. 148 | 149 | PermitRootLogin no 150 | PubkeyAuthentication yes 151 | AuthorizedKeysFile .ssh/authorized_keys 152 | PasswordAuthentication no 153 | ChallengeResponseAuthentication no 154 | UseBlacklist yes 155 | AllowUsers your-username 156 | 157 | Edit the following file. 158 | 159 | /etc/rc.conf 160 | 161 | Add the following line. 162 | 163 | sshd_enable="YES" 164 | 165 | Installing a graphical desktop 166 | ------------------------------ 167 | Run the following commands. 168 | 169 | # pkg install drm-kmod 170 | # sysrc kld_list+="/boot/modules/i915kms.ko" 171 | # pw groupmod video -m your-user 172 | 173 | Run the following commands. 174 | 175 | # pkg install xorg 176 | 177 | Run the following commands. 178 | Pay attention to the output about xorg.conf. 179 | 180 | # pkg install urwfonts 181 | # pkg install terminus-font 182 | 183 | Run the following commands. 184 | 185 | # pkg install i3 186 | # pkg install i3status 187 | # pkg install dmenu 188 | 189 | Enabling wireless networking 190 | ---------------------------- 191 | Plug in your nifty EW-7811Un. 192 | Edit the following file. 193 | 194 | /boot/loader.conf 195 | 196 | Add the following options. 197 | 198 | if_urtwn_load="YES" 199 | legal.realtek.license_ack=1 200 | 201 | Reboot. 202 | 203 | Forcing traffic through a VPN 204 | ----------------------------- 205 | Edit the following file. 206 | 207 | /boot/loader.conf 208 | 209 | Add the following options. 210 | 211 | if_tun="YES" 212 | 213 | Download the .ovpn file of your choice from your provider. 214 | Copy it in the following location. 215 | 216 | /usr/local/etc/openvpn.conf 217 | 218 | Apply the following change to the file. 219 | 220 | ---- auth-user-pass 221 | ++++ auth-user-pass /home/your-name/.vpn 222 | 223 | ++++ daemon 224 | 225 | Create the following file. 226 | 227 | /home/your-name/.vpn 228 | 229 | With the following content. 230 | 231 | username 232 | password 233 | 234 | Edit the following file. 235 | 236 | /etc/resolv.conf 237 | 238 | List only the DNS servers of your provider. 239 | 240 | nameserver 103.86.96.100 241 | nameserver 103.86.99.100 242 | 243 | Lock things up with the following command. 244 | 245 | chflags schg /etc/resolv.conf 246 | 247 | Edit the following file. 248 | 249 | /etc/pf.conf 250 | 251 | Set the following outbound rules. 252 | Use the DNS servers and IP address of your provider. 253 | 254 | block out all 255 | pass out on wlan0 proto {tcp udp} from any to {103.86.96.100 103.86.99.100} port 53 256 | pass out on wlan0 proto {tcp udp} from any to 67.215.14.197 257 | pass out on tun0 all 258 | -------------------------------------------------------------------------------- /procedures/installing-gentoo-laptop-firewall.md: -------------------------------------------------------------------------------- 1 | Setting up a firewall on a laptop 2 | --------------------------------- 3 | Run the following commands. 4 | 5 | $ emerge --ask net-firewall/iptables 6 | $ rc-service iptables save 7 | $ rc-update add iptables default 8 | 9 | Run the following commands. 10 | Where 162.219.176.19 is the address of your VPN. 11 | All traffic will be forced through there. 12 | 13 | iptables -F 14 | iptables -X 15 | iptables -Z 16 | 17 | iptables -P INPUT DROP 18 | iptables -P FORWARD DROP 19 | iptables -P OUTPUT DROP 20 | 21 | iptables -A INPUT -s 162.219.176.19 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 22 | iptables -A INPUT -p udp --sport 53 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 23 | iptables -A INPUT -i tun0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 24 | iptables -A INPUT -i lo -j ACCEPT 25 | 26 | iptables -A OUTPUT -d 162.219.176.19 -j ACCEPT 27 | iptables -A OUTPUT -p udp --dport 53 -j ACCEPT 28 | iptables -A OUTPUT -o tun0 -j ACCEPT 29 | iptables -A OUTPUT -o lo -j ACCEPT 30 | 31 | ip6tables -F 32 | ip6tables -X 33 | ip6tables -Z 34 | 35 | ip6tables -P INPUT DROP 36 | ip6tables -P FORWARD DROP 37 | ip6tables -P OUTPUT DROP 38 | -------------------------------------------------------------------------------- /procedures/installing-gentoo-laptop-kernel.md: -------------------------------------------------------------------------------- 1 | Kernel options for a laptop 2 | --------------------------- 3 | Select the following options. 4 | 5 | Processor type and features 6 | Processor family 7 | (X) Core 2/Newer Xeon 8 | 9 | Device drivers 10 | Multiple devices driver support (RAID and LVM) 11 | Device mapper support 12 | <*> Crypt target support 13 | Network device support 14 | Network core driver support 15 | <*> Universal TUN/TAP device driver support 16 | Ethernet driver support 17 | [*] Realtek devices 18 | Realtek 8169 gigabit ethernet support 19 | Wireless LAN 20 | Atheros Wireless Cards 21 | Atheros 802.11n wireless cards support 22 | [*] Atheros ath9k PCI/PCIe bus support 23 | 24 | Cryptographic API 25 | <*> XTS support 26 | <*> AES cipher algorithms (x86_64) 27 | -------------------------------------------------------------------------------- /procedures/installing-gentoo-laptop-network.md: -------------------------------------------------------------------------------- 1 | Setting up the network on a laptop 2 | ---------------------------------- 3 | Run the following commands. 4 | 5 | $ ln -s /etc/init.d/net.lo /etc/init.d/net.enp2s0 6 | $ ln -s /etc/init.d/net.lo /etc/init.d/net.wlp1s0 7 | 8 | Edit the following file. 9 | 10 | /etc/conf.d/hostname 11 | 12 | Modify the following variable. 13 | 14 | hostname="laptop" 15 | 16 | Edit the following file. 17 | 18 | /etc/issue 19 | 20 | Set the following content. 21 | 22 | This is \n (\s \m \r) \t 23 | 24 | Run the following commands. 25 | 26 | $ emerge --ask net-misc/dhcpcd 27 | $ emerge --ask net-wireless/wpa_supplicant 28 | 29 | Edit the following file. 30 | 31 | /etc/wpa_supplicant/wpa_supplicant.conf 32 | 33 | Set the following content. 34 | 35 | ctrl_interface=/var/run/wpa_supplicant 36 | eapol_version=1 37 | ap_scan=1 38 | 39 | network={ 40 | ssid="" 41 | psk="" 42 | } 43 | -------------------------------------------------------------------------------- /procedures/installing-gentoo-server-firewall.md: -------------------------------------------------------------------------------- 1 | Setting up a firewall on a server 2 | --------------------------------- 3 | Run the following commands. 4 | 5 | $ emerge --ask net-firewall/iptables 6 | $ rc-service iptables save 7 | $ rc-update add iptables default 8 | 9 | Run the following commands. 10 | This will only let in ssh and https. 11 | 12 | iptables -F 13 | iptables -X 14 | iptables -Z 15 | 16 | iptables -P INPUT DROP 17 | iptables -P FORWARD DROP 18 | iptables -P OUTPUT ACCEPT 19 | 20 | iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 21 | 22 | iptables -A INPUT -p tcp --dport 22 -j ACCEPT 23 | iptables -A INPUT -p tcp --dport 443 -j ACCEPT 24 | 25 | ip6tables -F 26 | ip6tables -X 27 | ip6tables -Z 28 | 29 | ip6tables -P INPUT DROP 30 | ip6tables -P FORWARD DROP 31 | ip6tables -P OUTPUT DROP 32 | -------------------------------------------------------------------------------- /procedures/installing-gentoo-server-kernel.md: -------------------------------------------------------------------------------- 1 | Kernel options for a server 2 | --------------------------- 3 | Select the following options. 4 | 5 | Processor type and features 6 | [*] Linux guest support 7 | Processor family 8 | (X) Core 2/Newer Xeon 9 | 10 | Device drivers 11 | Block devices 12 | <*> Virtio block driver 13 | Multiple devices driver support (RAID and LVM) 14 | Device mapper support 15 | <*> Crypt target support 16 | SCSI device suppoer 17 | SCSI low-lever drivers 18 | <*> virtio-scsi support 19 | Network device support 20 | Network driver support 21 | <*> Virtio network driver 22 | Virtuo drivers 23 | <*> PCI drivers for virtio devices 24 | [*] Support for legacy virtio draft 0.9.X and older devices 25 | <*> Virtio balloon driver 26 | <*> Platform bus driver for memory mapped virtio devices 27 | 28 | Cryptographic API 29 | <*> XTS support 30 | <*> AES cipher algorithms (x86_64) 31 | 32 | Virtualization 33 | [*] Host kernel accelerator for virtuo net 34 | -------------------------------------------------------------------------------- /procedures/installing-gentoo-server-network.md: -------------------------------------------------------------------------------- 1 | Setting up the network on a server 2 | ---------------------------------- 3 | Run the following commands. 4 | 5 | $ ln -s /etc/init.d/net.lo /etc/init.d/net.eth0 6 | $ rc-update add net.eth0 default 7 | 8 | Edit the following file. 9 | 10 | /etc/conf.d/hostname 11 | 12 | Modify the following variable. 13 | 14 | hostname="server-name" 15 | -------------------------------------------------------------------------------- /procedures/installing-gentoo.md: -------------------------------------------------------------------------------- 1 | Preparation 2 | ----------- 3 | Hook to the network using a cable. 4 | Boot from the minimal installation cd. 5 | Confirm the network is up with the following command. 6 | 7 | $ ping www.gentoo.org 8 | 9 | Creating the disk partitions 10 | ---------------------------- 11 | Run the following commands. 12 | 13 | $ parted -a optimal /dev/sda 14 | 15 | (parted) mklabel gpt 16 | (parted) unit mib 17 | 18 | (parted) mkpart primary 1 3 19 | (parted) name 1 grub 20 | (parted) set 1 bios_grub on 21 | 22 | (parted) mkpart primary 3 131 23 | (parted) name 2 boot 24 | (parted) set 2 boot on 25 | 26 | (parted) mkpart primary 131 643 27 | (parted) name 3 swap 28 | 29 | (parted) mkpart primary 643 -1 30 | (parted) name 4 root 31 | 32 | (parted) quit 33 | 34 | Creating the file systems 35 | ------------------------- 36 | Run the following commands. 37 | Safely ignore errors about busy devices. 38 | 39 | $ mkfs.ext4 /dev/sda2 40 | 41 | $ cryptsetup create -d /dev/urandom swap /dev/sd3 42 | $ mkswap /dev/mapper/swap 43 | $ swapon /dev/mapper/swap 44 | 45 | $ cryptsetup luksFormat /dev/sda4 46 | $ cryptsetup luksOpen /dev/sda4 root 47 | $ mkfs.ext4 /dev/mapper/root 48 | 49 | Mounting the disks 50 | ------------------ 51 | Run the following commands. 52 | 53 | $ mount /dev/mapper/root /mnt/gentoo 54 | $ mkdir /mnt/gentoo/boot 55 | $ mount /dev/sda2 /mnt/gentoo/boot 56 | 57 | Downloading the stage3 archive 58 | ------------------------------ 59 | Run the following commands. 60 | 61 | $ cd /mnt/gentoo 62 | $ links http://mirror.csclub.uwaterloo.ca/gentoo-distfiles/ 63 | releases/amd64/autobuilds/current-stage3-amd64/ 64 | 65 | Select the following file and press D. 66 | 67 | stage3-amd64-*.tar.bz2 68 | 69 | Run the following command. 70 | 71 | $ tar -xjpf stage3-amd64-*.tar.bz2 --xattrs 72 | 73 | Selecting the packages mirror 74 | ----------------------------- 75 | Run the following command. 76 | 77 | $ mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf 78 | 79 | Select the following mirror. 80 | 81 | http://mirror.csclub.uwaterloo.ca/gentoo-distfiles/ 82 | 83 | Setting the compile options 84 | --------------------------- 85 | Edit the following file. 86 | 87 | /mnt/gentoo/etc/portage/make.conf 88 | 89 | Set the following variables. 90 | Use the number of cores plus one for parallel builds. 91 | 92 | CFLAGS="-march=native -O2 -pipe" 93 | MAKEOPTS="-j5" 94 | 95 | Add the following flags to play videos on a desktop computer. 96 | 97 | CPU_FLAGS_X86="mmx mmxext sse sse2 sse3" 98 | 99 | Switching to the installed root 100 | ------------------------------- 101 | Run the following commands. 102 | 103 | $ cp -L /etc/resolv.conf /mnt/gentoo/etc/ 104 | 105 | $ mount -t proc proc /mnt/gentoo/proc 106 | $ mount --rbind /sys /mnt/gentoo/sys 107 | $ mount --rbind /dev /mnt/gentoo/dev 108 | 109 | $ chroot /mnt/gentoo 110 | $ source /etc/profile 111 | $ export PS1="(chroot) $PS1" 112 | 113 | Updating the packages 114 | --------------------- 115 | Run the following commands. 116 | 117 | $ emerge-webrsync 118 | $ eselect profile list 119 | $ eselect profile set X 120 | 121 | Where X should be the number one of these. 122 | 123 | - Server: default/linux/amd64/13.0 124 | - Desktop: default/linux/amd64/13.0/desktop 125 | 126 | Run the following commands. 127 | 128 | $ emerge --ask --update --deep --newuse @world 129 | 130 | You probably deserved a long nap. Take it now. 131 | 132 | Configuration 133 | ------------- 134 | Run the following commands. 135 | 136 | $ echo 'Canada/Eastern' > /etc/timezone 137 | $ emerge --config sys-libs/timezone-data 138 | 139 | Edit the following file. 140 | 141 | /etc/locale.gen 142 | 143 | Uncomment the following lines. 144 | 145 | en_US ISO-8859-1 146 | en_US.UTF-8 UTF-8 147 | 148 | Run the following commands. 149 | 150 | $ locale-gen 151 | $ eselect locale list 152 | $ eselect locale set X 153 | 154 | Where X is the number for en_US.utf8. 155 | Run the following commands. 156 | 157 | $ env-update 158 | $ source /etc/profile 159 | $ export PS1="(chroot) $PS1" 160 | 161 | Declaring the file systems 162 | -------------------------- 163 | Edit the following file. 164 | 165 | /etc/fstab 166 | 167 | Set the following content. 168 | 169 | /dev/sda2 /boot ext4 noauto,noatime 0 2 170 | /dev/mapper/root / ext4 noatime 0 1 171 | /dev/mapper/swap none swap sw 0 0 172 | /dev/cdrom /mnt/cdrom auto noauto 0 0 173 | /dev/usb /mnt/usb auto noauto 0 0 174 | 175 | Setting up system logging 176 | ------------------------- 177 | Run the following commands. 178 | 179 | $ emerge --ask app-admin/sysklogd 180 | $ emerge --ask app-admin/logrotate 181 | $ emerge --ask app-admin/dcron 182 | 183 | $ rc-update add sysklogd default 184 | $ rc-update add dcron default 185 | 186 | Setting up the network 187 | ---------------------- 188 | See one of the following procedures. 189 | 190 | - [Laptop](installing-gentoo-laptop-network.md) 191 | - [Server](installing-gentoo-server-network.md) 192 | 193 | Building the kernel 194 | ------------------- 195 | Run the following commands. 196 | 197 | $ emerge --ask sys-kernel/gentoo-sources 198 | $ cd /usr/src/linux 199 | $ make menuconfig 200 | 201 | See one of the following set of options. 202 | 203 | - [Laptop](installing-gentoo-laptop-kernel.md) 204 | - [Server](installing-gentoo-server-kernel.md) 205 | 206 | Run the following commands. 207 | 208 | $ make -j5 && make modules_install 209 | $ make install 210 | 211 | Setting up the bootloader 212 | ------------------------- 213 | Run the following commands. 214 | 215 | $ emerge --ask sys-fs/cryptsetup 216 | $ emerge --ask sys-fs/lvm2 217 | $ emerge --ask sys-kernel/genkernel 218 | 219 | For a desktop computer run the following command. 220 | 221 | $ genkernel --luks --lvm initramfs 222 | 223 | For a server run the following command. 224 | 225 | $ genkernel --luks --lvm --virtio initramfs 226 | 227 | Run the following commands. 228 | 229 | $ emerge --ask sys-boot/grub:2 230 | $ grub-install /dev/sda 231 | $ ls -l /dev/disk/by-uuid 232 | 233 | Note the GUID of /dev/sda4. 234 | Edit the following file. 235 | 236 | /etc/default/grub 237 | 238 | Modify the following variables. 239 | 240 | GRUB_CMDLINE_LINUX="crypt_root=UUID= root=/dev/mapper/root" 241 | 242 | Run the following command. 243 | 244 | $ grub-mkconfig -o /boot/grub/grub.cfg 245 | 246 | Setting up a firewall 247 | --------------------- 248 | See one of the following procedures. 249 | 250 | - [Laptop](installing-gentoo-laptop-firewall.md) 251 | - [Server](installing-gentoo-server-firewall.md) 252 | 253 | Configuring SSH 254 | --------------- 255 | Run the following command. 256 | 257 | $ emerge --ask net-misc/openssh 258 | 259 | Edit the following file. 260 | 261 | /etc/ssh/sshd_config 262 | 263 | Set the following options. 264 | 265 | PermitRootLogin no 266 | AuthorizedKeysFile .ssh/authorized_keys 267 | PasswordAuthentication no 268 | UsePAM no 269 | AllowUsers your-account 270 | 271 | Copy your public RSA key to this folder. 272 | 273 | /home/your-account/.ssh/authorized_keys 274 | 275 | Run the following command. 276 | 277 | $ rc-update add sshd default 278 | 279 | Final steps 280 | ----------- 281 | Run the following commands. 282 | 283 | $ rm stage3-amd64-*.tar.bz2 284 | $ passwd 285 | 286 | Reboot and pray. 287 | -------------------------------------------------------------------------------- /procedures/installing-openbsd-server.md: -------------------------------------------------------------------------------- 1 | Full Disk Encryption 2 | -------------------- 3 | Select the following option. 4 | 5 | (S)hell 6 | 7 | Run the following commands. 8 | 9 | # cd /dev && sh MAKEDEV sd0 10 | # dd if=/dev/urandom of=/dev/rsd0c bs=1m 11 | # fdisk -iy sd0 12 | # disklabel -E sd0 13 | 14 | sd0> a a 15 | offset: [64] 16 | size: [] 17 | FS type: [4.2BSD] RAID 18 | sd0*> w 19 | sd0> q 20 | 21 | # bioctl -c C -l sd0a softraid0 22 | # cd /dev && sh MAKEDEV sd1 23 | # dd if=/dev/zero of=/dev/rsd1c bs=1m count=1 24 | # exit 25 | 26 | OpenBSD Installation 27 | -------------------- 28 | Select the following options. 29 | 30 | (I)nstall 31 | 32 | system hostname: deep-thought 33 | network interface: vio0 34 | ipv4 address: dhcp 35 | ipv6 address: none 36 | 37 | start sshd: yes 38 | run x window system: no 39 | setup user: your-account 40 | password: hunter2 41 | root ssh login: no 42 | 43 | root disk: sd1 44 | whole disk mrb 45 | auto layout or edit auto layout 46 | 47 | sd0> R h 48 | new size (with unit) 8G 49 | sd0*> w 50 | sd0> q 51 | 52 | Create the file /etc/doas.conf 53 | 54 | permit persist :wheel 55 | 56 | Securing SSH 57 | ------------ 58 | Upload your public ssh key using scp 59 | and the password for your-user. 60 | 61 | scp key your-user@192.168.100.100:.ssh/authorized_keys 62 | 63 | Update the file /etc/ssh/sshd\_config. 64 | 65 | AuthenticationMethods publickey 66 | 67 | Update the file /etc/pf.conf. 68 | 69 | set skip on lo 70 | antispoof for vio0 inet 71 | 72 | block all 73 | block in quick from urpf-failed 74 | 75 | pass in log on vio0 proto tcp to server-ip port 22 76 | pass out on vio0 proto { tcp udp icmp } from server-ip 77 | 78 | Reboot feeling a little safer. 79 | 80 | Cherry Picking Services 81 | ----------------------- 82 | Create the file /etc/rc.conf.local 83 | 84 | ntpd_flags=NO 85 | slaacd_flags=NO 86 | smtpd_flags=NO 87 | sndiod_flags=NO 88 | 89 | Bells and Whistles 90 | ------------------ 91 | Update the file ~/.profile. 92 | 93 | PS1="\[\033[31m\]\u@\h:\w\\$\[\033[0m\] " 94 | export PS1 95 | -------------------------------------------------------------------------------- /procedures/installing-salix-laptop.md: -------------------------------------------------------------------------------- 1 | Configuring the BIOS 2 | -------------------- 3 | Apply the following settings. 4 | 5 | - Date and time: Now as UTC 6 | - Secure Boot Control: Disabled 7 | - Launch CSM: Enabled 8 | - Boot option #1: [P0: SanDisk] 9 | 10 | Use the boot override feature and select the DVD. 11 | 12 | Salix installation 13 | ------------------ 14 | Select the following options. 15 | 16 | - Keep the current keymap 17 | - Exit the installation 18 | 19 | Creating the disk partitions 20 | ---------------------------- 21 | Run the following commands. 22 | 23 | $ fdisk /dev/sda 24 | 25 | Command (m for help): o 26 | Command (m for help): n p 1 default +128M 27 | Command (m for help): n p 2 default +235G 28 | Command (m for help): n p 3 default +1G 29 | Command (m for help): a 1 30 | Command (m for help): t 3 82 31 | Command (m for help): w 32 | 33 | $ cryptsetup -s 256 -y luksFormat /dev/sda2 34 | $ cryptsetup luksOpen /dev/sda2 lukssda2 35 | $ setup 36 | 37 | Salix installation 38 | ------------------ 39 | Pay attention to the following options. 40 | 41 | - Partitions editor: Exit 42 | - Select Linux installation partition: /dev/mapper/lukssda2 43 | - Select other Linux partitions: /dev/sda1 at /boot 44 | - Select installation mode: Core 45 | - Install LILO: simple standard MBR 46 | - Network: laptop laptop NetworkManager 47 | - Exit to command line 48 | 49 | Configuring the file systems 50 | ---------------------------- 51 | Edit the following file. 52 | 53 | /mnt/etc/crypttab 54 | 55 | Add the following lines. 56 | 57 | lukssda2 /dev/sda2 58 | lukssda3 /dev/sda3 none swap 59 | 60 | Edit the following file. 61 | 62 | /mnt/etc/fstab 63 | 64 | Adjust the following line. 65 | 66 | /dev/mapper/lukssda3 swap swap defaults 0 0 67 | 68 | Configuring the boot loader 69 | --------------------------- 70 | Run the following commands. 71 | 72 | $ mount -o bind /proc /mnt/proc 73 | $ mount -o bind /sys /mnt/sys 74 | $ chroot /mnt 75 | 76 | $ mkinitrd -c -k 4.4.19 -m ehci-pci:xhci-hcd:usbhid:hid-generic \ 77 | -f ext4 -r lukssda2 -C /dev/sda2 -L 78 | 79 | Edit the following file. 80 | 81 | /etc/lilo.conf 82 | 83 | Modify the following settings. 84 | 85 | append="quiet vt.default_utf8=1 video=640x480@60" 86 | 87 | image = /boot/vmlinuz 88 | initrd = /boot/initrd.gz 89 | root = /dev/mapper/cryptroot 90 | label = linux 91 | read-only 92 | 93 | Run the following command then reboot. 94 | 95 | $ lilo 96 | 97 | Connecting to the wireless network 98 | ---------------------------------- 99 | Plugin a network cable. 100 | Run the following commands. 101 | 102 | $ dhcdcp 103 | 104 | $ spi -u 105 | $ spi -U 106 | $ spi -i rfkill 107 | $ spi -i wpa_supplicant 108 | 109 | Edit the following file. 110 | 111 | /etc/wpa_supplicant.conf 112 | 113 | Add the following lines. 114 | 115 | network={ 116 | ssid="name" 117 | psk="password" 118 | } 119 | 120 | Disconnect the network cable and reboot. 121 | Run following commands. 122 | 123 | $ rfkill unblock wan 124 | $ wpa_supplicant -Dnl80211 -iwlan0 -c /etc/wpa_supplicant.conf -B 125 | $ dhcpcd 126 | 127 | Forcing the network traffic through a VPN 128 | ----------------------------------------- 129 | Create the following file. 130 | 131 | /etc/rc.d/rc.firewall 132 | 133 | With the following content. 134 | Where 184.75.221.106 is the VPN address. 135 | 136 | #!/bin/bash 137 | if [ "$1" = "start" ] 138 | then 139 | echo "Applying firewall configuration" 140 | 141 | iptables -F 142 | iptables -X 143 | iptables -Z 144 | 145 | iptables -P INPUT DROP 146 | iptables -P FORWARD DROP 147 | iptables -P OUTPUT DROP 148 | 149 | iptables -A INPUT -s 184.75.221.106 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 150 | iptables -A INPUT -p udp --sport 53 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 151 | iptables -A INPUT -i tun0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 152 | iptables -A INPUT -i lo -j ACCEPT 153 | 154 | iptables -A OUTPUT -d 184.75.221.106 -j ACCEPT 155 | iptables -A OUTPUT -p udp --dport 53 -j ACCEPT 156 | iptables -A OUTPUT -o tun0 -j ACCEPT 157 | iptables -A OUTPUT -o lo -j ACCEPT 158 | 159 | ip6tables -F 160 | ip6tables -X 161 | ip6tables -Z 162 | 163 | ip6tables -P INPUT DROP 164 | ip6tables -P FORWARD DROP 165 | ip6tables -P OUTPUT DROP 166 | fi 167 | 168 | Run the following command. 169 | 170 | $ chmod +x /etc/rc.d/rc.firewall 171 | 172 | Installing the i3 windows manager 173 | --------------------------------- 174 | Run the following commands. 175 | 176 | $ slapt-get --install-set x 177 | $ spi -i i3 178 | $ spi -i i3status 179 | 180 | The following manual interventions will be requied. 181 | 182 | - Comment out the line about /usr/man in i3.Slackbuild 183 | - Make the script executable then run it by hand 184 | - Install the package using installpkg 185 | 186 | Configuring the screen resolution 187 | --------------------------------- 188 | Create the following file. 189 | 190 | /etc/X11/xorg.conf 191 | 192 | With the following content. 193 | 194 | Section "Monitor" 195 | Identifier "eDP" 196 | EndSection 197 | 198 | Section "Screen" 199 | Identifier "Screen0" 200 | Monitor "eDP" 201 | DefaultDepth 24 202 | SubSection "Display" 203 | Depth 24 204 | Modes "1280x720" 205 | EndSubSection 206 | EndSection 207 | 208 | Configuring the keyboard 209 | ------------------------ 210 | Edit the following file. 211 | 212 | /etc/inputrc 213 | 214 | Modify the following lines. 215 | 216 | # Set various nice escape sequences: 217 | "\e[1;5C": forward-word 218 | "\e[1;5D": backward-word 219 | -------------------------------------------------------------------------------- /procedures/installing-salix-server.md: -------------------------------------------------------------------------------- 1 | Salix installation 2 | ------------------ 3 | Select the following options. 4 | 5 | - Keep the current keymap 6 | - Exit the installation 7 | 8 | Creating the disk partitions 9 | ---------------------------- 10 | Run the following commands. 11 | 12 | $ fdisk /dev/vda 13 | 14 | Command (m for help): o 15 | Command (m for help): n p 1 default +128M 16 | Command (m for help): n p 2 default +235G 17 | Command (m for help): n p 3 default +1G 18 | Command (m for help): a 1 19 | Command (m for help): t 3 82 20 | Command (m for help): w 21 | 22 | $ cryptsetup -s 256 -y luksFormat /dev/vda2 23 | $ cryptsetup luksOpen /dev/vda2 luksvda2 24 | $ setup 25 | 26 | Salix installation 27 | ------------------ 28 | Pay attention to the following options. 29 | 30 | - Partitions editor: Exit 31 | - Select Linux installation partition: /dev/mapper/luksvda2 32 | - Select other Linux partitions: /dev/vda1 at /boot 33 | - Select installation mode: Core 34 | - Install LILO: simple standard MBR 35 | - Network: laptop laptop DHCP 36 | - Exit to command line 37 | 38 | Configuring the file systems 39 | ---------------------------- 40 | Edit the following file. 41 | 42 | /mnt/etc/crypttab 43 | 44 | Add the following lines. 45 | 46 | luksvda2 /dev/vda2 47 | luksvda3 /dev/vda3 none swap 48 | 49 | Edit the following file. 50 | 51 | /mnt/etc/fstab 52 | 53 | Adjust the following line. 54 | 55 | /dev/mapper/luksvda3 swap swap defaults 0 0 56 | 57 | Configuring the boot loader 58 | --------------------------- 59 | Run the following commands. 60 | 61 | $ mount -o bind /proc /mnt/proc 62 | $ mount -o bind /sys /mnt/sys 63 | $ chroot /mnt 64 | 65 | $ mkinitrd -c -k 4.4.19 -f ext4 -r vda2 -C /dev/vda2 -L 66 | 67 | Edit the following file. 68 | 69 | /etc/lilo.conf 70 | 71 | Set the following options. 72 | 73 | append="quiet vt.default_utf8=1 video=640x480@60" 74 | 75 | disk = /dev/vda bios=0x80 max-partitions=7 76 | boot = /dev/vda 77 | 78 | image = /boot/vmlinuz 79 | initrd = /boot/initrd.gz 80 | root = /dev/mapper/luksvda2 81 | label = Salix 82 | read-only 83 | 84 | Run the following command then reboot. 85 | 86 | $ lilo 87 | 88 | Enabling SSH 89 | ------------ 90 | Edit the following file. 91 | 92 | /etc/ssh/sshd_config 93 | 94 | Set the following options. 95 | 96 | PermitRootLogin no 97 | PubkeyAuthentication yes 98 | AuthorizedKeysFile .ssh/authorized_keys 99 | PasswordAuthentication no 100 | AllowUsers your-account 101 | 102 | Copy your public RSA key to this file. 103 | 104 | /home/your-account/.ssh/authorized_keys 105 | 106 | Run the following commands. 107 | 108 | $ chmod +x /etc/rc.d/rc.sshd 109 | $ /etc/rc.d/rc.sshd start 110 | 111 | Configuring the firewall 112 | ------------------------ 113 | Create the following file. 114 | 115 | /etc/rc.d/rc.firewall 116 | 117 | With the following content. 118 | 119 | #!/bin/bash 120 | if [ "$1" = "start" ] 121 | then 122 | echo "Applying firewall configuration" 123 | 124 | iptables -F 125 | iptables -X 126 | iptables -Z 127 | 128 | iptables -P INPUT DROP 129 | iptables -P FORWARD DROP 130 | iptables -P OUTPUT ACCEPT 131 | 132 | iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 133 | iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set 134 | iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 300 --hitcount 10 -j DROP 135 | iptables -A INPUT -p tcp --dport 22 -j ACCEPT 136 | iptables -A INPUT -p tcp --dport 443 -j ACCEPT 137 | 138 | ip6tables -F 139 | ip6tables -X 140 | ip6tables -Z 141 | 142 | ip6tables -P INPUT DROP 143 | ip6tables -P FORWARD DROP 144 | ip6tables -P OUTPUT DROP 145 | fi 146 | 147 | Run the following command. 148 | 149 | $ chmod +x /etc/rc.d/rc.firewall 150 | -------------------------------------------------------------------------------- /procedures/installing-salix-tombstone.md: -------------------------------------------------------------------------------- 1 | Configuring the BIOS 2 | -------------------- 3 | Apply the following settings. 4 | 5 | - Date and time: Now as UTC 6 | - Secure Boot: Disabled 7 | 8 | Reboot with the USB DVD connected. 9 | 10 | Salix installation 11 | ------------------ 12 | Select the following options. 13 | 14 | - Keep the current keymap 15 | - Exit the installation 16 | 17 | Creating the disk partitions 18 | ---------------------------- 19 | Run the following commands. 20 | 21 | $ gdisk /dev/mmcblk0 22 | 23 | Command (? for help): o 24 | Command (? for help): n 1 default +128M ef00 25 | Command (? for help): n 2 default +24G default 26 | Command (? for help): n 3 default +1G 8200 27 | Command (? for help): w 28 | 29 | $ mkfs.msdos -F 32 /dev/mmcblk0p1 30 | $ cryptsetup -s 256 -y luksFormat /dev/mmcblk0p2 31 | $ cryptsetup luksOpen /dev/mmcblk0p2 luksmmcblk0p2 32 | $ setup 33 | 34 | Salix installation 35 | ------------------ 36 | Pay attention to the following options. 37 | 38 | - Partitions editor: Exit 39 | - Select Linux installation partition: /dev/mapper/luksmmcblk0p2 40 | - Select installation mode: Core 41 | - Install LILO: skip 42 | - Network: tombstone tombstone DHCP 43 | - Exit to command line 44 | 45 | Configuring the file systems 46 | ---------------------------- 47 | Edit the following file. 48 | 49 | /mnt/etc/crypttab 50 | 51 | Add the following lines. 52 | 53 | luksmmcblk0p2 /dev/mmcblk0p2 54 | luksmmcblk0p3 /dev/mmcblk0p3 none swap 55 | 56 | Edit the following file. 57 | 58 | /mnt/etc/fstab 59 | 60 | Adjust the following line. 61 | 62 | /dev/mapper/luksmmcblk0p3 swap swap defaults 0 0 63 | 64 | Configuring the boot loader 65 | --------------------------- 66 | Run the following commands. 67 | 68 | $ mount -o bind /proc /mnt/proc 69 | $ mount -o bind /sys /mnt/sys 70 | $ chroot /mnt 71 | 72 | Run the following command to get the modules loaded by the installer. 73 | Join them with : for the -m option of the next command. 74 | 75 | $ lsmod 76 | 77 | Run the following command. 78 | 79 | $ mkinitrd -c -k 4.4.19 -f ext4 -m mmc_core:mmc_block:... 80 | -r /dev/mapper/luksmmcblk0p2 -C /dev/mmcblk0p2 -L 81 | 82 | Edit the following file. 83 | 84 | /usr/sbin/eliloconfig 85 | 86 | Hack the following variable assignations. 87 | 88 | EFI_DEVICE="/dev/mmcblk0" 89 | EFI_PARTITION=1 90 | 91 | Run the following command. 92 | 93 | $ mkdir /boot/efi 94 | $ mount /dev/mmcblk0p1 /boot/efi 95 | $ eliloconfig 96 | 97 | Edit the following file. 98 | 99 | /boot/efi/EFI/Salix-Core-14.2/elilo.conf 100 | 101 | Delete the last line. 102 | 103 | append="root=..." 104 | 105 | Reboot and pray. 106 | 107 | Enabling SSH 108 | ------------ 109 | Edit the following file. 110 | 111 | /etc/ssh/sshd_config 112 | 113 | Set the following options. 114 | 115 | PermitRootLogin no 116 | PubkeyAuthentication yes 117 | AuthorizedKeysFile .ssh/authorized_keys 118 | PasswordAuthentication no 119 | AllowUsers your-account 120 | 121 | Copy your public RSA key to this file. 122 | 123 | /home/your-account/.ssh/authorized_keys 124 | 125 | Run the following commands. 126 | 127 | $ chmod +x /etc/rc.d/rc.sshd 128 | $ /etc/rc.d/rc.sshd start 129 | 130 | Configuring the firewall 131 | ------------------------ 132 | Create the following file. 133 | 134 | /etc/rc.d/rc.firewall 135 | 136 | With the following content. 137 | 138 | #!/bin/bash 139 | if [ "$1" = "start" ] 140 | then 141 | echo "Applying firewall configuration" 142 | 143 | iptables -F 144 | iptables -X 145 | iptables -Z 146 | 147 | iptables -P INPUT DROP 148 | iptables -P FORWARD DROP 149 | iptables -P OUTPUT ACCEPT 150 | 151 | iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT 152 | 153 | iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set 154 | iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 300 --hitcount 10 -j DROP 155 | iptables -A INPUT -p tcp --dport 22 -j ACCEPT 156 | 157 | iptables -A INPUT -p tcp --dport 25 -m state --state NEW -m recent --set 158 | iptables -A INPUT -p tcp --dport 25 -m state --state NEW -m recent --update --seconds 300 --hitcount 10 -j DROP 159 | iptables -A INPUT -p tcp --dport 25 -j ACCEPT 160 | 161 | iptables -A INPUT -p tcp --dport 587 -m state --state NEW -m recent --set 162 | iptables -A INPUT -p tcp --dport 587 -m state --state NEW -m recent --update --seconds 300 --hitcount 10 -j DROP 163 | iptables -A INPUT -p tcp --dport 587 -j ACCEPT 164 | 165 | iptables -A INPUT -p tcp --dport 993 -m state --state NEW -m recent --set 166 | iptables -A INPUT -p tcp --dport 993 -m state --state NEW -m recent --update --seconds 300 --hitcount 10 -j DROP 167 | iptables -A INPUT -p tcp --dport 993 -j ACCEPT 168 | 169 | ip6tables -F 170 | ip6tables -X 171 | ip6tables -Z 172 | 173 | ip6tables -P INPUT DROP 174 | ip6tables -P FORWARD DROP 175 | ip6tables -P OUTPUT DROP 176 | fi 177 | 178 | Run the following command. 179 | 180 | $ chmod +x /etc/rc.d/rc.firewall 181 | 182 | Generating a self signed SSL certificate 183 | ---------------------------------------- 184 | Run the following commands. 185 | 186 | $ sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 187 | -keyout /etc/ssl/private/mail.key 188 | -out /etc/ssl/certs/mailcert.pem 189 | 190 | Setting up a SMTP server 191 | ------------------------ 192 | Create a MX record pointing to your server. 193 | This can be confirmed with the following command. 194 | 195 | $ dig MX your-domain.com +short 196 | 50 your-domain.com 197 | 198 | Run the following commands. 199 | 200 | $ groupadd -g 200 postfix 201 | $ groupadd -g 201 postdrop 202 | $ useradd -u 200 -d /dev/null -s /bin/false -g postfix postfix 203 | $ sudo spi -i postfix 204 | 205 | Edit the following file. 206 | 207 | /etc/postfix/main.cf 208 | 209 | Adjust the following settings. 210 | 211 | myhostname = your-domain.com 212 | mydomain = your-domain.com 213 | myorigin = $mydomain 214 | mydestination = $mydomain 215 | mynetworks_style = host 216 | relay_domains = 217 | 218 | smtpd_relay_restrictions = permit_sasl_authenticated, reject_unauth_destination 219 | smtpd_recipient_restrictions = permit_sasl_authenticated, reject_unauth_destination 220 | 221 | smtpd_sasl_auth_enable = yes 222 | smtpd_sasl_type = dovecot 223 | smtpd_sasl_path = private/auth 224 | 225 | smtp_tls_security_level = may 226 | smtpd_tls_security_level = may 227 | smtpd_tls_cert_file = /etc/ssl/certs/mailcert.pem 228 | smtpd_tls_key_file = /etc/ssl/private/mail.key 229 | 230 | home_mailbox = Maildir/ 231 | 232 | Run the following commands. 233 | 234 | $ userdel mail 235 | $ useradd -m -U mail 236 | $ passwd mail 237 | 238 | Create the following file. 239 | 240 | /etc/aliases 241 | 242 | With the following content. 243 | 244 | postmaster: mail 245 | root: mail 246 | 247 | Run the following command. 248 | 249 | $ newaliases 250 | 251 | Setting up an IMAP server 252 | ------------------------- 253 | Run the following command. 254 | 255 | $ groupadd -g 202 dovecot 256 | $ useradd -d /dev/null -s /bin/false -u 202 -g 202 dovecot 257 | $ groupadd -g 248 dovenull 258 | $ useradd -d /dev/null -s /bin/false -u 248 -g 248 dovenull 259 | $ spi -i dovecot 260 | 261 | Create the following file. 262 | 263 | /etc/dovecot/dovecot.conf 264 | 265 | With the following content. 266 | 267 | protocols = imap 268 | 269 | service imap-login { 270 | inet_listener imap { 271 | port = 0 272 | } 273 | } 274 | 275 | userdb { 276 | driver = passwd-file 277 | args = username_format=%u /etc/dovecot/users 278 | } 279 | 280 | passdb { 281 | driver = passwd-file 282 | args = scheme=CRYPT username_format=%u /etc/dovecot/users 283 | } 284 | 285 | ssl = required 286 | ssl_cert = users 304 | 305 | Run the following commands. 306 | 307 | $ mv users /etc/dovecot/ 308 | $ chown dovecot:dovecot /etc/dovecot/users 309 | 310 | Edit the following file. 311 | 312 | /etc/postfix/master.cf 313 | 314 | Uncomment the following lines. 315 | 316 | submission inet n - - - - smtpd 317 | -o syslog_name=postfix/submission 318 | 319 | Run the following commands. 320 | 321 | $ chmod +x /etc/rc.d/rc.postfix 322 | $ /etc/rc.d/rc.postfix start 323 | 324 | $ chmod +x /etc/rc.d/rc.dovecot 325 | $ /etc/rc.d/rc.dovecot start 326 | -------------------------------------------------------------------------------- /procedures/installing-slackware-on-my-laptop.md: -------------------------------------------------------------------------------- 1 | Installing slackware 14.1 on my laptop 2 | ====================================== 3 | 4 | Selecting the packages to install 5 | --------------------------------- 6 | Select the following packages: 7 | 8 | A - Base Linux System 9 | Everything 10 | 11 | AP - Various Applications that do not need X 12 | alsa-utils 13 | ghostscript 14 | groff 15 | man 16 | man-pages 17 | 18 | F - FAQ lists, HOWTO documentation 19 | Everything 20 | 21 | L - System Libraries (Needed by KDE, GNOME, X, and more) 22 | alsa-lib 23 | alsa-oss 24 | dbus-glib 25 | dbus-python 26 | glib2 27 | libffi 28 | libnl3 29 | pygobject 30 | urwid 31 | 32 | N - Networking (TCP/IP, UUCP, Mail, News) 33 | dhcpcd 34 | iputils 35 | net-toolsdf 36 | network-scripts 37 | wireless-tools 38 | wpa-supplicant 39 | 40 | Booting straight to slackware 41 | ----------------------------- 42 | Run the following commands: 43 | 44 | # vi /etc/lilo.conf 45 | 46 | Perform the following edits: 47 | 48 | - Comment the section named Boot BMP Image 49 | - Uncomment the section named Standard menu 50 | 51 | Perform the following edits: 52 | 53 | append="logo.nologo vt.default_uft8=1" 54 | compact 55 | # prompt 56 | vga=791 57 | 58 | Run the following commands: 59 | 60 | # lilo 61 | 62 | Mounting the DVD drive 63 | ---------------------- 64 | Run the following commands: 65 | 66 | # vi /etc/fstab 67 | 68 | Perform the following edits: 69 | 70 | - Uncomment the line starting with /dev/cdrom 71 | 72 | Then run the following commands to mount a DVD: 73 | 74 | # su root 75 | # mount /dev/cdrom 76 | # exit 77 | 78 | # cd /mnt/cdrom 79 | 80 | Connecting to a network 81 | ----------------------- 82 | Run the following commands: 83 | 84 | # vi /etc/rc.d/rc.inet1.conf 85 | 86 | Perform the following edits: 87 | 88 | IPADDR[0]="" 89 | NETMASK[0]="" 90 | USE_DHCP[0]="" 91 | DHCP_HOSTNAME[0]="" 92 | GATEWAY[0]="" 93 | 94 | Run the following commands: 95 | 96 | # installpkg /mnt/cdrom/extra/wicd/wicd-1.7.2.4-x86_64-4.txz 97 | 98 | Run the following commands to disable automatic networking: 99 | 100 | # chmod -x /etc/rc.d/rc.wicd 101 | 102 | Then run the following commands to connect to a network: 103 | 104 | # su root 105 | # wicd 106 | # wicd-curses 107 | # exit 108 | 109 | Displaying UTF-8 characters 110 | --------------------------- 111 | Run the following commands: 112 | 113 | # vi /etc/profile.d/lang.sh 114 | 115 | Perform the following edits: 116 | 117 | # export LANG=en_US 118 | export LANG=en_US.UTF-8 119 | 120 | Run the following commands: 121 | 122 | # installpkg /mnt/cdrom/slackware64/ap/terminus-font-4.38-noarch-1.txz 123 | 124 | Run the following commands: 125 | 126 | # echo "setfont ter-v18n" >> ~/.bash_profile 127 | 128 | Connecting a printer 129 | -------------------- 130 | Get information about the printer: 131 | 132 | - Browse to www.openprinting.org 133 | - Find the printer model in the database 134 | - Download and install the recommended driver if applicable 135 | - Download the printer PPD file if applicable 136 | 137 | Alternatively: 138 | 139 | - Browse to the manufacturer web site 140 | - Download and install the printer driver 141 | 142 | Run the following commands to launch the printing daemon: 143 | 144 | # cupsd 145 | 146 | Perform the following actions: 147 | 148 | - Browse to localhost:631 149 | - Click on Administration / Add printer then select the printer 150 | - Give the printer a friendly name, let's say Samsung 151 | - Select the printer model if applicable 152 | - Select the PPD file if applicable 153 | 154 | Run the following commands to set the deault printer: 155 | 156 | # lpadmin -d Samsung 157 | 158 | Then run the following commands to print a document: 159 | 160 | # su root 161 | # cupsd 162 | # exit 163 | 164 | # lp document.txt 165 | 166 | Making noises 167 | ------------- 168 | Run the following commands: 169 | 170 | # su root 171 | # alsactl init 172 | # alsamixer 173 | 174 | Perform the following actions: 175 | 176 | - Adjust the default volume levels 177 | - Beware that the value MM indicates a muted channel 178 | - Type the m key to toggle muting 179 | 180 | Run the following commands: 181 | 182 | # alsactl store 183 | # exit 184 | 185 | Then run the following commands to play music: 186 | 187 | # aplay music.wav 188 | 189 | And optionally run the following commands to adjust volume: 190 | 191 | # alsamixer 192 | -------------------------------------------------------------------------------- /procedures/opting-out-from-tracking.md: -------------------------------------------------------------------------------- 1 | Do not give them your IP address 2 | -------------------------------- 3 | Open an account with NordVPN. 4 | This service has to be paid for. 5 | 6 | https://nordvpn.com/ 7 | 8 | Download the .ovpn file of your choice from their website. 9 | Copy it in the following location. 10 | 11 | /etc/openvpn/openvpn.conf 12 | 13 | Apply the following change to the file. 14 | 15 | ---- auth-user-pass 16 | ++++ auth-user-pass /home/your-name/.vpn 17 | 18 | ++++ daemon 19 | 20 | Create the following file. 21 | 22 | /home/your-name/.vpn 23 | 24 | With the following content. 25 | 26 | nordvpn-username 27 | nordvpn-password 28 | 29 | Simply refuse to talk to them 30 | ----------------------------- 31 | Download the hosts file from the following website. 32 | 33 | https://github.com/StevenBlack/hosts 34 | 35 | Put its content in the following file. 36 | 37 | /etc/hosts 38 | -------------------------------------------------------------------------------- /procedures/self-hosting.md: -------------------------------------------------------------------------------- 1 | Requirements 2 | ------------ 3 | You will need the following. 4 | 5 | - 1 Raspberry PI 6 | - 1 SD card 7 | - 1 static IP address (ask your ISP) 8 | - 2 drops of dedication 9 | 10 | Imaging the micro SD card 11 | ------------------------- 12 | Get the latest raspbian lite image from the following site. 13 | 14 | https://www.raspberrypi.org/downloads/ 15 | 16 | Connect the SD card to your computer. 17 | Run the following command to locate its device name. 18 | 19 | $ df -h 20 | ... 21 | /dev/sdX0 1.3G 831M 362M 70% /media/xxx 22 | ... 23 | 24 | Note the one mounted under media, where X is a letter and 0 is a number. 25 | Double check the device size to make sure. 26 | 27 | Run the following commands. 28 | 29 | $ umount /dev/sdX0 30 | $ sudo dd bs=4M if=2015-11-21-raspbian-jessie-lite.img of=/dev/sdX 31 | $ sync 32 | 33 | Insert the SD card into the pi and connect its network cable. 34 | Time for a first boot. 35 | 36 | Figuring out the pi's address 37 | ----------------------------- 38 | Run the following command from your laptop. 39 | 40 | $ ip addr 41 | ... 42 | 3: wlan0: mtu 1500 qdisc mq state UP group default qlen 1000 43 | ... 44 | 45 | Note the name of your connected network interface. 46 | Run the following command. 47 | 48 | $ sudo arp-scan --interface=wlan0 --localnet 49 | ... 50 | 192.168.1.102 b8:27:eb:cb:c2:cf (Unknown) 51 | ... 52 | 53 | Note the IP address for the MAC address starting with b8:27. 54 | This is the pi's current address on your network. 55 | 56 | Connecting to the pi 57 | -------------------- 58 | Run the following commands. 59 | 60 | $ ssh pi@192.168.1.102 61 | password: raspberry 62 | 63 | $ sudo adduser your-name 64 | $ sudo adduser your-name sudo 65 | $ exit 66 | 67 | Reconnect as yourself and run the following commands. 68 | 69 | $ ssh your-name@192.168.1.102 70 | $ sudo deluser -remove-home pi 71 | 72 | Resizing the file system 73 | ------------------------ 74 | Run the following command. 75 | 76 | $ sudo fdisk /dev/mmcblk0 77 | 78 | Type the command p. 79 | 80 | Device Boot Start End Sectors Size Id Type 81 | /dev/mmcblk0p1 8192 131071 122880 60M c W95 FAT32 (LBA) 82 | /dev/mmcblk0p2 131072 2848767 2717696 1.3G 83 Linux 83 | 84 | Note the start of the Linux partition. 85 | Type the following commands. 86 | 87 | - d 88 | - 2 89 | - n 90 | - p 91 | - 2 92 | - 131072 93 | - enter 94 | - w 95 | 96 | Run the following commands. 97 | 98 | $ sudo shutdown --reboot now 99 | $ sudo resize2fs /dev/mmcblk0p2 100 | 101 | Basic setup 102 | ----------- 103 | Run the following commands. 104 | 105 | $ sudo apt-get update 106 | $ sudo apt-get upgrade 107 | 108 | $ sudo hostnamectl set-hostname tombstone 109 | $ sudo dpkg-reconfigure tzdata 110 | 111 | Configuring SSH 112 | --------------- 113 | Run the following command from your laptop. 114 | Do so from a folder containing your public key. 115 | 116 | $ scp id_rsa.pub your-name@192.168.1.102:id_rsa.pub 117 | 118 | Run the following commands on the server. 119 | 120 | $ mkdir .ssh 121 | $ mv ~/id_rsa.pub .ssh/authorized_keys 122 | $ chmod 600 .ssh/authorized_keys 123 | 124 | Edit the following file on the server. 125 | 126 | /etc/ssh/sshd_config 127 | 128 | Apply the following changes. 129 | 130 | ---- PermitRootLogin without-password 131 | ++++ PermitRootLogin no 132 | ++++ AllowUsers your-name 133 | 134 | ---- #AuthorizedKeysFile %h/.ssh/authorized_keys 135 | ++++ AuthorizedKeysFile %h/.ssh/authorized_keys 136 | 137 | ---- #PasswordAuthentication yes 138 | ++++ PasswordAuthentication no 139 | 140 | Run the following command on the server. 141 | 142 | $ sudo /etc/init.d/ssh restart 143 | 144 | Run the following commands from your laptop. 145 | Do so from a folder containing your private key. 146 | 147 | $ cp id_rsa ~/.ssh 148 | $ chmod 600 ~/.ssh/id_rsa 149 | 150 | Reconnect to the server without a password. 151 | 152 | Setting up a firewall 153 | --------------------- 154 | Run the following command to install the firewall. 155 | 156 | $ sudo apt-get install ufw 157 | 158 | Edit the following file and set IPV6=no. 159 | 160 | /etc/default/ufw 161 | 162 | Run the following commands. 163 | 164 | $ sudo ufw default allow outgoing 165 | $ sudo ufw default deny incoming 166 | $ sudo ufw limit 22/tcp 167 | $ sudo ufw enable 168 | 169 | Preventing brute force logins 170 | ----------------------------- 171 | Edit the following file. 172 | 173 | /etc/pam.d/common-auth 174 | 175 | Add the following line at the beginning of the file. 176 | 177 | ++++ auth required pam_tally2.so file=/var/log/tallylog deny=3 even_deny_root unlock_time=300 178 | 179 | Edit the following file. 180 | 181 | /etc/pam.d/common-account 182 | 183 | Add the following line at the beginning of the file. 184 | 185 | ++++ account required pam_tally2.so 186 | 187 | Run the following command. 188 | 189 | $ sudo /etc/init.d/ssh restart 190 | 191 | Blacklisting script kiddies from china 192 | -------------------------------------- 193 | Run the following command. 194 | 195 | sudo apt-get install libpam-geoip 196 | 197 | Edit the following file. 198 | 199 | /etc/security/geoip.conf 200 | 201 | Set the following configuration. 202 | 203 | # 204 | * sshd allow CA, * 205 | * sshd allow UNKNOWN 206 | * sshd deny * 207 | * * allow * 208 | 209 | Download the GeoIP database from the following site. 210 | 211 | http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz 212 | 213 | Edit the following file. 214 | 215 | /etc/pam.d/common-account 216 | 217 | Add the following line at the beginning of the file. 218 | 219 | ++++ account required pam_geoip.so geoip_db=/etc/security/geoip.dat 220 | 221 | Run the following command. 222 | 223 | $ sudo /etc/init.d/ssh restart 224 | 225 | Generating a self signed SSL certificate 226 | ---------------------------------------- 227 | Run the following commands. 228 | 229 | $ sudo openssl req -x509 -nodes -days 3650 -newkey rsa:2048 230 | -keyout /etc/ssl/private/mail.key 231 | -out /etc/ssl/certs/mailcert.pem 232 | 233 | Setting up a mail server 234 | ------------------------ 235 | Create a MX record pointing to your server. 236 | This can be confirmed with the following command. 237 | 238 | $ dig MX your-domain.com +short 239 | 50 your-domain.com 240 | 241 | Run the following commands. 242 | 243 | $ sudo apt-get install postfix 244 | $ sudo postfix stop 245 | 246 | Answer the following when prompted. 247 | 248 | - Internet Site 249 | - your-domain.com 250 | 251 | Edit the following file. 252 | 253 | /etc/postfix/main.cf 254 | 255 | Replace its content with the following lines. 256 | 257 | compatibility_level = 2 258 | 259 | myhostname = your-domain.com 260 | mydomain = your-domain.com 261 | myorigin = $mydomain 262 | mydestination = $mydomain 263 | mynetworks_style = host 264 | relay_domains = 265 | 266 | smtpd_relay_restrictions = reject_unauth_destination 267 | smtpd_recipient_restrictions = reject_unauth_destination 268 | 269 | smtp_tls_security_level = may 270 | smtpd_tls_security_level = may 271 | smtpd_tls_cert_file = /etc/ssl/certs/mailcert.pem 272 | smtpd_tls_key_file = /etc/ssl/private/mail.key 273 | 274 | home_mailbox = Maildir/ 275 | 276 | Edit the following file. 277 | 278 | /etc/aliases 279 | 280 | Define the following aliases. 281 | 282 | mail: your-user 283 | 284 | Run the following commands. 285 | 286 | $ sudo ufw limit 25/tcp 287 | 288 | Run the following command. 289 | 290 | $ sudo newaliases 291 | $ sudo postfix start 292 | 293 | Using the mail server remotely 294 | ------------------------------ 295 | Run the following command. 296 | 297 | $ sudo apt-get install dovecot-core dovecot-imapd 298 | 299 | Edit the following file. 300 | 301 | /etc/dovecot/dovecot.conf 302 | 303 | Replace its content with the following lines. 304 | 305 | protocols = imap 306 | 307 | service imap-login { 308 | inet_listener imap { 309 | port = 0 310 | } 311 | } 312 | 313 | userdb { 314 | driver = passwd 315 | } 316 | 317 | passdb { 318 | driver = pam 319 | args = dovecot 320 | } 321 | 322 | ssl = required 323 | ssl_cert = /usr/local/bin/gnome-keyring-daemon << "EOF" 6 | #!/bin/sh 7 | /usr/bin/gnome-keyring-daemon --start -c pkcs11,secrets 8 | EOF 9 | 10 | $ sudo chmod 777 /usr/local/bin/gnome-keyring-daemon 11 | 12 | Installing the yubikey tools 13 | ---------------------------- 14 | Run the following commands: 15 | 16 | $ sudo apt-get install yubikey-personalization-gui yubikey-neo-manager yubikey-personalization 17 | $ sudo apt-get install pcscd scdaemon gnupg2 pcsc-tools 18 | 19 | Enabling CCID on the yubikey 20 | ---------------------------- 21 | Run the following command: 22 | 23 | $ ykpersonalize -m82 24 | 25 | Generating the encryption keys 26 | ------------------------------ 27 | Run the following command: 28 | 29 | $ gpg --card-edit 30 | admin 31 | generate 32 | Make off-card backup of encryption key? (Y/n) n 33 | quit 34 | 35 | Exporting the public key 36 | ------------------------ 37 | Run the following command: 38 | 39 | $ gpg --armor --export your_email@address.com 40 | 41 | Share it with the world. 42 | 43 | Generating a revocation key 44 | --------------------------- 45 | Run the following command: 46 | 47 | $ gpg --gen-revoke your_email@address.com 48 | 49 | Do NOT share it with the world. 50 | Do NOT save it to file. 51 | 52 | Common operations 53 | ----------------- 54 | Sending a message to yourself: 55 | 56 | $ gpg --encrypt --armor -r your_email@address.com 57 | Hello 58 | CTRL+D 59 | 60 | Reading a message sent to yourself: 61 | 62 | $ gpg 63 | -----BEGIN PGP MESSAGE----- 64 | Version: GnuPG v1 65 | ... 66 | -----END PGP MESSAGE----- 67 | CTRL+D 68 | Hello 69 | -------------------------------------------------------------------------------- /scripts/wireless-scan: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ifconfig wlan0 scan 3 | -------------------------------------------------------------------------------- /scripts/wireless-up: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ifconfig wlan0 create wlandev rtwn0 3 | wpa_supplicant -Dbsd -i wlan0 -c /usr/local/etc/wpa_supplicant.conf -B 4 | dhclient wlan0 5 | openvpn /usr/local/etc/openvpn.conf 6 | --------------------------------------------------------------------------------