wsl笔记【转!推荐】

目录

 

wsl 下的 ubuntu 系统一些问题总结!

参考文献:

Windows 10生产力提升之WSL实践

在wsl下安装使用sshd全攻略.md

环境

win10 下 wsl 环境安装 ubuntu

修改更新源

  1. 备份文件

    sudo cp /etc/apt/sources.list  /etc/apt/sources.list.old
    
  2. 使用阿里源

    打开文件:

    sudo vi /etc/apt/sources.list
    

    整个文件替换成阿里源:

    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    
  3. 更新

    sudo apt-get update
    sudo apt-get upgrade
    

新建用户

Linux 创建、删除和改变用户信息 —— adduser useradd usermod deluser

linux用户管理(1)----创建用户(adduser和useradd)和删除用户(userdel)

  • adduser user1

    ubuntu建用户最好用adduser,虽然adduser和useradd是一样的在别的linux糸统下,但是我在ubuntu下用useradd时,并没有创建同名的用户主目录。

    # 新建用户,会创建同名的用户主目录
    adduser user1
    # ubuntu查看用户列表
    cat /etc/passwd
    # 用linux代替想要删除的用户账户, -r 表示连同用户主目录一块删除
    userdel -r user1
    # 查看是否正确删除用户:
    id user1
    

设置超级用户

ubuntu的su初始密码设置

sudo passwd

环境变量

  • 不同用户不共享环境变量

    # 所有用户都生效
    sudo vim  /etc/profile 
    source /etc/profile
    

    存在退出终端后不生效问题!

  • 退出终端后不生效问题

    # 当前用户生效
    sudo vim  ~/.bashrc   
    ## 在每个用户的 ~/.bashrc 添加 source /etc/profile 共享全局的path
    

zsh美化终端

安装使用oh-my-zsh(Win10+WSL或Ubuntu)

设zsh为默认shell

chsh -s /bin/zsh # 设置 bash 同理 

环境变量PATH

使用zsh后,环境变量需要在 ~/.zshrc 配置文件中定义,/etc/profile 是不会生效的

开启 ssh 远程连接

wsl下的ubuntu自带ssh服务有问题需要卸载重装一遍ssh服务

# 重装 openssh-server
sudo apt-get remove openssh-server
sudo apt-get install openssh-server

# 修改 shd_config文件
sudo vi /etc/ssh/sshd_config
# Port 22 #默认即可,如果有端口占用可以自己修改
# PasswordAuthentication yes # 允许用户名密码方式登录
# PermitRootLogin yes # 允许管理员ssh登录

# 重启ssh服务
sudo service ssh restart

apt命令与问题

[Ubuntu的apt命令详解]

  1. 搜索软件
sudo  apt-cache  search  package_name
  1. WSL Ubuntu 解决出现 E: Could not read response to hello message from hook ...问题

    执行以下命令

    sudo rm -rf /etc/apt/apt.conf.d/20snapd.conf
    

windows 和 wsl 互相访问文件

  • 打开wsl文件

    使用explorer.exe,wsl下切换用户就不能使用这个命令。。。

    explorer.exe .
    
  • 访问windows文件,使用挂载方式/mnt/

    cd /mnt/c/Users/Ben/Documents/
    

wsl开机没有自启动ssh

需要在wsl中手动运行一下:

sudo service ssh start

由于是wsl内部是类似docker运行的,没有 systemd 服务

重装python

  1. 检查python路径:

    # 方式一:
    type -a python
    
    # 方式二:
    ls -l /usr/bin/python
    ls -l /usr/bin/python*
    
    # 方式三:
    which python
    
  2. 安装python2、python3

    # 安装python2
    $ sudo apt-get install python
    # 安装python3
    $ sudo apt-get install python3
    
  3.  

https://www.cnblogs.com/jarvankuo/p/11955057.html#windows-%E5%92%8C-wsl-%E4%BA%92%E7%9B%B8%E8%AE%BF%E9%97%AE%E6%96%87%E4%BB%B6

posted @ 2021-01-26 16:04  阿波罗任先生  阅读(123)  评论(0编辑  收藏  举报