Linux -- newgrp

NEWGRP(1)                          用户命令                          NEWGRP(1)

名称
       newgrp - 登录到一个新组

大纲
       newgrp [-] [group]

描述
       The newgrp command is used to change the current group ID during a
       login session. If the optional - flag is given, the user's environment
       will be reinitialized as though the user had logged in, otherwise the
       current environment, including current working directory, remains
       unchanged.

       newgrp changes the current real group ID to the named group, or to the
       default group listed in /etc/passwd if no group name is given.  newgrp
       also tries to add the group to the user groupset. If not root, the user
       will be prompted for a password if she does not have a password (in
       /etc/shadow if this user has an entry in the shadowed password file, or
       in /etc/passwd otherwise) and the group does, or if the user is not
       listed as a member and the group has a password. The user will be
       denied access if the group password is empty and the user is not listed
       as a member.

       If there is an entry for this group in /etc/gshadow, then the list of
       members and the password of this group will be taken from this file,
       otherwise, the entry in /etc/group is considered.

配置文件
       在 /etc/login.defs 中有如下配置变量,可以用来更改此工具的行为:

       SYSLOG_SG_ENAB (boolean)
           允许“syslog”记录 sg 的活动。

文件
       /etc/passwd
           用户账户信息。

       /etc/shadow
       /etc/group
           组账户信息。

       /etc/gshadow
           安全组账户信息。

参见
       id(1), login(1), su(1), sg(1), gpasswd(1), group(5), gshadow(5).

shadow-utils 4.1.5.1              2014-02-17                         NEWGRP(1)


转载于:https://www.cnblogs.com/IceSword-syy/p/3953438.html

### 回答1: `newgrp`是一个Linux命令,用于切换到另一个组。这个命令可以让用户在不注销的情况下更改其组ID,以获得该组的权限。当用户使用`newgrp`命令时,会切换到指定的组,并且该组将变为用户的默认组,直到用户退出该组或注销。 例如,如果用户属于“group1”和“group2”两个组,但是当前的默认组是“group1”,那么可以使用以下命令切换到“group2”组: ``` newgrp group2 ``` 这将更改用户的默认组为“group2”,并且用户现在可以访问该组的文件和目录。 ### 回答2: newgrp命令是Linux系统中的一个命令,用于切换当前用户所属的群组。它允许用户在登录后切换到其他的群组,以便在这个群组下运行其他命令。 当用户登录系统后,默认情况下,会分配一个主要群组(primary group)给该用户。newgrp命令可以让用户切换到其他已存在的群组,从而拥有该群组下的权限和资源。切换到新的群组后,用户可以运行一些只有新群组成员才有权限执行的命令。 newgrp命令的语法为newgrp [选项] [群组名称]。选项包括-s、-l和-v。-s选项告诉newgrp在切换群组后启动一个新的shell。-l选项告诉newgrp要重新初始化环境变量,以便更新用户的群组信息。-v选项用于输出详细的切换信息。 使用newgrp命令,用户可以在登录后执行类似sudo命令的功能,但只能切换到已存在的群组。比如,用户A登录系统后默认属于groupA群组,但想要运行只有groupB群组成员才有权限执行的命令,可以使用newgrp命令切换到groupB群组后执行相应的命令。 需要注意的是,newgrp命令只能切换到已存在的群组,而无法创建新的群组。而且切换群组后,用户的身份证明(例如有效用户ID和有效组ID)会随之改变,因此该命令需要谨慎使用,以避免产生潜在的安全风险。 ### 回答3: newgrp命令是Linux系统中的一个命令,它的作用是让用户可以切换到不同的组身份。当用户加入一个新的组后,可以使用newgrp命令切换到该组的身份,从而获取该组的权限。 使用newgrp命令时,需要指定要切换的组名作为参数。例如,使用“newgrp developers”命令,就可以切换到developers组的身份。 在切换到新的组身份后,用户拥有该组的权限,可以访问该组的文件和目录。新的组身份也会影响用户在该组下创建的新文件,这些文件的所属组将是当前工作组。 需要注意的是,newgrp命令只能切换到用户已经加入的组。如果用户没有加入要切换的组,将会返回一个错误提示。 此外,使用newgrp命令切换到新的组身份后,用户原来所属的组身份并不被立即清除,只是在用户退出newgrp所切换的组时才会回到原来的身份。用户可以使用exit命令或Ctrl+D组合键来退出newgrp。 总结来说,newgrp命令是用来在Linux系统中切换用户组身份的命令。通过切换到不同的组身份,用户可以获得特定组的权限,访问该组的文件和目录。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值