WSL2-Linux on Windows- (Part 2: Introduce basic tools)

This article is a continuation of: WSL2 ~ Linux on Windows ~ (Part 1: Introduction)

1.First of all

Summary of this article

In the first part, we introduced Ubuntu 20.04 with WSL2. The following environment will be prepared on Ubuntu-20.04.

  1. Proxy settings
  2. Package update
  3. Prepare the environment to connect to Ubuntu by SSH (SSH from Windows environment to Ubuntu)
  4. Introduce familiar tools (ifconfig, etc.)

2. Main story

2-1. Proxy settings (environment variables)

Set the proxy as needed. Looking at the github community, there seem to be two types of setting methods. https://github.com/microsoft/WSL/issues/1570

--Setting by environment variables --Settings for apt

Tools such as curl and wget also use proxies, so I decided to use environment variables.

(1) Editing ~/.bashrc

Command execution


cd ~/
vi .bashrc

~/.bashrc


export http_proxy=http://proxy-server:PortNumber
export https_proxy=http://proxy-server:PortNumber

(2) Log out & login to reflect environment variables

Log out


exit

Re-login


wsl -d Ubuntu-20.04

Reference: Settings for apt (not set this time)

sudo vi /etc/apt/apt.conf.d/proxy.conf
Acquire::http::Proxy "http://proxy-server:PortNumber";
Acquire::https::Proxy "http://proxy-server:PortNumber";

2-2. Package update

Package update


sudo -E apt-get -y update

"-E" is for inheriting and executing environment variables.

2-3. Prepare the environment to connect to Ubuntu with SSH (SSH server)

(1) Installation

Installation


sudo -E apt -y install openssh-server 

Execution result


Abbreviation
0 upgraded, 0 newly installed, 0 to remove and 74 not upgraded.

It's already in!

(2) Authentication method setting

/etc/ssh/sshd_Edit config


$sudo -E vi /etc/ssh/sshd_config 

Turn on password authentication


- PasswordAuthentication no
+ PasswordAuthentication yes

Security is loose because it is a local environment.

(3) Generation of host key

Key creation command


$ sudo ssh-keygen -A

result


ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519

(4) Starting the service

Service start command


$sudo service ssh restart

Execution result


 * Restarting OpenBSD Secure Shell server sshd                    [ OK ]

(5) Login from the client

Windows command prompt


C:\>ssh -l [Ubuntu username] [Ubuntu IP address]
[A user]@[IP address]'s password:●●●●●●  <=====Login password
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 4.19.128-microsoft-standard x86_64)

***Omitted***

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

[User]@[PC-NAME]:~$

2-4. Introduce familiar tools

In the early days, we didn't have the following basic commands that we were used to.

I think that the above command does not exist because it has moved to the ip command, but I will introduce it because I want a familiar command.

(1) Install network related tools

command


sudo -E apt -y install net-tools <==== arp,ifconfig,netstat,rarp,route 
sudo -E apt -y install bridge-utils <==== brctl
sudo -E apt -y install inetutils-traceroute <=== traceroute

Finally

Summary

In order to create a comfortable usage environment, we will investigate and add the following. --Set SSH to start automatically --Make the proxy settings smarter (take over the proxy from the Windows side?)

Recommended Posts

WSL2-Linux on Windows- (Part 2: Introduce basic tools)
python basic on windows ②
WSL2 ~ Linux on Windows ~ (Part 1: Introduction)
Python on Windows
Installing Python 3 on Mac and checking basic operation Part 1
Linux (WSL) on Windows
Use pyvenv on Windows
Python basic memorandum part 2
Anaconda on Windows Terminal
Install Anaconda on Windows 10
Install python on windows
Python basic memo --Part 2
Install pycuda on Windows10
Build TensorFlow on Windows
Try FEniCS on Windows!
Build XGBoost on Windows
Install pygraphviz on Windows 10
Use Ansible on Windows
Try Poerty on Windows
Install Chainer 1.5.0 on Windows
Use QuTiP on Windows
Use pip on Windows
Python basic memo --Part 1
Build a GVim-based Python development environment on Windows 10 (2) Basic settings