# Linux 通用配置

# myzsh 安装与配置

### Check the env

```
cat /etc/shells 

```

[![](http://www.netflt.com/uploads/images/gallery/2024-08/scaled-1680-/TxQN9Vo7JYQbvuKm-image-1723181940883.png)](http://www.netflt.com/uploads/images/gallery/2024-08/TxQN9Vo7JYQbvuKm-image-1723181940883.png)

### Install zsh

```
sudo apt-get install zsh
## replace zsh as default shell manager
sudo chsh -s $(which zsh) $USER

```

[![](http://www.netflt.com/uploads/images/gallery/2024-08/scaled-1680-/LWnBH59Litac4Bu3-image-1723181948839.png)](http://www.netflt.com/uploads/images/gallery/2024-08/LWnBH59Litac4Bu3-image-1723181948839.png)

### Install oh-my-zsh

```
sudo apt-get install wget
sudo apt-get install git

wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh

```

[![](http://www.netflt.com/uploads/images/gallery/2024-08/scaled-1680-/oyFLmvZwtcxuP0L2-image-1723181959516.png)](http://www.netflt.com/uploads/images/gallery/2024-08/oyFLmvZwtcxuP0L2-image-1723181959516.png)

### Install plugin

```

git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

```

### Edit myzsh theme

```
vim ~/.zshrc
##add plugin
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
### select a theme
ZSH_THEME="ys"
source ~/.zshrc 

```

### Install autojump

```
sudo apt-get install autojump

# add autojump.zsh in .zshrc
. /usr/share/autojump/autojump.zsh





```

### oh-my-zsh 在 `git` 目录下执行命令会卡顿明显，简单的 `cd` 和 `ls` 都会。

> ##### 原因:
> 
> 插件会读取 git 的配置信息，如果项目目录下有太多的文件，卡顿会非常明显。可以使用以下命令禁止 zsh 自动获取 git 信息，解决卡顿问题：
> 
> ##### 解决：
> 
> 1. 设置 oh-my-zsh 不读取文件变化信息  
>     git config --add oh-my-zsh.hide-dirty 1
> 2. 设置 oh-my-zsh 不读取任何 git 信息  
>     git config --add oh-my-zsh.hide-status 1
> 3. 全局设置 oh-my-zsh 不读取文件变化信息  
>     git config --global oh-my-zsh.hide-dirty 1
> 4. 全局设置 oh-my-zsh 不读取任何 git 信息  
>     git config --global oh-my-zsh.hide-status 1

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/OHMt4bXvftK8cexY-image-1735725824393.png)](http://www.netflt.com/uploads/images/gallery/2025-01/OHMt4bXvftK8cexY-image-1735725824393.png)

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/8u2s8LMO7mmSPtWY-image-1735726419540.png)](http://www.netflt.com/uploads/images/gallery/2025-01/8u2s8LMO7mmSPtWY-image-1735726419540.png)

# SSH 免密登陆

原文链接：[https://blog.csdn.net/weixin\_43922901/article/details/106078558](https://blog.csdn.net/weixin_43922901/article/details/106078558)

该方法和什么终端无关，主要是根据ssh key方式登陆，无需远程主机登录密码，非常方便。

### 1 生成ssh秘钥和公钥文件

进入本地终端：

```
ssh-keygen -t rsa

```

出现如下图所示，这时候请不要一直回车，输入相应的文件名称，因为不输入的话是默认生成id\_rsa和id\_rsa.pub两个文件。然而，由于很多人其实在本地配置了GitHub的钥匙，因此会存在这样的文件，所以在这里我们需要改个名，比如id\_ssh。

[![](/uploads/images/gallery/2024-08/scaled-1680-/KVPrbNd01ZvA4Rmb-image-1723127521085.png)](/uploads/images/gallery/2024-08/KVPrbNd01ZvA4Rmb-image-1723127521085.png)

输入秘钥文件名：

[![](/uploads/images/gallery/2024-08/scaled-1680-/9L6d6nynDn9uEGaP-image-1723127534556.png)](/uploads/images/gallery/2024-08/9L6d6nynDn9uEGaP-image-1723127534556.png)

输入完钥匙文件名称后，在路径~/.ssh/下会生成文件id\_ssh和id\_ssh.pub

[![](/uploads/images/gallery/2024-08/scaled-1680-/a7stlBNBS4D7tRAQ-image-1723127559322.png)](/uploads/images/gallery/2024-08/a7stlBNBS4D7tRAQ-image-1723127559322.png)

然后执行：

```
cat id_ssh.pub

```

**把文件中的公钥复制到远程主机的~/.ssh/authorized\_keys中**，如果没有这个文件，那么请创建一个新的。

[![](/uploads/images/gallery/2024-08/scaled-1680-/lyFY68zVz3Ng2ug2-image-1723127576215.png)](/uploads/images/gallery/2024-08/lyFY68zVz3Ng2ug2-image-1723127576215.png)

### 2 配置config文件

同样**进入到本地 .ssh目录**

```
cd ~/.ssh/ 
vim config

```

按如下格式修改目录下的config文件。有几个主机就可以配置几个，但是本地的id\_ssh.pub内的公钥内容一定记得复制到远程主机的~/.ssh/authorized\_keys中。

```
Host workhost0  # 远程主机别名
  HostName 192.168.63.8  # 远程主机ip
  User zhangsan  # 你在远程主机的用户名
  Port 22
  IdentityFile ~/.ssh/id_ssh  # 你的ssh秘钥文件

Host workhost1
  HostName 192.168.63.9
  User zhangsan
  Port 22
  IdentityFile ~/.ssh/id_ssh

```

### 3 登录

在本地终端执行：

```
ssh workhost0

```

即可成功免密登录。

# Nginx 安装及配置

### 安装nginx

```bash
wget http://soft.vpser.net/lnmp/lnmp1.6.tar.gz -cO lnmp1.6.tar.gz 
tar zxf lnmp1.6.tar.gz 
cd lnmp1.6 
./install.sh nginx

```

### 添加网站

```bash
lnmp vhost add

```

### 代理HTTP

```bash
server {
    listen       80;
    server_name  www.netflt.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
    }
}

```

### 代理HTTPS

```bash
server {
    listen 443 ssl;
    server_name netflt.com;
    ssl_certificate /home/ubuntu/lisence/netflt.com.crt;
    ssl_certificate_key /home/ubuntu/lisence/netflt.com.key;
    ssl_session_cache builtin:1000 shared:SSL:10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    location / 
    {
        proxy_pass http://localhost:8181;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
    }
}

```

# 基于 LazyVim 将 nvim 打造成 c++ IDE

工欲善其事,必先利其器. (以下这部分时废话)

从事 C++ 开发这么多年,一直都在用 vscode 作为 IDE, 其插件丰富以及优雅的 UI 交互让人爱不释手.直到有一天发现身边同事用 nvim 一通行云流水的操作,让我意识到自己过去的开发过程中,实际操作效率并不高.于是我决定有必要开始做些改变. 目前开源有不少非常优秀的 nvim 插件管理项目开箱即用,对于小白来说非常友好.但由于其默认集成了了不少通用插件,导致 nvim 启动的时候不够丝滑. 并且这些通用插件又未必都是你需要的,这时候你可能需要了解一些自定义安装插件的方法. 这几天花了一些时间将 nvim 打造成 c++ 开发利器,中间遇到不少坑,总结了些配置,仅供参考.

---

### 下载并安装 nvim

主要参考官方手册: https://github.com/neovim/neovim/blob/master/INSTALL.md

#### macos

```bash
brew install neovim

```

#### linux

```
sudo apt-get install neovim

```

### 基于 LazyVim 安装初始版本

如果你之前已经安装过 nvim, 为了保险起见,可以先备份或者删除;但确保本次启动前你的配置目录是干净的;

#### 备份原有配置(必须)

```
mv ~/.config/nvim{,.bak}

```

#### 备份插件及缓存(可选)

```
mv ~/.local/share/nvim{,.bak}
mv ~/.local/state/nvim{,.bak}
mv ~/.cache/nvim{,.bak}

```

#### 克隆官方给的 starter, 这个项目只是一个空壳,主要是用于安装 lazy 以及默认的一些插件

```
git clone https://github.com/LazyVim/starter ~/.config/nvim

```

#### 删除 .git 目录,后续你可以创建为自己的 git repo

```
rm -rf ~/.config/nvim/.git
nvim

```

首次启动效果如下:

[![](http://wiki.netflt.com/uploads/images/gallery/2024-09/scaled-1680-/LgMyEuzyTMdfSO3a-image-1725162687947.png)](http://wiki.netflt.com/uploads/images/gallery/2024-09/LgMyEuzyTMdfSO3a-image-1725162687947.png)

### 接下来开始配置插件

lazyvim 安装完后,默认的目录结构如下,其中 config 目录下的文件是固定的,不可改变;每个文件对应的功能也有对应的解释,这里不再赘述. Plugins 目录是用来自定义插件的,这里的文件名无所谓, lazyvim 会自动扫描这个目录下的所有文件并尝试加载;

[![](http://wiki.netflt.com/uploads/images/gallery/2024-09/scaled-1680-/wpZoo7vTew5KAXdY-image-1725163248700.png)](http://wiki.netflt.com/uploads/images/gallery/2024-09/wpZoo7vTew5KAXdY-image-1725163248700.png)

#### 自定义主题

这里已经有一个 `example.lua`,从这里入手,将文件改名为 `default.lua`; 并安装自己喜欢的主题, 默认使用的是 `tokyonightly`; 个人更喜欢 `github_dark`;

```
-- Plugins/default.lua
return {
  { "projekt0n/github-nvim-theme" },
  {
    "LazyVim/LazyVim",
    opts = {
      colorscheme = "github_dark",
    },
  },
}

```

效果如下: [![](http://wiki.netflt.com/uploads/images/gallery/2024-09/scaled-1680-/qvXqVmUMDybZlAoE-image-1725164007425.png)](http://wiki.netflt.com/uploads/images/gallery/2024-09/qvXqVmUMDybZlAoE-image-1725164007425.png)

#### 设置 tab 宽度并显示空格,

```
-- config/options.lua
-- utf8
vim.g.encoding = "UTF-8"

-- 缩进4个空格等于一个Tab
vim.opt.tabstop = 4
vim.opt.softtabstop = 4

-- >> << 时移动长度
vim.opt.shiftwidth = 4

-- 空格替代tab
vim.opt.expandtab = true

-- 不可见字符的显示，这里只把空格显示为一个点
vim.opt.listchars = "space:·"

-- 默认关闭保存文件时自动格式化
vim.g.autoformat = false


```

[![](http://wiki.netflt.com/uploads/images/gallery/2024-09/scaled-1680-/YEW6NKzjxmaLyvvD-image-1725165239230.png)](http://wiki.netflt.com/uploads/images/gallery/2024-09/YEW6NKzjxmaLyvvD-image-1725165239230.png)

#### neo-tree 配置

默认情况下,neo-tree 不显示隐藏的文件和目录,但有时候我们是需要的;

```
return {
  "nvim-neo-tree/neo-tree.nvim",
  opts = {
    filesystem = {
        filtered_items = {
            visible = true,
            show_hidden_count = true,
            hide_dotfiles = false,
            hide_gitignored = true,
            hide_by_name = {
                --'.git', '.DS_Store',  -- 'thumbs.db',
            },
            never_show = {'.git'},
        },
    }
  }
}


```

# 在 docker 中打造 ubuntu 开发环境

#### 拉取 ubuntu image

```
docker pull ubuntu

```

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/mnOrW9LUP0IdMi5l-image-1735723850572.png)](http://www.netflt.com/uploads/images/gallery/2025-01/mnOrW9LUP0IdMi5l-image-1735723850572.png)

#### 查看 image 是否存在

```
docker images

```

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/RDOH4Y65ZAwYvFrW-image-1735715227640.png)](http://www.netflt.com/uploads/images/gallery/2025-01/RDOH4Y65ZAwYvFrW-image-1735715227640.png)

#### 启动容器

```
docker run --name ubuntu-dev -t -i -d -p 3316:22 ubuntu:latest

```

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/HAsxFSNFP7E7Egcl-image-1735723968943.png)](http://www.netflt.com/uploads/images/gallery/2025-01/HAsxFSNFP7E7Egcl-image-1735723968943.png)参数说明:

- –name 指定生成的容器的名称
- -i: 以交互模式运行容器，保证容器中STDIN是开启的。通常与 -t 同时使用；
- -t: 为容器重新分配一个伪tty终端，通常与 -i 同时使用；
- -d: 后台运行容器，并返回容器ID；
- -p:可以指定要映射的IP和端口，但是在一个指定端口上只可以绑定一个容器。支持的格式有 hostPort:containerPort、ip:hostPort:containerPort、 ip::containerPort。
- ubuntu 则是镜像名称/版本，镜像ID也可以的。

#### 设置 root password

```
passwd root


```

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/0EQgApM5CTSbCQ5A-image-1735724555302.png)](http://www.netflt.com/uploads/images/gallery/2025-01/0EQgApM5CTSbCQ5A-image-1735724555302.png)

#### 创建 sudo 用户

```
# 更新源并安装 vim
apt-get update
apt-get install vim

# 安装 sudo
apt-get install sudo

# 创建用户
adduser danny

# 添加到 sudo 分组
usermod -aG sudo danny



```

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/9lJWfOmBrhjqCciP-image-1735724818337.png)](http://www.netflt.com/uploads/images/gallery/2025-01/9lJWfOmBrhjqCciP-image-1735724818337.png)

#### 安装 ssh 服务

```
apt-get install openssh-client -y
apt-get install openssh-server -y

```

### 设置端口, 并启动 ssh 服务

```
vim /etc/ssh/sshd_config
service ssh start

```

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/GanhxAJNlITZFVLU-image-1735724426703.png)](http://www.netflt.com/uploads/images/gallery/2025-01/GanhxAJNlITZFVLU-image-1735724426703.png)[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/roSj37LxlO1aZthO-image-1735715627500.png)](http://www.netflt.com/uploads/images/gallery/2025-01/roSj37LxlO1aZthO-image-1735715627500.png)

### 配置 zsh,

参看: http://www.netflt.com/books/linux/page/myzsh-1xF

# neonvim 安装与配置

### 基于 cmd 安装, (有可能版本会比较旧)

```
sudo apt-get install neovim

```

### 基于源码安装

```
## install gcc build env
sudo apt-get install build-essential
sudo apt-get install cmake

### could not find luajit
sudo apt-get install luajit

## Could NOT find Gettext
sudo apt-get install gettext libgettextpo-dev

# get source
git clone https://github.com/neovim/neovim.git

cd neovim

#switch stable branch
gco stable

make CMAKE_BUILD_TYPE=RelWithDebInfo

sudo make install

```

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/F9BxQ9kk9e1OOAeh-image-1735727423884.png)](http://www.netflt.com/uploads/images/gallery/2025-01/F9BxQ9kk9e1OOAeh-image-1735727423884.png)

### 下载 nvim 配置

```
mkdir -p ~/.config/
git clone https://github.com/netflt/nvim-cpp.git nvim
nvim ./

```

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/MoqNEglRVbxKjFm3-image-1735727673990.png)](http://www.netflt.com/uploads/images/gallery/2025-01/MoqNEglRVbxKjFm3-image-1735727673990.png)

> 可能出现以下错误原因是 blink\_cmp\_fuzzy 依赖文件找不到
> 
> 1. curl 没有安装导致 blink\_cmp\_fuzzy 下载失败; 可以安装 curl 重新启动 nvim 解决
> 2. libblink\_cmp\_fuzzy 找不到对应的版本,可以手动编译

[![](http://www.netflt.com/uploads/images/gallery/2025-01/scaled-1680-/8sD69dXoqthAdq9m-image-1735727637439.png)](http://www.netflt.com/uploads/images/gallery/2025-01/8sD69dXoqthAdq9m-image-1735727637439.png)

# 基于源码安装 gdb

> nvim-dap 依赖 gdb 建议使用 gdb-14.2, (低版本不支持 dap协议,而高版本可能提示 set breakpints not stopped)

```
wget https://ftp.gnu.org/gnu/gdb/gdb-14.2.tar.gz
tar xf gdb-14.2.tar.gz
cd gdb-14.2

mkdir build
cd build
../configure --enable-targets=all --with-expat --with-python=/usr/bin/python3

## error: Building GDB requires GMP 4.2+, and MPFR 3.1.0+.
sudo apt-get install libmpc-dev

## makeinfo: not found
sudo apt-get install texinfo 

##编译期间可能会遇到各类依赖错误,可以选择安装
sudo apt-get install flex bison libreadline-dev


make
sudo make install

```