linux系统下的用户管理

linux下对用户的增删改查

1.adduser

**adduser test**
adduser在创建用户的时候,自动创建该用户,为用户分配组,创建家目录以及创建邮箱目录,并设置好密码。
Adding user `test' ...
Adding new group `test' (1003) ...
Adding new user `test' (1002) with group `test' ...
Creating home directory `/home/test' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

2.useradd

useradd在创建的时候不会自动为用户分配,只是单单创建了一个用户。需要我们用参数去设置内容.
**sudo useradd -m -s /bin/bash -g 1000 -p test test ** 
-m  创建家目录
-s  制定shell
-g  指定用户组
-p  指定密码

3.userdel

**userdel -r test**
-r:删除用户的同时,删除与用户相关的所有文件。
1、可能遇到的情况: user test is currently used by process 9974
    1.查看用户占用的进程
        ps -u test
    2.杀死这些进程
        kill 9974
    3.userdel -r username
2.删除时候忘记加-r,这时候需要手动删除用户的目录
     sudo rm -rf /home/test   删除用户的家目录
     ls /var/spool/mail       查看用户是否创建了邮箱
     sudo rm /var/spool/mail/test  如果有的话删除这个邮箱信息

4.usermod

usermod修改用户信息
    **sudo usermod -u 10001 test**   修改test用户的用户id为10001
    **sudo usermod -g 1000 test**   修改test用户的组id为1000

猜你喜欢

转载自blog.csdn.net/webEvelement/article/details/81609622