Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is user in dialout group?

Tags:

bash

In my script I need to find out whether user is in dialout group and if he is not, add him to the group. I have found out how to add him but is there a way how to know if he is in the group ?

like image 604
Jesse_Pinkman Avatar asked Apr 01 '16 15:04

Jesse_Pinkman


2 Answers

You can do this in both ways:

  • Check all groups a specific user is member of and check if dialout is there:

    id username
    

    Or as Wolf said already:

    groups username
    
  • Check all members of the specific group (dialout) and check if the user is in the list:

    getent group dialout
    
like image 81
heemayl Avatar answered Oct 13 '22 10:10

heemayl


You are looking for the groups command. Here's an example of me using it on a server I just happened to be talking to at the moment (I'm logged in as the lprod user):

[lprod@milazgit01 ~] $ groups wolf
wolf : prod tools

Then you can compare that to a regular expression in whatever shell you are using.

like image 28
Wolf Avatar answered Oct 13 '22 09:10

Wolf