Originally published on 2015-09-20; fully revised and updated.
This page is a practical Chef CLI quick reference for DevOps engineers who need common commands in one place. It covers local recipe execution, cookbook generation, cookbook distribution, node bootstrap, and routine Knife operations, with notes where version differences can affect syntax.
Chef command families at a glance
| Tool/command family | Primary purpose | Typical use case |
|---|---|---|
| chef-solo | Run a recipe without Chef Server | Local or standalone execution from a solo.rb config |
| chef-apply | Apply a single recipe file directly | Quick local tests on one machine |
| chef-client –local-mode | Converge locally using a run list | Test cookbook behavior without full server workflow |
| knife cookbook * | Create/download/upload cookbooks | Manage cookbook lifecycle between local repo and server |
| knife bootstrap | Register and provision a node | Initial onboarding of a target machine |
| knife node * | Inspect and edit node metadata/run lists | Operational node management |
| knife ssh | Run remote commands on selected nodes | Trigger chef-client runs across nodes |
Generate cookbook structure and files
Use these commands to scaffold a new cookbook and add template files. The examples below preserve the command intent from the original post.
chef generate cookbook learn_chef_httpd
knife cookbook create smartmontools -r md
chef generate template learn_chef_httpd index.htmlCode language: CSS (css)
Run recipes and cookbooks locally
These commands are commonly used during development and troubleshooting before deploying to managed nodes.
chef-solo -c /opt/chef/repo/config/solo.rb -o 'my_cookbook::recipe'
chef-apply hello.rb
sudo chef-client --local-mode --runlist 'recipe[learn_chef_httpd]'Code language: JavaScript (javascript)
Download and upload cookbooks
Use Knife cookbook commands to fetch cookbook artifacts and publish local cookbooks to Chef Server.
knife cookbook site download learn_chef_httpd
knife cookbook site install learn_chef_httpd
knife cookbook upload learn_chef_httpd
knife cookbook upload -a
Bootstrap nodes and manage run lists with Knife
The following examples show common node onboarding and day-2 operations. Replace hostnames, usernames, and credentials with your environment values.
knife bootstrap ADDRESS --ssh-user USER --ssh-password 'PASSWORD' --sudo --use-sudo-password --node-name node1 --run-list 'recipe[learn_chef_apache2]'
knife bootstrap uvo1t75faaktzc532w6.vm.cld.sr -x root -P Br356YS0iy --sudo --node-name firefox
knife bootstrap 123.45.6.789 -x username -P password --sudoCode language: JavaScript (javascript)
knife node list
knife node show node1
knife node edit name_of_node
knife node run_list add C2445575914.domain 'recipe[hptrain]'
knife node run_list set test-node 'recipe[iptables]'Code language: PHP (php)
knife ssh ADDRESS 'sudo chef-client' --manual-list --ssh-user USER --ssh-password 'PASSWORD'
ssh username@ipaddress -i mycredentials.pem sudo chef-clientCode language: PHP (php)
Typical Chef workflow
flowchart LR
A[Generate cookbook] --> B[Add recipe and template]
B --> C[Run local converge]
C --> D[Download dependencies]
D --> E[Upload cookbook]
E --> F[Bootstrap node]
F --> G[Run chef-client on node]
G --> H[Validate node state]
Reference link preserved from the original post
The original page included a YouTube API-key troubleshooting reference: https://www.youtube.com/watch?v=ZCfrNvu6nMc.
Best practices and common pitfalls
- Prefer SSH keys over plaintext passwords in bootstrap and remote execution commands.
- Run local convergence first (chef-apply, chef-solo, or local-mode) before server upload.
- Keep run lists explicit and review node state after every run-list change.
- Validate command flags against your installed Chef Infra/Knife version, especially on older tutorials.
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals
Chef commands become much easier to use when you understand what each command changes on a node or server. Before running commands in production, test them in a safe environment and check the output for errors. It also helps to keep notes on common tasks, such as running recipes, managing cookbooks, and checking client status. Always verify the target environment before making changes. This habit can prevent small command mistakes from causing bigger configuration problems.
When using Chef commands across multiple environments, I find it important to distinguish between commands that only inspect configuration and those that can modify live infrastructure. A command that works on a development node may have very different consequences when executed against production systems. Keeping environment-specific configuration under version control, reviewing changes before applying them, and testing cookbook updates on a small group of nodes first can reduce unexpected configuration drift. It is also worth documenting version-specific command behavior so team members do not rely on outdated syntax during troubleshooting.