6

As a member of sudo can I add myself to a group I don't belong to?

$ getent group thegroupname 
thegroupname:x:123794798:administrator,users,auser,moreusers,manymoreusers

$ sudo usermod -a -G thegroupname myusername
usermod: group 'thegroupname' does not exist

When I run the above I can't add myself to the group. The error message says the group doesn't exist, but it does.

Here I'll make a new group as per @terdon's comment.

$ sudo groupadd testgroup
useradd: user 'myusername' already exists
$ groups
myusername sudo users

$ getent group testgroup
testgroup:x:01234:


$ sudo usermod -a -G testgroup myusername
$ groups myusername
myusername : myusername sudo users testgroup

Sorry for the typo with just using groups instead of groups myusername. I'm not sure if that information is helpful as it still shows me as not belonging to the test group while groups myusername does.

$ groups
myusername sudo users
Louis Waweru
  • 23,945
  • 39
  • 132
  • 198
  • I suppose that creating a new group and adding your user to it does work as expected right? It's only `thisgroupname` that fails? – terdon Jun 07 '15 at 16:12
  • @terdon I'm not sure. I could use `usermod` but not `groupadd`. I've updated the question based on your feedback. – Louis Waweru Jun 08 '15 at 05:40
  • @terdon reading that again, it seems the answer to your question is "yes". – Louis Waweru Jun 08 '15 at 05:46
  • Hmm. Strange. Could you fix the typo you where `groupadd` prints a `useradd` error message (2nd code line in your edit)? – terdon Jun 08 '15 at 10:39
  • @terdon Doh, I overlooked something obvious trying to add a local account to an Active Directory group. If you want to post that in an answer, feel free! Thanks for your troubleshooting. – Louis Waweru Jun 09 '15 at 16:36
  • Huh? You mean the issue was thta you were running `sudo useradd testgroup` instead of `groupadd`? If so, lol, and nah, not worth posting an answer, just delete it. It's unlikely to help anyone else. – terdon Jun 09 '15 at 17:05
  • @terdon No, I forgot the group belonged to Active Directory and that the account I was trying to add it to was a local only account (not a user on AD). I guess the question should be can I add a local account to an AD group... – Louis Waweru Jun 09 '15 at 18:45

1 Answers1

2

I was trying to add a local user to an Active Directory group. This is not allowed.

Louis Waweru
  • 23,945
  • 39
  • 132
  • 198