1. 程式人生 > >6.11 2.27-3.3

6.11 2.27-3.3

創建用戶 創建組 刪除用戶 刪除組 文件互傳

2.27 linuxwindows互傳文件

使用條件:

使用XshenllSecureCRTputty不支持);

安裝特定的包:

[root@hyc-01-01 ~]# yum install -y lrzsz

Linuxwindows傳文件:

1

[root@hyc-01-01 ~]# ls

111 222 3.txt anaconda-ks.cfg.1 hyc2 ls2

[root@hyc-01-01 ~]# sz 3.txt

2

技術分享圖片

輸入命令回車後在彈出的對話框選擇文件在windows上保存的位置

技術分享圖片

Windowslinux傳文件

1

Xshell輸入rz

2

技術分享圖片

在彈出的對話框選擇要上傳的文件

傳輸目前在使用的文件可能會失敗

傳輸空文件可能會失敗

被傳輸文件與當前目錄下某文件重名傳輸會失敗

技術分享圖片

文件會被傳輸到linux下的當前目錄

3.1 用戶配置文件和密碼配置文件

每創建一個用戶都會在/etc/passwd中添加一行該用戶的信息

[root@hyc-01-01 ~]# cat /etc/passwd

root:x:0:0:root:/root:/bin/bash

bin:x:1:1:bin:/bin:/sbin/nologin

daemon:x:2:2:daemon:/sbin:/sbin/nologin

adm:x:3:4:adm:/var/adm:/sbin/nologin

lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

sync:x:5:0:sync:/sbin:/bin/sync

shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

halt:x:7:0:halt:/sbin:/sbin/halt

mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

operator:x:11:0:operator:/root:/sbin/nologin

games:x:12:100:games:/usr/games:/sbin/nologin

ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

nobody:x:99:99:Nobody:/:/sbin/nologin

systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin

dbus:x:81:81:System message bus:/:/sbin/nologin

polkitd:x:999:997:User for polkitd:/:/sbin/nologin

postfix:x:89:89::/var/spool/postfix:/sbin/nologin

sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin

chrony:x:998:996::/var/lib/chrony:/sbin/nologin

hyc:x:1000:1000::/home/hyc:/bin/bash

hyc1:x:1001:1001::/home/hyc1:/bin/bash

在文件中每個用戶獨占一行;

除了hyc開頭的兩個用戶其他用戶為系統安裝完後就默認存在的;

第一段:用戶名

第二段:原先這裏存放用戶的密碼,目前用戶密碼由專門的文件存儲

第三段:用戶uid

第四段:用戶組idgid

第五段:表示用戶的註釋信息,一般為空

第六段:用戶家目錄

第七段:用戶的shell,用戶每次用終端登錄機器都會獲得一個可以和機器交互的窗口,該窗口即為shell,常見的shell/bin/bash/sbin/nologin

/bin/bash:表示該用戶可以登錄

/sbin/nologin:該用戶無法登錄

從前向後每個用戶與/etc/passwd對應,專門用於控制用戶密碼

[root@hyc-01-01 ~]# cat /etc/shadow

root:$6$7wgDiZg1$fc9tgPTcsrgR3IBGPaafhRgXK14ByF1I9Fj09ezA8YtOHEJ1HEFSFPThAdtJtye6eNXxIUCRXCaPAoMTYADql/:17680:0:99999:7:::

bin:*:17110:0:99999:7:::

daemon:*:17110:0:99999:7:::

adm:*:17110:0:99999:7:::

lp:*:17110:0:99999:7:::

sync:*:17110:0:99999:7:::

shutdown:*:17110:0:99999:7:::

halt:*:17110:0:99999:7:::

mail:*:17110:0:99999:7:::

operator:*:17110:0:99999:7:::

games:*:17110:0:99999:7:::

ftp:*:17110:0:99999:7:::

nobody:*:17110:0:99999:7:::

systemd-network:!!:17675::::::

dbus:!!:17675::::::

polkitd:!!:17675::::::

postfix:!!:17675::::::

sshd:!!:17675::::::

chrony:!!:17675::::::

hyc:$6$TWH9da/v$ge4.QfW0swR/a4S1RcWEfP4SXxrgUeRHsuyByOts0b9rnCfjIz53rZMJyhiLLl4w22udQWuVcyMdXmfagiqj//:17689:0:99999:7:::

hyc1:$6$phKSf3Hn$D4NVl/0AB9OkuI.QoY.nfB6y62q0tjfs19nnEMeSQVl2oFo74oHoVuqvgdmd4idUxHHa5lJ6StJ29zH11jh390:17689:0:99999:7:::

第一段:用戶名

第二段:用戶密碼,此處密碼加密,無法反編譯(可以由明文獲得加密密碼,但無法由加密密碼獲得明文密碼)

第三段:表示天數,即上次修改密碼距離197011號的天數

第四段:表示要過多少天才能修改密碼,默認為0,即不受限制

第五段:表示多少天內密碼必須更改,即多少天後密碼到期,到期後密碼無法更改

第六段:若將該值設置為7則表示距離密碼到期還有7天時提醒用戶密碼即將到期需要修改密碼

第七段:用戶在密碼到期前都未修改密碼,該值表示從密碼到期開始過多少天後賬戶會被鎖定,無法繼續使用

第八段:表示用戶被鎖定的日期距離197011日有多少天

第九段:保留未用

[root@hyc-01-01 ~]# head -1 /etc/shadow;tail -2 /etc/shadow

root:$6$7wgDiZg1$fc9tgPTcsrgR3IBGPaafhRgXK14ByF1I9Fj09ezA8YtOHEJ1HEFSFPThAdtJtye6eNXxIUCRXCaPAoMTYADql/:17680:0:99999:7:::

hyc:$6$TWH9da/v$ge4.QfW0swR/a4S1RcWEfP4SXxrgUeRHsuyByOts0b9rnCfjIz53rZMJyhiLLl4w22udQWuVcyMdXmfagiqj//:17689:0:99999:7:::

hyc1:$6$phKSf3Hn$D4NVl/0AB9OkuI.QoY.nfB6y62q0tjfs19nnEMeSQVl2oFo74oHoVuqvgdmd4idUxHHa5lJ6StJ29zH11jh390:17689:0:99999:7:::

想在一行敲兩個命令可以使用;分割

3.2 用戶組管理

用戶組配置文件

[root@hyc-01-01 ~]# cat /etc/group

root:x:0:

bin:x:1:

daemon:x:2:

sys:x:3:

adm:x:4:

tty:x:5:

disk:x:6:

lp:x:7:

mem:x:8:

kmem:x:9:

wheel:x:10:

cdrom:x:11:

mail:x:12:postfix

man:x:15:

dialout:x:18:

floppy:x:19:

games:x:20:

tape:x:30:

video:x:39:

ftp:x:50:

lock:x:54:

audio:x:63:

nobody:x:99:

users:x:100:

utmp:x:22:

utempter:x:35:

ssh_keys:x:999:

input:x:998:

systemd-journal:x:190:

systemd-network:x:192:

dbus:x:81:

polkitd:x:997:

postdrop:x:90:

postfix:x:89:

sshd:x:74:

chrony:x:996:

hyc:x:1000:

hyc1:x:1001:

slocate:x:21:

該配置文件為每個組添加一行信息

[root@hyc-01-01 ~]# cat /etc/gshadow

root:::

bin:::

daemon:::

sys:::

adm:::

tty:::

disk:::

lp:::

mem:::

kmem:::

wheel:::

cdrom:::

mail:::postfix

man:::

dialout:::

floppy:::

games:::

tape:::

video:::

ftp:::

lock:::

audio:::

nobody:::

users:::

utmp:!::

utempter:!::

ssh_keys:!::

input:!::

systemd-journal:!::

systemd-network:!::

dbus:!::

polkitd:!::

postdrop:!::

postfix:!::

sshd:!::

chrony:!::

hyc:!::

hyc1:!::

slocate:!::

/etc/shadow對應,記錄組密碼信息

以下以-結尾的文件均為對應文件的備份文件,用戶誤刪原文件後可以拷貝以-結尾的同名文件來恢復原來的信息;

可能帶-的文件由於更新不及時導致缺失部分信息;

[root@hyc-01-01 ~]# ls /etc/shadow

/etc/shadow

[root@hyc-01-01 ~]# ls /etc/sha*

/etc/shadow /etc/shadow-

[root@hyc-01-01 ~]# ls /etc/gsh*

/etc/gshadow /etc/gshadow-

[root@hyc-01-01 ~]# ls /etc/pass*

/etc/passwd /etc/passwd-

[root@hyc-01-01 ~]# ls /etc/grou*

/etc/group /etc/group-

創建組

[root@hyc-01-01 ~]# groupadd grp1

[root@hyc-01-01 ~]# tail -1 /etc/group

grp1:x:1002:

[root@hyc-01-01 ~]# groupadd -g 1005 grp2 指定創建組的組id

[root@hyc-01-01 ~]# tail -1 /etc/group

grp2:x:1005:

只有當組沒有用戶時才可刪除組

[root@hyc-01-01 ~]# groupdel hyc

groupdel:不能移除用戶“hyc”的主組

3.3 用戶管理

[root@hyc-01-01 ~]# tail -2 /etc/passwd

hyc:x:1000:1000::/home/hyc:/bin/bash

hyc1:x:1001:1001::/home/hyc1:/bin/bash

所有普通用戶的uid1000開始,根據用戶增加有規律的增加

[root@hyc-01-01 ~]# useradd -u 1006 -g hyc1 hyc2

添加用戶hyc2,指定uid1006,指定組為hyc1

[root@hyc-01-01 ~]# tail -3 /etc/passwd

hyc:x:1000:1000::/home/hyc:/bin/bash

hyc1:x:1001:1001::/home/hyc1:/bin/bash 指定組是hyc1組,所以hyc1hyc2gid一致

hyc2:x:1006:1001::/home/hyc2:/bin/bash

被指定的組必須是已經存在的組

[root@hyc-01-01 ~]# useradd -u 1007 -g grp2 -d /home/hyc111 -s /sbin/nologin hyc3

[root@hyc-01-01 ~]# tail -1 /etc/passwd

hyc3:x:1007:1005::/home/hyc111:/sbin/nologin

指定uid和組,指定家目錄和shell

[root@hyc-01-01 ~]# ls /home

3.txt- hyc hyc1 hyc111 hyc2

創建用戶時不創建家目錄(有家目錄但不創建)

[root@hyc-01-01 ~]# useradd -M hyc4

[root@hyc-01-01 ~]# tail -1 /etc/passwd

hyc4:x:1008:1008::/home/hyc4:/bin/bash

[root@hyc-01-01 ~]# ls /home

3.txt- hyc hyc1 hyc111 hyc2 家目錄下沒有hyc4

[root@hyc-01-01 ~]# tail -5 /etc/passwd

hyc:x:1000:1000::/home/hyc:/bin/bash

hyc1:x:1001:1001::/home/hyc1:/bin/bash

hyc2:x:1006:1001::/home/hyc2:/bin/bash

hyc3:x:1007:1005::/home/hyc111:/sbin/nologin

hyc4:x:1008:1008::/home/hyc4:/bin/bash

[root@hyc-01-01 ~]# groupadd -g 1011 grp5

[root@hyc-01-01 ~]# useradd -g grp5 hyc5

[root@hyc-01-01 ~]# useradd hyc6

[root@hyc-01-01 ~]# tail -7 /etc/passwd

hyc:x:1000:1000::/home/hyc:/bin/bash

hyc1:x:1001:1001::/home/hyc1:/bin/bash

hyc2:x:1006:1001::/home/hyc2:/bin/bash

hyc3:x:1007:1005::/home/hyc111:/sbin/nologin

hyc4:x:1008:1008::/home/hyc4:/bin/bash

hyc5:x:1009:1011::/home/hyc5:/bin/bash

hyc6:x:1010:1010::/home/hyc6:/bin/bash

用戶gid不會由上一位gid順序增加,而是根據uid順序增加

adduseruseradd用法相同

[root@hyc-01-01 ~]# adduser hyc7

[root@hyc-01-01 ~]# tail -1 /etc/passwd

hyc7:x:1011:1012::/home/hyc7:/bin/bash

刪除用戶

[root@hyc-01-01 ~]# userdel hyc7

/etc/passwd等配置文件中刪除hyc7的信息,但不會刪除hyc7的家目錄

[root@hyc-01-01 ~]# ls /home

3.txt- hyc hyc1 hyc111 hyc2 hyc5 hyc6 hyc7 目錄hyc7依然存在

[root@hyc-01-01 ~]# userdel -r hyc6

[root@hyc-01-01 ~]# ls /home

3.txt- hyc hyc1 hyc111 hyc2 hyc5 hyc7 指定-r參數會在刪除用戶時將家目錄一並刪除


6.11 2.27-3.3