系统安装
下载烧录工具
- Windows 版、macOS 版、Ubuntu X86 版
- 具体烧录步骤参考:烧录步骤
插入存储卡、通电
第一次安装需要注意: 1. 清除配置后烧录系统 2. 通电开机后,需要连接显示器,进行配置(涉及到用户初始化、网络设置、语言选择、时区选择等)
系统初始化
登陆
通过shell远程登录树莓派
ssh sunhao@192.168.1.107
其中:sunhao为开机后设置的用户名
更换国内源
查看系统版本:
sunhao@raspberrypi:/etc/apt $ cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" NAME="Debian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)" VERSION_CODENAME=bookworm ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"
如上,根据
PRETTY_NAME
或VERSION
字段,你可以确定树莓派的操作系统版本。根据以上,可知系统版本为
bookworm
备份原始文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak sudo cp /etc/apt/sources.list.d/raspi.list /etc/apt/sources.list.d/raspi.list.bak
编辑软件源配置
1. 编辑 /etc/apt/sources.list 文件(软件源),删除原来的配置,用以下配置替换 deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm main contrib non-free-firmware deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free-firmware deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates main contrib non-free-firmware 2. 编辑 /etc/apt/sources.list.d/raspi.list 文件(系统更新源),删除原来的配置,用以下配置替换 deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi bookworm main
更新
#更新软件源列表 sudo apt-get update #更新软件版本 sudo apt-get upgrade sudo apt-get dist-upgrade
对于其他系统版本,请阅读这篇文章
安装vim
安装
sudo apt install -y vim
配置
安装插件
# 安装Vundle git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim .vimrc
"显示行号 set nu "启动时隐去援助提示 set shortmess=atI "语法高亮 syntax on "使用vim的键盘模式 set nocompatible "不需要备份 set nobackup "没有保存或文件只读时弹出确认 set confirm "鼠标可用 "set mouse=a "tab缩进 set tabstop=4 set shiftwidth=4 set expandtab set smarttab "文件自动检测外部更改 set autoread "c文件自动缩进 set cindent "自动对齐 set autoindent "智能缩进 set smartindent "高亮查找匹配 set hlsearch "显示匹配 set showmatch "显示标尺,就是在右下角显示光标位置 set ruler "去除vi的一致性 set nocompatible "设置键盘映射,通过空格设置折叠 nnoremap <space> @=((foldclosed(line('.')<0)?'zc':'zo'))<CR> """""""""""""""""""""""""""""""""""""""""""""" "不要闪烁 set novisualbell "启动显示状态行 set laststatus=2 "浅色显示当前行 autocmd InsertLeave * se nocul "用浅色高亮当前行 autocmd InsertEnter * se cul "显示输入的命令 set showcmd "被分割窗口之间显示空白 set fillchars=vert:/ set fillchars=stl:/ set fillchars=stlnc:/ " vundle 环境设置 filetype off set rtp+=~/.vim/bundle/Vundle.vim " vundle 管理的插件列表必须位于 vundle#begin() 和 vundle#end() 之间 call vundle#begin() Plugin 'VundleVim/Vundle.vim' Plugin 'tomasr/molokai' Plugin 'powerline/powerline' Plugin 'Raimondi/delimitMate' " 插件列表结束 call vundle#end() filetype plugin indent on " 配色方案 set background=dark colorscheme molokai " 禁止显示菜单和工具条 set guioptions-=m set guioptions-=T " 总是显示状态栏 set laststatus=2 " 禁止折行 set nowrap " 设置状态栏主题风格 let g:Powerline_colorscheme='solarized256' syntax keyword cppSTLtype initializer_list " 基于缩进或语法进行代码折叠 "set foldmethod=indent set foldmethod=syntax " 启动 vim 时关闭折叠代码 set nofoldenable "允许用退格键删除字符 set backspace=indent,eol,start "编码设置 set encoding=utf-8 "共享剪切板 set clipboard=unnamed " powerline 配置 set rtp+=/usr/local/lib/python2.7/site-packages/powerline/bindings/vim " These lines setup the environment to show graphics and colors correctly. set nocompatible set t_Co=256 " vim 头部自动生成 " 创建sh文件时,生成以下注释模板 autocmd BufNewFile *.sh exec ":call AddTitle()" " 注释模板 function AddTitle() call setline(1, "#!/bin/bash") call append(1, "# @Author: 孙昊(Crazy Coder)") call append(2, "# @Email: sunhao.java@gmail.com") call append(3, "# @Date: " . strftime("%Y-%m-%d %H:%M")) call append(4, "# @Desc: .") call append(5, "") endf " 光标跳转到最后一行,并且按下键盘的o键,进入下一行并且是编辑模式 autocmd BufNewFile *.sh normal G autocmd BufNewFile *.sh normal o
安装插件
vim shift+: PluginInstall
安装oh-my-zsh
安装zsh
sudo apt install -y zsh
安装oh-my-zsh
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
安装插件
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions git clone https://github.com/zsh-users/zsh-syntax-highlighting $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
切换主题、设置alias
vim ~/.zshrc 1. 修改为如下(其他不动): ZSH_THEME="ys" plugins=( z git zsh-autosuggestions zsh-syntax-highlighting docker docker-compose ) 2. 文件最后,新增 alias ll='ls -a -l -G --block-size=m' alias ld='ls -d -l */' 3. 完成后:source ~/.zshrc
禁用密码登陆,使用ssh登录
修改ssh端口
1. sudo vim /etc/ssh/sshd_config 2. #Port 22 -> Port xxx 3. sudo service ssh restart
防火墙放行端口
sudo ufw allow xxx/tcp sudo ufw enable sudo ufw status
添加ssh pub key
cd ~/.ssh sudo touch authorized_keys sudo chmod 600 authorized_keys # add pub key to authorized_keys sudo vim authorized_keys
禁用密码登录
sudo vim /etc/ssh/sshd_config # 修改 PasswordAuthentication yes 为如下 PasswordAuthentication no