目录
用户的提权
su - 切换用户
[root@localhost home]# su -
上一次登录:四 2月 24 14:53:59 CST 2022pts/0 上
[root@localhost ~]#
[root@localhost ~]# su - test
[test@localhost ~]$ su -
Password:
Last login: Tue Mar 15 10:19:02 CST 2022 on pts/0
[root@localhost ~]# exit
logout
[test@localhost ~]$ exit
logout
[root@localhost ~]# exit
logout
sudo命令的使用
//创建用户qq
[root@localhost ~]# useradd qq
[root@localhost ~]# id qq
uid=6668(qq) gid=6668(qq) 组=6668(qq)
//设置密码为1
[root@localhost ~]# passwd qq
更改用户 qq 的密码 。
新的 密码:
无效的密码: 密码是一个回文
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
//切换用户qq
[root@localhost ~]# su - qq
//试图创建用户
[qq@localhost ~]$ useradd tt
useradd: Permission denied.
useradd: cannot lock /etc/passwd; try again later.
[qq@localhost ~]$ sudo useradd tt
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
[sudo] password for mika:
mika is not in the sudoers file. This incident will be reported.
//使用sudo方法创建qq
[mika@localhost ~]$ sudo userdel -r tt
[sudo] password for mika:
mika is not in the sudoers file. This incident will be reported.
[mika@localhost ~]$ exit
logout
[root@localhost ~]# visudo
//将qq加到管理员组
[root@localhost ~]# su - qq
上一次登录:二 3月 15 10:32:30 CST 2022pts/0 上
[qq@localhost ~]$ sudo useradd tt
qq is not in the sudoers file. This incident will be reported.
[qq@localhost ~]$ su -
Password:
Last login: Thu Feb 24 14:53:59 CST 2022 on pts/0
//编辑管理员组
[root@localhost ~]# vim /etc/group
//切换用户为qq
[root@localhost ~]# su - qq
Last login: Tue Mar 15 10:36:02 CST 2022 on pts/0
//创建用户
[qq@localhost ~]$ sudo useradd tt
[sudo] password for qq:
useradd: user 'tt' already exists
//因为我没做删除操作所以这里tt已经存在了
//查看tt和qq qq已经在管理员组了
[qq@localhost ~]$ id tt
uid=6669(tt) gid=6669(tt) groups=6669(tt)
[qq@localhost ~]$ id qq
uid=6668(qq) gid=6668(qq) groups=6668(qq),10(wheel)
//或者是直接登录root账户把tt添加到管理员组
[qq@localhost ~]$ su -
Password:
Last login: Tue Mar 15 10:36:28 CST 2022 on pts/0
[root@localhost ~]# usermod tt -aG 10
[root@localhost ~]# id tt
uid=6669(tt) gid=6669(tt) groups=6669(tt),10(wheel)
//查看管理员组
[root@localhost ~]# cat /etc/group
root:x:0:
wheel:x:10:teacher1,qq,tt
qq:x:6668:
tt:x:6669:
增加管理员权限主要用的两种方法
- 使用[root@localhost ~]# visudo 更改权限
- 使用[root@localhost ~]# vim /etc/group 加到管理员组
权限管理
//查看权限
[root@localhost ~]# ll
total 40
-rw-r--r--. 1 root root 111 Mar 8 10:18 123
-rw-r--r--. 1 root root 7 Mar 8 11:34 1.txt
-rw-r--r--. 1 root root 7 Mar 8 10:35 3.txt
-rw-r--r--. 1 root root 0 Mar 8 10:17 4.txt
-rw-r--r--. 1 root root 21 Mar 1 11:30 6.txt
drwxr-xr-x. 3 root root 70 Mar 3 11:42 A
-rw-------. 1 root root 2793 Feb 24 12:13 anaconda-ks.cfg
drwxr-xr-x. 3 root root 15 Mar 1 10:53 C
drwxr-xr-x. 2 root root 6 Mar 1 11:17 E
-rw-r--r--. 1 root root 105 Mar 1 11:27 e.gzip
drwxr-xr-x. 3 root root 15 Mar 1 11:24 F
-rw-r--r--. 1 root root 131 Mar 1 11:26 f.bz2
-rw-------. 1 root root 2057 Feb 24 12:13 original-ks.cfg
-rw-r--r--. 1 root root 2631 Mar 8 11:22 passwd
drwxr-xr-x. 3 root root 39 Mar 3 10:46 student
lrwxrwxrwx. 1 root root 5 Mar 8 11:25 test2.txt -> 1.txt
-rw-r--r--. 1 root root 697 Mar 3 11:41 test.txt
//这里老师想找个空一点的文件夹来着
//“这文件夹里怎么都是乱七八糟的啊”
[root@localhost ~]# cd A
[root@localhost A]# ll
total 4
-rw-r--r--. 1 root root 697 Mar 3 11:42 11.txt
-rw-r--r--. 1 root root 0 Mar 1 10:40 2.txt
-rw-r--r--. 1 root root 0 Mar 1 10:44 444.txt
-rw-r--r--. 1 root root 0 Mar 1 10:42 5.txt
drwxr-xr-x. 2 root root 6 Mar 1 10:48 B
//无法直接从A切换到F 需要绝对路径
[root@localhost A]# cd F
-bash: cd: F: No such file or directory
[root@localhost A]# cd /root/F
//查看F文件夹
[root@localhost F]# ll
total 0
drwxr-xr-x. 2 root root 6 Mar 1 11:17 E
//创建文件file1和dirA(我也忘了这是为了干什么了)
[root@localhost F]# touch file1
[root@localhost F]# mkdir dirA
[root@localhost F]# ll
total 0
drwxr-xr-x. 2 root root 6 Mar 15 10:48 dirA
drwxr-xr-x. 2 root root 6 Mar 1 11:17 E
-rw-r--r--. 1 root root 0 Mar 15 10:48 file1
我是みか,祝你开心。
- 一稿:2022/03/15
- 二稿:2022/06/15