Skip to content

Instantly share code, notes, and snippets.

@rolambert
Last active December 4, 2020 03:05
Show Gist options
  • Save rolambert/f82729130cb1e69b84cfc0925833b341 to your computer and use it in GitHub Desktop.
Save rolambert/f82729130cb1e69b84cfc0925833b341 to your computer and use it in GitHub Desktop.
Ubuntu 20.04 LTS Machine Learning Setup and Security Hardening Script.
#!/bin/bash
# Author: Robert Lambert
# Version: 0.1.0
# Use this script to automate the set up of a Ubuntu 20.04 LTS for use as a machine learning workhorse
# ref: https://askubuntu.com/a/30157/8698
# Root user check
if [ $SUDO_USER || $(id -u) = 0 ]; then
echo "The script need to be run as user." >&2
exit 1
else
real_user=$(whoami)
sudo -l
fi
# Ubuntu check
if ! lsb_release -i | grep 'Ubuntu'; then
echo "Ubuntu only. Exiting."
echo
exit 1
fi
# x86_64 check
if ! uname -i | grep 'x86_64'; then
echo "x86_64 only. Exiting. this is for the cuda install"
echo
exit 1
fi
# Enable firewall
ufw enable
#Refresh repository index
apt update
# Upgrades packages with auto-handling of dependencies
apt full-upgrade -y
# Check for other os
os-prober
# Update grub
update-grub
# Install powershell
# Update the list of packages
sudo apt-get update
# Install pre-requisite packages.
sudo apt-get install -y wget apt-transport-https
# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb
# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb
# Update the list of products
sudo apt-get update
# Enable the "universe" repositories
sudo add-apt-repository universe
# Install PowerShell
sudo apt-get install -y powershell
# Start PowerShell
#pwsh
# install git, pip3
apt install -y git python3-pip make build-essential bzip2 libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl gparted
# optional harden ubuntu 20.0.4 LTS
harden=False
if harden; then
echo " grub passsword write this down!"
echo
#grub-mkpasswd-pbkdf2
#git clone https://github.com/konstruktoid/hardening.git
# make sure to read parmeters before running this see ./ubuntu.cfg file
#apt install arp-scan net-tools procps
#cd ./hardening
#sed -i "s/CHANGEME=.*/CHANGEME='ok'/" './ubuntu.cfg'
#bash ./ubuntu.sh
fi
# cuda for x86_64
# Dl Cuda
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
# Move the file
mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
# Get the file key
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
# Update repository
add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
# Update
apt update
# Install Cuda
apt -y install cuda
# Update path
export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
# validate cuda install
echo
echo
nvcc -V
echo
# systemctl status nvidia-persistenced
# Install cuda dev extra
apt install g++ freeglut3-dev build-essential libx11-dev libxi-dev libglu1-mesa libglu1-mesa-dev -y
# Update bash shell: git exec "$BASH"
apt install git -y
# change back to user
su $real_user
# Install pyenv as user
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
exec "$SHELL"
pyenv init
# Install some basics
pip3 install poetry black jupyter numpy pandas lightgbm matplotlib scipy xgboost
pip3 install sklearn
# VS Code Config
# TODO
# sudo apt install jq
# Read JSON File
# Append pyenv file locations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment