本文简单介绍我的环境setup,随缘更新。
0x00 初衷
出于种种原因,需要在Win10中的terminal中使用一個“完整版”的Linux。众所周知,WSL就是个残废,于是有了本文。
本文采用的方案則是:Windows Terminal + Terminal settings + wsl + VMware VM + VMware自启脚本,实现开机自启no gui的ubuntu 18.04,其后运行terminal的時候无感知对该vm发起ssh。
0x01 设置VMware虚拟机
- 我下载的是Desktop版,安装时选择Mini版本,时区选择HongKong,最后skip。
(可以选中国时区,可以裝完,没想到还是有147个包,所以还是skip吧。
- 配置桥接网络静态IP 192.168.99.96。
0x02 设置WSL
其实这一步不是必须,但是经过测试,powershell或者cmd在结束连接后,会在下一次连接时出現令人菲姐的[?1;0c符号,因强迫症而改用wsl.exe进行跳板连接。
1 | Win10安装Ubuntu子系统教程(附安装图形化界面) - Windows10.Pro |
之后在wsl中生成wsl公私钥并传送給VMware.
1 | # ssh-keygen -t rsa -b 2048 -C "m4d3bug@wsl" |
0x03 设置Windows Terminal
下载,安裝。下面是它的配置文件。(ctrl + ,)
由于Terminal默认启动powershell,需要修改default的guid,使其自动连接。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97// This file was initially generated by Windows Terminal 1.0.1401.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
// You can add more global application settings here.
// To learn more about global settings, visit https://aka.ms/terminal-global-settings
// If enabled, selections are automatically copied to your clipboard.
"copyOnSelect": false,
// If enabled, formatted data is also copied to your clipboard
"copyFormatting": false,
// A profile specifies a command to execute paired with information about how it should look and feel.
// Each one of them will appear in the 'New Tab' dropdown,
// and can be invoked from the commandline with `wt.exe -p xxx`
// To learn more about profiles, visit https://aka.ms/terminal-profile-settings
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
},
"list":
[
{
"guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
"hidden": false,
"name": "Ubuntu-18.04",
"source": "Windows.Terminal.Wsl",
"commandline": "wsl.exe ssh -X m4d3bug@192.168.99.96"
},
{
"guid": "{a8202b0e-781a-5dab-98e2-e9d469a63619}",
"hidden": false,
"name": "CentOS8",
"source": "Windows.Terminal.Wsl",
"commandline": "wsl.exe ssh -X m4d3bug@192.168.99.93"
},
{
// Make changes here to the powershell.exe profile.
"guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"name": "WSL",
//"commandline": "powershell.exe wsl.exe ssh -X m4d3bug@192.168.99.96",
"commandline": "powershell.exe wsl.exe",
"hidden": false
},
{
// Make changes here to the cmd.exe profi le.
"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
"name": "CMD",
"commandline": "cmd.exe",
"hidden": false
},
{
"guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
"hidden": false,
"name": "Azure Cloud Shell",
"source": "Windows.Terminal.Azure"
},
]
},
// Add custom color schemes to this array.
// To learn more about color schemes, visit https://aka.ms/terminal-color-schemes
"schemes": [],
// Add custom keybindings to this array.
// To unbind a key combination from your defaults.json, set the command to "unbound".
// To learn more about keybindings, visit https://aka.ms/terminal-keybindings
"keybindings":
[
// Copy and paste are bound to Ctrl+Shift+C and Ctrl+Shift+V in your defaults.json.
// These two lines additionally bind them to Ctrl+C and Ctrl+V.
// To learn more about selection, visit https://aka.ms/terminal-selection
{ "command": {"action": "copy", "singleLine": false }, "keys": "ctrl+c" },
{ "command": "paste", "keys": "ctrl+v" },
// Press Ctrl+Shift+F to open the search box
{ "command": "find", "keys": "ctrl+shift+f" },
// Press Alt+Shift+D to open a new pane.
// - "split": "auto" makes this pane open in the direction that provides the most surface area.
// - "splitMode": "duplicate" makes the new pane use the focused pane's profile.
// To learn more about panes, visit https://aka.ms/terminal-panes
{ "command": { "action": "splitPane", "split": "auto", "splitMode": "duplicate" }, "keys": "alt+shift+d" }
]
}
0x04 VMware VM开机自启
创建脚本,注意替换自己的路径以及双引号
1
"D:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe" start "G:\Virtual Machines\ubuntu18.madebug.net\ubuntu18.madebug.net.vmx" nogui
之后保存在以下路径:
1
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
0x05 个人Ubuntu的使用设置
关闭sudo的密码验证
1
2
3
4
5
6
7
8$ sudo visudo
26 %sudo ALL=(ALL:ALL) NOPASSWD:ALL
$ sudo hostnamectl set-hostname ubuntu18.madebug.net
$ sudo vim /etc/hosts
127.0.0.1 localhost
127.0.0.1 ubuntu18
127.0.0.1 ubuntu18.madebug.net
...安裝fish
1
$ sudo apt install fish
安裝omf
1
2$ curl -x http://192.168.99.99:1081 -L https://get.oh-my.fish | fish
$ chsh -s /usr/bin/fish为m4d3bug的fish shell和root的bash shell设置proxy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58$ cat /etc/profile.d/bash_proxy.sh
function proxy_off() {
unset HTTP_PROXY
unset HTTPS_PROXY
unset FTP_PROXY
unset SOCKS5_PORXY
unset http_proxy
unset https_proxy
unset ftp_proxy
unset socks5_proxy
echo -e "已关闭代理"
}
function proxy_on() {
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
export MY_PROXY_URL="http://192.168.99.99:1081"
export HTTP_PROXY=$MY_PROXY_URL
export HTTPS_PROXY=$MY_PROXY_URL
export FTP_PROXY=$MY_PROXY_URL
export SOCKS5_PORXY=$MY_PROXY_URL
export http_proxy=$MY_PROXY_URL
export https_proxy=$MY_PROXY_URL
export ftp_proxy=$MY_PROXY_URL
export socks5_proxy=$MY_PROXY_URL
echo -e "已开启代理"
}
$ cat /etc/fish/conf.d/proxy.fish
function proxy_off
set -e HTTP_PROXY
set -e HTTPS_PROXY
set -e FTP_PROXY
set -e SOCKS5_PORXY
set -e http_proxy
set -e https_proxy
set -e ftp_proxy
set -e socks5_proxy
echo -e "已关闭代理"
end
function proxy_on
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
export MY_PROXY_URL="http://192.168.99.99:1081"
export HTTP_PROXY=$MY_PROXY_URL
export HTTPS_PROXY=$MY_PROXY_URL
export FTP_PROXY=$MY_PROXY_URL
export SOCKS5_PORXY=$MY_PROXY_URL
export http_proxy=$MY_PROXY_URL
export https_proxy=$MY_PROXY_URL
export ftp_proxy=$MY_PROXY_URL
export socks5_proxy=$MY_PROXY_URL
echo -e "已开启代理"
end
$ npm config set proxy http://192.168.99.99:1081
$ npm config set https-proxy http://192.168.99.99:1081
$ git config --global http.proxy http://192.168.99.99:1081
$ git config --global https.proxy http://192.168.99.99:1081设置bash prompt,root用红色提示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42Ubuntu
# cat >> .profile << EOF
function prompt_color_on (){
if [ $(id -u) -eq 0 ]; then
# export PROMPT='%F{10}%n@%m%f:%F{12}%~%f%# '
export PROMPT="%F{135}%n%f@%F{166}%m%f %F{118}%~%f %# "
export PS1='\[\e[01;31m\]\u@\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[00m\]\# '
else
# export PROMPT='%F{10}%n@%m%f:%F{12}%~%f\$ '
export PROMPT="%F{135}%n%f@%F{166}%m%f %F{118}%~%f %$ "
export PS1='\[\e[01;32m\]\u@\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[00m\]\$ '
fi
}
if [ -n "$BASH_VERSION" ]; then
prompt_color_on
else
prompt_color_on
fi
EOF
CentOS
# cat >> /etc/profile.d/prompt.sh << EOF
function prompt_color_on (){
if [ $(id -u) -eq 0 ]; then
# export PROMPT='%F{10}%n@%m%f:%F{12}%~%f%# '
# export PROMPT="%F{135}%n%f@%F{166}%m%f %F{118}%~%f \# "
export PS1='[\[\e[01;31m\]\u@\h\[\e[01;31m\] \[\e[01;31m\]\w\[\e[00m\]]# '
else
# export PROMPT='%F{10}%n@%m%f:%F{12}%~%f\$ '
# export PROMPT="%F{135}%n%f@%F{166}%m%f %F{118}%~%f %$ "
export PS1='[\[\e[01;32m\]\u@\h\[\e[00m\] \[\e[01;34m\]\w\[\e[00m\]\$ '
fi
}
if [ -n "$BASH_VERSION" ]; then
prompt_color_on
else
prompt_color_on
fi
EOF设置byobu
1
2
3
4$ apt install byobu -y
$ byobu-select-backend
1 tmux
$ byobu-enable设置虚拟机共享宿主机目录,能share自然不copy。
0x06 设置x11转发
xorg - Setting up X11 forwarding over SSH on Windows 10 Subsystem for Linux? - Super User
0x07 结语
摆脱wsl一大步
0x08 更新
2021/07/10 真的有更新,换成Ubuntu20.04了,并且把fish换成了zsh,配置文件直接拷了kali的出来,高亮插件和自动补全的都有。 并且设定了新的自动挂载分享文件。
1
.host:/ /mnt/hgfs fuse.vmhgfs-fuse allow_other,defaults,nonempty 0 0
0x09 鸣谢
- Ubuntu Server 18.04下sudo速度很慢原因及解决办法_Linux教程_云网牛站
- Win10安装Ubuntu子系统教程(附安装图形化界面) - Windows10.Pro
- [18.04/美化] 总结一下Ubuntu安装完之后都会做的事情 - 知乎
- [VMware]主机与虚拟机共享文件 - 知乎
- Windows 开机自启 VMware 虚拟机 - 云+社区 - 腾讯云
- oh-my-fish/oh-my-fish: The Fish Shell Framework
- 你不需要花哨的命令提示符 - 知乎
- git - fish shell -eq and -a in if statement - Stack Overflow
- How do I unset a variable in the fish shell? - Stack Overflow