brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: newgrp gives your shell the permissions of a new group without logging out

Permissions
~/tips/tip-permissions-newgrp-new-group-now

newgrp media

Starts a shell that already has a group you were just added to.

After usermod -aG, your current session still has the old group list. Logging out and in fixes it, but for a quick test newgrp is faster.

Run it with the group name:

sudo usermod -aG media "$USER"
id -nG
newgrp media
id -nG

The first id doesn’t show media yet. After newgrp media you’re in a new shell where it does, and that group is your current primary group, so new files you create there get media as their group.

For a single command there is sg, which does the same without leaving you in a new shell:

sg media -c 'touch /srv/media/test.txt'

I find it handy right after adding yourself to a group, to confirm the permissions work before you tell anyone it’s done.

It only fixes that one shell. Other terminal windows, your desktop session, tmux sessions that were already running and services you started earlier keep the old groups until you log in again. Typing exit takes you back to the shell you came from, still without the group. On a desktop, a full logout is the only way to get the group everywhere.

Further reading: newgrp(1) manual page, sg(1) manual page

More Permissions tips sudo su -s /bin/bash www-data sudo setfacl -R -d -m g:media:rwX /srv/media sudo cp -r /srv/site /srv/site.r ls -ln /srv/data sudo journalctl -k --since '10 min ago' | grep 'apparmor="DENIED"' All Permissions tips (30) All topics

Link