Ubuntu 22.04 版本常用设置
- [Ubuntu 22.04 版本常用设置](#Ubuntu 22.04 版本常用设置)
Ubuntu 22.04 版本常用设置
默认情况下,root 用户不能远程登录,习惯上使用 CRT 工具远程连接服务器。
修改 root 密码
shell
sudo passwd root
远程登录
Ubuntu 系统需先进行一些设置才能进行登录。
- 安装 ssh 服务,支撑后续使用
ssh通过 22 端口远程连接
shell
sudo apt install -y openssh-server
# 检查 sshd 状态
systemctl status ssh
# 设置随机启动
systemctl enable ssh
- 配置
/etc/ssh/sshd_config配置文件
shell
vim /etc/ssh/sshd_config
找到 #PermitRootLogin prohibit-password 这一行数据,在其下面新添加一行
PermitRootLogin yes

- 重启 ssh 服务
shell
systemctl restart ssh
至此,可通过 root 用户,使用 CRT 工具远程登录服务器。
网络配置
Ubuntu 中一些网络命令不能使用,例如:ifconfig、netstat等。
需先安装依赖包。
- 如下安装命令,使用
root用户执行。
shell
apt install -y net-tools
VSCode 安装
执行如下安装命令
shell
snap install code --classic
当前安装 Ubuntu 是用来做嵌入式开发,使用 VSCode 进行 C 开发。
故需安装 gcc,命令如下:
shell
apt install -y gcc
验证版本:
shell
root@test-virtual-machine:~# gcc --version
gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
root@test-virtual-machine:~#
使用 root 用户登录图形化
默认情况下,不能使用 root 用户登录图形化界面(gdm3)。
需进行如下设置后,可实现登录。
- 编辑
/etc/pam.d/gdm-password文件
shell
vim /etc/pam.d/gdm-password
# 找到如下一行,将其注释掉
# auth required pam_succeed_if.so user != root quiet_success
- 编辑
/etc/pam.d/gdm-autologin文件
shell
vim /etc/pam.d/gdm-autologin
# 同样,找到如下一行,将其注释掉
#auth required pam_succeed_if.so user != root quiet_success
- 编辑
/etc/gdm3/custom.conf文件
shell
vim /etc/gdm3/custom.conf
# 在 [security] 下面新添加一行 AllowRoot = true
[security]
AllowRoot = true
补丁等更新
- 更新指令如下
shell
# 1. 更新软件源缓存
apt update
# 2. 升级所有已安装软件、系统补丁、内核、驱动
apt upgrade -y
# 如果上面更新完还有残留包,用这个:
apt full-upgrade -y
- 清理残留 依赖包
shell
apt autoremove -y
apt clean
若有转载,请标明出处:https://blog.csdn.net/CharlesYuangc/article/details/160461447