树莓派重装系统及基础设置

1 安装系统

1.1 下载镜像

https://www.raspberrypi.org/downloads/

1.2. 格式化

使用 SD Card Formatter 工具快速格式化

1.3. 写镜像

使用 Etcher 将下载的镜像写入SD卡

2 系统配置

2.1 开启SSH

# 在boot盘中创建ssh文件
tianshl@tianshl boot $ touch ssh

2.2 WiFi设置

# 在boot盘中新建wpa_supplicant.conf
tianshl@tianshl boot $ vim wpa_supplicant.conf

# 内容如下 
country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="你的wifi名"
    psk="你的wifi密码"
    key_mgmt=WPA-PSK
}

3 通电启动 并 ssh远程登录

3.1 从路由器管理页面 查找树莓派IP

http://192.168.1.1

3.2 默认账户登录

tianshl@tianshl $ ssh pi@192.168.1.149
# 默认密码: raspberry
# 记得重置密码, 或禁止密码登录, 仅使用秘钥登录

4 系统设置

4.1 修改软件源

# 编辑sources.list
pi@raspberry $ sudo vi /etc/apt/sources.list

# 内容替换为
deb http://mirrors.aliyun.com/raspbian/raspbian/ wheezy main non-free contrib
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ wheezy main non-free contrib

# 更新系统软件
pi@raspberry $ sudo apt-get update && sudo apt-get upgrade -y

4.2 设置时区

pi@raspberry $ dpkg-reconfigure tzdata

# 1. 选择Asia, 回车
# 2. 选择Shanghai, 回车

4.3 Vim 安装及配置

# 卸载系统自带的vim-common
pi@raspberry $ sudo apt-get remove vim-common
# 安装vim
pi@raspberry $ sudo apt-get install vim

# 配置
pi@raspberry $ vim ~/.vimrc

# 内容如下:
set number
syntax on
set tabstop=4

4.4 启用root

# 设置root密码
pi@raspberry $ sudo passwd root
# 启用root账户
pi@raspberry $ sudo passwd --unlock root

# 修改ssh配置
pi@raspberry $ sudo vim /etc/ssh/sshd_config
# 修改或新增:
PermitRootLogin yes
# 保存并退出

# 重启ssh
pi@raspberry $ service ssh restart

4.5 设置秘钥登录

tianshl@tianshl $ ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.149

4.6 禁止密码登录, 仅使用秘钥登录

root@raspberry $ vim /etc/ssh/sshd_config
# 内容如下 
# 允许root登录
PermitRootLogin yes

# 秘钥验证
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

# 禁止密码登录
PasswordAuthentication no

ChallengeResponseAuthentication no

UsePAM yes

X11Forwarding yes
PrintMotd no
AcceptEnv LANG LC_*

Subsystem   sftp    /usr/lib/openssh/sftp-server
root@raspberry $ service ssh restart

4.7 PS1设置 及 常用指令

root@raspberry $ vim ~/.bashrc
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        color_prompt=yes
    else
        color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \$\[\033[00m\] '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

unset color_prompt force_color_prompt

case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

alias ll='ls -lh'
alias l='ls'

5 其他

5.1 Git记住密码

root@raspberry $ git config --global credential.helper store

5.2 开启VNC

5.2.1 临时开启
vncserver
5.2.2 永久开启
root@raspberry $ sudo raspi-config
# 1. 选择 Interfacing Options 回车
# 2. 选择 VNC 回车
# 3. 选择 是 回车

5.3 区域编码

默认不支持en_US.UTF-8 和 zh_CN.UTF-8
# 查看 已存在的编码
root@raspberrypi:~ # locale -a
# 添加编码
# 编辑 locale.gen 去掉 en_US.UTF-8和zh_CN.UTF-8 的注释
root@raspberrypi:~ # vim /etc/locale.gen

# 生成字符集
root@raspberrypi:~ # locale-gen

# 查看 是否已经生成最新的字符集
root@raspberrypi:~ # locale -a
# 更改区域编码
# 更改locale
root@raspberrypi:~ # vim /etc/default/locale

# 内容如下
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN.UTF-8"
LC_ALL="zh_CN.UTF-8"

# 注销重新登录后 locale生效
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值