Ubuntu 服务器配置指南

科学上网

安装 V2ray

通过 fhs-install-v2ray 安装(未配置代理的情况下,通过 github 下载文件会比较慢):

1
2
3
4
5
6
7
8
# install
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)

# setup client config json (for outbound not inbound!)
vim /usr/local/etc/v2ray/config.json

# start service
systemctl start v2ray

设置 Proxy

1
2
3
4
5
6
7
8
9
10
# ~/.bashrc
export http_proxy=http://127.0.0.1:1087; export https_proxy=http://127.0.0.1:1087; export ALL_PROXY=socks5://127.0.0.1:1080; export NO_PROXY="localhost,127.0.0.1,::1"

# or create aliases
alias proxy='export http_proxy="http://127.0.0.1:1087";export https_proxy="http://127.0.0.1:1087";'
alias unproxy='unset http_proxy https_proxy'

# setup proxy for git, or edit ~/.gitconfig
git config --global http.proxy http://127.0.0.1:1087
git config --global https.proxy http://127.0.0.1:1087

Shell

安装 oh-my-zsh

1
2
3
4
apt install zsh -y

sh -c "$(curl -fsSL \
https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

安装插件

1
2
3
4
5
6
7
8
9
10
# vim ~/.zshrc
plugins=(
autojump
dirhistory
git
ubuntu
zsh-autosuggestions
zsh-hist
zsh-syntax-highlighting
)

其中 autojump 需要先安装依赖:

1
apt install autojump -y

有的插件需要单独安装到第三方插件目录:

1
2
3
4
5
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

git clone https://github.com/marlonrichert/zsh-hist.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-hist

Vim 配置

插件管理器 vim-plug

1
2
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

安装插件只需要在 ~/.vimrc 中添加插件名称,然后重新加载 ~/.vimrc 并执行 :PlugInstall 就可以了。

其它见 vim-cheatsheet

SSH 登录

创建 .ssh 文件夹:

1
mkdir ~/.ssh

复制客户端的 ssh 公钥(macOS):

1
cat ~/.ssh/id_rsa.pub | pbcopy

编辑服务端的 authorized_keys

1
2
3
4
# 粘贴公钥到该文件的最后一行
vim ~/.ssh/authorized_keys
# 修改为读写权限
chmod 600 ~/.ssh/authorized_keys