Skip to content

Instantly share code, notes, and snippets.

@upretip
Last active April 23, 2020 15:31
Show Gist options
  • Save upretip/77f7af7e34dc39b93ed5c60b526f10f1 to your computer and use it in GitHub Desktop.
Save upretip/77f7af7e34dc39b93ed5c60b526f10f1 to your computer and use it in GitHub Desktop.
noting down steps taken to effectively using Linux subsystem on windows
Hi there!
This is a reminder on how to do a few things on WSL

Location of the Linux system Folders in local computer PS C:\Users\<username>\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState \rootfs\

Default Linux folders:

There are some linux default folders. I see them by ls -lah /

  • / - Root Directory. Everything is located here. Like filesystem
  • bin - Essential Binaries - contains program binaries such as cat, echo, etc.
  • boot - Static Boot Files -files needed to boot the system
  • cdrom - not needed
  • dev - Device Files -(eg. dev/sta = SATA. not actual files but appear as file) or pseudo-devices that do not correspond to hardware.
  • etc - Config Files - systemwide config files IMPORTANT to learn in detail for management
  • home - Home Folder - users home folder where a user's data files and user level configuration are located. Need elevated permission (sudo) to change other's file in home
  • lib - Essential Shared Libraries - shared libraries that is required by programs in bin and sbin
  • media - Removable Media - attached media viz. flash drive, disk drive, etc.
  • mnt - Mount points - Load additional file system. For example, mounting ./C:/Users//Document location on WSL
  • opt - Optional Packages - subdirectories for external software that may not adhere to standard file system hierarachy (think about when I installed XAMPP on linux to create the webapp)
  • proc - Kernal and Process Files - for process and system (similar to files in /dev)
  • root - Root Home Directory - home directory of root user. Should not work as a root. Better to use an user with root access.
  • run - Application State Files - Location for application to store transient files lik sockets and process IDs that cannot be stored in /tmp
  • sbin - similar to bin but for system administration binaries
  • snap - Ony appeared on my WSL not on ubuntu vm
  • srv - Service Data - data for services provided by the system. Eg. if using Apache HTTP server, place to store website's files in directory here
  • sys -
  • tmp - Temporary Files - temporary files. They get deleted when system restarts
  • usr - User Binary -user's binary and read only data, similar to system but specific to user? Has its own usr/bin, usr/lib, usr/sbin, etc. Installs locally compiled applications to /usr/local to prevent them from murking up the rest of the system
  • var - Variable Data Files - writable counterpart to usr directory. is read only in normal operation. Log files written to /usr during normal opearion will be written to /var directory

Other directories I have seen:

  • share
  • games
  • include
  • src

Few files from /etc related to user and what they mean

/etc/passwd - The User database, with fields giving username, real name, home dir, and other info
/etc/group - similar to User but for groups, their name, privilates, etc
/etc/shadow - encrypted file that stores user passwords

Group + USER

add group
groupadd <groupname> -g <groupid>

make a group sudoer - add the group in /etc/sudoer
%<group> ALL =(ALL) NOPASSWD:ALL - no passwd to do sudo

add user
useradd -d <homedir> -u <uid> -g <gid> -G <group1,group3,group7> -c <comment about name, etc> -e <account expiry date> -f <pwd expiry after days> -s <default bash ie. /bin/bash> <user>

change user password
passwd <user>

make an user sudoer - add following line in /etc/sudoers(.d)
<user> ALL=(ALL) NOPASSWD:ALL

add user to a group
usermod -a -G

check for group
cat /etc/group | grep <groupname>

delete group
need to remove users first
userdel <username>
groupdel <groupname>

List current user with thier privilage
sudo -l

Reading Resources

Windows Subsystem for Linux (WSL Docs)

To start the WSL:

  • turn windows features on or off (I usually search that on windows menu)
  • Then find windows subsystem for linux and click checkbox
  • It may require restart the computer
  • Go to Microsoft store and download and install Ubuntu

Corey Schafer has an excellent video on how to install

  • Open powershell then bash <once installed, linux could be run on powershell>
  • change default location by source cd /mnt/c/Users/<localuser>/Documents Casing matters
  • find out which user you are logged in as whoami``>> root
  • if default user hasn't been created, create an user
    • useradd -G admin -u 1000 admin
  • to set default user as the "default user" logout of bash $ exit
    • in powershell > ubuntu config --default-user admin
    • in powershell > bash now ubuntu logs in as admin@...$ can find user by $ whoami
  • in case if you forgot password to your default account, reset password by forcing password change from root
    • in powershell > ubuntu config --default-user root
    • open bash > bash will open bash shell
    • change password to default account passwd admin and confirm the new password
    • exit bash $ exit
    • in powershell > ubuntu config --default-user admin
    • in powershell > bash to go to bash

adding awscli

  • sudo apt install awscli need to create and save config files with key and secret
  • aws ls s3 s3://bucketname to list the buckets

adding ssh keys

SSH sign in to access resources between local machine and web account: eg. GitHub

Github example from

  • Check for existing keys

    • List the files in folder .ssh
      • ls -al ~/.ssh. public keys are the ones ending in .pub
    • Can use the existing key, or create a new one to add on.
  • Set up SSH and add it to SSH agent

    • ssh-keygen -t rsa -b 4096 -C "email@email.com" -> creates label using the provided email.
    • return to accept default file loc
    • provide passphrase or hit return for no passphrase
  • add the key to SSH- Agent (locally)

    • start the ssh-agent in the background eval "$(ssh-agent -s)" should return Agent pid #### (personally issue faced here)
    • add ssh file by ssh-add ~/.ssh/id_rsa
  • add the public? key to Github

    • copy the public key copy < ~/.ssh/rsa_id.pub
      • sometimes may need to install xclip (do sudo apt-get install xclip)
    • go to
      • settings in github,
      • open ssh and gpc keys
      • click **Add/New SSH Keys **
      • In the title filed use something descriptive such as "personal surface book" or "cloud computer 1 with fedora red hat on ec2".
    • paste the key copied above and click add
    • confirm with password
  • Testing

    • ssh -T git@github.com will see a warning or asking to verify the fingerprint.
  • Debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment