linux中添加一个用户到指定用户组的两种方式,修改一个用户到指定用户组的一种方式
添加一个用户到指定用户组:
gpasswd –a 用户名 组名
usermod –G 组名 用户名
//第一种:gpasswd –a 用户名 组名
[root@localhost ~]# id user1
uid=501(user1) gid=501(user1) groups=501(user1)
[root@localhost ~]# gpasswd -a user1 user_group
Adding user user1 to group user_group
[root@localhost ~]# id user1
uid=501(user1) gid=501(user1) groups=501(user1),500(user_group)
//第二种:usermod –G 组名 用户名
[root@localhost ~]# id user1
uid=501(user1) gid=501(user1) groups=501(user1)
[root@localhost ~]# usermod -G user_group user1
[root@localhost ~]# id user1
uid=501(user1) gid=501(user1) groups=501(user1),500(user_group)
很显然,这两种方式得到的结果是一样的。其实对于上面两种方式正确来说是将用户组添加到指定用户的用户附加组中。
但是这个使用时候我们创建文件得到所属的组还是原来的user1组。可以使用newgrp来切换用户组,但是这个newgrp切换用户组只是临时切换的,当账号重新登录后就会变回去的。这个情况我们可以使用id和id 用户名 命令看出来。
[user1@localhost ~]$ touch file1
[user1@localhost ~]$ ls -l
total 0
-rw-rw-r--. 1 user1 user1 0 Jul 1 11:19 file1
[user1@localhost ~]$ id
uid=501(user1) gid=501(user1) groups=501(user1),500(user_group) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[user1@localhost ~]$ id user1
uid=501(user1) gid=501(user1) groups=501(user1),500(user_group)
[user1@localhost ~]$ newgrp user_group
[user1@localhost ~]$ touch file2
[user1@localhost ~]$ ls -l
total 0
-rw-rw-r--. 1 user1 user1 0 Jul 1 11:19 file1
-rw-r--r--. 1 user1 user_group 0 Jul 1 11:20 file2
[user1@localhost ~]$ id
uid=501(user1) gid=500(user_group) groups=501(user1),500(user_group) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[user1@localhost ~]$ id user1
uid=501(user1) gid=501(user1) groups=501(user1),500(user_group)
修改一个用户到指定用户组
[root@localhost ~]# id user1
uid=501(user1) gid=501(user1) groups=501(user1)
[root@localhost ~]# usermod -g user_group user1
[root@localhost ~]# id user1
uid=501(user1) gid=500(user_group) groups=500(user_group)
对于gpasswd -a命令和usermod -G添加用户到用户组同时会保留这个用户之前所在组信息因为是将用户添加到用户群组中修改的是groups,而usermod会将这个用户之前添加的组信息删除直接修改的是gid,所以如果想让指定用户临时加入指定组,可以使用gpasswd –a或者usermod -G命令。
linux中添加一个用户到指定用户组的两种方式,修改一个用户到指定用户组的一种方式的更多相关文章
- 在linux中添加ftp用户,并设置相应的权限
在linux中添加ftp用户,并设置相应的权限,操作步骤如下: 1.环境:ftp为vsftp.被限制用户名为test.被限制路径为/home/test 2.建用户:在root用户下: useradd ...
- linux中添加ftp用户,并设置相应的权限
在linux中添加ftp用户,并设置相应的权限,操作步骤如下: 1.环境:ftp为vsftp.被限制用户名为test.被限制路径为/home/test 2.建用户:在root用户下: useradd ...
- 如何在Linux中添加新的系统调用
系统调用是应用程序和操作系统内核之间的功能接口.其主要目的是使得用户 可以使用操作系统提供的有关设备管理.输入/输入系统.文件系统和进程控制. 通信以及存储管理等方面的功能,而不必了解系统程序的内部结 ...
- Linux中添加管理员权限问题:xxx is not in the sudoers file. This incident will be reported.
在各个不同版本的linux中添加拥有管理员权限账户有不同的简便方式. 问题: 今天遇见将新添用户添加到root用户组后,运行sudo仍然提示 ”xxx is not in the sudoers fi ...
- 在Windows Server 2008 R2中使用web方式修改域用户账户密码
在Windows的domain环境下,加域的客户端修改账户密码是一件很easy的事情:即使没有加域的客户端如果组织中,使用Exchange邮件系统,借助Exchange的owa也可以轻松修改账户密码. ...
- Window通过Web方式修改域用户密码
如何通过web方式修改域用户密码: 1.在Windows Server 2003上,系统默认提供了iisadmpwd作为一种修改域用户密码的方式 2.在Windows Server 2008上,可以提 ...
- Linux中添加、修改和删除用户和用户组
宽为限 紧用功 功夫到 滞塞通 一.用户: 在创建用户时,需要为新建用户指定一用户组,如果不指定其用户所属的工作组,自动会生成一个与用户名同名的工作组.创建用户user1的时候指定其所属工作组user ...
- linux 中添加自己的库路径的方法 cannot open shared object file: No such file or directory
本文转自:http://blog.csdn.net/maotianwang/article/details/44619197 库文档在连接(静态库和共享库)和运行(仅限于使用共享库的程式)时被使用,其 ...
- arm linux中添加开机启动
微处理器:S5PV210操作系统:linux3.0.8 前言: 在产品中,基本上都要屏蔽arm开发板中linux系统的对外通信,只应该通过产品的相关APP做相关操作. 因此需要把该APP添 ...
随机推荐
- rn-splash-screen 启动页 安卓
1. 进入项目npm install --save rn-splash-screen 2.react-native link rn-splash-screen 3.在项目android/app/src ...
- 子div块中设置margin-top时影响父div块位置的解决办法及其原因
解决办法①: 若子DIV块中使用margin-top,则在父DIV块中添加:overflow:hidden; 解决办法②: 在子DIV块中用padding-top代替margin-top. 有个叫 b ...
- mysql 安装和修改编码(utf8mb4)
安装mysql(linux 我的环境centos 7) 安装MySQL官方的Yum Repository wget -i -c http://dev.mysql.com/get/mysql57-com ...
- 502的错误其实不是nginx的问题,要从后端找原因。php-cgi进程数不够用、php执行时间长、或者是php-cgi进程死掉,都会出现502错误。
502的错误其实不是nginx的问题,要从后端找原因.php-cgi进程数不够用.php执行时间长.或者是php-cgi进程死掉,都会出现502错误.
- Gym 101149I I - It's the Police
http://codeforces.com/gym/101149/problem/I 考虑下面这个例子 4 3 1 2 1 3 1 4 应该是选 0 0 1 1这样是最优的,我们不选1号,因为如果选1 ...
- Linux 批量杀进程的命令
使用awk批量杀进程的命令: ps -ef | grep firefox | grep -v grep | awk '{print "kill -9 "$2}'|sh #列出了当前 ...
- C++面试中的singleton类
引子 “请写一个Singleton.”面试官微笑着和我说. “这可真简单.”我心里想着,并在白板上写下了下面的Singleton实现: 1 class Singleton 2 { 3 public: ...
- dataTable 中数据的居中显示
遇到了一个小问题,就是在向dataTable中添加数据时,数据总是向左对齐,而dataTable又没有设置数据对齐的方法,这里写一个在网上看到的一个方法,分享出来看一下,简单实用. html代码如图1 ...
- iOS之核心动画
.将动画的所有方法封装到一个类里面 MyCAHelper.h #import <Foundation/Foundation.h> #import <QuartzCore/Quartz ...
- iOS 循环引用解决方案
一.BLOCK 循环引用 一般表现为,某个类将block作为自己的属性变量,然后该类在block的方法体里面又使用了该类本身.构成循环引用. // 定义 block 的时候,会对外部变量做一次 cop ...