2

I am trying to execute a command with a specific user group as described in the linked question (How to run a process with a specific group?) on Alpine Linux, but the system says "not found"

~/work $ sg
sh: sg: not found

I checked shadow package with apk info -a shadow and it looks like the sg command is present:

[...]
cmd:pwunconv
cmd:sg
cmd:su
[...]

Reference of shadow package on Alpine: https://pkgs.alpinelinux.org/contents?branch=edge&name=shadow&arch=x86&repo=community

xenoid
  • 8,888
  • Is it just not in your PATH? Perhaps in one of the directories of root's path only? Does sudo sg work? – terdon Jan 25 '20 at 12:37
  • I am using a Docker container. I tried executing sg with root user and I get tha same error – alessionossa Jan 25 '20 at 13:26
  • 1
    Well, according to your link, it should be at /usr/bin/sg. What does ls /usr/bin/sg give you? If it isn't there, you should probably try reinstalling the package. – terdon Jan 25 '20 at 13:29
  • Tried reinstalling the package, it works now! Probably the preinstalled version of the package lacks of some parts. Thanks – alessionossa Jan 25 '20 at 13:33

3 Answers3

0

I got the same error today with the latest alpine (3.16.0) image. The sg command is gone again. I had to switch back to 3.15.4:

docker run --rm alpine:3.15.4 sh -c "apk add shadow && sg root -c id"

uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)

works, while 3.16.0 does not:

docker run --rm alpine:3.16.0 sh -c "apk add shadow && sg root -c id"

sh: sg: not found

0

sg migrated to the shadow-login package

apk add shadow-login

https://pkgs.alpinelinux.org/package/v3.16/community/x86_64/shadow-login

You can use this search tool to locate binaries:

https://pkgs.alpinelinux.org/contents?file=sg&path=&name=&branch=v3.16&repo=community&arch=x86_64

5andr0
  • 63
-1

Alpine Linux is designed to have a very small footprint (it was originally designed for embedded Linux) and all its shell commands are implemented with "busybox". There are other particularities, such as uncommon libraries, that make it difficult to use for containers.

This said, I wonder why you need to do this in a container, since you can set the id and group of any files when building the container image, run the container with any id.

xenoid
  • 8,888
  • I need this to let me access files generated by a script executed inside the container, from the host (files are saved in a volume, owned by group that has same ID in the container and in the host. reference: https://stackoverflow.com/questions/29245216/write-in-shared-volumes-docker) – alessionossa Jan 25 '20 at 13:46
  • Not all of Alpine's shell commands are implemented with BusyBox. Many of them are based on the same sources used on other distributions (e.g., if you apk add openssh, you get actual openssh, not some weird BusyBox version of openssh). If I apk add shadow in a local Alpine container, the sg command works without a problem. – larsks Jan 25 '20 at 13:55
  • @alessionossa You can run the container with a user that has the adequate group id, create user and group with RUN statements in the Dockerfile, and then either use a USER directive for the image or use the --user parameter. Both forms let you specify a user:group pair. – xenoid Jan 25 '20 at 14:14