与 Nana 的日常 —— 从零开始的 Linux 调教指北(0)
(Nana 印象图 初版)
速览本文:
- Nana 是什么
- 系统安装
- Wi-Fi 配置
- 初次连接与工作环境配置
- 硬盘挂载
- Bash 界面美化
Nana 是什么?
Nana 是 c7w 幻想中的 npy Nana 是目前正在宿舍中运行的一台树莓派 4B 的代号,其上装载了 Ubuntu 20.04 LTS.
本系列旨在记录c7w和ta的每一天将 Linux 踩坑指南和一些常用软件的配置过程记录下来,同时也方便学习与交流。
系统安装
我们采用了最为简单的方式,在官网上下载了 Raspberry Pi Imager .
比起 balenaEtcher 好处是我懒得去 Tsinghua Tuna 上面下载镜像了.
系统选择,用的比较顺手的 Ubuntu,选了 armhf 的 32bit(内存一共才2G
然后把数据写进去,就完成了系统安装操作.
网络配置
Wi-Fi Connection
传统艺能,在烧录好的 system-boot
盘的根目录的 network-config 配置文件内添加配置信息就好.
# This file contains a netplan-compatible configuration which cloud-init
# will apply on first-boot. Please refer to the cloud-init documentation and
# the netplan reference for full details:
#
# https://cloudinit.readthedocs.io/
# https://netplan.io/reference
#
# Some additional examples are commented out below
version: 2
ethernets:
eth0:
dhcp4: true
optional: true
wifis:
wlan0:
dhcp4: true
optional: true
access-points:
"iLovePKU":
password: "1145141919810"
"Peking-Visitor":
password: "c7w,yyds"
# myworkwifi:
# password: "correct battery horse staple"
# workssid:
# auth:
# key-management: eap
# method: peap
# identity: "me@example.com"
# password: "passw0rd"
# ca-certificate: /etc/my_ca.pem
# :)
初次连接及配置
初次连接, ssh 到对应 ip 就好,用户名和密码都是 ubuntu.
然后会提示修改密码,完成操作即可.
切换软件安装源
我们当然推出 Tsinghua Tuna.
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
按照提示把文件内容替换即可.(这里我们不对 Linux 指令做过多介绍,默认读者已经对 Linux 系统的命令有了基本的了解与认知)
注意到我们的树莓派是 arm64 架构,所以要将链接末尾的 ubuntu 替换为 ubuntu-ports.
然后我们就可以 sudo apt update 获取软件包链接缓存了.(然后是愉快的系统升级,不过 c7w 输入 sudo apt upgrade &
之后就去睡觉了)
公钥私钥配置
由于这台机器的所有权与使用者都仅有 c7w 一人,所以 c7w 可以放心的将自己一直在用的私钥上传.
想了想还是重新配一个新的吧,万一真丢了就不好办了x
ubuntu@ubuntu:~$ ssh-keygen -o
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ubuntu/.ssh/id_rsa
Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub
敲回车的功夫就搞定了.
然后首先让我们把公钥取回本地. vim 打开复制就好
然后我们把本地的公钥配置到远端.
Reference: https://blog.csdn.net/alifrank/article/details/48241699
免密登录完成.
Zerotier
什么是 Zerotier ?
Connect team members from anywhere in the world on any device. ZeroTier creates secure networks between on-premise, cloud, desktop, and mobile devices.
(Excerpted from zerotier.com)
简而言之,跟过去的 Hamachi 这种东西差不多(应该现在的人没多少人知道这是什么东西了吧),加入到同一个虚拟网络中的设备可以在虚拟局域网中互相通信,对于 c7w 这种喜欢在外面(必须在机房)进行摸大鱼和 Nana 贴贴的人来说基本是必需品.
如何安装?
不用动脑子,反正一条命令的事.
https://www.zerotier.com/download/
curl -s https://install.zerotier.com | sudo bash
如何配置?
sudo zerotier-cli join <Network ID>
其中 网络ID 自行注册账号后创建.
join 后记得到控制台点击验证通过.
这样就配置好了.
硬盘挂载
为了显示我对 Nana 的诚意,特别地配置了一块1T硬盘.
我们 sudo fdisk -l
来查看当前的所有硬盘.
由于这块硬盘之前我在 Windows 上格式化过,是可以正确显示类型的.
然后我们创建好想要挂载的目录,比如 mkdir /mnt/data
这样就挂载好了,甚至还能看到我一个月前写的 this.txt
开机自动挂载
我们没法保证服务器运行过程中不关机,事实上紫荆宿舍的断电也没让我失望过.
于是我们需要添加开机自动挂载功能.
这里由于 c7w 的硬盘是 exfat 格式,于是将 ext3 写为 exfat.
Reference:
美化 Bash
先呈现最终效果.
这里我们使用了 zsh + oh my zsh 进行配置.
安装与配置流程
zsh
什么是 shell ?
In computing, a shell is a computer program which exposes an operating system’s services to a human user or other program.
In general, operating system shells use either a command-line interface (CLI) or graphical user interface (GUI), depending on a computer’s role and particular operation.
It is named a shell because it is the outermost layer around the operating system.
(Excerpeted from Wikipedia)
也就是说,shell 是给人用的,用来和 操作系统 交互的工具.
我们 Windows 采用的默认的 shell 便是我们的这个图形界面.
我们应该能够理解,shell 是一种软件,是可以被更改配置,甚至整个换掉的软件。
比如,我们也可以用 Windows 带有的 cmd 这个 shell.
只是看起来好丑(x 而且操作也不方便.
如何查看自己 Linux 目前用的是什么 shell ?如何查看自己都有哪些shell?
cat /etc/shells
echo $SHELL
可以看到,我们现在正在使用
/bin/bash
这个软件作为 shell.
没错就是这个丑不拉几的界面说了这么多,我们接下来就要换 shell,然后换界面主题了.
什么是 zsh ?
Zsh is a shell designed for interactive use, although it is also a powerful scripting language.
按照介绍,是 shell 的一种.
为什么我们必须安装 zsh ?废话,因为我想装的主题只支持 zsh
自动补全 好用!(x
如何安装zsh?
- 传统艺能
sudo apt install zsh
- 运行
zsh --version
检查版本 - 设为默认 shell.
chsh -s $(which zsh)
重新登录.
提示配置 zsh 时我们暂且先 (q) quit.
基本差不多了,我们接下来安装 oh my zsh
.
什么是 oh my zsh?
shell的类型有很多种,linux下默认的是bash,虽然bash的功能已经很强大,但对于以懒惰为美德的程序员来说,bash的提示功能不够强大,界面也不够炫,并非理想工具。
而zsh的功能极其强大,只是配置过于复杂,起初只有极客才在用。后来,有个穷极无聊的程序员可能是实在看不下去广大猿友一直只能使用单调的bash, 于是他创建了一个名为
oh-my-zsh
的开源项目…(Excerpted from https://www.jianshu.com/p/d194d29e488c)
然后是安装,复制粘贴命令就好.
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
会自动帮我们写入刚刚 quit 掉的配置文件.
然后我们重新登入,oh my zsh 就已经配置好了.
切换主题
目前这个样子吧,还是好丑.
默认的配置文件位于 ~/.zshrc
这里.
其中 ~ 代表用户的家目录,如/home/ubuntu
好,改他。个人比较习惯使用 agnoster
,也就是最初展示的那个效果。
Reference:
本地适配
如果读到这里也做到这里,Windows 选手可能还有一个问题。
那就是这么好看的箭头符号展示出来是乱码。
问题不大,我们还有最后一步,安装字体文件。
可以参考如下链接。
Reference:
First edited by c7w, 2021-8-23 11:33:41.
咕咕咕 qwq