linux 列出用户组_如何在Linux中列出所有用户和组

linux 列出用户组

linux 列出用户组

Users and group files are important for Linux. Normal users will interact with Linux systems by using credentials provided in the user ad group file.

用户和组文件对于Linux很重要。 普通用户将使用用户广告组文件中提供的凭据与Linux系统进行交互。

打印名为passwd的用户文件 (Print User File Named passwd)

We can get content of the user file like below.  This file provides usernames home directories and shell information.

我们可以获取用户文件的内容,如下所示。 该文件提供用户名主目录和外壳程序信息。

$cat /etc/passwd
Print User File Named passwd
Print User File Named passwd
打印名为passwd的用户文件

As we can see each line of the output provides the user name, user id, user group, user shell, user home path etc.

我们可以看到输出的每一行都提供了用户名,用户ID,用户组,用户外壳程序,用户主目录路径等。

仅打印用户名 (Print Only Usernames)

We can print only usernames by filtering other columns like below.

我们可以通过过滤以下其他列来仅打印用户名。

$cat /etc/passwd | cut -d : -f 1
Print Only Usernames
Print Only Usernames
仅打印用户名

打印已登录的用户(Print Users Who Have Login)

By default normal users will login to the Linux box. But in some cases service users do not need to login Linux system. This is also a security measure. We can list users who do not have login right with the following command. This login information is stored in the /etc/passwd file.

默认情况下,普通用户将登录Linux框。 但是在某些情况下,服务用户不需要登录Linux系统。 这也是一种安全措施。 我们可以使用以下命令列出没有登录权限的用户。 此登录信息存储在/etc/passwd文件中。

$ cat /etc/passwd | grep -v nologin
Print Users Who Have Login
Print Users Who Have Login
打印已登录的用户

打印具有家庭目录的用户(Print Users Who Have Home Directories)

We can print only users who have home directories in /home. This command will first look in to the passwd to list users how have /home and then print only user names from result.

我们只能打印在/ home中具有主目录的用户 此命令将首先在passwd中列出用户的/ home权限,然后仅打印结果中的用户名。

$ cat /etc/passwd | grep "/home/" | awk -F':' '{ print $1}'
Print Users Who Have Home Directories
Print Users Who Have Home Directories
打印具有家庭目录的用户

打印组文件(Print Group File)

Linux users have primary and secondary groups. These group names are stored in the /etc/group file. We can print this group information and assigned user with cat command. For more details read following tutorial.

Linux用户具有主要和次要组。 这些组名存储在/etc/group文件中。 我们可以使用cat命令打印此组信息并分配用户。 有关更多详细信息,请阅读以下教程。

How To Add User To A Group In Linux

如何在Linux中将用户添加到组

$cat /etc/group
Print Group File
Print Group File
打印组文件

仅打印组名(Print Only Group Names)

We can print only group names by cutting other column like below.

我们可以通过如下切割其他列来仅打印组名称。

$cat /etc/group | cut -d : -f 1
Print Only Group Names
Print Only Group Names
仅打印组名
LEARN MORE  Linux Su Command Tutorial With Examples
通过示例了解更多Linux Su命令教程

翻译自: https://www.poftut.com/list-users-groups-linux/

linux 列出用户组

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值