當前位置:編程學習大全網 - 源碼破解 - linux加組命令linux加組

linux加組命令linux加組

如何在Linux下添加/刪除/修改,用戶及用戶組?

Linux刪除用戶組和用戶時常用的壹些命令和參數。

1、從組中刪除用戶

編輯/etc/group找到GROUP1那壹行,刪除A

或者用命令

gpasswd-dAGROUP

2、建用戶:

adduserphpq//新建phpq用戶

passwdphpq//給phpq用戶設置密碼

3、建工作組

groupaddtest//新建test工作組

4、新建用戶同時增加工作組

useradd-gtestphpq//新建phpq用戶並增加到test工作組

註::-g所屬組-d家目錄-s所用的SHELL

5、給已有的用戶增加工作組

usermod-Ggroupnameusername

或者:gpasswd-ausergroup

6、臨時關閉:在/etc/shadow文件中屬於該用戶的行的第二個字段(密碼)前面加上*就可以了。想恢復該用戶,去掉*即可。

或者使用如下命令關閉用戶賬號:

passwdpeter_l

重新釋放:

passwdpeter_u

6、永久性刪除用戶賬號

userdelpeter

groupdelpeter

usermod_Gpeterpeter(強制刪除該用戶的主目錄和主目錄下的所有文件和子目錄)

7、顯示用戶信息

iduser

cat/etc/passwd

linux怎麽刪除添加附加組的用戶?

user用戶在組group01裏面,所以只要從這個組裏面刪除用戶就行了gpasswd-dusergroup01

如何創建Linux的用戶組?

1、首先我們在Linux系統命令行中輸入groupadd命令,用它創建壹個用戶組,如下圖所示。

2、創建好了以後運用cat命令,打開etc下面的group文件,我們創建的用戶組都會在裏面,如下圖所示。

3、打開group文件以後,我們看到了剛才創建的用戶組,這是鑒別用戶組是否創建成功的根據。

4、還可以通過在命令行中輸入groupmod命令後,多敲幾次tab鍵,終端會自動列舉出當前所有的組,如下圖所示。

5、另外,如果妳創建壹個用戶的時候,如下圖所示,運用useradd命令創建壹個用戶,默認是已經創建了用戶組的,用戶組和用戶名稱壹樣。

6、最後當妳在創建文件的時候,妳用哪個用戶創建的,文件的所屬組就會自動歸屬這個用戶的所屬組,如下圖所示。

linux裏怎麽樣給文件或文件夾添加指定組權限?

妳可以使用chgrp命令給文件、或者文件夾添加指定組的權限。例如:$chgrpmygroupmyfile

如何在linux上用命令實現用戶和組的管理?

Linux上用命令實現本地用戶和組的管理

本地用戶和組:管理文件和進程等等

本地用戶和組:

1)root:超級管理員系統創建的第壹個賬戶

特點:

id為:0

家目錄:/root

具有系統的完全控制權:小心使用。

#id

uid=0(root)gid=0(root)groups=0(root)context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

#

2)普通用戶:不具有管理員權限

特點:

id範圍:

1000=id=60000

家目錄:/home/用戶名

#idstudent

uid=1000(student)gid=1000(student)groups=1000(student),10(wheel)

#

3)服務用戶:為服務提供權限

特點:

id範圍:

0id1000

家目錄:應用程序服務目錄

#idapache

uid=48(apache)gid=48(apache)groups=48(apache)

#

如果是yum,rpm安裝的軟件:由rpm包中的腳本創建服務賬戶

Includeconf.modules.d/*.conf

#

#Ifyouwishhttpdtorunasadifferentuserorgroup,youmustrun

#httpdasrootinitiallyanditwillswitch.

#

#User/Group:Thename(or#number)oftheuser/grouptorunhttpdas.

#Itisusuallygoodpracticetocreateadedicateduserandgroupfor

#runninghttpd,aswithmostsystemservices.

#

Userapache

Groupapache

#'Main'serverconfiguration

#

本地組:

1)主組:壹個用戶壹定要屬於某個主組中。當些用戶在創建文件時,給文件的歸屬組

2)從屬組:用戶容器,組織和管理用戶權限管控

作用:

文件:

進程:

$ps-ux

USERPID%CPU%MEMVSZRSSTTYSTATSTARTTIMECOMMAND

student321780.00.4930529360?Ss15:000:00/usr/lib/system

student321820.00.32537767072?S15:000:00(sd-pam)

student321880.00.21594124980?S15:000:00sshd:student@p

student321890.00.22339124864pts/0Ss15:000:00-bash

student322930.30.21594085192?D15:430:00sshd:student@p

student322940.30.22339124924pts/1Ss15:430:00-bash

student323190.50.22339404804pts/1S15:430:00/bin/bash

student323410.00.22693123876pts/1R+15:430:00ps-ux

$

賬戶文件:

1)/etc/passwd:保存用戶信息

#cat/etc/passwd|grepstudent

student:x:1000:1000:StudentUser:/home/student:/bin/bash

用戶名密碼uid主組ID描述家目錄登錄shell

#

#cat/etc/passwd|grep-wroot:x

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

#

#cat/etc/passwd|grepapache

apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin

服務賬號無法登錄系統

#

2./etc/shadow:保存用戶密碼的HASH,密碼的有效性信息,密碼修改時間,賬戶有效期。

#

#ls-l/etc/shadow

----------.1rootroot1014Mar2911:39/etc/shadow

#

#

#cat/etc/shadow|grepstudent

student:$6$8oIjLCsc$/n1iQXYh1E6.uOEuJKgioqAtmqm2TQmkJGF2RwyteIr1tIfrPdiRYgWe6Sjen5/eMij2uHM/a1tue/QRlo3X80:18038:0:99999:7:::

#

密碼的HASH:sha512

8oIjLCsc$/n1iQXYh1E6.uOEuJKgioqAtmqm2TQmkJGF2RwyteIr1tIfrPdiRYgWe6Sjen5/eMij2uHM/a1tue/QRlo3X80

18038:天數密碼最後壹次修改的時間從1970-01-01+18038天之後那壹天

0:密碼最少使用天數0沒有限制用戶隨時可以改密碼

99999:天數,密碼最大修改時間永久200多年

7:warning警告時間,當密碼快到最後修改時間前7天,通知用戶修改。

::天數失效時間inactive用戶密碼過了最後修改時間,未改變密碼,再過多少天,賬戶將被鎖定

::賬戶有效期

創建用戶和組:

創建時,沒有密碼:

#useraddzhangsan

#useraddlisi

#idzhangsan

uid=1001(zhangsan)gid=1001(zhangsan)groups=1001(zhangsan)

#idlisi

uid=1002(lisi)gid=1002(lisi)groups=1002(lisi)

#

無法登錄:與PAM有關

$

$su-zhangsan

Password:

Password:

su:Authenticationfailure

$

設置密碼:

#

#cat/etc/passwd|grepzhangsan

zhangsan:x:1001:1001::/home/zhangsan:/bin/bash

#cat/etc/shadow|grepzhangsan

zhangsan:!!:18350:0:99999:7:::#!!未設置密碼

#

#passwdzhangsan

Changingpasswordforuserzhangsan.

Newpassword:

BADPASSWORD:Thepasswordisshorterthan8characters

Retypenewpassword:

passwd:allauthenticationtokensupdatedsuccessfully.

#

#

#cat/etc/shadow|grepzhangsan

zhangsan:$6$3wxuXomVbQ58wQcK$oQW6injgldxa2N/Pt4tCPDVRqWRVGw.UNZdxE4R0nhEt8K/3UDKzxap6ReIReEvDpG.GdwjpMiiDh7.f6DJNQ0:18350:0:99999:7:::

#

chage可以查看用戶密碼屬性

#chage-lzhangsan

Lastpasswordchange:Mar29,2020

Passwordexpires:never

Passwordinactive:never

Accountexpires:never

Minimumnumberofdaysbetweenpasswordchange:0

Maximumnumberofdaysbetweenpasswordchange:99999

Numberofdaysofwarningbeforepasswordexpires:7

#

創建組:從屬組

#

#groupaddit

#

#

#groupaddsales

#

#

#

#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:student

cdrom:x:11:

mail:x:12:postfix

man:x:15:

dialout:x:18:

floppy:x:19:

games:x:20:

tape:x:33:

video:x:39:

ftp:x:50:

lock:x:54:

audio:x:63:

users:x:100:

nobody:x:65534:

dbus:x:81:

utmp:x:22:

utempter:x:35:

input:x:999:

kvm:x:36:

render:x:998:

systemd-journal:x:190:

systemd-coredump:x:997:

systemd-resolve:x:193:

tss:x:59:

polkitd:x:996:

rpc:x:32:

unbound:x:995:

ssh_keys:x:994:

sssd:x:993:

setroubleshoot:x:992:

rpcuser:x:29:

insights:x:991:

cockpit-ws:x:990:

sshd:x:74:

chrony:x:989:

tcpdump:x:72:

student:x:1000:

printadmin:x:988:

libstoragemgmt:x:987:

slocate:x:21:

postdrop:x:90:

postfix:x:89:

apache:x:48:

zhangsan:x:1001:

lisi:x:1002:

it:x:1003:組成員列表

sales:x:1004:

#

#idstudent

uid=1000(student)gid=1000(student)groups=1000(student),10(wheel)

#

將用戶添加進組:zhangsan,加入it組,lisi,sales組

#idstudent

uid=1000(student)gid=1000(student)groups=1000(student),10(wheel)

#usermod-aGitzhangsan

#

#

#usermod-aGsaleslisi

#

#

#idzhangsan

uid=1001(zhangsan)gid=1001(zhangsan)groups=1001(zhangsan),1003(it)

#idlisi

uid=1002(lisi)gid=1002(lisi)groups=1002(lisi),1004(sales)

#

刪除用戶:

#useraddandy

默認刪除,保留用戶的文件:

#

#userdelandy

#

#

#useraddandy#重建andy會不壹樣,uid會不同

useradd:warning:thehomedirectoryalreadyexists.

Notcopyinganyfilefromskeldirectoryintoit.

Creatingmailboxfile:Fileexists

#

#useradduser1

#useradduser2

#idandy

uid=1003(andy)gid=1005(andy)groups=1005(andy)

#userdel-rany

userdel:user'any'doesnotexist

#

#userdel-randy#不保留用戶的文件。家目,郵箱文件,skel文件都會

#

#

#idandy

id:‘andy’:nosuchuser

#useraddandy

#idandy

uid=1006(andy)gid=1008(andy)groups=1008(andy)

#

從組中移除用戶:

#

#idzhangsan

uid=1001(zhangsan)gid=1001(zhangsan)groups=1001(zhangsan),1003(it)#zhangsan主組,it從屬組

#

命令:

#gpasswd-dzhangsanit

Removinguserzhangsanfromgroupit

#

#

#idzhangsan

uid=1001(zhangsan)gid=1001(zhangsan)groups=1001(zhangsan)

#

#

#usermod-aGitzhangsan

#

#

#idzhangsan

uid=1001(zhangsan)gid=1001(zhangsan)groups=1001(zhangsan),1003(it)

#

#

#

#groupszhangsan

zhangsan:zhangsanit

#

直接修改文件:

#vim/etc/group

#cat/etc/group|grepit:

it:x:1003:

#

刪除組:

#groupaddtest

#

#

#groupdeltest

創建自定義用戶和組:

實驗:用戶名mary,指定用戶id2000,家目錄/maryhome,不用登錄系統描述thisismaryuser

#

#useradd-u2000-d/maryhome-s/sbin/nologin-c"thisismary"mary

#

#idmary

uid=2000(mary)gid=2000(mary)groups=2000(mary)

#cat/etc/passwd|grepmary

mary:x:2000:2000:thisismary:/maryhome:/sbin/nologin

#

#su-mary

Lastlogin:SunMar2916:48:49CST2020onpts/0

Thisaccountiscurrentlynotavailable.

#

創建自定義組:指定組id

#groupadd-g3000group1

#cat/etc/group|grepgroup1

group1:x:3000:

#

  • 上一篇:oppor9和vivo x7哪個好
  • 下一篇:華為p30手機可以用5g網絡嗎
  • copyright 2024編程學習大全網