chris ~ $ 

software_developer devops_engineer ethical_hacker cheshire_uk

...

  Linux 

linux   server   devops

Cloud init

note: The #cloud-config is required.

#cloud-config
users:
  - default
  - name: chris
    groups: [docker, sudo]
    ssh_import_id:
      - gh:weavc
    lock_passwd: true
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    shell: /bin/bash

package_update: true
package_upgrade: true
packages:
 - docker.io
 - docker-compose

Setting up a persistant ssh tunnel to a firewalled server

Tunnel

ssh -g -N -T -o "ExitOnForwardFailure yes" -o "ServerAliveInterval 60" -R <listen on ip>:<listen on port>:localhost:22 <user>@<domain>

sshd_config

GatewayPorts yes

systemd

[Unit]
Description=SSH Tunnel
After=network.target

[Service]
Restart=always
RestartSec=20
User=<user>
ExecStart=/usr/bin/ssh -g -N -T -o "ExitOnForwardFailure yes" -o "ServerAliveInterval 60" -R <listen on ip>:<listen on port>:localhost:22 <user>@<domain>

[Install]
WantedBy=multi-user.target

Yubikey configuration

Yubikey setup, resources and guides

Useful Commands

Note: You often have to configure the yubikey do allow certain behaviours and create/setup pins and security credentials before running these commands. All of that can be done with yubikey-manager or ykman.

Install packages:

sudo apt-add-repository ppa:yubico/stable
sudo apt install yubikey-manager libfido2-dev gnupg pcscd scdaemon -y

Git config signing:

git config --global user.email "weavc@pm.me"
git config --global user.name "weavc"
git config --global user.signingkey 04FE6CA73DB1B038
git config --global gpg.program gpg
git config --global commit.gpgsign true

SSH Resident key:

Generate new key:
ssh-keygen -t ed25519-sk -O resident -C "weavc@pm.me"

Add from device to keychain:
ssh-add -K

Get local files from key (for backups or common use):
ssh-keygen -K

Import Public GPG key:

curl -fsSL http://www.weav.ovh/weavc@pm.me_pub.gpg | gpg --import

Resources

OpenSSL commands for generating RSA key pair

Used in Jwt and other similar things.

openssl genrsa -out <path>/privkey.pem 4096 && \
openssl rsa -in <path>/privkey.pem -pubout > <path>/pubkey.pem

Samba Network Share on Raspberry Pi

Using alexandreroman/rpi-samba

Create a directory for the share

mkdir [path-to-share]
  • This will be bind mounted to the docker container

Clone the repo & build the image

git clone https://github.com/alexandreroman/rpi-samba.git
cd rpi-samba
make

Run

docker run -d -it --name samba --restart=unless-stopped -v [path-to-share]:/data/share -p 445:445 rpi-samba

Luks / Cryptsetup Encrypted USB

Picking a cipher, mode, hash and key size

I ended up going with aes-xts-plain64.

Find where usb is mounted

fdisk -h

...

Disk /dev/sdb: 29.45 GiB, 31609323520 bytes, 61736960 sectors
Disk model: Mass-Storage
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Wipe the device

umount [/dev/sdb]
wipefs -a [/dev/sdb]

Encrpyt the device

cryptsetup -y --cipher [cipher] --key-size [keysize] luksFormat [/dev/sdb]

Will be prompted for the password here

Open

cryptsetup luksOpen [/dev/sdb] [some-volume-name]

Format

sudo mkfs.ext4 /dev/mapper/[some-volume-name] -L [some-volume-name]

Close

cryptsetup luksClose [volume-name]