Changing file ownership

This program will take the file provided and change the user and group ownership. This could be used in tandem with the example that finds files that you have permission to modify.

Go provides os.Chown() in the standard library, but it does not accept string values for the user and group names. The user and group must be provided as integer ID values. Fortunately, Go also comes with an os/user package that contains functions for looking up an ID based on a name. These functions are user.Lookup() and user.LookupGroup().

You could look up your own user and group information on Linux/Mac with the id, whoami, and groups commands.

Note that this does not work on Windows because ownership is treated differently. The following ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.