1、history命令
2、用户和用户组
3、管道符
一、History命令:
- 显示当前用户所有历史操作记录命令:
1、!682
- 意思就是执行第682行的命令
场景:我们在生产上执行了一些操作想要删除历史记录:
cat .bash_history
echo "" > .bash_history 清空历史命令
生产上如何排查这种问题?
使用root用户进入此目录:/home/XXX/.bash_history
发现了这个命令:rm -rf /data
-
原因:公司生产环境没有安装堡垒机;
-
公司生产环境不与互联网相通;比如我们的电脑在家里,想要去链接生产环境不能直连;需要通过堡垒机去链接,(VPN级别太低),就算我们把生产上的history删除,堡垒机也会做出记录。
拓展知识:堡垒机和跳板机的区别?
2、用户和用户组的常用命令:
- 系统中是有不同的用户及用户组的,
用户目录所在:/usr/sbin/下进行模糊匹配
[root@hadoop001 ~]# ll /usr/sbin/user*
-rwxr-x---. 1 root root 111320 May 11 2016 /usr/sbin/useradd
-rwxr-x---. 1 root root 73656 May 11 2016 /usr/sbin/userdel
-rws--x--x. 1 root root 33952 Aug 23 2010 /usr/sbin/userhelper
-rwxr-x---. 1 root root 115096 May 11 2016 /usr/sbin/usermod
-rwsr-xr-x. 1 root root 9000 May 12 2016 /usr/sbin/usernetctl
用户组:不同的人属于不同的项目组,一个组中可以有多个用户,一个人也可以属于多个项目组,但是必须有一个主组
[root@hadoop001 ~]# ll /usr/sbin/group*
-rwxr-x---. 1 root root 59096 May 11 2016 /usr/sbin/groupadd
-rwxr-x---. 1 root root 54800 May 11 2016 /usr/sbin/groupdel
-rwxr-x---. 1 root root 54960 May 11 2016 /usr/sbin/groupmems
-rwxr-x---. 1 root root 73680 May 11 2016 /usr/sbin/groupmod
- 用户组:不同的人属于不同的项目组,一个组中可以有多个用户,一个人也可以属于多个项目组,但是必须有一个主组
1、自动创建一个用户组,但是必须有一个主组
[root@hadoop001 ~]# useradd ruoze
2、gid是主组,groups是所有组
[root@hadoop001 ~]# id ruoze
uid=516(ruoze) gid=516(ruoze) groups=516(ruoze)
- 它会在/Home目录下创建家目录,同时它的记录是在/etc/passwd下插入一条记录。
[root@hadoop001 ~]# cd /home
[root@hadoop001 home]# ll
total 12
drwx------ 2 ruoze ruoze 4096 Nov 13 16:46 ruoze
//如下会在这个文件下擦汗如一条记录:
[root@hadoop001 home]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
ruoze:x:516:516::/home/ruoze:/bin/bash
ruoze用户的id是516,主组id是516,它的家目录是在/home/ruoze,/bin/bash表示ruoze用户是可执行的。
肯定是先创建组然后再创建用户的:
cat /etc/passwd
cat /etc/group
如何删除用户?
- userdel ruoze
查看/etc/passwd和/etc/group中都是没有关于ruoze的信息的了,原因是ruoze该组只有一个用户,用户被删除,组校验就只有它自己;但是ruoze的家目录还是存在的。
重新创建ruoze用户:
我们测试:我们再次使用命令useradd ruoze;
[root@hadoop001 home]# useradd ruoze
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
Creating mailbox file: File exists
1、查看该用户在不在
[root@hadoop001 home]# id ruoze
uid=516(ruoze) gid=516(ruoze) groups=516(ruoze)
对组group进行操作:
1、greoupadd bigdata
- 增加bigdata用户组
2、[root@hadoop001 home]# cat /etc/group
bigdata❌517:
- 发现是有这条group的记录的
3、[root@hadoop001 home]# id ruoze
uid=516(ruoze) gid=516(ruoze) groups=516(ruoze)
- 目前它还是再516这个组的
4、如何操作把ruoze这个用户加到bigdata这个组中,
- usermod -a -G bigdata ruoze
进行查看:它既在ruoze又在bigdata用户组
[root@hadoop001 home]# id ruoze
uid=516(ruoze) gid=516(ruoze) groups=516(ruoze),517(bigdata)
使用命令帮助:
[root@hadoop001 home]# usermod
Usage: usermod [options] LOGIN
Options:
-c, --comment COMMENT new value of the GECOS field
-d, --home HOME_DIR new home directory for the user account
-e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-a, --append append the user to the supplemental GROUPS
mentioned by the -G option without removing
him/her from other groups
-h, --help display this help message and exit
-l, --login NEW_LOGIN new value of the login name
-L, --lock lock the user account
-m, --move-home move contents of the home directory to the
new location (use only with -d)
-o, --non-unique allow using duplicate (non-unique) UID
-p, --password PASSWORD use encrypted password for the new password
-R, --root CHROOT_DIR directory to chroot into
-s, --shell SHELL new login shell for the user account
-u, --uid UID new UID for the user account
-U, --unlock unlock the user account
-Z, --selinux-user SEUSER new SELinux user mapping for the user account
怎样自己去学习使用而不是都是老师来教了使用
为ruoze用户设置密码:
passwd ruoze
- 123456
普通用户临时获得root权限:
su - ruoze和su ruoze的区别:
-
区别是有-进入到的是ruoze用户的家目录,无-还是在当前目录
-
-指的是切用户后,进入该用户的家目录且执行环境变量文件。