树莓派4 安装ubuntu20.10系统

安装步骤

  • 用官方系统安装器安装完系统
  • 在系统根目录新建 ssh 空文件(用于ssh远程登陆
  • 默认的登录用户名密码 ubuntu

启用并设置root

1
sudo passwd root
  • 创建对应普通用户
1
2
3
4
5
6
7
8
sudo useradd username -m
#注意要在后面加-m,否则不会在home路径下创建该用户的文件夹
#在CLI中执行
cat /etc/passwd #可以查看passwd文件中是否有刚才添加的用户名,如果有,则表示添加成功
cat /etc/passwd | cut -f 1 -d: # 查看系统用户
#设置密码
sudo passwd username
sudo userdel -r username # 加上-r可以删除/home/路径下的用户文件夹,否则不能
  • ubuntu下允许普通用户使用sudo权限
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
chmod u+w /etc/sudoers # 写权限,
# 找到这行 root ALL=(ALL) ALL,在他下面添加xxx ALL=(ALL) ALL (这里的xxx是你的用户名)
# ps:这里说下你可以sudoers添加下面四行中任意一条
#==============================================================================
youuser            ALL=(ALL)                ALL
%youuser           ALL=(ALL)                ALL
youuser            ALL=(ALL)                NOPASSWD: ALL
%youuser           ALL=(ALL)                NOPASSWD: ALL
#==============================================================================
#第一行:允许用户youuser执行sudo命令(需要输入密码).
#第二行:允许用户组youuser里面的用户执行sudo命令(需要输入密码).
#第三行:允许用户youuser执行sudo命令,并且在执行的时候不输入密码.
#第四行:允许用户组youuser里面的用户执行sudo命令,并且在执行的时候不输入密码。

chmod u-w /etc/sudoers
  • 配置ssh
1
sudo vim /etc/ssh/sshd_config
  • 配置ssh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 修改前:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

# 修改后:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
PermitRootLogin yes
StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

重启ssh服务(尝试下面两个命令: )

1
2
service sshd restart
systemctl restart sshd.service
  • 更换(阿里云源)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
vim /etc/apt/sources.list
# vim清空文件所有内容
# 在命令模式下,首先执行
gg
# 这里是跳至文件首行
# 再执行:
dG
## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
## or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl

# See http:#help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http:#mirrors.aliyun.com/ubuntu-ports focal main restricted
# deb-src http:#mirrors.aliyun.com/ubuntu-ports focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http:#mirrors.aliyun.com/ubuntu-ports focal-updates main restricted
# deb-src http:#mirrors.aliyun.com/ubuntu-ports focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http:#mirrors.aliyun.com/ubuntu-ports focal universe
# deb-src http:#mirrors.aliyun.com/ubuntu-ports focal universe
deb http:#mirrors.aliyun.com/ubuntu-ports focal-updates universe
# deb-src http:#mirrors.aliyun.com/ubuntu-ports focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http:#mirrors.aliyun.com/ubuntu-ports focal multiverse
# deb-src http:#mirrors.aliyun.com/ubuntu-ports focal multiverse
deb http:#mirrors.aliyun.com/ubuntu-ports focal-updates multiverse
# deb-src http:#mirrors.aliyun.com/ubuntu-ports focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http:#mirrors.aliyun.com/ubuntu-ports focal-backports main restricted universe multiverse
# deb-src http:#mirrors.aliyun.com/ubuntu-ports focal-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http:#archive.canonical.com/ubuntu focal partner
# deb-src http:#archive.canonical.com/ubuntu focal partner

deb http:#mirrors.aliyun.com/ubuntu-ports focal-security main restricted
# deb-src http:#mirrors.aliyun.com/ubuntu-ports focal-security main restricted
deb http:#mirrors.aliyun.com/ubuntu-ports focal-security universe
# deb-src http:#mirrors.aliyun.com/ubuntu-ports focal-security universe
deb http:#mirrors.aliyun.com/ubuntu-ports focal-security multiverse
# deb-src http:#mirrors.aliyun.com/ubuntu-ports focal-security multiverse

更新源

1
2
sudo apt update // 更新软件列表,换源完成。
sudo apt-get upgrade