Example 2: Managing Users
Important
AWS OpsWorks Stacks is no longer accepting new customers. Existing customers will be able to use the OpsWorks console, API, CLI, and CloudFormation resources as normal until May 26, 2024, at which time they will be discontinued. To prepare for this transition, we recommend you transition your stacks to AWS Systems Manager as soon as possible. For more information, see AWS OpsWorks Stacks End of Life FAQs and Migrating your AWS OpsWorks Stacks applications to AWS Systems Manager Application Manager.
Another simple task is managing users on an instance. The following recipe adds a new user to a Linux instance.
user "myuser" do home "/home/newuser" shell "/bin/bash" end
You use a usermyuser
and
specifies their home directory and shell. There is no action specified, so the resource
uses the default create
action. You can add attributes to user
to specify a variety of other settings, such as their password or group ID. You can also
use user
for related user-management tasks such as modifying user settings
or deleting users. For more information, see user
To run the recipe
-
Create a directory within
opsworks_cookbooks
namednewuser
and navigate to it. -
Create a
metadata.rb
file that contains the following code and save it tonewuser
.name "newuser" version "0.1.0"
-
Initialize and configure Test Kitchen, as described in Example 1: Installing Packages, and add a
recipes
directory inside thenewuser
directory. -
Add
default.rb
file with the example recipe to the cookbook'srecipes
directory . -
Run
kitchen converge
to execute the recipe. -
Use
kitchen login
to log in to the instance and verify the new user's existence by runningcat /etc/passwd
. Themyuser
user should be at the bottom of the file.