Linux下用戶操作常用命令

1、添加用戶

[root@TRAMOMAP ~]# adduser test1  //新建用戶test1
[root@TRAMOMAP ~]#passwd test1  //爲test1修改密碼
Changing password for user test1.
New UNIX password:(123456)  //設置新密碼爲123456

2、添加用戶組

[root@TRAMOMAP ~]# groupadd testgroup  //新建用戶組testgroup

3、查看用戶信息

[root@TRAMOMAP ~]#id test1
uid=503(test1) gid=504(test1) groups=504(test1) context=root:system_r:unconfined_t:SystemLow-SystemHigh

[root@TRAMOMAP ~]#grep test1 /etc/passwd etc/shadow /etc/group
/etc/passwd:test1:x:503:504::/home/test1:/bin/bash
/etc/shadow:test1:!!$l$mc/UeA7v$qaRiYTHKzX0Wbr2of14EE.:16827:0:99999:7:::
/etc/group:test1:x:504:
/etc/group:testgroup:x:505:test1

4、將已有用戶添加(移除)用戶組

[root@TRAMOMAP ~]# gpasswd –a test1 testgroup //將用戶test1添加到用戶組testgroup中
[root@TRAMOMAP ~]# id test1
uid=503(test1) gid=504(test1) groups=504(test1) ,505(testgroup) context=root:system_r:unconfined_t:SystemLow-SystemHigh
[root@TRAMOMAP ~]# gpasswd -d test1 testgroup//將用戶test1移除用戶組testgroup
Removing user testuser4 from group testgroup

5、新建用戶的同時指定用戶組

[root@TRAMOMAP ~]# useradd –g testgroup testuser2//新建用戶testuser2,並將其添加到用戶組testgroup中

[root@TRAMOMAP ~]# id testuser2
uid=504(testuser2) gid=505(testgroup) groups=505(testgroup) context=root:system_r:unconfined_t:SystemLow-SystemHigh

6、臨時關閉用戶和重新釋放

[root@TRAMOMAP ~]#passwd test1 –l
Locking password for user test1
passwd: Success

[root@TRAMOMAP ~]#passwd test1 –u
Unlocking password for user test1
passwd: Success

7、永久性刪除用戶

[root@TRAMOMAP ~]#userdel testuser3
[root@TRAMOMAP ~]#groupdel testuser3
groupdel: group testuser3 does not exist
[root@TRAMOMAP ~]#usermod –g testuser3 testuser3
usermod: user testuser3 does not exist
[root@TRAMOMAP ~]#id testuser3
id: testuser3: No such user
發佈了40 篇原創文章 · 獲贊 52 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章