Table of contents
1.
Introduction
2.
About Knife User
2.1.
Create
2.2.
Delete
2.3.
Edit 
2.4.
List
2.5.
Password 
2.6.
Key Create 
2.7.
Key Delete 
2.8.
Key List 
2.9.
Key Show 
2.10.
List 
2.11.
Reregister 
2.12.
Show 
3.
Frequently Asked Questions
3.1.
What is Knife in chef?
3.2.
How do I download the Chef server cookbook?
3.3.
What are the three main components of Chef?
3.4.
What do you mean by a client in Chef?
3.5.
What do you understand about a node in Chef?
4.
Conclusion
Last Updated: Mar 27, 2024
Medium

About knife user subcommand

Author Yashi Agarwal
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

A knife is a command-line tool connecting the Chef Infra Server and a local chef-repo. The knife is an integral part of the Chef's Workstation. It is a command-line tool.

It acts as an interface between the Chef Infra Server and a local chef-repo.

Knife User Subcommand

The knife has many functionalities. It allows the user to manage the following things: Knife helps users to manage:

  • Cookbooks and recipes
  • Nodes
  • Searching for indexed data on the Chef Infra Server
  • Resources that are within different cloud environments
  • Roles, Environments, and Data Bags

About Knife User

The knife user subcommand is used for managing the list of users and the associated public key pairs with them. It has a plethora of options and plugins available like create, delete, key create, key delete, etc. We are going to look at very popular plugins and subcommands.

Create

The create argument is used to create a new user. The public key will be saved on the Chef Infra Server, whereas the private key will be shown on STDOUT or it can also be written to a named file. And for the named user this process will create an RSA pair key.

  1. The private key will be copied to the system as given below: /etc/chef/client.pem.
  2. For knife, the private key is copied to ~/.chef/client_name.pem, referenced in the config.rb configuration file.
     

Syntax 

The syntax is given below: 

knife user create USERNAME FIRST_NAME LAST_NAME DISPLAY_NAME EMAIL PASSWORD 


Options 

This has the options given below: 

  • Save a private key to the particular file name.
    --file FILE, -f FILE
     
  • The user password.
    --password PASSWORD
     
  • The path to a file that has the public key.
    --user-key FILENAME
     
  • To prevent Chef Infra Server from generating a default key pair for you. It cannot be passed with –user-key.
    -k, --prevent-keygen
     
  • The first name of the user
    --first-name FIRST_NAME
     
  • The last name of the user
    --last-name LAST_NAME
     
  • Email for the user
    --email EMAIL
     
  • Prompt for user password
    --prompt-for-password, -p
     
syntax

Delete

Use the above command to delete a registered user.

Syntax 

This argument has the following syntax:

knife user delete User_Name


Options 

  • Don’t disassociate the user first
    --no-disassociate-user, -d
     
  • If the given user is a member of any admin groups(org), attempt to remove them from those groups.
    --remove-from-admin-groups, -R

Edit 

Use this command to edit the user's details. The knife will open the editor when this argument is run. Chef Infra Server will be updated by knife with all the changes once updated all the things.

Syntax 

This argument has the following syntax:

knife user edit UserName


Options 

  • Name of file to use for POST and PUT
    ---i FILENAME, input FILENAME
     
  • To Write private key to FILENAME
    -- -f FILENAME, filename FILENAME

List

Use the above command to show a list of all registered users.

Syntax 

This argument has the following syntax:

knife user list


Options 

  • Show corresponding URIs. 
    -w, --with-uri,

Password 

Use the above command for managing passwords and authentication for a user.

Syntax 

This argument has the following syntax:

knife user password USE [PASSWORD] 


Options 

  • To Enable external authentication for this user (such as LDAP).
    --enable_external_auth

Key Create 

Use the key to create an argument to create a public key.

Syntax 

This argument has the following syntax:

knife user key create USER_NAME (options)


Options 

This argument has the following options:

  • The expiration date for the public key is specified as a formatted string: 
    -e DATE--expiration-date DATE (YYYY-MM-DD HH:MM:SS) 
     
  • Save a private key to the particular file name.
    -f FILE--file FILE
     
  • The name of the public key.
    --key-name FILE_NAME, -k FILE_NAME 

Key Delete 

Use the above argument to delete a public key.

Syntax 

This argument has the following syntax:

knife user key delete USER_NAME KEY

Key List 

Use the above command to show the named user's public keys.

Syntax 

knife user key list USERNAME (of any given option)


Options 

This argument has the following options:

  • To show a list of public keys that have expired.
    --only-expired, -e
     
  • To show a list of public keys that have yet to expire.
    --only-non-expired,-n
     
  • To show a list of public keys, including expiration status and URIs.
    --with-details, -w

Key Show 

Use the above command to view details for a particular public key.

Syntax 

knife user key show USERNAME KEY_NAME

List 

Use the above argument to view a list of registered users.

Syntax 

This argument has the following syntax:

knife user list (options)


Options 

This argument has the following options:

  • Show the corresponding URIs.
    -w--with-uri

Reregister 

Use the above argument to regenerate an RSA key pair for a user.

Syntax 

This argument has the following syntax:

knife user reregister USER_NAME (options)

 
Options 

This argument has the following options:

  • Save a private key to the specified file name. 
    -f FILE_NAME--file FILE_NAME

Show 

Use the show argument to show the details of a user.

Syntax 

This argument has the following syntax:

knife user show USER_NAME (options)


Options 

This argument has the following options:

  • Show the organizations of which the user is a member.
    --with-orgs-l

Frequently Asked Questions

What is Knife in chef?

A knife is a command-line tool that connects the Chef Infra Server and a local chef-repo.

How do I download the Chef server cookbook?

In that case, use the -f option (or –force) to download the cookbook and overwrite the local directory with the version downloaded from the Chef server. Instead of downloading it under the current directory, you can specify a download directory using the -d option (or –dir option).

What are the three main components of Chef?

Workstations, servers, and nodes are the three main components of Chef.

What do you mean by a client in Chef?

On each node that Chef is responsible for managing, an agent called a chef-client runs locally.

What do you understand about a node in Chef?

A node is a machine or system managed by the Chef server. It can be attached to any network that can send and receive information.

Conclusion

This article has extensively discussed the knife User subcommand, its properties, and syntax.

Check out more articles on Knife like Knife CookbookKnife Role SubcommandKnife Node Subcommand, and Knife Search Subcommand

Recommended Readings:

Also, check out these exciting courses from coding ninjas to expand your knowledge, Coding CourseCode StudioInterview ExperienceGuided PathInterview ProblemsTest SeriesLibrary, and Resources

Happy Coding!

Live masterclass