Windows10+新安装WSL的root密码设置及文件复制
Windows10+上安装WSL时,经常可能会直接设置了一个普通用户和密码,但是在后继的工作过程中很可能会用到root账号。但由于安装过程中未设置过root账号的密码,切换不了root:
Installing, this may take a few minutes... Please create a default UNIX user account. The username does not need to match your Windows username. For more information visit: https://aka.ms/wslusers Enter new UNIX username: xurm New password: Retype new password: passwd: password updated successfully Installation successful! To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.15.79.1-microsoft-standard-WSL2 x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Wed Feb 22 11:05:18 CST 2023 System load: 0.11 Processes: 9 Usage of /: 0.1% of 1006.85GB Users logged in: 0 Memory usage: 7% IPv4 address for eth0: 172.28.161.50 Swap usage: 0% 1 update can be applied immediately. To see these additional updates run: apt list --upgradable The list of available updates is more than a week old. To check for new updates run: sudo apt update This message is shown once a day. To disable it please create the /home/xurm/.hushlogin file. xurm@xurm-pad:~$ su root Password: su: Authentication failure xurm@xurm-pad:~$
当然你也可以按上面的提示使用"sudo <command>"执行你想执行的命令,但如果就是想切换到root账号做操作呢?这时需要重新设置一下root密码了:
xurm@xurm-pad:~$ sudo passwd root New password: Retype new password: passwd: password updated successfully xurm@xurm-pad:~$ su root Password: root@xurm-pad:/home/xurm#
最后提一下如何将Windows本地目录中的文件复制到WSL中,比如我本地E盘的master1.crt文件(E:\Dowloads\master1.crt)需要复制到WSL系统里的 /etc/docker/certs.d/master1/ 目录下:
[xurm@xurm-pad ~]$ pwd /home/xurm [xurm@xurm-pad ~]$ sudo mkdir -p /etc/docker/certs.d/master1/ [sudo] password for xurm: [xurm@xurm-pad ~]$ ls /etc/docker/certs.d/master1/ [xurm@xurm-pad ~]$ cd /mnt [xurm@xurm-pad mnt]$ ls c d e wsl wslg [xurm@xurm-pad mnt]$ ls /mnt/e/Dowloads/ cert-manager.yaml jenkins.war master1.crt [xurm@xurm-pad mnt]$ sudo cp /mnt/e/Dowloads/master1.crt /etc/docker/certs.d/master1/ [xurm@xurm-pad mnt]$ ls /etc/docker/certs.d/master1/ master1.crt [xurm@xurm-pad mnt]$
注意红色标记的命令或目录!