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: chown alice: with a trailing colon also sets the user's own group

Linux
~/tips/tip-permissions-chown-user-colon-login-group

sudo chown alice: report.pdf

Gives a file to a user and that user's own group in one short command.

Plenty of people type the name twice, chown alice:alice, every time they hand a file to someone. The second name is optional, and I think the short form is one of the nicer bits of chown.

sudo chown alice: report.pdf
sudo chown -R alice: /srv/share/alice
ls -l report.pdf

The GNU chown manual spells it out: if a colon but no group name follows the user name, that user becomes the owner and the group changes to that user’s login group. That’s the primary group from /etc/passwd, which on Ubuntu and Debian is normally a group with the same name as the user. So alice: gives you alice alice in ls -l, and it’s the quick fix for files you copied around as root.

The same man page lists the other short forms, and they’re easy to mix up:

chown alice file     # owner only, group stays
chown alice: file    # owner and alice's login group
chown :www-data file # group only, same as chgrp
chown : file         # changes nothing

My advice is to look at the colon before you hit enter. The difference between the first two lines is one character, and on a shared folder that character decides whether the group keeps access.

The caveat: “login group” really means the primary group of the account. On systems where everyone’s primary group is users, chown alice: sets the group to users, which may be broader than you meant. Check with id -gn alice first if you’re not sure. And with -R on a big tree it does it all in one go, so run it on a single file first.

Further reading: chown manual page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link