第四天重定向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/

[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)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章