在/etc/group文件中可以看到,需要修改的组信息并不多。修改组的GID(加-g选项) 或组名(加-n参数)
添加一个组,为了节省博客篇幅,删除了部分组信息
[root@localhost home]# groupadd test
[root@localhost home]# cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
cdrom:x:11:
......
test:x:1015:
可以看到,默认添加的组没有用户列表。
接下来我们创建一个用户,使他成为test组成员。
[root@localhost home]# useradd -G test testUser
[root@localhost home]# useradd -G test testUser2
[root@localhost home]# cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:
.......
www:x:1014:
test:x:1015:testUser,testUser2
testUser:x:1011:
testUser2:x:1016:
可以看到最后三行,testUser,testUser2都已成为test组成员了,注意useradd的参数G,如果使用的是参数g,则会影响该成员的默认组。
因为用的是G参数,可以看到用户组信息,除了默认的组还有新添加的组。
[root@localhost home]# id testUser
uid=1011(testUser) gid=1011(testUser) 组=1011(testUser),1015(test)
如果使用参数g,可以看到默认组testUser已经没有了。
[root@localhost home]# usermod -g test testUser
[root@localhost home]# id testUser
uid=1011(testUser) gid=1015(test) 组=1015(test)
修改组名(-n)
[root@localhost home]# groupmod -n newGroup test
[root@localhost home]# cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
........
testgroup:x:1012:
elasticsearch:x:1013:
www:x:1014:
testUser:x:1011:
testUser2:x:1016:
newGroup:x:1015:testUser,testUser2
可以看到,test组已经改名成newGroup,并不会影响之前组成员。
修改组名时,GID和组成员不会变,只有组名改变。由于所有的安全权限都是基于GID的,
你可以随意改变组名而不会影响文件的安全性。
本文介绍了如何在Linux系统中使用groupmod命令修改组信息,包括更改GID和组名,并通过useradd创建用户并将其加入特定组。同时,详细阐述了usermod在添加用户到组时-G和-g参数的区别,以及如何通过groupadd创建新组。在修改组名后,展示了组名变更但GID和成员保持不变,确保了文件系统的安全性。
255

被折叠的 条评论
为什么被折叠?



