0%

搭建一个舒适的虚拟机

前言

最近总是重搭虚拟机。简单记录下如何快速的让虚拟机好用。

下载

清华源 Ubuntu Release

换源

清华源 Ubuntu 软件镜像仓库
阿里云 Ubuntu 软件镜像仓库

用阿里源的可以手动注释掉 deb-src 的行。

设置 root 密码

1
sudo passwd

常用包

1
net-tools

oh-my-zsh

1
2
apt install zsh
chsh -s /bin/zsh

通过 gitee 同步仓库安装:

1
2
curl -o install.sh https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
REMOTE=https://gitee.com/mirrors/oh-my-zsh.git sh install.sh

建议再加个插件: zsh-syntax-highlighting

1
2
3
git clone https://gitee.com/testbook/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
# 在插件列表中添加 zsh-syntax-highlighting
vim .zshrc

fish

fishshell 是个好东西,虽然我还是习惯 zsh

vim

vim 有好多版本,如果是桌面操作系统例如 GNOME 建议装 vim-gtk3

无图形化界面或单纯在命令行中使用建议装 vim-nox。因为它支持 Perl、Python、Ruby 和 TCL 脚本

ssh-server

配置文件 /etc/ssh/sshd_config

加入自己的 keys

1
curl https://github.com/<username>.keys | tee -a ~/.ssh/authorized_keys

git

通过 https 端口连接 git@github.com(有时能绕开 DNS 污染)

修改 ~/.ssh/config

1
2
3
Host github.com
Hostname ssh.github.com
Port 443

生成 key

1
ssh-keygen -t ecdsa -b 521 -C "your_email@example.com"

开启共享文件夹

先在 GUI 设置,然后

1
vmhgfs-fuse .host:/ /mnt/hgfs

当然,也有可能不需要这么干,如果提示 nonempty 的话说明 GUI 设置完自动处理好了

clash

参考这篇博客

下载安装:

1
2
3
4
5
6
# 使用了公益镜像源,可能会失效
curl -O https://download.nuaa.cf/Dreamacro/clash/releases/download/v1.14.0/clash-linux-amd64-v1.14.0.gz
# curl -O https://github.com/Dreamacro/clash/releases/download/v1.14.0/clash-linux-amd64-v1.14.0.gz
gzip -d clash-linux-amd64-v1.14.0.gz
sudo install -m 755 ./clash-linux-amd64-v1.14.0 /usr/local/bin/clash
clash -v

拷贝配置:

1
2
3
4
5
6
sudo mkdir /etc/clash
# 自己的 config.yaml 例如可以在 windows 的 clash 那里搞出来
sudo cp config.yaml /etc/clash
# Country.mmdb 可以下载
sudo curl -O https://proxy.freecdn.ml/?url=https://github.com/Dreamacro/maxmind-geoip/releases/download/20230512/Country.mmdb
# sudo curl -O https://github.com/Dreamacro/maxmind-geoip/releases/download/20230512/Country.mmdb

编写 systemd 服务配置 sudo vim /etc/systemd/system/clash.service:

1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=Clash daemon, A rule-based proxy in Go.
After=network.target

[Service]
Type=simple
Restart=always
ExecStart=/usr/local/bin/clash -d /etc/clash

[Install]
WantedBy=multi-user.target

开启服务:

1
2
3
sudo systemctl enable clash
sudo systemctl start clash
sudo systemctl status clash

可以看到端口,export 到变量里即可

1
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890

取消的话

1
unset  http_proxy  https_proxy