Sobes.tech
Junior — Middle

How can you programmatically change user or group access rights to the system?

sobes.tech AI

Answer from AI

Programmatic modification of user or group access rights to a system depends on the operating system and the tools used.

In Linux, for example, commands like chmod, chown, and setfacl can be used to change file permissions and ownership. For automation and programmatic control, scripts in Bash or programming languages can invoke system commands.

An example in Python using the os module to change file permissions:

import os

# Set file permissions: rw-r--r-- (644)
os.chmod('example.txt', 0o644)

To manage user and group rights, system utilities can be called via subprocess, for example:

import subprocess

# Add user to a group
subprocess.run(['usermod', '-aG', 'groupname', 'username'])

In Windows, PowerShell scripts or APIs can be used to manage access rights.