Quick way to consistently set up and connect to an ec2 linux instance with my personal dev preferences for Machine Learning.
Assumes Deep Learning AMI (full, NOT base) is installed on the ec2 instance as documented here.
- First start the instance using the AWS EC2 Console
- Note the Public DNS (IPv4) for the instance as listed in the AWS EC2 Console
- Run
chmod 400 /path/my-key-pair.pem
- Run
ssh -i /path/my-key-pair.pem [email protected]
- To disconnect, run
exit
If you want to edit files on the remote machine you are connected to via SSH, you essentially have to use command line editors (e.g. vim). If you want to use something fancier, like vscode or sublime text you have two options:
- Edit everything on a different machine and commit / push to git. Git pull and only run on the remote machine without any editing. For any minimal editing / config on the remote machine, get friendly with vim.
- Set up remote vscode. This just allows you to edit a single file at a time (not an entire folder). See https://codeyarns.com/2018/05/03/how-to-edit-remote-files-using-remote-vscode/โโ.
- Use sshfs or similar tool to mount a folder on the remote ec2 machine as a local drive on MacOS. I have not tried this yet, so any PRs documenting how to do this are welcome.
- Run
screen
and initiate your long-running process - To detach, enter
Ctrl-a, d
and now you can disconnect. - When you reconnect, enter
screen -r
to reattach and continue your long-running process. - If more than one screens are running, you can run
screen -ls
to list.
- Set up git lfs using the steps here: https://github.com/git-lfs/git-lfs/wiki/Installation#ubuntu. Specifically, run:
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:git-core/ppa
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
git lfs install --skip-smudge
- Configure git username:
git config --global user.name "Your Name"
git config --global user.email [email protected]
- Clone your repos, then make sure credentials are persisted:
git clone https://.../foo.git
- Specify username and password (ideally a single use token) to clone
- cd into the cloned repo dir, then run
git config credential.helper store
- Run
git pull
again, then specify the username and password again. This time it will be persisted.
- Set up
screen
for long-running processes that keep running after SSH disconnects:sudo apt install screen
Run remote Jupyter using the instructions here: https://medium.com/@margaretmz/setting-up-aws-ec2-for-running-jupyter-notebook-on-gpu-c281231fad3f
- Update list of available packages:
sudo apt update --yes
- Upgrade packages:
sudo apt upgrade --yes