1. 安装
首先打开microsoft store,搜索ubuntu:
商店搜索
选择下载人数最多的
ubuntu
下面就可以开始摇摆了。没有别的需求本篇结束。
2. 系统迁移
由于wsl默认安装位置是系统盘,我的系统盘是一个256G的固态,容量比较珍贵,所以进行迁移,用这个工具:LxRunOffline,选择最新的工具进行下载。
迁移工具
下载完成后解压缩,在解压缩后的目录下打开power_shell(需要按住shift的同时右键),
打开power_shell
- 打开后首先输入
.\LxRunOffline.exe list,检查当前有多少个linux版本:
检查版本
- 之后将wsl关闭:输入
wsl --shutdown命令关闭当前运行的linux子系统。 - 之后进行迁移:
.\LxRunOffline.exe move -n Ubuntu -d D:\Ubuntu,-d后面跟的是想要迁移到的位置,自己定义即可。命令输入后,会有一系列的warning,但是不需要管,等待程序静静执行完自己终止即可。
warning
完成后,输入.\LxRunOffline.exe get-dir -n Ubuntu即可看到目前系统已经迁移到的位置。
image.png
3 配置镜像源
wsl默认的镜像下载地址还是比较慢的,可以配置成阿里云的镜像,进入配置文件所在目录cd /etc/apt/,下面的sources.list文件就是存放镜像的地址,首先对其进行备份,只需要复制一份在当前目录下即可,不备份也无所谓。删除文件后新建一个同样名字的文件,将下面的地址拷贝进去:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
4 配置ssh登陆
之前三步做完之后,如果你想通过ssh的方式登陆这台虚拟机,进行文件传输等工作的话,还需要有ssh服务,
- 首先卸载原有服务 :
sudo apt-get remove openssh-server - 之后重新进行安装:
sudo apt-get install openssh-server - 之后进行配置:进入配置文件所在目录:
cd /etc/ssh/,打开配置文件:sudo vim sshd_config,注意,要用sudo命令进行打开,否则没有修改权限,再次,要注意是sshd_config文件而不是ssh_config文件。 - 配置端口:
Port 39000,默认是22,被占用。指定监听地址:ListenAddress 0.0.0.0,这个影响不大,用127.0.0.1或者本机ip地址都可以。将PasswordAuthentication yes密码登陆打开,root登陆禁止:PermitRootLogin yes,如果有不成功的可以用下面的配置文件:
# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
Include /etc/ssh/sshd_config.d/*.conf
Port 39000
#UsePrivilegeSeparation no
#AddressFamily any
ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
PermitRootLogin yes
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem sftp /usr/lib/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
- 尝试一下,通过winscp进行文件传输:
winscp连接
,可以连接。或者用ssh -p 39000 你的user@localhost亦可尝试连接。














网友评论