linux下添加,刪除,修改,查看使用者和使用者組

來源:互聯網
上載者:User

標籤:

一、組操作

1、建立組

groupadd  test

增加一個test組

 

2、修改組

groupmod -n test2  test

將test組的名子改成test2

3、刪除群組

groupdel test2

刪除 組test2

4、查看組

a)、查看當前登入使用者所在的組 groups,查看apacheuser所在組groups apacheuser

b)、查看所有組 cat /etc/group

c)、有的linux系統沒有/etc/group檔案的,這個時候看下面的這個方法

cat /etc/passwd |awk -F [:] ‘{print $4}‘ |sort|uniq | getent group |awk -F [:] ‘{print $1}‘

這裡用到一個命令是getent,可以通過組ID來尋找組資訊,如果這個命令沒有的話,那就很難尋找,系統中所有的組了.

二、使用者操作

1、增加使用者

[[email protected] mytest]# useradd --help  Usage: useradd [options] LOGIN    Options:   -b, --base-dir BASE_DIR       設定基本路徑作為使用者的登入目錄   -c, --comment COMMENT         對使用者的注釋   -d, --home-dir HOME_DIR       設定使用者的登入目錄   -D, --defaults                改變設定   -e, --expiredate EXPIRE_DATE  設定使用者的有效期間   -f, --inactive INACTIVE       使用者到期後,讓密碼無效   -g, --gid GROUP               使使用者只屬於某個組   -G, --groups GROUPS           使使用者加入某個組   -h, --help                    協助   -k, --skel SKEL_DIR           指定其他的skel目錄   -K, --key KEY=VALUE           覆蓋 /etc/login.defs 設定檔   -m, --create-home             自動建立登入目錄   -l,                           不把使用者加入到lastlog檔案中   -M,                           不自動建立登入目錄   -r,                           建立系統帳號   -o, --non-unique              允許使用者擁有相同的UID   -p, --password PASSWORD       為新使用者使用加密密碼   -s, --shell SHELL             登入時候的shell   -u, --uid UID                 為新使用者指定一個UID   -Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping  

useradd test

passwd test

增加使用者test,有一點要注意的,useradd增加一個使用者後,不要忘了給他設定密碼,不然不能登入的。

2、修改使用者

usermod -d /home/test -G test2 test

將test使用者的登入目錄改成/home/test,並加入test2組,注意這裡是大G。

gpasswd -a test test2 將使用者test加入到test2組
gpasswd -d test test2 將使用者test從test2組中移出

3、刪除使用者

userdel test

將test使用者刪除

4、查看使用者

a)、查看當前登入使用者

[[email protected] ~]# w
[[email protected] ~]# who

b)、查看自己的使用者名稱

[[email protected] ~]# whoami

c)、查看單個使用者資訊

[[email protected] ~]# finger apacheuser
[[email protected] ~]# id apacheuser

d)、查看使用者登入記錄

[[email protected] ~]# last 查看登入成功的使用者記錄
[[email protected] ~]# lastb 查看登入不成功的使用者記錄

e)、查看所有使用者

[[email protected] ~]# cut -d : -f 1 /etc/passwd
[[email protected] ~]# cat /etc/passwd |awk -F \: ‘{print $1}‘

linux下添加,刪除,修改,查看使用者和使用者組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.