linux系统中usermod命令
1、linux系统中usermod命令用于修改已创建用户的信息
用法:usermod [选项] username
[root@linuxprobe home]# tail -n 3 /etc/group
tcpdump:x:72:
linuxprobe:x:1000:
apache:x:48:
[root@linuxprobe home]# useradd liujiaxin01;useradd liujiaxin02;groupadd grouptest01 ## 分别创建两个普通用户,一个用户组
[root@linuxprobe home]# tail -n 3 /etc/group
liujiaxin01:x:1001:
liujiaxin02:x:1002:
grouptest01:x:1003:
2、 改变基本用户组
[root@linuxprobe home]# id liujiaxin01
uid=1001(liujiaxin01) gid=1001(liujiaxin01) groups=1001(liujiaxin01)
[root@linuxprobe home]# id liujiaxin02
uid=1002(liujiaxin02) gid=1002(liujiaxin02) groups=1002(liujiaxin02)
[root@linuxprobe home]# usermod -g grouptest01 liujiaxin01 ## -g + 用户组 改变用户的基本用户组
[root@linuxprobe home]# id liujiaxin01
uid=1001(liujiaxin01) gid=1003(grouptest01) groups=1003(grouptest01)
3、改变扩展用户组
[root@linuxprobe home]# usermod -G root liujiaxin02 ## -G + 用户组 改变用户的扩展用户组
[root@linuxprobe home]# id liujiaxin02
uid=1002(liujiaxin02) gid=1002(liujiaxin02) groups=1002(liujiaxin02),0(root)
4、 改变用户的U ID
[root@linuxprobe home]# usermod -u 6666 liujiaxin02 ## -u 改变用户的UID号码值
[root@linuxprobe home]# id liujiaxin02
uid=6666(liujiaxin02) gid=1002(liujiaxin02) groups=1002(liujiaxin02),0(root)
5、删除测试的用户、用户组
[root@linuxprobe home]# tail -n 3 /etc/passwd
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
liujiaxin01:x:1001:1003::/home/liujiaxin01:/bin/bash
liujiaxin02:x:6666:1002::/home/liujiaxin02:/bin/bash
[root@linuxprobe home]# userdel -r liujiaxin01 ## 删除用户liujiaxin01
userdel: group liujiaxin01 not removed because it is not the primary group of user liujiaxin01.
[root@linuxprobe home]# userdel -r liujiaxin02 ##删除用户liujiaxin02
[root@linuxprobe home]# tail -n 3 /etc/passwd
tcpdump:x:72:72::/:/sbin/nologin
linuxprobe:x:1000:1000:linuxprobe:/home/linuxprobe:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
[root@linuxprobe home]# tail -n 3 /etc/group
apache:x:48:
liujiaxin01:x:1001:
grouptest01:x:1003:
[root@linuxprobe home]# groupdel liujiaxin01 ## 删除用户组liujiaxin01
[root@linuxprobe home]# tail -n 3 /etc/group
linuxprobe:x:1000:
apache:x:48:
grouptest01:x:1003:
[root@linuxprobe home]# groupdel grouptest01 ##删除用户组grouptest01
[root@linuxprobe home]# tail -n 3 /etc/group
tcpdump:x:72:
linuxprobe:x:1000:
apache:x:48: