Adding a user to group and make groups command reflect changes without reboot?

CaffeineAddict

Well-Known Member
Joined
Jan 21, 2024
Messages
2,499
Reaction score
2,045
Credits
20,243
I add myself to group:
Bash:
sudo adduser <your_username> <group_name>

Then run groups command but it does not yet list me as being part of new group <group_name>

I tried log out and log in however this doesn't make groups list me as being part of the group.
The only way is to reboot system.

Question, how do I make groups command list me as being part of new group without reboot?
 


Usually you don't have to reboot. Just logout, and log back in.
 
After this
Code:
sudo adduser <your_username> <group_name>

Try this.

Code:
newgrp <group_name>

Don't use sudo on the second command, run it as the user.

Code:
groups
 
Don't use sudo on the second command, run it as the user.
I should have mentioned this in my OP but the group in question is not one that I manually created, it is libvirt group that was created by qemu packages upon installation of libvirt-manager so I have to work with that.

The libvirt group was likely created by sudo because of sudo apt install ...

But I'll test your scenario anyway to see if it produces same result soon.
 
Try this.

newgrp <group_name>
Don't use sudo on the second command, run it as the user.
That worked flawlessly! you're true admin, thanks!

edit:

That worked flawlessly! you're true admin, thanks!
But not quite, the newgrp make a user login to group, so groups lists me as part of the new group.

but as soon as I login to previous group with newgrp old_group then groups command no longer displays me as part of group.
So in other words it's only temporary.
 
Last edited:
When I use newgrp, it's kind of like opening another shell on top of the login you already have.
If you type "exit" you'll still be logged in, but in the "old" session.
But when I use this, I still have to logout, and log back in for it to be "permanent". But I don't reboot.

A least that works for me.
 
When I use newgrp, it's kind of like opening another shell on top of the login you already have.
If you type "exit" you'll still be logged in, but in the "old" session.
But when I use this, I still have to logout, and log back in for it to be "permanent". But I don't reboot.

A least that works for me.
Sadly does not work on Debian 12.

I did newgrp new_group
exit
log out and log in again

groups does not list me added.
 
I add myself to group:
Bash:
sudo adduser <your_username> <group_name>

Then run groups command but it does not yet list me as being part of new group <group_name>

I tried log out and log in however this doesn't make groups list me as being part of the group.
The only way is to reboot system.

Question, how do I make groups command list me as being part of new group without reboot?
From the adduser manpage:
adduser and addgroup add users and groups to the system according to command line options and configuration information in /etc/adduser.conf. They are more Debian specific front ends to the useradd, groupadd and usermod programs, which are more distribution agnostic ...

Perhaps try:
Code:
usermod -aG libvirt $USER
 
I guess you could add the user name directly into the /etc/group file, then logout and login.
I could try that but if it would work this is a hack, I'd prefer more conventional method with a command, such as restarting a service or running a command etc.

editing files to get expected result is at best a workaround.
 
Debian specific front ends to the useradd, groupadd and usermod programs, which are more distribution agnostic ...

Hmmm... I read this twice, and spaced right over it. Getting old I guess. :)


In "some" distro's you get useradd but not adduser. There is a difference.
 
I could try that but if it would work this is a hack, I'd prefer more conventional method with a command, such as restarting a service or running a command etc.

editing files to get expected result is at best a workaround.
That's an interesting point of view. There are others :).

Linux uses text files for configurations. One reason for that is to make them accessible to the user, especially because configurations can be altered in many ways, in some cases in undocumented ways. So, as a general rule, they are available for user alteration. Some are inadvisedly alterable and come with messages to that effect. In that case one is best to know just what they are doing if they choose to make alterations. Other config files are not so, and specifically not so as is indicated by the numerous commented lines which are alterable in them. There are many examples.

In the case of some configuration utilities, they alter more than a single file, and can be more involved. For example, adding a new user through the adduser or useradd command may add a new directory and then add a bunch of dotfiles such as those from /etc/skel. In that case, using a relevant command can be useful. It's not however, necessary, but rather, convenient. On the other hand, if the user wishes to make a single alteration to a configuration file, like adding a user to a group, the option of doing that is available without any negative consequences or repercussions for the system, rather, a benefit for the user.

If the the term "hack" has a perjorative sense for some, there are other interpreted senses that are far more positive and with perhaps less influence in restricting a user's behaviour in their use of the system. To be entirely dependent on one version of how things can be achieved to the exclusion of effective alternatives seems to me to be needlessly self-confining if that is happening.

In any case, on the idea of a "hack", linux distros can be considered as full-on hacking distributions. That said, it's hard for me to consider the addition of a single configuration such as adding a username in /etc/group as a hack, but YMMV. I guess it's worth noting that for many configuration options, no command exists and it's direct alteration of the configuration files that is going to achieve an intended end.

In this case where the relevant commands appear to be failing, there appears to be an underlying problem for which troubleshooting could be gone into. To resolve the immediate problem however, the option of direct alteration to the configuration file is available. I wish I could see what the problem is, but I can't at the moment because I'm not familiar with it.
 
Last edited:
editing files to get expected result is at best a workaround.

LOL That was quite normal for many things, once upon a time...

Documentation was important because of this. Poor documentation meant hacking at config files for hours until you finally got it to work.
 
LOL That was quite normal for many things, once upon a time...
I think there is misunderstanding...

Editing configuration files is something completely different, editing configuration files is necessary to configure services or programs etc. and that's completely fine and totally different story.

However this case is different, we're not talking about configuring something but about expected result of a command.
If I'm added to group by a command then the expected result is that I'm added to group.

If logout and login is required for the change to take effect that's also OK, but in my case not even that works, so something is very wrong.

I've been googling out and found this super user question:

The question and answers clearly indicate that log out and log in should made the groups command list me, but it does not, so again something is wrong, my system doesn't function as expected.
 
@KGIII and @osprey have a point though. In the "old days" we didn't have utilities like adduser or useradd.
We edited everything by hand.
 
@KGIII and @osprey have a point though. In the "old days" we didn't have utilities like adduser or useradd.
We edited everything by hand.
I still do that sometimes depending on what needs to get done. ie: vipw
 


Members online


Top