linux howto get user's group,Add a User to a Group (or Second Group) on Linux

写的很清楚: 尤其是两点,一个是新增,一个是已有用户修改。

放在这里backup

Changing the group a user is associated to is a fairly easy task, but not everybody knows the commands, especially to add a user to a secondary group. We’ll walk through all the scenarios for you.

Add a New Group

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

groupadd

Add an Existing User to a Group

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

usermod -a -G 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 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

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 .

groups

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 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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值