Check if a user is in a group

后端 未结 13 2035
梦如初夏
梦如初夏 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 02:56

    Try doing this :

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

    or

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

提交回复
热议问题