操作
[root@SVR-IM2 ~]# head /etc/passwd > passwd # 打印 /etc/passwd 的前十行 并清空重定向 至passwd文件
[root@SVR-IM2 ~]# man head # man 手册命令
NAME
head - output the first part of files # 输出文件的第一部分
DESCRIPTION
Print the first 10 lines of each FILE to standard output. With more than one FILE, # 将文件的前10行打印为标准输出
Vim替换
:s/root/ROOT/g # 将光标行 root 替换为 ROOT
:%s/root/ROOT/g # 将全篇 root 替换为 ROOT
实战
### 1 将passwd文件中所有sbin换为SBIN
### 2 将第s八行的SBIN换为sbin
命令
pwd # 打印出当前路径
cp 1.txt /root # 将当前路径1.txt 复制至/root 路径
mv 2.txt /root # 将当前路径2.txt 移动至/root 路径
mv 3.txt /root/4.txt # 将当前路径3.txt 移动至/root 路径 并重命名为4.txt
mv 5.txt 6.txt # 重命名
cp anaconda-ks.cfg /tmp/anaconda-ks.cfg.bak # 备份文件操作
用户管理
[root@localhost ~]# id zhangsan
id: zhangsan: no such user
[root@localhost ~]# useradd zhangsan
[root@localhost ~]# id zhangsan
uid=1001(zhangsan) gid=1001(zhangsan) groups=1001(zhangsan)
[root@localhost ~]# passwd zhangsan # 在root用户下修改普通用户密码
Changing password for user zhangsan.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully. # 已成功更新所有身份验证令牌
### /etc/passwd
### 用户名:密码占位符:UID:GID:描述:家目录:用户shell
### zhangsan:x:1001:1001::/home/zhangsan:/bin/bash
提权操作
### 首先使用普通用户登录服务器
ssh [email protected] # 如无法连接 1)IP输入错误 2)用户未添加 3)用户密码错误
### 普通用户提权操作
[zhangsan@localhost ~]$ sudo su -
[sudo] password for zhangsan:
zhangsan is not in the sudoers file. This incident will be reported. # 报错Zhangsan不在Sudoes文件中
### 切换root授权
ssh [email protected]
vim /etc/sudoers
复制 # %wheel ALL=(ALL) NOPASSWD: ALL
粘贴至 末尾 并修改为如下所示
保存并退出
再次尝试
[zhangsan@localhost ~]$ sudo su -
Last login: Sat Nov 6 17:38:45 CST 2021 from 192.168.0.110 on pts/2 # 成功切换root