Example 2: Managing Users
Important
The AWS OpsWorks Stacks service reached end of life on May 26, 2024 and has been disabled for both new and existing customers.
We strongly recommend customers migrate their workloads to other solutions as soon as possible. If you have questions about migration, reach out to the AWS Support Team on AWS re:Post
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.