Add a User to a Group (or Second Group) on Linux

本文介绍如何在Linux系统中管理用户组,包括添加新用户组、将用户添加到组、更改用户的主组、查看用户所属组及同时添加用户并指定组等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Add a New Group

To add a new group, all you need to do is use the groupadd command like so:

groupadd <groupname>

Add an Existing User to a Group

Next we’ll add a user to the group, using this syntax:

usermod -a -G <groupname> username

For example, to add user geek to the group admins, use the following command:

usermod -a -G admins geek

Change a User’s Primary Group

Sometimes you might want to switch out the primary group that a user is assigned to, which you can do with this command:

usermod -g <groupname> username

View a User’s Group Assignments

If you’re trying to figure out a permissions issue, you’ll want to use the id command to see what groups the user is assigned to:

id <username>

This will display output something like this:

uid=500(howtogeek) gid=500(howtogeek) groups=500(howtogeek), 1093(admins)

You can also use the groups command if you prefer, though it is the same as using id -Gn <username>.

groups <username>

View a List of All Groups

To view all the groups on the system, you can just use the groups command:

groups

Add a New User and Assign a Group in One Command

Sometimes you might need to add a new user that has access to a particular resource or directory, like adding a new FTP user. You can do so with the useradd command:

useradd -g <groupname> username

For instance, lets say you wanted to add a new user named jsmith to the ftp group:

useradd -G ftp jsmith

And then you’ll want to assign a password for that user, of course:

passwd jsmith

Add a User to Multiple Groups

You can easily add a user to more than one group by simply specifying them in a comma-delimited list, as long as you are assigning the secondary groups:

usermod -a -G ftp,admins,othergroup <username>

That should cover everything you need to know about adding users to groups on Linux.



From:http://www.howtogeek.com/50787/add-a-user-to-a-group-or-second-group-on-linux/



select * from ( SELECT -- 手工入库字段 a.id, a.tag_num, a.orgid, a.createperson, a.damageid, a.type, a.weight, a.createtime, a.operator, d.wasteCode, d.dangerName, d.wasteCategory, s.name AS orgName, '贮存' AS direction, -- 手工入库无方向 '人工' AS source FROM incoming_parameter a LEFT JOIN dangerwaste d ON a.damageid = d.id LEFT JOIN scrap s ON a.orgid = s.id where a.type=1 and a.orgid in ( 1526361506692370433 ) UNION ALL SELECT -- 手工出库字段 b.id, b.tag_num, b.orgid, b.createperson, b.damageid, b.type, b.weight, b.createtime, b.operator, d.wasteCode, d.dangerName, d.wasteCategory, s.name AS orgName, b.direction, '人工' AS source FROM outbound_parameter b LEFT JOIN dangerwaste d ON b.damageid = d.id LEFT JOIN scrap s ON b.orgid = s.id LEFT JOIN incoming_parameter ipc ON b.in_num = ipc.tag_num where b.type=1 and b.orgid in ( 1526361506692370433 ) UNION ALL SELECT -- 设备产废字段,自动补齐其他列为 NULL NULL AS id, d.deviceCode AS tag_num, d.scrapId AS orgid, ( SELECT su.name FROM haolan_message hm JOIN sys_user su ON su.id = hm.create_user WHERE hm.point_id = wg.device_code AND hm.message LIKE '%DOOR%' AND hm.create_time BETWEEN wg.create_time - INTERVAL 600 SECOND AND wg.create_time ORDER BY hm.create_time DESC LIMIT 1 ) AS createperson, d.danger_waste_id AS damageid, NULL AS type, wg.increment_or_decrement_weight AS weight, wg.create_time AS createtime, NULL AS operator, dw.wasteCode, dw.dangerName, dw.wasteCategory, d.scrapName AS orgName, '贮存' AS direction, '设备' AS source FROM waste_generation_data wg JOIN device d ON wg.scrap_id = d.scrapId LEFT JOIN dangerwaste dw ON d.danger_waste_id = dw.id WHERE wg.flag = 1 AND wg.increment_or_decrement_weight > 1 and wg.scrap_id in ( 1526361506692370433 ) group by wg.id UNION ALL SELECT -- 设备转运字段 NULL AS id, d.deviceCode AS tag_num, d.scrapId AS orgid, su.name AS createperson, d.danger_waste_id AS damageid, NULL AS type, wtd.weight AS weight, wtd.create_time AS createtime, su.name AS operator, -- 来源于 sys_user dw.wasteCode, dw.dangerName, dw.wasteCategory, d.scrapName AS orgName, '转运' AS direction, '设备' AS source FROM waste_transport_data wtd JOIN device d ON wtd.deviceCode = d.deviceCode LEFT JOIN dangerwaste dw ON d.danger_waste_id = dw.id LEFT JOIN sys_user su ON wtd.create_user = su.id where 1=1 and d.scrapId in ( 1526361506692370433 ) group by wtd.id ) t ORDER BY createtime DESC 这个sql如何优化速度
最新发布
07-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值