Skip to content

Instantly share code, notes, and snippets.

@jordanluyke
Last active March 24, 2024 09:59
Show Gist options
  • Save jordanluyke/0118cb3d83c7b1f6659f1b4c470920d7 to your computer and use it in GitHub Desktop.
Save jordanluyke/0118cb3d83c7b1f6659f1b4c470920d7 to your computer and use it in GitHub Desktop.
Linux Setup

Linux Setup

Server

  • Download

  • Image:

    sudo fdisk -l
    

    Ubuntu:

    sudo dd if=ubuntu-server.iso of=/dev/sda bs=8M conv=fdatasync status=progress
    

    Fedora:

    sudo unxz --keep Fedora-Server-38-1.6.aarch64.raw.xz
    sudo dd if=Fedora-Server-38-1.6.aarch64.raw of=/dev/sda bs=8M conv=fdatasync status=progress
    
  • Timezone

    sudo timedatectl set-timezone America/Denver
    
  • Disable sleep

    systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
    
  • Add user

    sudo adduser username
    sudo usermod -aG sudo username
    sudo vi /etc/hostname
    
  • Resize LVM

    sudo lvdisplay
    sudo lvm lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
    sudo resize2fs -p /dev/mapper/ubuntu--vg-ubuntu--lv
    
  • Network: /etc/netplan/00-installer-config.yaml

    network:
      ethernets:
        eno1:
          dhcp4: true
          dhcp6: true
          optional: true
        enp6s0:
          dhcp4: true
          dhcp6: true
          optional: true
      version: 2
    
  • Wifi: /etc/netplan/50-cloud-init.yaml

    wifis:
      wlan0:
        dhcp4: true
        dhcp6: true
        optional: true
        access-points:
          "***":
            password: "***"
    
  • Swap Space

    sudo swapon -s
    sudo swapoff -a
    sudo fallocate -l 4G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    sudo swapon -s
    echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
    

VSCode

  • Tunnels

    tar zxvf vscode_cli_alpine_x64_cli.tar.gz
    ./code tunnel service install
    sudo loginctl enable-linger $USER
    

NodeJS

  • Install

    sudo apt install build-essential
    curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    sudo apt install nodejs
    
  • Self signed certificates

    openssl req -nodes -new -x509 -days 9999 -keyout key.pem -out cert.pem
    

Java

Config

  • ~/.gitconfig

    [user]
        email = x@y.z
    [alias]
        co = checkout
        s = status
        d = diff
    [core]
        editor = vim
    
  • ~/.vimrc

    set number
    syntax on
    
  • ~/.zshrc

    ZSH_THEME="steeef"
    
    export M2_HOME=$HOME/maven
    export PATH=$M2_HOME/bin:$PATH
    export PATH=/opt/homebrew/bin:$PATH
    export GPG_TTY=$(tty)
    

Startup

  • sudo touch /etc/systemd/system/azores.service

    [Unit]
    Description=Azores
    After=network.service
    
    [Service]
    ExecStart=/home/[username]/azores.sh
    
    [Install]
    WantedBy=default.target
    
  • touch azores.sh

    #!/bin/sh
    
    CMD="java -jar /home/[username]/server.jar > /home/[username]/server.log"
    #sudo -u [username] screen -dmS [screenname] bash -c "$CMD"
    su - [username] -c screen -dmS [screenname] bash -c "$CMD"
    
    chmod +x azores.sh
    sudo systemctl start azores
    sudo systemctl enable azores
    

SSH

  • Server

    sudo ssh-keygen -A
    sudo apt install openssh-server
    sudo systemctl enable ssh
    # optional: copy over .ssh folder
    eval $(ssh-agent -s)
    ssh-add
    
  • Create key

    ssh-keygen -t ed25519 -C x@y.z
    eval $(ssh-agent -s)
    ssh-add ~/.ssh/id_ed25519
    

GPG

  • Import from Keybase

    keybase pgp export | gpg --import
    keybase pgp export -s | gpg --allow-secret-key-import --import
    gpg --list-secret-keys --keyid-format LONG
    git config --global user.signingkey XXX
    git config --global commit.gpgsign true
    
    • ~/.gnupg/gpg-agent.conf
    default-cache-ttl 34560000
    max-cache-ttl 34560000
    
  • MacOS

    brew install pinentry-mac
    echo "pinentry-program /opt/homebrew/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
    gpgconf --kill gpg-agent && gpg-agent --daemon
    
  • Create key

    gpg --full-generate-key
    gpg --armor --export-secret-keys XXX | keybase pgp import --push-secret
    

Keybase

  • Install

    curl -OL https://prerelease.keybase.io/keybase_amd64.deb
    sudo apt install ./keybase_amd64.deb
    run_keybase -g
    keybase login
    

ZSH

  • Install

    sudo apt install zsh
    sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    
  • EC2

    sudo vi /etc/passwd
    username:x:1634231:100:Your Name:/home/username:/bin/zsh
    

Git

  • Install

    sudo add-apt-repository ppa:git-core/ppa
    sudo apt install git
    

Python

  • Install

    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt install python3.9 python3.9-dev python3.9-venv
    sudo apt install python3.10 python3.10-dev python3.10-venv
    sudo apt install python3.11 python3.11-dev python3.11-venv
    
    • Fix apt_pkg error on sudo apt update:
    sudo apt-get install python3-apt --reinstall
    cd /usr/lib/python3/dist-packages
    sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so
    
  • Versions

    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 3
    sudo update-alternatives --config python3
    
  • Pip

    curl -OL https://bootstrap.pypa.io/get-pip.py
    python3 get-pip.py
    
    export PATH=$HOME/.local/bin:$PATH
    
  • Venv

    python3 -m venv venv
    

CUDA

  • Install

    wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
    sudo dpkg -i cuda-keyring_1.1-1_all.deb
    sudo apt update
    
    sudo apt install cuda=12.2.2-1
    sudo apt-mark hold cuda
    
    sudo apt install libcudnn8=8.9.7.29-1+cuda12.2
    sudo apt-mark hold libcudnn8
    
    export PATH=/usr/local/cuda-12.2/bin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/usr/local/cuda-12.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    

Overclock

  • Setup

    sudo nvidia-xconfig -a --cool-bits=28 --allow-empty-initial-configuration
    sudo vi /etc/X11/Xwrapper.config
    allowed_users=anybody
    sudo apt install xorg lightdm # optional?
    sudo xinit & export DISPLAY=:0
    sudo reboot
    
  • oc.sh

    #!/bin/sh
    
    export DISPLAY=:0 
    export XAUTHORITY=/run/user/122/gdm/Xauthority
    
    POWER_LIMIT=300
    FAN_SPEED=90
    GPU_OFFSET=-200
    MEMORY_OFFSET=1200
    
    sudo nvidia-settings -q gpus -c :0
    sudo nvidia-smi -pl $POWER_LIMIT
    sudo nvidia-settings -a :0/GpuPowerMizerMode=1
    sudo nvidia-settings -a :0/GPUFanControlState=1
    sudo nvidia-settings -a :0/GPUTargetFanSpeed=$FAN_SPEED
    sudo nvidia-settings -a :0/GPUGraphicsClockOffsetAllPerformanceLevels=$GPU_OFFSET
    sudo nvidia-settings -a :0/GPUMemoryTransferRateOffsetAllPerformanceLevels=$MEMORY_OFFSET
    

lolMiner

  • Run

    ./1.35/lolMiner --coin ETH --pool ethash.unmineable.com:3333 --user ETH:0x
    

Syncthing

  • Install

    https://apt.syncthing.net

    sudo mkdir -p /etc/apt/keyrings
    sudo curl -L -o /etc/apt/keyrings/syncthing-archive-keyring.gpg https://syncthing.net/release-key.gpg
    sudo apt update
    sudo apt install syncthing
    syncthing # creates config file
    
  • Edit: ~/.local/state/syncthing/config.xml or ~/.config/syncthing/config.xml

    <gui>
        <address>0.0.0.0:8384</address>
    </gui>
    

    https://docs.syncthing.net/users/autostart.html#linux

    sudo systemctl enable syncthing@myuser.service
    sudo systemctl start syncthing@myuser.service
    

SDRPP

  • Install

    sudo launchctl stop com.sdrplay.sdrplay_service
    

Logging

  • Papertrail

    curl -OL [rsyslog].deb
    sudo dpkg -i [rsyslog].deb
    mkdir ~/logs
    touch ~/logs/[app].log
    sudo systemctl start remote_syslog
    sudo systemctl enable remote_syslog
    sudo vi /etc/log_files.yml
    
    files: 
      - /path/to/your/file.log
    destination:
      host: logs2.papertrailapp.com
      port: 123
      protocol: tls
    pid_file: /var/run/remote_syslog.pid
    

MySQL

  • Install

    sudo apt install mysql-server
    sudo systemctl status mysql
    sudo systemctl enable mysql
    sudo mysql_secure_installation
    
    brew install mysql@5.7
    echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
    source ~/.zshrc
    brew link --force mysql@5.7
    brew services start mysql@5.7
    sudo mysql_secure_installation
    
  • /etc/mysql/my.cnf

    [mysqld]
    character-set-server=utf8mb4
    collation-server=utf8mb4_general_ci
    default-time-zone='+00:00'
    wait_timeout=999999999
    interactive_timeout=999999999
    
    sudo mysql
    mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
    mysql> FLUSH PRIVILEGES;
    mysql> exit
    sudo systemctl restart mysql
    
  • Import/Export

    mysqldump -uroot -p reversi > reversi.sql
    mysql -uroot -p reversi < reversi.sql
    

Sound

  • Alsa setup

    sudo apt install libasound2 alsa-utils alsa-oss
    sudo usermod --append --groups audio <username>
    sudo reboot
    

    List devices:

    aplay -l
    arecord -l
    

    Stream:

    ffmpeg -f alsa -i hw:3 -f alsa hw:2
    ffmpeg -f alsa -i hw:3 -af 'asetrate=48000*1.0091,aresample=48000,atempo=1/1.0091' -f alsa hw:2
    
  • IQAudio

    #dtparam=audio=on
    dtoverlay=iqaudio-dacplus
    dtoverlay=iqaudio-dacplus,auto_mute_amp
    

Airplay

  • Install shairport-sync

    sudo apt update && sudo apt upgrade
    sudo iwconfig wlan0 power off # optional
    # Reboot
    sudo apt install build-essential git xmltoman autoconf automake libtool libpopt-dev libconfig-dev libasound2-dev avahi-daemon libavahi-client-dev libssl-dev libsoxr-dev
    git clone https://github.com/mikebrady/shairport-sync.git
    cd shairport-sync
    autoreconf -fi
    ./configure --sysconfdir=/etc --with-alsa --with-avahi --with-ssl=openssl --with-metadata --with-soxr --with-systemd
    make
    sudo make install
    sudo systemctl unmask shairport-sync
    sudo systemctl enable shairport-sync
    
  • /etc/shairport-sync.conf

    general = {
        name = "Bedroom";
        resync_threshold_in_seconds = 0.150;
    };
    
    alsa = {
        output_device = "hw:1,0";
    };
    
    sudo systemctl start shairport-sync
    

OpenWRT

  • Download: https://downloads.openwrt.org/snapshots/targets/bcm27xx/bcm2711/

  • Image Builder

    sudo apt install build-essential libncurses5-dev libncursesw5-dev zlib1g-dev gawk git gettext libssl-dev xsltproc wget unzip python
    # kmod-r8169: RTL8111
    # kmod-usb-net-rtl8152: RTL8152
    make info
    make image PROFILE=rpi-4 PACKAGES="kmod-r8169 luci luci-ssl"
    
  • Install

    sudo fdisk -l
    gunzip openwrt-21.02.0-bcm27xx-bcm2711-rpi-4-ext4-factory.img.gz
    sudo dd if=openwrt-21.02.0-bcm27xx-bcm2711-rpi-4-ext4-factory.img of=/dev/sda bs=4K
    sudo parted /dev/sda
    (parted) print
    (parted) resizepart 2 30G
    (parted) print
    (parted) quit
    sudo resize2fs /dev/sda2
    
    ssh root@192.168.1.1
    passwd
    
  • Update

    opkg update
    opkg install screen
    screen -S update
    opkg update && opkg list-upgradable| awk '{print $1}'| tr '\n' ' '| xargs -r opkg upgrade
    

    CM4 wifi fix:

    cd /lib/firmware/brcm
    cp brcmfmac43455-sdio.raspberrypi,4-model-b.txt brcmfmac43455-sdio.raspberrypi,4-compute-module.txt
    reboot
    
  • /etc/config/network

    config globals 'globals'
        ...
        packet_steering '1'
    
    config interface 'wan'
            option ifname 'eth0.201' # centurylink
            option proto 'pppoe'
            option username '***'
            option password '***'
            option mtu '1492'
            option peerdns '0'
            option dns '1.1.1.1 1.0.0.1'
    
    config interface 'lan'
            option type 'bridge'
            option ifname 'eth1'
            option proto 'static'
            option ipaddr '11.0.0.1'
            option netmask '255.255.255.0'
            option ip6assign '60'
    
  • /etc/config/wireless

    config wifi-device 'radio0'
            option type 'mac80211'
            option channel '100'
            option hwmode '11a'
            option path 'platform/soc/fe300000.mmcnr/mmc_host/mmc1/mmc1:0001/mmc1:0001:1'
            option legacy_rates '0'
            option htmode 'VHT40'
            option disabled '0'
            option country 'US'
    
    config wifi-iface
            option device 'radio0'
            option network 'lan'
            option mode 'ap'
            option ssid '***'
            option encryption 'sae'
            option key '***'
    
    config wifi-device 'radio1'
            option type 'mac80211'
            option channel '1'
            option hwmode '11g'
            option path 'platform/soc/fe300000.mmcnr/mmc_host/mmc1/mmc1:0001/mmc1:0001:1'
            option legacy_rates '0'
            option htmode 'HT20'
            option short_gi_40 '0'
            option disabled '0'
            option country 'US'
    
    config wifi-iface
            option device 'radio1'
            option network 'lan'
            option mode 'ap'
            option ssid '***'
            option encryption 'sae'
            option key '***'
    
  • /etc/config/firewall

    config defaults
        option flow_offloading 1
        option flow_offloading_hw 1
    
    config redirect
        option name 'forward 8080'
        option src 'wan'
        option dest 'lan'
        option src_dport '8080'
        option dest_ip '11.0.0.200'
        option dest_port '8080'
        option target 'DNAT'
    

Raspberry Pi eMMC

  1. sudo ./rpiboot (usbboot)
  2. Toggle RPiBOOT switch
  3. Power on

Other

  • Disable bluetooth

    sudo systemctl disable bluetooth.service
    
  • Apple keyboard Fn default off

    sudo bash -c "echo 2 > /sys/module/hid_apple/parameters/fnmode"
    echo options hid_apple fnmode=2 | sudo tee -a /etc/modprobe.d/hid_apple.conf
    sudo update-initramfs -u -k all
    
  • Nvidia font fix

    sudo nvidia-xconfig --no-use-edid-dpi 
    # Add under "monitor": Option "DPI" "96 x 96"
    
  • Terminator layout custom command

    cd /home/username/Documents; exec zsh
    
  • Read-only filesystem fix

    sudo fsck.ext4 -f /dev/sda1
    
  • Github Pages on Cloudflare

    • DNS only root and www CNAME's
    • Wait for Github to retrieve TLS cert
    • Enforce https
    • Switch records to proxied
    • Change SSL/TLS encryption to Full (strict)
  • Util

    • ncdu
  • Windows ISO boot

    sudo sh Ventoy2Disk.sh -i /dev/sda
    sudo mount /dev/sda /media/usb1
    
  • RTL8125 Ethernet interface

    sudo add-apt-repository ppa:awesometic/ppa
    sudo apt install realtek-r8125-dkms
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment