Skip to main content

How to run Commands as sudo on macOS with Swif

Updated over a week ago

This guide explains how to configure and run commands as sudo on macOS using Swif's command system, a tool that lets you run commands on Swif-managed Mac devices.

Prerequisites

  • Swif Admin Access: You need the Swif admin password for your device. This password is unique to each device and can be found under Device > Accounts in the Swif management interface.

Running Commands with Root Permissions

By default, Swif commands are executed under the SYSTEM user, who already has root permissions. This allows you to run commands as sudo without additional configuration.

However, if you want to run commands under a Swif admin user, follow these steps:

  1. Use the following command structure to run commands as sudo:

    echo '{{SWIF_ADMIN_PASSWORD}}' | sudo -S ls
    • Replace ls with your desired command.

    Example:

    echo 'YourAdminPassword' | sudo -S your-command-here
  2. Note: Each Swif admin has a randomized password per device, meaning this method will only work on the specific device you're targeting.

Running on the Swif Admin Account

Swif allows you to use a placeholder like {{SWIF_ADMIN_PASSWORD}} to automatically insert the Swif admin password into your commands, making it easier to run commands across multiple devices. For more details, please refer to Running on the Swif Admin Account.

For Windows Devices

If you're working with a Windows device, you can run a command as an administrator. For more information, visit the Windows command guide.


Let me know if you need any further adjustments or clarifications!

Did this answer your question?