DevOps Bootcamp · Lesson

Privilege Escalation with become

Run tasks as root using sudo.

Lesson 4 of 413 steps

Privilege Escalation with become is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 4 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.

Some Tasks Need Root

Installing packages or restarting services usually needs root. Ansible handles that with privilege escalation, not a separate root login. 🔐

Enable It with become

Add the --become flag, often shortened to -b, to run your ad-hoc command with elevated privileges on the remote host.

ansible all -b -m package -a "name=git state=present"

sudo Is the Default Method

By default become uses sudo to escalate. That works on most Linux systems without any extra configuration.

ansible web -b -m service -a "name=nginx state=restarted"

Become root by Default

When you escalate, Ansible becomes the root user unless you say otherwise. That is the right target for most admin tasks.

Switch User with become_user

Use --become-user to become someone other than root, like deploying files as the postgres or deploy account.

ansible db -b --become-user postgres -m command -a "psql -c '\\l'"

Choose the Method

The --become-method flag picks how to escalate, such as sudo, su or doas, depending on what your hosts allow.

ansible all -b --become-method su -m ping

Prompt for the sudo Password

If sudo asks for a password, add --ask-become-pass, often -K, and Ansible will prompt you once before running.

ansible all -b -K -m package -a "name=vim state=present"

Three Pieces to Remember

Escalation has three knobs: become turns it on, become_user sets who, become_method sets how. Together they cover any host.

Same Keys in Playbooks

These flags map to directives: become: true, become_user and become_method, which you will reuse inside playbooks later.

become: true

Connect, Then Escalate

Ansible first logs in as your SSH user, then escalates on the host. The two users are separate steps, so do not confuse them.

ansible web -u deploy -b -m ping

Escalate Only When Needed

Skip become for read-only tasks like ping or gathering facts. Reserve it for actions that truly require elevated rights.

Quick Check

What is the default escalation method when you use become?

Recap

You can now go root safely: become enables escalation, become_user sets the target, and -K prompts for the password. 🔐

Free to start

Learn DevOps Bootcamp with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
142
Lessons
568

Frequently Asked Questions

Is the “Privilege Escalation with become” lesson free?

Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Privilege Escalation with become”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.

What will I learn in “Privilege Escalation with become”?

Run tasks as root using sudo. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 4 of 4.

How long does the “Privilege Escalation with become” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Anatomy of the ansible Command
  2. Patterns: Targeting all, web & host1
  3. Run Shell Commands with command & shell
  4. Privilege Escalation with become
← Back to DevOps Bootcamp