检查用户是否在组中 [英] Check if a user is in a group

查看:61
本文介绍了检查用户是否在组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台运行服务器的服务器,在该服务器上,我使用php运行bash脚本来验证用户的某些信息.例如,我设置了一个虚拟主机服务器,为了能够向其帐户添加另一个域,我想验证用户是否实际上是客户"组的成员.最好的方法是什么?

I have a server running where I use php to run a bash script to verify certain information of a user. For example, I have a webhosting server set up, and in order to be able to add another domain to their account I want to verify if the user is actually a member of the 'customers' group. What would be the best way to do this?

我已经搜索过google,但是它所提供的只是一种检查用户或组是否存在的方法,因此google现在并不是一个很大的帮助.

I have searched google, but all it comes up with is ways to check whether a user or a group exists, so google is not being a big help right now.

推荐答案

尝试执行此操作:

username=ANY_USERNAME
if getent group customers | grep -q "\b${username}\b"; then
    echo true
else
    echo false
fi

username=ANY_USERNAME
if groups $username | grep -q '\bcustomers\b'; then
    echo true
else
    echo false
fi

这篇关于检查用户是否在组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆