centos系統添加/刪除使用者和使用者組的例子

來源:互聯網
上載者:User

1、建使用者:

adduser phpq                            //建立phpq使用者
passwd phpq                            //給phpq使用者佈建密碼

2、建工作群組
groupadd test                          //建立test工作群組

3、建立使用者同時增加工作群組
useradd -g test phpq               //建立phpq使用者並增加到test工作群組

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

4、給已有的使用者增加工作群組

usermod -G groupname username

或者:gpasswd -a user group

5、臨時關閉:在/etc/shadow檔案中屬於該使用者的行的第二個欄位(密碼)前面加上*就可以了。想恢複該使用者,去掉*即可。

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

passwd peter –l

重新釋放:

passwd peter –u

6、永久性刪除使用者帳號

userdel peter

groupdel peter

usermod –G peter peter   (強制移除該使用者的主目錄和主目錄下的所有檔案和子目錄)

7、從群組移除使用者

編輯/etc/group 找到GROUP1那一行,刪除 A 或者用命令 gpasswd -d A GROUP

8、顯示使用者資訊

id user
cat /etc/passwd

補充:查看使用者和使用者組的方法

使用者列表檔案:/etc/passwd
使用者組列表檔案:/etc/group

查看系統中有哪些使用者:cut -d : -f 1 /etc/passwd
查看可以登入系統的使用者:cat /etc/passwd | grep -v /sbin/nologin | cut -d : -f 1
查看使用者操作:w命令(需要root許可權)
查看某一使用者:w 使用者名稱
查看登入使用者:who
查看使用者登入記錄:last

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.