背景简介
新安装的 Linux 系统添加 sudo 功能。
环境配置
- 系统:Debian 6.1.66-1 (2023-12-09) x86_64 GNU/Linux
详细步骤
更新软件包信息
root@peag-k8s-master:~# apt update
Hit:1 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm InRelease
Hit:2 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates InRelease
Hit:3 http://security.debian.org/debian-security bookworm-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
安装 sudo
root@peag-k8s-master:/home/myserver# apt install sudo
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
sudo
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,889 kB of archives.
After this operation, 6,199 kB of additional disk space will be used.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/debian bookworm/main amd64 sudo amd64 1.9.13p3-1+deb12u1 [1,889 kB]
Fetched 1,889 kB in 0s (4,263 kB/s)
Selecting previously unselected package sudo.
(Reading database ... 33379 files and directories currently installed.)
Preparing to unpack .../sudo_1.9.13p3-1+deb12u1_amd64.deb ...
Unpacking sudo (1.9.13p3-1+deb12u1) ...
Setting up sudo (1.9.13p3-1+deb12u1) ...
Processing triggers for man-db (2.11.2-2) ...
Processing triggers for libc-bin (2.36-9+deb12u3) ...
给用户添加 sudo 权限
root@peag-k8s-master:/home/myserver# usermod -aG sudo myserver
验证
切换至用户
root@peag-k8s-master:/home/myserver# su myserver
myserver@peag-k8s-master:~$
使用sudo指令
myserver@peag-k8s-master:~$ sudo ls -l
[sudo] password for myserver:
total 0
- 输入用户密码后即可
至此,sudo 功能已添加完成~