Skip to content

Instantly share code, notes, and snippets.

@BenFausch
Created May 16, 2018 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenFausch/0df20d936dc41b4ff299694ebc748d2a to your computer and use it in GitHub Desktop.
Save BenFausch/0df20d936dc41b4ff299694ebc748d2a to your computer and use it in GitHub Desktop.
Tensorflow setup for gcloud micro box including ssh
#config ssh:
#add rsa.pub to instance metadata
#1. go to gcloud instance, click edit
#2. go to 'custom metadata' section, add 'enable-oslogin':TRUE
#3. click 'show and edit' under SSH key section, add the contents outputted by command 'cat ~/.ssh/id_rsa.pub' to add your public ssh key (use the outputted username as the key here ex. benfausch)
#4. go to gcloud terminal through gcloud webpage, run 'mkdir .ssh && touch .ssh/authorized_keys', then authorized_keys > "your ouputted public ssh key here"
#5. go to normal terminal, then use same username gcloud uses in browser terminal (ex benjamin_fausch_gmail), your private SSH key, and the public IP of the instance
#=>=>=>=> ssh -i id_rsa benjamin_fausch@35.123.17.04
#6. then you can just use ssh benjamin_fausch@35.xxx and create an alias
#check install python
which python
#tensorflow for ubuntu: https://www.tensorflow.org/install/install_linux
#install pip
sudo apt-get install python-pip python-dev
#create swap file====>
#check for no active swap
sudo swapon --show
free -h
#check for space
df -h
#create swapfile
sudo fallocate -l 1G /swapfile
#verify perms are -rw-r--r--
ls -lh /swapfile
#set to root only and verify
sudo chmod 600 /swapfile
ls -lh /swapfile
#mark as swap
sudo mkswap /swapfile
#turn on swap and verify
sudo swapon /swapfile
sudo swapon --show
free -h
#back up swap
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
#install tensorflow and keras if needed, use --no-cache-dir to avoid memoryerror
pip install tensorflow
pip --no-cache-dir install keras
#now you can run a python script with python *script*.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment