Skip to content

Instantly share code, notes, and snippets.

@Mic92
Last active January 28, 2025 13:39
Show Gist options
  • Save Mic92/3846bb589a84061b38ada9f5a309726b to your computer and use it in GitHub Desktop.
Save Mic92/3846bb589a84061b38ada9f5a309726b to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eux -o pipefail
# Create mount point if it doesn't exist
mkdir -p /run/testmount
# Clean up on exit
trap 'umount /run/testmount; rmdir /run/testmount' EXIT
# Enter new namespace with same mapping and mount tmpfs inside it
sudo -u joerg unshare --map-auto --map-root-user \
--user \
--mount \
--uts \
--ipc \
--pid \
--fork \
/bin/bash -c "
mount -t tmpfs tmpfs /run/testmount;
touch /run/testmount/testfile;
chmod u+s /run/testmount/testfile;
ls -la /run/testmount/testfile"
❯ command bat /etc/sub{uid,gid}
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /etc/subuid
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ joerg:100000:65536
   2   │ nix:165536:65536
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
───────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: /etc/subgid
───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ joerg:100000:65536
   2   │ nix:165536:65536
───────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment