Code 4: Create new Users in WSL

Quick instructions to set up a new user in wsl
coding
linux
Author

Tony Phung

Published

March 15, 2024

1. Creating a new user with sudo priviledges

sudo: allows you to run the following command with elevated privileges (like root access).
adduser: creates a new user account in your WSL distribution.
usermod: modifies existing user accounts.
-aG: adds the user to a specific group.
cut -d: -f1 /etc/passwd: list users.
su - username: login to username.
groups username: groups a user belongs to.

  1. sudo adduser tonyjustkaggles - add user
  2. sudo usermod -aG sudo tonyjustkaggles - add priviledges
  3. sudo visudo - open nano
  4. “tonyjustkaggles ALL=(ALL) NOPASSWD: ALL” - add more priviledges
  5. Ctrl + O, Enter, Ctrl + X - save and exit

3. VS Code (pre-installed on Windows)

Add PATH variable in new user so by typing code ., VS Code opens for the existing folder.

export PATH="$PATH:/mnt/c/Users/tonyp/AppData/Local/Programs/Microsoft VS Code/bin

4. [Quick Fire] Other Useful Setup Things to do

4.1 miniforge

  1. su - tonyjustkaggles - login
  2. mkdir downloads + cd downloads
  3. wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh
  4. bash Miniforge33-*.sh -b - run bash script to install
  5. ~/miniforge3/bin/conda init bash - add paths
  6. which python - see python is from miniforge

4.2 conda virtual environment

  1. conda create -n kaggle_venv - create venv for individual projects + avoid dependency issues
  2. conda activate kaggle_venv - create venv for individual projects + avoid dependency issues
  3. conda install python - install python into venv

4.3 pytorch

  1. conda install pytorch torchvision torchaudio cpuonly -c pytorch - install pytorch from official site
  2. ipython -> import torch -> torch + [tab] - Test pytorch works

4.4 jupyter

  1. conda install -c conda-forge jupyterlab - install jlab from official site

4.5 bash shortcuts

  1. vim ~/.bashrc -> G,i -> alias vb="vim ~/.bashrc" -> esc :wq - shortcut for vim bash
  2. vb -> i -> alias jl="jupyterlab --no-browser" - jupyter lab short-cut
  3. vb -> i -> alias dl="cd ~/downloads" -> esc :wq - downloads
  4. vb -> i -> alias bl="cd ~/blog" -> esc :wq - blog (or :q! - don't save)
  5. vb -> i -> alias kv="conda activate kaggle_venv" -> esc :wq - activate venv

4.6 kaggle

  1. conda install conda-forge::kaggle - install kaggle api from official site
  2. Kaggle -> Settings -> Create Token -> Paste into: /home/tonyjustkaggles/.kaggle

4.7 ssh, github and blog

  1. ssh-keygen -> cat pub-key -> copy into Github
  2. git clone git@github.com:tonyjustdevs/blog.git with ssh option

4.8 visudo

  1. sudo visudo -> User privilege specification -> tonyjustkaggles ALL=(ALL) NOPASSWD: ALL -> ctrl O + Enter + ctrl X
  2. export PATH="$PATH:/mnt/c/Users/tonyp/AppData/Local/Programs/Microsoft VS Code/bin"

5. Complete