第四天重定向tr命令用户名密码修改

直接指针间接指针ext4格式

硬链接特点不能跨分区


[mage@centos7 data]$ln /root/f3 /data/f3.lnk
ln: failed to create hard link ‘/data/f3.lnk’ => ‘/root/f3’: Invalid cross-device link

硬链接本质是一个文件多个名称,夸分区则文件不同

不能针对目录

[mage@centos7 data]$ln /data /data/link
ln: ‘/data’: hard link not allowed for directory
会增长链接数
[root@centos7 data]# ln hosts host1
[root@centos7 data]# ll
total 4
-rw-r--r--.  2 root root    0 Mar  8 14:54 host1
-rw-r--r--.  2 root root    0 Mar  8 14:54 hosts

软连接本质 类似快捷方式
ln -s filename linkname

源文件链接数不增长
和源文件不是同一个文件
软连接是指向原始文件路径 软连接只关心文件名

[root@centos7 data]#ln -s host1  hhhaa
ln: failed to create symbolic link ‘hhhaa’: File exists
[root@centos7 data]#ll -i
total 4
     120 lrwxrwxrwx.  1 root root    5 Mar 11 19:08 hhhaa -> host1
      67 -rw-r--r--.  2 root root    0 Mar  8 14:54 host1

软连接对原始文件有依赖性, 如果删除原始文件在建同名字则原始文件被毁同名文件为新内容文件

[root@centos7 data]#\rm -f host1
[root@centos7 data]#echo 11111 > host1
[root@centos7 data]#cat hhhaa
11111

支持跨分区
支持对目录创建软连接
ln相对路径相对于 软连接本身的路径 就是软连接目录本身相对文件路径
ln -s
连接路径的字符就是软连接文件大小
软连接针对网络资源,可以跨主机

rm 本质删除文件的inode 和文件名
链接数递减,从而释放的inode号可以被重用

rm -rf dir1.link 看看源文件有没有动
【A】----依赖---->【B】----依赖---->【C】
我们的终极目的是要解决问题A,
那么三个问题的处理顺序如下:
开始处理问题A;
由于A依赖B,因此开始处理问题B;
由于B依赖C,开始处理问题C;
结束处理问题C;
结束处理问题B;
结束处理问题A。

rm -rf 删除
rm -rf dir1.link/ 如果加/则破坏软连接里的原始文件数据,
并不破坏软连接和源文件目录 软连接是链接路径
删除 dir1.link/下文件
cd 123.link/

扫描二维码关注公众号,回复: 5729056 查看本文章
[root@centos7 123.link]#ll
total 0
-rw-r--r--. 1 root mage 0 Mar 11 10:32 1
-rw-r--r--. 1 root mage 0 Mar 11 10:32 2

linux对后缀并不关注
用file看文件头部 magic namber 头部
[root@centos7 data]#file /usr/share/pixmaps/faces/legacy/fish.jpg
/usr/share/pixmaps/faces/legacy/fish.jpg: JPEG image data, JFIF standard 1.01

locate fish.jpg
[root@centos7 data]#locate fish.jpg
/usr/share/pixmaps/faces/fish.jpg
/usr/share/pixmaps/faces/legacy/fish.jpg

file -b 不显示文件名

[root@centos7 data]#file -b /usr/share/pixmaps/faces/legacy/fish.jpg
JPEG image data, JFIF standard 1.01

file -f 批量查看文件

[root@centos7 data]#cat file.txt 
/data/hhhaa
/data/host1
/data/wanghome
[root@centos7 data]#file -f file.txt
/data/hhhaa:    symbolic link to `host1'
/data/host1:    ASCII text
/data/wanghome: directory

file -L 查看文件原本属性而不是软连接属性

[root@centos7 data]#file -Lf file.txt 
/data/hhhaa:    ASCII text
/data/host1:    ASCII text
/data/wanghome: directory

centos7 上软连接用的非常多 ,去判断系统状态
echo "$1"
echo "$2"
echo "$3"
echo basename $0
[root@centos7 bin]#f1link.sh 1 2 3
1
2
3
f1link.sh

标准输出与管道

fd 文件描述符 文件打开就会分配数字 file descriptor

tail -f /var/log/messages

[root@centos7 ~]#tail -f /var/log/messages
Mar 11 19:27:03 centos7 dbus[6258]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Mar 11 19:27:03 centos7 dbus[6258]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'

cd /proc 里头的进程编号

pidof tail 看进程编号

[root@centos7 proc]#pidof tail
39126
[root@centos7 39126]#echo $$
31382
   ├─sshd(10651)─┬─sshd(31378)───bash(31382)───pstree(39171)
           │             └─sshd(39064)───bash(39068)───tail(39126)

[root@centos7 proc]#pidof tail
39126

cd pidof tail 进程编号

hexdump -C

ll fd 看tail 文件描述符

[root@centos7 39126]#cd fd
[root@centos7 fd]#ll
total 0
lrwx------. 1 root root 64 Mar 11 19:39 0 -> /dev/pts/2
lrwx------. 1 root root 64 Mar 11 19:39 1 -> /dev/pts/2
lrwx------. 1 root root 64 Mar 11 19:39 2 -> /dev/pts/2
lr-x------. 1 root root 64 Mar 11 19:39 3 -> /var/log/messages
lr-x------. 1 root root 64 Mar 11 19:39 4 -> anon_inode:inotify

ll /proc/$$/fd 看就当前进程文件描述符

[root@centos7 fd]#ll /proc/$$ -d
dr-xr-xr-x. 9 root root 0 Mar 11 08:51 /proc/31382

只要文件打开就会生成文件描述符,nano本身并没有编译这个文件

[root@centos7 fd]#ll   /proc/`pidof nano`/fd
total 0
lrwx------. 1 root root 64 Mar 11 19:44 0 -> /dev/pts/2
lrwx------. 1 root root 64 Mar 11 19:44 1 -> /dev/pts/2
lrwx------. 1 root root 64 Mar 11 19:44 2 -> /dev/pts/2

vim变向产生临时文件

[root@centos7 fd]#ll   /proc/`pidof vim `/fd
total 0
lrwx------. 1 root root 64 Mar 11 19:46 0 -> /dev/pts/2
lrwx------. 1 root root 64 Mar 11 19:46 1 -> /dev/pts/2
lrwx------. 1 root root 64 Mar 11 19:46 2 -> /dev/pts/2
lrwx------. 1 root root 64 Mar 11 19:46 4 -> /root/.f1.swo

标准输入 0 键盘默认标准输入设备 STDIN <
标准输入重定向要跟文件
< 而且输出重定向最先执行 也是从顺序右向左

[root@centos7 ~]#cat file.txt   out.txt 
11
11
22
33

aaabbbccc

[root@centos7 ~]#cat <file.txt  < out.txt 
aaabbbccc

[root@centos7 ~]#cat > file.txt  < out.txt 
[root@centos7 ~]#cat file.txt 
aaabbbccc

[root@centos7 ~]#vim file.txt 
[root@centos7 ~]# file.txt  > out.txt 
bash: file.txt: command not found.

[root@centos7 ~]#cat < file.txt  > out.txt 
[root@centos7 ~]#cat out.txt 
1123345

标准输入 1 终端窗口默认标准输出设备STDOUT 1>
标准错误 2 终端窗口默认标准错误设备 STDDERL 2>

[root@centos7 data]#ll aa  host1
ls: cannot access aa: No such file or directory
-rw-r--r--. 1 root root 6 Mar 11 19:11 host1
[root@centos7 data]#ll aa  host1  > f1
ls: cannot access aa: No such file or directory
[root@centos7 data]#ll aa  host1  2> f1
-rw-r--r--. 1 root root 6 Mar 11 19:11 host1

[root@centos7 data]#ll aa  host1  2> f1   1>&2 ;cat f1
ls: cannot access aa: No such file or directory
-rw-r--r--. 1 root root 6 Mar 11 19:11 host1

[root@centos7 data]#ll aa  host1  2> f1   2>&1 
ls: cannot access aa: No such file or directory
-rw-r--r--. 1 root root 6 Mar 11 19:11 host1
[root@centos7 data]#cat f1 
 f1为空

[root@centos7 data]#ll aa  host1  > f1   2>&1 
[root@centos7 data]#cat f1
ls: cannot access aa: No such file or directory
-rw-r--r--. 1 root root 6 Mar 11 19:11 host1

[root@centos7 data]#ll aa  host1    2>&1  >f1 
ls: cannot access aa: No such file or directory
[root@centos7 data]#cat f1
-rw-r--r--. 1 root root 6 Mar 11 19:11 host1

-rw-r--r--. 1 root root 6 Mar 11 19:11 host1
[root@centos7 data]#ll aa  host1    1>&2  2>f1 
-rw-r--r--. 1 root root 6 Mar 11 19:11 host1
[root@centos7 data]#cat f1
ls: cannot access aa: No such file or directory

[root@centos7 data]#ll aa  host1    1>&2  >f1 
ls: cannot access aa: No such file or directory
[root@centos7 data]#cat f1
-rw-r--r--. 1 root root 6 Mar 11 19:11 host1

在1>&2 >f1
1>&2 2>f1
2>&1 >f1

f1 2>&1
2> f1 1>&2
2> f1 2>&1
命令是按先从右向左顺序执行

文件可以做标准输入 ,改变默认位置就是重定向,改变方向

[root@centos7 ~]#cat file.txt   out.txt 
11
11
22
33

aaabbbccc

[root@centos7 ~]#tty
/dev/pts/2

[root@centos7 data]# w > /dev/pts/2  

w > /dev/pts/1 把w输出到另一个窗口

[root@centos7 ~]# 20:10:11 up 1 day, 11:47,  4 users,  load average: 0.01, 0.02, 0.06
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     :0       :0               Sat09   ?xdm?   2:40m  0.78s /usr/libexec/gnome-session-binary --s
root     pts/0    :0               08:50   11:19m  0.07s  0.07s bash
root     pts/1    172.22.150.233   08:51    3.00s  1.30s  0.03s w
root     pts/2    172.22.150.233   19:32   35.00s  0.13s  0.13s -bash

hostname > systeminfo.txt

w > systeminfo.txt

重定向会丢失以前文件 > systeminfo.txt 不加任何 会清空文件意思就是无输出文件

有些shell/bin/csh不支持 >f1清空

[root@centos7 /data]# > f1
Invalid null command.

passwd wang >/dev/null 标准输出进/dev/null

[root@centos7 /data]# echo "111" >/dev/null

不支持

/dev/null 不希望看到屏幕上的

cat /dev/null > list.txt
[root@centos7 /data]# cat /dev/null > list.txt
[root@centos7 /data]#  list.txt
list.txt: Command not found.
[root@centos7 /data]# cat list.txt
[root@centos7 /data]# 为空

bin/csh 有些shell不支持>list.txt 清除文件 用上边的方法

>追加

>两个大于号创建空文件更安全
[root@centos7 /data]# echo "111" >> list.txt
[root@centos7 /data]# cat list.txt
111
111

[root@centos7 /data]# echo "111" > list.txt 
[root@centos7 /data]# cat
cat       catchsegv catman    
[root@centos7 /data]# cat list.txt 
111
[root@centos7 /data]# set -C 
set: Variable name must begin with a letter.

/bin/bash
set -C 不能覆盖 可以追加 注意+C -C须连着不加空格
set +C 可以覆盖 可以追加

[root@centos7 data]#set -C
[root@centos7 data]#ls
f1  file.txt  hhhaa  host1  hosts  list.txt  rm  wanghome
[root@centos7 data]#echo 111 > f1
-bash: f1: cannot overwrite existing file
>|   强制覆盖

[root@centos7 data]#echo 111 > f1
-bash: f1: cannot overwrite existing file
[root@centos7 data]#echo 111 >| f1
[root@centos7 data]#cat f1
111

隐藏1> >默认是1>

2>标准错误
2>&1 标准错误重定向标准输出
&> 都
(1+2)*3
提高优先级 ()括号优先级最高

2^3
2+2
[root@centos7 123]#vim bc.txt
[root@centos7 123]#bc < bc.txt
8
4
8
4
4

cat 标准输入之后把输入结果输出
cat <bc.txt > bc.txt 清空文件

cat<bc.txt >> bc.txt 无线追加死循环

SET字符

tr SET1 [SET2] tr命令是按从右向左数据来替换字符
[root@centos7 ~]#tr "fsfs" "1234"
fs
34

tr 'abc' '1234'

只替换abc

tr 'abcde' '1235'
替换abcde 为12355 tr命令以替换第一个命令为主
tr -d 删除字符串

root@centos7 data]#tr -d "123"
123 456
456
123456abc
456abc

tr -t 同等字符替换
tr -c 默认替换最后一个字符
[root@centos7 data]#tr -c "123" "ab"

123456789
123bbbbbbb[root@centos7 data]#

[root@centos7 data]#tr -dc "123"
123456asdf
123[root@centos7 data]#

\b 空格
\n 换行
\r 回车
\t tab
hexdump -C
0a换行\n 0d回车\r
换行符和回车键 纸往前走就是换行 回车就是到开始头
linux换行回车就0a
window 则0d 0a

echo {1..100} |tr " " "+" |bc

tr -s "abc" 压缩字符
[root@centos7 data]#tr -s "123"
123
123
1122233
123
445566
445566

tr -c "123 " "d" 除了123其他都替换d

tr命令的符号 [:upper:] [:alnmu:] [:alpha:] [:lower:] [:blank:] [:space:]
tr则表示[:lower:]就是小写字母

通配符 ls [[:lower:]]* [[::]] 双括号表示1个字符

hexdump  -C     马哥教育7.txt
[root@centos7 ~]#hexdump -C 马哥教育7.txt 
00000000  d5 fd d4 f2 b1 ed b4 ef  ca bd c5 e4 d6 c3 d3 ca  |................|
00000010  cf e4 0d 0a d5 fd d4 f2  b1 ed b4 ef ca bd c5 e4  |................|
00000020  d6 c3 ca d6 bb fa ba c5  0d 0a c9 ed b7 dd d6 a4  |................|
00000030  ba c5 0d 0a 71 71 ba c5  0d 0a 0d 0a 0d 0a 73 68  |....qq........sh|
00000040  65 6c 6c b1 e0 b3 cc d6  d0 0d 0a d3 ef b7 a8 ce  |ell.............|
00000050  ca cc e2 c4 ac c8 cf b2  bb bb e1 d6 b4 d0 d0 cf  |................|

hexdump -c 看 不是16进制本身字符,通过解释器可以转换2进制字符

[root@centos7 ~]#hexdump -c 马哥教育7.txt   linux本身字符可转换2机制或者16进制字符
0000000 325 375 324 362 261 355 264 357 312 275 305 344 326 303 323 312
0000010 317 344  \r  \n 325 375 324 362 261 355 264 357 312 275 305 344
0000020 326 303 312 326 273 372 272 305  \r  \n 311 355 267 335 326 244
0000030 272 305  \r  \n   q   q 272 305  \r  \n  \r  \n  \r  \n   s   h
0000040   e   l   l 261 340 263 314 326 320  \r  \n 323 357 267 250 316
0000050 312 314 342 304 254 310 317 262 273 273 341 326 264 320 320 317
0000060 302 310 245  \r  \n  \r  \n 303 374 301 356 264 355 316 363 262
[root@centos7 ~]#hexdump -C f1
00000000  61 62 63 0a                                       |abc.|

[root@centos7 ~]#hexdump -c f1
0000000   a   b   c  \n                                                

[root@centos7 ~]#hexdump  f1
0000000 6261 0a63                              

tr 命令只是显示tr结果 ,意思就是tr命令只是处理一些内容,如接受标准输出在标准输出内容

如果2个文件名相同时非常危险的 1是清空f1 2是追加循环
1 cat <f1 > f1 1
2 cat <f1 >>f1

[root@centos7 ~]#cat <f1 >>f1
00
00
[root@centos7 ~]#cat <f1 > f1 
[root@centos7 ~]#cat f1
[root@centos7 ~]#

cat > f1.txt
单行重定向, 换行一次就重定向

cat <f1 << EOF end of file
多行重定向
EOF一定孤立一行才是结束

第二个终端变化在输入EOF则文件变化
[root@centos7 ~]#cat >f1 <<EOF

11

22

333
EOF

可以用于写脚本生成文件

cat 可以以用变量可以用命令

[root@centos7 123]#cat $PATH
cat: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin: No such file or directory
[root@centos7 123]#cat uname -r
cat: 3.10.0-957.el7.x86_64: No such file or directory

跑不同的命令结果不一样

mail -s "hi" wang
cat > wang.txt
mail -s "hi" wang <wang.txt
mail -s "hi" wang << EOF

多行重定向 就地文本heretext

管道利用 ,临时性的管道技术 管道在内存里边没有生成永久文件
cmd --->pipe |
cmd 2 <---pipe |

cmd 1 | cmd 2 管道只接受标准输出 不接受标准错误
把cmd1命令输出作为cmd2标准输入
如果cmd1是错误命令则不能处理
cmd | tr " a-z" "A-Z"
[root@centos7 ~]#cmd | tr "a-z" "A-Z"
bash: cmd: command not found...
Similar command is: 'mcd'

cmd 2>&1 | tr " a-z" "A-Z" 错误命令变成正确在输出 管道输出

[root@centos7 ~]#cmd 2>&1 | tr "a-z" "A-Z"
BASH: CMD: COMMAND NOT FOUND...
SIMILAR COMMAND IS: 'MCD'
cmd |& tr " a-z" "A-Z" 都变成正确在输出 管道输出

[root@centos7 ~]#cmd |& tr "a-z" "A-Z"
BASH: CMD: COMMAND NOT FOUND...
SIMILAR COMMAND IS: 'MCD'

管道最后一个命令会在当前shell进程的子shell进程中执行

标准输入
tee
bc
mail
tr
bc

echo {1..100} | tr " " "+" | bc

tee T 己重定向又显示命令

echo{a..d} |tee f1.txt 标准输出 又重定向tee

针对.tar
tar -cvf - /home | tar -xvf - 先打包/home -表示前一个命令的标准输出
Examples:
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xf archive.tar # Extract all files from archive.tar.

在解包 home

令牌token ,identity 登陆成功(令牌uid,gid,gid2)之后通过token来对文件进行访问
token是是在登陆时候得到的,如果改uid gid,一定要等用户退出才能改

root 0
用户编号 linux 判断是不是管理员看UID是不是0

centos6 500+ 1-500 是系统uid 系统账号给进程使用
centos7 1000+ 1-999 是系统uid 系统账号给进程使用

windows 只要把账号加进管理员组就成了管理员
net user test 123 /add创建一个账号test 密码123
localgroup test /add 建立组
net user test 123 /del 删组
net user

linux组权限是累加权限

如果他是本文件所有者则可以修改任何权限包括文件的所属组,文件的所有权限,但不能修改文件的所有者
如果这个文件的所有者他可以Gid 改文件gid名字但不能改uid名字
[mage@centos7 ~]$chmod g=,o= /usr/bin/cat
[mage@centos7 ~]$ll /usr/bin/cat
-rwx------. 1 mage root 54160 Oct 31 03:16 /usr/bin/cat
[mage@centos7 ~]$chown root /usr/bin/cat
chown: changing ownership of ‘/usr/bin/cat’: Operation not permitted
[mage@centos7 ~]$chmod u=,g=,o= /usr/bin/cat
[mage@centos7 ~]$ll /usr/bin/cat
----------. 1 mage root 54160 Oct 31 03:16 /usr/bin/cat
[mage@centos7 ~]$chgrp mage /usr/bin/cat
[mage@centos7 ~]$ll /usr/bin/cat
----------. 1 mage mage 54160 Oct 31 03:16 /usr/bin/cat
[mage@centos7 ~]$

文件的所属组不能更改文件任何权限,
但是他可以对文件的本身所属组权限进行操作

drwxr-x---. 3 abb mage 78 Mar 11 21:47 abb
chmod: changing permissions of ‘abb’: Operation not permitted
[mage@centos7 home]$chmod g=rxw abb
chmod: changing permissions of ‘abb’: Operation not permitted
[mage@centos7 home]$chmod o=rxw abb
chmod: changing permissions of ‘abb’: Operation not permitted
[mage@centos7 home]$chmod u=rxw abb
chmod: changing permissions of ‘abb’: Operation not permitted
[mage@centos7 home]$
[mage@centos7 home]$cd apps

linux安全上下文 命令能不能访问 得到一个令牌,进程访问,文件访问取决于令牌

linux创建一个用户必须有一个组这个组就是主要组,
组名用户名相同,仅包含一个组私有组机制,组编号可以不同,

[root@centos7 home]#getent passwd laowang ;getent group laowang ;getent shadow laowang ;getent gshadow laowang
laowang:x:1011:1012::/home/laowang:/bin/bash
laowang:x:1012:
laowang:!!:17967:0:99999:7:::
laowang:!::

一个用户属于其他的组,并不是必须有的,叫辅助组,附加组

[root@centos7 home]#usermod -G root laowang
[root@centos7 home]#getent group root
root:x:0:gentoo,mage,laowang

/etc/passwd passwd文件不能随便改,/etc/group /etc/gshadow

文件也不能随便改应该用命令让附加组同步
[root@centos7 home]#getent gshadow root ;getent group root
root:::gentoo,mage,laowang
root:x:0:gentoo,mage,laowang

[root@centos7 123]#ll /etc/passwd
-rw-r--r--. 1 root root 2695 Mar 9 20:01 /etc/passwd

/etc/group
/etc/shadow
/etc/gshadow

chfn mage 编辑马哥GOES
[root@centos7 home]#getent passwd laowang
laowang:x:1011:1012:laowang,huatengdasha,110,120:/home/laowang:/bin/bash

ps aux 显示系统运行进程列表
[root@centos7 ~]#ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 194088 6180 ? Ss Mar10 0:23 /usr/lib/systemd/systemd --swit
root 2 0.0 0.0 0 0 ? S Mar10 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Mar10 0:01 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S< Mar10 0:00 [kwo

chsh -s /bin/csh mage 改shell

[root@centos7 home]#chsh -s /bin/csh laowang
Changing shell for laowang.
Shell changed.
[root@centos7 home]#getent passwd laowang
laowang:x:1011:1012:laowang,huatengdasha,110,120:/home/laowang:/bin/csh

/sbin/nologin 进程登录瞬间退出

$1 md5
$6 sh512
加随机字符salt $djsdjakl$ 加盐式命令随机

echo date +%s /3600/24 |bc

[root@centos7 home]#echo date +%s/3600/24|bc
17967
[root@centos7 home]#getent shadow laowang
laowang:!!:17967:0:99999:7:::

[root@centos7 home]#echo laowangdate=$[date +%s/3600/24]
laowangdate=17967

[root@centos7 home]#echo laowangdate=$((date +%s/3600/24))
laowangdate=17967

[root@centos7 home]#let laowangdate=date +%s/3600/24
[root@centos7 home]#echo $laowangdate
17967

chage
[root@centos7 ~]#chage laowang
Changing the aging information for laowang
Enter the new value, or press ENTER for the default

Minimum Password Age [0]: 3
Maximum Password Age [99999]: 15
Last Password Change (YYYY-MM-DD) [2019-03-12]: 2019-03-12
Password Expiration Warning [7]: 7
Password Inactive [-1]: 30
Account Expiration Date (YYYY-MM-DD) [-1]: 2019-05-30

-1 就是从不
[root@centos7 ~]#chage -l bbc
Last password change : Mar 12, 2019
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7

[root@centos7 ~]#getent shadow laowang
laowang:!!:17967:3:15:7:30:18046:

用户修改密码时间从1970年来算设置为0 ,需要用户立即修改密码
[root@centos7 ~]#getent shadow laowang
laowang:$6$xmk5H5QH$IK7OxMUyYV3uPEaxJ2LrpDlTVeE7t5Q1S
05an3BCJF.U9lW7cb1z9Hxk7OSh2Kt7Q51OQRyoUE2zNyl5l9lZ11:0:3:15:7:30:18046:

最长口令过期需要重新改密码
[root@centos7 ~]#getent shadow laowang
laowang:$6$hpvGtKCl$11rxvaKR64mXoEKQuRgEzq
CUAIBjNj3I4c4E7kLjXEBhT6wDgYrxmPX.7ZKYKGiUap/sT4mEkhC
Ff7jSch8S40:17967:3:15:7:30:18046:

[root@centos7 ~]#date -s "20 day"
Mon Apr 1 09:41:55 CST 2019

如果延迟5天还不改口令则过期就类似sbin/nologin

最后一个是账户有效期,过期就会提醒怎么过期
chage -E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE账户有效期按1970年来算
-1

/etc/group
如果知道组口令密码也可以进组

wang:x:1000:wang,bin,mage
最有一个 wang ,bin ,mage 用户的附加组是王

!就是把口令加锁定

unbutu
sudo nano /etc/shadow

用wang用户加入
newgrp zhang 加入zhang组 zhang成为wang用户主组
在建文件就成了 uid wang gid zhang

[mage@centos7 ~]$newgrp laowang1
Password:
[mage@centos7 ~]$id
uid=1001(mage) gid=1014(laowang1)
groups=1014(laowang1),0(root),1001(mage)
context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

/etc/gshadow 和/etc/group格式必须一样

usrmod -aG 保护账户附加组

usermod -L zhang
密码输入正确很有可能是锁定了

[root@centos7 ~]#getent shadow laowang
laowang:!$6$5UL2M795$cdNrOOnb0K1sFw1TjO.Lul/9H4R77dLpml7GeZ6jdgLH1MgEdFC9tUcw.d7V0md4lkB4XLqWREvRe5OW2WG0e1:18007:3:99999:7:15:18099:

usermod -U zhang 如果没有口令则不能解锁

[root@centos7 ~]#getent shadow laowang
laowang:!:18007:3:99999:7:15:18099:

[root@centos7 ~]#usermod laowang -U
usermod: unlocking the user's password would result in a passwordless account.
You should set a password with usermod -p to unlock this user's password.
usermod -U zhang 有口令则可以解锁

[root@centos7 ~]#usermod laowang -U
[root@centos7 ~]#getent shadow laowang
laowang:$6$5UL2M795$cdNrOOnb0K1sFw1TjO.Lul/9H4R77dLpml7GeZ6jdgLH1MgEdFC9tUcw.d7V0md4lkB4XLqWREvRe5OW2WG0e1:18007:3:99999:7:15:18099:

tcpdump::17960:::::: 空口令不要密码

authconfig --passalgo=sha256 --update 改口令加密算法

openssl rand -base64 12 base64编码机制

cat /dev/urandom |tr -dc "a-zA-Z0-9" |head -c12查看 随机字符

vipw =vim pw 有语法检查功能改错会报提示
vigr

pwck 直接命令有语法检查功能改错会报提示
grpck

useradd -u 9527 li
-o强制
-g 如果不指定就是同名主组

rpm -q --script bash 看rpm包安装script脚本
-N 不创建主组用默认主组users
-r centos6 500以下 centos71000 以下

getent passwd haha 从数据库查

-r 系统用户默认不用-m 建家目录 会生成杂文件
[root@centos7 home]#ls
abb bash ckw git mage nginx user
apps bbc gentoo laowang mysql tomcat varnish
[root@centos7 ~]#useradd -r bbb
[root@centos7 ~]#cd~bbb
bash: cd~bbb: command not found...
[root@centos7 ~]#cd ~bbb
-bash: cd: /home/bbb: No such file or directory

-r 系统用户默认不用-m 建家目录 会生成杂文件

cp -r /home/wang/. /data/wanghome 把wang下的所有文件传wanghome

cat /etc/default/useradd =useradd -D

/etc/skel新建用户家目录来源 模板路径

/etc/login.defs

批量改用户要求模板一样参考/etc/passwd

newusers f1.txt

echo haha: centos |chpasswd

nano pw.txt批量改口令方法

haha: centos

cat pw.txt | chpasswd

userdel -r 删家目录用户账号
userdel 如果删除用户不删除家目录则以后创建同名的uidgid附属到同名uidgid会出问题

[root@centos7 home]#userdel abb
[root@centos7 home]#ll
[root@centos7 home]#useradd -g1010 bbbc
total 8
drwx------. 3 1010 1011 78 Mar 11 21:47 abb
[root@centos7 home]#ll
total 8
drwx------. 3 bbbc 1011 78 Mar 11 21:47 abb

su switch user

su root 临时切换切换身份 并且在当地文件

su - root 完全切换改变/etc/配置 彻底切换并且切换自己家目录

su - root -c 'cat /etc/passwd' 做完操作又回来了自己账户

passwd -e mage 立刻改口令 口令过期 修改口令时间则为0

groupadd -g 指定组id
groupadd -r 系统组
groupdel
如果删组是用户的主组则不能删

gpasswd -a user 组 加user进组
gpasswd -d user 组 删user组

[root@centos7 home]#useradd -g 1010 cc2
[root@centos7 home]#gpasswd -a apps root
Adding user apps to group root
[root@centos7 home]#getent group root
root:x:0:gentoo,mage,laowang,apps
[root@centos7 home]#gpasswd -d apps root
Removing user apps from group root

groupmems -g 组 -a 用户
groupmems -g 组 -d 用户

[root@centos7 home]#groupmems -a apps -g root
[root@centos7 home]#getent group root
root:x:0:gentoo,mage,laowang,apps
[root@centos7 home]#groupmems -d apps -g root
[root@centos7 home]#getent group root
root:x:0:gentoo,mage,laowang
[root@centos7 home]#

groupmems -l -g 组名 看组成员
[root@centos7 home]#groupmems -l -g root
gentoo mage laowang
[root@centos7 home]#groupmems -l -g apps
[root@centos7 home]#groupmems -a mage -g apps
[root@centos7 home]#groupmems -l -g apps
mage

usermod -G "" wang

reboot 普通用户没有权限随便关机

chgrp -R wang / data/ 把全部人变成wang
chown -R wang /data

chown --reference=f1 f2 参考f1设置f2 权限

rwxrwxrwx
用户拿到token(uid,gidgroup) 然后文件判断权限先看所有者所属组其他人
如果权限直接生效后边不看而且看文件直接看文件对应权限

所有者不能改为自己的文件设为其他人

所有者可以改自己文件权限

chmod who opt per file
u g o a

    • =
      rwx

如果只有w写权限可以用重定向追加写入文件

1111 >> f2

chmod a-x /bin/chmod chmod命令则失效

finger 看用户几点几分登录什么终端运行多长时间
[root@centos7 bin]#finger -lmps root
Login: root Name: root
Directory: /root Shell: /bin/bash
On since Sat Mar 9 09:46 (CST) on :0 from :0 (messages off)
On since Mon Mar 11 08:50 (CST) on pts/0 from :0
123 days 1 hour idle
On since Fri Jul 12 05:24 (CST) on pts/1 from 172.22.150.233
17 minutes 45 seconds idle
On since Fri Jul 12 02:27 (CST) on tty2 8 hours 5 minutes idle
On since Fri Jul 12 02:29 (CST) on pts/5 from 172.22.150.233
1 second idle
Mail last read Mon Mar 11 14:16 2019 (CST)

猜你喜欢

转载自blog.51cto.com/14230597/2372100