Newer Version Available

This content describes an older version of this product. View Latest

Generate or Change a Password for a Scratch Org User

By default, new scratch orgs contain 1 administrator user with no password. You can optionally set a password when you create a new user. Use the CLI to generate or change a password for any scratch org user. Once set, you can’t unset a password, you can only change it.
  1. Generate a password for a scratch org user with this command:
    1sfdx force:user:password:generate --targetusername <username>

    You can run this command for scratch org users only. The command outputs the generated password.

    The target username must be an administrator user. The --onbehalfof parameter lets you assign permsets to multiple users at once, including admin users, or to users who don’t have permissions to do it themselves. Specify multiple users by separating them with commas; enclose them in quotes if you include spaces. The command still requires an administrator user which you specify with the --targetusername parameter. For example, let’s say the administrator user has alias admin-user and you want to generate a password for users with aliases ci-user and qa-user:

    1sfdx force:user:password:generate --targetusername admin-user --onbehalfof ci-user,qa-user
  2. View the generated password and other user details:
    1sfdx force:user:display --targetusername ci-user
    2
    3=== User Description
    4KEY              VALUE
    5───────────────  ───────────────────────────────────────────────────────────
    6Access Token     <long-string>
    7Alias            ci-user
    8Id               005xx000001SvBaAAK
    9Instance Url     https://innovation-ability-4888-dev-ed.cs46.my.salesforce.com
    10Login Url        https://innovation-ability-4888-dev-ed.cs46.my.salesforce.com
    11Org Id           00D9A0000000SXKUA2
    12Profile Name     Standard User
    13Username         1505774874884_test-sug5dr2vzoj1@your_company.net
  3. Log in to the scratch org with the new password:
    1. From the force:user:display output, copy the value of Instance URL and paste it into your browser. In our example, the instance URL is https://site-fun-3277.cs46.my.salesforce.com.
    2. If you’ve already opened the scratch org with the force:org:open command, you’re automatically logged in again. To try out the new password, log out and enter the username and password listed in the output of the force:user:display command.
    3. Click Log In to Sandbox.

If you change a scratch org user’s password using the Salesforce UI, the new password doesn’t show up in the force:user:display output.

Note