Logo

In this section

  1. Access WSL from PowerShell
  2. User management
  3. File system management and installation
  4. Resource management

1. Access WSL from PowerShell

WSL Install, List and Uninstall

wsl --install
wsl --list --verbose
wsl --unregister Ubuntu

Start WSL

wsl
Start-Process wsl -ArgumentList "-d Ubuntu -e tail -f /dev/null" -WindowStyle Hidden
wsl.exe -d Ubuntu --launch
wsl -u root
wsl -u barry75

Access WSL2 from Win Explorer

\\wsl$

Stop WSL

wsl --shutdown

Transfer directory and file from PowerShell

scp -r dirname barry75@barryonweb.com:/home/barry75/
scp filename.conf barry75@barryonweb.com:/home/barry75/

2. User management

List all users on the system

cat /etc/passwd

Change username as root

usermod -l barry75 oldname

Rename home dir

usermod -d /home/barry75 -m barry75

Update group

groupmod -n barry75 oldname

Get details on user

id barry75

Switch user

su - barry75

Permissions

Each file or directory in Linux has two ownership attributes:

Check status

ls -ld /home/barry75/
ls -l
groups barry75

Change assigned group / owner / both (-R=recursive) of /var/www

sudo chown -R :www-data /var/www
sudo chown -R barry75 /var/www
sudo chown -R barry75:www-data /var/www

Add user to www-data group

sudo usermod -a -G www-data barry75

Adjust the directory permissions to allow members of assigned group to write:

sudo chmod -R g+w /var/www

Adjust the directory permissions to allow owner to execute:

sudo chmod -R u+x /var/www

Skip password for user

sudo visudo
barry75 ALL=(ALL) NOPASSWD:ALL

3. File system management and installation

Change default user

nano /etc/wsl.conf
    [user]
    default=newuser

Change default dir to home on open WSL

nano ~/.bashrc 
    cd ~ # add to end of file

Delete empty dir / dir / content within current dir

rm dirName
rm -rf dirname
rm -rf ./*

Check if systemd is enabled / check status

ps -p 1 -o comm=
systemctl status

After installation

Get internal WSL IP adress

ip addr show eth0 
hostname -I

Install UFW

sudo apt install ufw -y 

Install Apache web server

sudo apt install apache2 -y 

4. Resource management

Check ports listening

sudo lsof -i -P -n | grep 808
sudo netstat -tulpn | grep 808