简体   繁体   中英

What are the best practices to create and manage users used in Google Compute Engine virtual machine

I am trying to create a gcp compute engine vm and create some users and user groups and define some folders and files and applications that are only accessible by certain users or groups. I did that through ssh-ing into the instance and manually create new users and groups with useradd and groupadd commands and set the owner and permissions of files or folders manually as well. I feel this is very time consuming and error prone. Are there best practices to set these things without ssh-ing the instance? If I want to define an internally facing tool that should be accessed only by a small group of people, how do I systematically do it?? Should I use some post-installation scripts to run all these Linux environment configuring commands??

I manually created the users and groups and permissions of interested files, folders and allocations.

You can either use a configuration management tool such as Chef, Ansible, puppet or startup script or even a provisioning tool.

For your use case, i think a simple startup script would suffice [1].


[1] https://cloud.google.com/compute/docs/startupscript

#!/bin/bash

# Create a new user
useradd -m <username>

# Create a new group
groupadd <groupname>

# Add the user to the group
usermod -a -G <groupname> <username>

# Create a new directory
mkdir <directory>

# Set the group ownership of the directory
chown :<groupname> <directory>

# Set the permissions for the directory so that only members of the group can access it
chmod 770 <directory>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM