Ubuntu从入门到应用
更改镜像源
Ubuntu 22.4
maisi@ecs:~$ sudo sed -i 's|http://[a-z0-9\.]*\.archive\.ubuntu\.com|https://mirrors.aliyun.com|g;s|http://security\.ubuntu\.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list maisi@ecs:~$ sudo apt update && apt upgrade && apt full-upgradeUbuntu 24.4
maisi@ecs:~$ sudo sed -i 's|http://[a-z0-9\.]*\.archive\.ubuntu\.com|https://mirrors.aliyun.com|g;s|http://security\.ubuntu\.com|https://mirrors.aliyun.com|g' /etc/apt/sources.list.d/ubuntu.sources maisi@ecs:~$ sudo apt update && apt upgrade && apt full-upgrade
开启root用户
设置root用户密码
maisi@ecs:~$ sudo passwd root切换root用户
maisi@ecs:~$ su - Password: root@ecs:~#开启root ssh登录
root@ecs:~# sed -i '/#PermitRootLogin/a \PermitRootLogin yes' /etc/ssh/sshd_config root@ecs:~# sed -i '/#PasswordAuthentication/a \PasswordAuthentication yes' /etc/ssh/sshd_config root@ecs:~# sed -i '/#PermitEmptyPasswords/a \PermitEmptyPasswords no' /etc/ssh/sshd_config root@ecs:~# systemctl restart ssh如果缺少/etc/ssh/sshd_config,原因是没有安装ssh服务。
查看是否安装ssh
maisi@ecs:~$ dpkg -l | grep openssh-server安装openssh
maisi@ecs:~$ sudo apt update maisi@ecs:~$ sudo apt install openssh-server maisi@ecs:~$ sudo systemctl enable --now ssh
用户及组
查看所有用户
root@ecs:~# sudo getent passwd root@ecs:~# cat /etc/passwd查看用户所属组
root@ecs:~# sudo groups maisi maisi : maisi adm cdrom sudo dip plugdev lxd查看所有组
root@ecs:~# cat /etc/group查看组内所有用户
root@ecs:~# sudo getent group sudo将用户加入组
将用户maisi加入sudo、root组
root@ecs:~# sudo usermod -aG sudo maisi root@ecs:~# sudo usermod -aG root maisi移除组内用户
root@ecs:~# sudo gpasswd -d maisi root
关闭Shell Integration
Ubuntu 26.04默认启用了Shell Integration,systemd会向终端发送OSC(Operating System Command)控制序列。
格式:08;start=e6c9b7d8-7b8c-4e57-81ff-a15fa02ce61b;machineid=6bb9d3950534460ba96e415cc64f1cd6;user=root;hostname=ubuntu;bootid=1f7bf34f-bbc9-4f40-9782-ad0ed2ce4f0e;pid=00000000000000052777;type=command;cwd=/root。
如果SSH客户端不支持OSC,则会在终端直接输出原始代码,可以在Ubuntu关闭Shell Integration。
root@ecs:~$ cat >> ~/.bashrc <<EOF
if [[ -n "$SSH_CONNECTION" ]]; then
PROMPT_COMMAND=(
"${PROMPT_COMMAND[@]/__systemd_osc_context_precmdline}"
)
PS0=
fi
EOF
root@ecs:~$ source ~/.bashrc