Raspberry Pi OS (Raspbian) 新系统初始化 | 树莓派

标签: none

Snipaste_2020-10-24_03-27-45.png

OS: Raspberry Pi OS (32-bit) Lite - 2020-08-20

默认主机名是 raspberrypi 默认用户是 pi 密码为 raspberry

1.开启SSH
2.修改系统语言, 键盘布局
3.解锁root
4.关闭不需要的服务 (Bluetooth, WiFi, avahi)
5.关闭SSH X11Forwarding 监听 6100端口
6.安装 pip
7.切换默认python

开启SSH

使用树莓派自带配置工具

sudo raspi-config

进入 Interfacing Options -> SSH, 选择 YES 启用

修改系统语言, 键盘布局

使用树莓派自带配置工具

sudo raspi-config

进入 Localisation Options 一共有4项

1.Change Locale 设置为 [*] en_US.UTF-8 UTF-8 按空格选中
2.Change Time Zone 设置为 Asia -> Shanghai
3.Change Keyboard Layout 设置为 Logitech -> Other -> English (US) -> English (US) 剩下的保持默认即可

解锁root

树莓派的 Raspberry Pi OS (Raspbian) 系统上游是 Debian, 所以树莓派启用 root和Debian是相同的。
Debian里root账户默认没有密码,但账户锁定。

pi@raspberrypi:~$ sudo passwd root
pi@raspberrypi:~$ sudo passwd --unlock root

关闭不需要的服务 (Bluetooth, WiFi, avahi)

关闭加载无线驱动
关闭加载蓝牙和WiFi驱动的程序。除了减少接口数量之外,还可以减少功耗。

# cat > /etc/modprobe.d/raspi-blacklist.conf <<EOF

# WiFi
blacklist brcmfmac
blacklist brcmutil

# Bluetooth
blacklist btbcm
blacklist hci_uart
EOF

关闭蓝牙服务
禁用蓝牙服务不是必须的

# systemctl disable bluetooth
# systemctl stop bluetooth

关闭 avahi
The Pi is going to use simple uni-cast DNS - multi-cast DNS support is not required.

# systemctl disable avahi-daemon
# systemctl stop avahi-daemon

Disable TriggerHappy 这个是 raspi-config 依赖程序
The Pi isn't being used with button. Disable the TriggerHappy daemon (not that it is a init.d service)

# systemctl disable triggerhappy
# systemctl stop triggerhappy

关闭SSH X11Forwarding 监听 6100端口

When I finally finished setting up a new VPS for my side projects, I realized this unknown (at least for me) open port: 6010.

port6010.md.png

It took me a quick search on Google to find out it was related to the X11 Forwarding feature present on SSH. If you don't need this feature in your server, disabling it is actually very simple.

Edit your SSH server configuration file:

# vi /etc/ssh/sshd_config

Find the line containing the X11Forwarding option and change it to no:

X11Forwarding no

Save the file and restart SSH server:

# service sshd restart

Don't forget to reconnect to server before checking the listening ports again!

# lsof -i4 | grep LISTEN

That's it!

安装 pip

apt-get install python3-pip
pip3 install --upgrade pip
pip install speedtest-cli

切换默认python

为了更方便地使用python3,我们将其设置为系统默认的版本。为了不破坏 Python2.7 我们采用软链接来使用.
这一步主要是将原有的python2.x版本和python之间的链接删除并添加python3.x的链接。

首先我们查看python2.7和python3的详细版本:

# python --version
Python 2.7.16
# python3 --version
Python 3.7.3

接下来查看python2.7和python3的编译器位置:

# which python
/usr/bin/python
# which python3
/usr/bin/python3

# ls /usr/bin/ -all | grep python
lrwxrwxrwx  1 root root          7 Mar  4  2019 python -> python2
lrwxrwxrwx  1 root root          9 Mar  4  2019 python2 -> python2.7
-rwxr-xr-x  1 root root    2984816 Oct 11  2019 python2.7
lrwxrwxrwx  1 root root          9 Mar 26  2019 python3 -> python3.7
-rwxr-xr-x  2 root root    4275580 Jul 25 21:03 python3.7
-rwxr-xr-x  2 root root    4275580 Jul 25 21:03 python3.7m
lrwxrwxrwx  1 root root         10 Mar 26  2019 python3m -> python3.7m

检查软连接关系之后, 建立软链接:

rm -f /usr/bin/python
ln -s /usr/bin/python3 /usr/bin/python

测试

# python --version
Python 3.7.3

Disable unwanted Raspbian Services
Disabling port 6010 on Ubuntu 16.04
树莓派——升级为python3.x


扫描二维码,在手机上阅读!

添加新评论