Check if a user is in a group

后端 未结 13 2187
梦如初夏
梦如初夏 2021-01-31 02:42

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

13条回答
  •  天命终不由人
    2021-01-31 03:11

    You could use groups $username_here | grep -q '\busergroup\b'

    The exitcode will be 0 if a match was found, 1 if no match was found.

    user_in_group()
    {
        groups $1 | grep -q "\b$2\b"
    }
    

    you could use this function as user_in_group userfoo groupbar

提交回复
热议问题