Check if a user is in a group

后端 未结 13 1884
梦如初夏
梦如初夏 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:57

    Sounds like an another answer:

    username='myuser'
    if grep -q -E "^customers:.*[:,]$username(,.*|\b)" /etc/group; then
        echo 'true'
    else
        echo 'false'
    fi
    

    As reported by sputnick the output of the groups command may depend on your OS. I am not sure how this code is going to perform, but most probably it will do better.

提交回复
热议问题