Linux基礎學習-用戶的建立修改刪除

用戶添加修改刪除

1 useradd添加用戶
添加一個新用戶hehe,指定uid爲3000,家目錄爲/home/hahalinux

[root@qdlinux ~]# useradd -u 3000 -d /home/haha hehe

hehe:x:3000:3000::/home/haha:/bin/bash
[root@qdlinux ~]# ls /home/
haha

這裏-u是uid,-g能夠指定組id,不定值系統自動分配,-G能夠指定附加組,若是不想讓用戶登陸系統能夠指定參數-s /sbin/nologin,例如apache,nginx等等nginx

2 groupadd添加新組
添加新組使用groupadd sql,dba,it,htsql

[root@qdlinux ~]# groupadd sql
[root@qdlinux ~]# groupadd dba
[root@qdlinux ~]# groupadd it
[root@qdlinux ~]# groupadd ht

3 usermod修改用戶信息
修改用戶uid爲2000,基本組爲it組,添加附加組爲dba,ht,而且移動用戶家目錄爲/home/heihei,且修改shellsh,添加一條註釋信息,最後修改用戶名稱.shell

[root@qdlinux ~]# usermod -u 2000 -g it -G dba,ht -md /home/heihei -s /bin/sh -c "2019 student" -l kiki hehe

[root@qdlinux ~]# id hehe
id: hehe: no such user
[root@qdlinux ~]# id kiki
uid=2000(kiki) gid=3003(it) groups=3003(it),3002(dba),3004(ht)

hehe:x:3000:
sql:x:3001:
dba:x:3002:kiki
it:x:3003:
ht:x:3004:kiki

如今須要使用戶添加新的附加組sql不影響原有的組apache

[root@qdlinux ~]# usermod -aG sql kiki
[root@qdlinux ~]# id kiki
uid=2000(kiki) gid=3003(it) groups=3003(it),3001(sql),3002(dba),3004(ht)

[root@qdlinux ~]# ls /home
heihei

如今原來的家目錄已經由haha修改成heihei,若是不想讓用戶擁有家目錄能夠使用-M參數,-L參數能夠鎖定用戶,-U能夠解除鎖定.bash

4 chfn修改用戶信息ui

[root@qdlinux ~]# chfn kiki
Changing finger information for kiki.
Name [2019 student]: 2020 student
Office []: +86
Office Phone []: 18610000000
Home Phone []: 266^H^H
chfn: control characters are not allowed
Home Phone []: 12345678

Finger information changed.
[root@qdlinux ~]# finger kiki
Login: kiki                     Name: 2020 student
Directory: /home/heihei                 Shell: /bin/sh
Office: +86, +1-861-000-0000        Home Phone: 12345678
Never logged in.
No mail.
No Plan.

[root@qdlinux ~]# tail -n1 /etc/passwd
kiki:x:2000:3003:2020 student,+86,18610000000,12345678:/home/heihei:/bin/sh

5 chsh修改用戶shell,使用usermod -s /bin/bash kiki,能夠達到一樣效果code

[root@qdlinux ~]# chsh kiki
Changing shell for kiki.
New shell [/bin/sh]: /bin/bash
Shell changed.
[root@qdlinux ~]# tail -n1 /etc/passwd
kiki:x:2000:3003:2020 student,+86,18610000000,12345678:/home/heihei:/bin/bash

6 userdel刪除用戶orm

直接使用userdel kiki是刪除用戶,保留家目錄,若是要連同家目錄一塊兒刪除使用-r參數。groupdel刪除不用的用戶組。it

[root@qdlinux ~]# userdel -r kiki
[root@qdlinux ~]# ls /home/
[root@qdlinux ~]#
[root@qdlinux ~]#tail -n5 /etc/group
hehe:x:3000:
sql:x:3001:
dba:x:3002:
it:x:3003:
ht:x:3004:

[root@qdlinux ~]# groupdel dba
相關文章
相關標籤/搜索