Step 6: Update the Cookbook to Add a User
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.
Update your cookbook by adding a recipe that adds a local user to the instance and sets the user's home directory and shell. This is similar to running the Linux adduser or useradd commands or the Windows net user command. You add a local user to an instance, for example, when you want to control access to the instance's files and directories.
You can also manage users without using cookbooks. For more information, see Managing Users.
To update the cookbook on the instance and to run the new recipe
-
On your local workstation, in the
recipes
subdirectory in theopsworks_cookbook_demo
directory, create a file namedadd_user.rb
with the following code (for more information, go to user): user "Add a user" do home "/home/jdoe" shell "/bin/bash" username "jdoe" end
-
At the terminal or command prompt, use the tar command create a new version of the
opsworks_cookbook_demo.tar.gz
file, which contains theopsworks_cookbook_demo
directory and its updated contents. -
Upload the updated
opsworks_cookbook_demo.tar.gz
file to your S3 bucket. -
Follow the procedures in Step 5: Update the Cookbook on the Instance and Run the Recipe to update the cookbook on the instance and to run the recipe. In the "To run the recipe" procedure, for Recipes to execute, type
opsworks_cookbook_demo::add_user
.
To test the recipe
-
Log in to the instance, if you have not done so already.
-
From the command prompt, run the following command to confirm that the new user was added:
grep jdoe /etc/passwd
Information similar to the following is displayed about the user, including details such as the user's name, ID number, group ID number, home directory, and shell:
jdoe:x:501:502::/home/jdoe:/bin/bash
In the next step, you will update the cookbook to create a directory on the instance.