I have created a scratch org on my home machine and it is active and can be seen in the devhub. And I am now on my office computer.

However, when I use sfdx force:org:list I can't see that particular scratch org. And if I directly use sfdx force:org:open -u [userName] it comes back with an error message. And I am not quite sure what the password is for that particular scratch org.

What should I do in this case?

sfdx force:org:list

The above command is specific to the machine you used. So don't think your office laptop has any knowledge of what orgs you authenticated with and set as the default hub org and the default scratch org.

You will need to authorize all the orgs you have with your office laptop again, and create your scratch org again from the office CLI.

Follow the below steps

1.Again authorize your scratch org using the sfdx force:auth:web:login and entering the username and password

2.Use force:config:set to set the default scratch org

sfdx force:config:set defaultusername=test-wvkpnfm5z113@example.com

Optioanlly you can use sfdx force:alias:set to set alias as well default scratch org and the hub org .

  • 1
    Thank you, Mohith. I will check them. But currently your link is pointing to about:blank. And I have noticed that I need to generate my password for my scratch org user before it has one. So does that mean I can't login to my scratch org before generating the pwd? – Lance Shi Jan 25 '18 at 5:53
  • I think you have to. But anyway, you shouldn’t worry too much about a specific scratch org. Everything should be in your repo, as Scratch orgs are ephemeral, so just git clone your repo again and create a new Scratch org from it. – Fabien Taillon Jan 25 '18 at 8:00
  • well, I started work on my scratch org at home, and now you're telling me I can't pull that code into my project here at work - I have to wait until I go back home again and pull the changes out and commit to my VCS – bkwdesign Mar 1 '19 at 15:54

Here are the commands I used to reconnect to a scratch org that was initiated on another machine. Please note, I had my .sfdx/ folder included in my git repo, so the org definition existed when I pulled my code down to my other machine.

It was not necessary to reauth to the scratch org in this case (which would be difficult since the password is not known).

shanekenyon@Shanes-MacBook-Pro ~/Documents/git/csvupload (master) $ sfdx force:config:set  defaultusername=dev
=== Set Config
NAME             VALUE
───────────────  ─────
defaultusername  dev
shanekenyon@Shanes-MacBook-Pro ~/Documents/git/csvupload (master) $ sfdx force:org:list
=== Orgs
  ALIAS      USERNAME                     ORG ID              CONNECTED STATUS
  ─────────  ───────────────────────────  ──────────────────  ────────────────
  devhub     userid@domain.com            ****000001Uj0****   Connected

     ALIAS  SCRATCH ORG NAME     USERNAME                       ORG ID              EXPIRATION DATE
───  ─────  ───────────────────  ─────────────────────────────  ──────────────────  ───────────────
(U)  dev    shanekenyon Company  test-t8k7wnruwd66@example.com  ****000000982****   2018-10-23
  • 1
    Just seeing this now .Storing .sfdx folder on git can mean potential security risk . – Mohith Shrivastava Feb 19 '19 at 14:16
  • 1
    Yeah its not a good idea to have the .sfdx folder in the repo. We stopped doing it a while ago because it simply causes problems and doesn't work all that well. There is no reason to share scratch org creds, and you rightly point out that keeping sandbox org auth there is a security risk and violation of the principle to keep "secrets" out of source control. – Shane Feb 19 '19 at 17:30
  • 1
    Another option is to create another user with System Administrator access in the scratch org and do a password reset on that user to get access for multiple developers. – Shane Apr 14 '20 at 15:33

If you used your own connected app to authenticate with the DevHub which was used to create the scratch org, then you can use that connected app to connect to any scratch org created using the same connected app.

You'll need the username, your connected app's private key and your client id (consumer key)


sfdx force:auth:jwt:grant -u test-abcdefgh@example.com -f server.key -i <ConsumerKey> -a <MyAlias> -r https://test.salesforce.com

Full documentation here under Authorize a Scratch Org

  • so, if Machine 1 auth'd to DevHub using web flow and then created scratch org Foo; then machine 2, even if using a Connected App on the devhub configured for JWT, cannot authorize FOO? The whole chain of devhub auth/scratch org creation/scratch org auth has to be done for all machines using the JWT flow with the same consumer_key and server.key? – cropredy Jul 9 '20 at 1:02
  • You can always use the username and password with sfdx force:auth:web:login. But if you use the JWT flow with your own connected app, when the org is created that Connected App is automatically preauthed for the creating user (you can see the connected app consumer_key in the ScratchOrgInfos object, alongside a short lived auth_code used to grab a refresh_token on creation, and your connected app listed in Connected Apps Oauth Usage). – James Jul 21 '20 at 21:43
  • It looks like the same process used with Trialforce orgs to allow the ISV to access the provisioned org without knowing the password set by the new org admin. If you could get the cert for the Global Connected App then you could access any scratch org, which seems like a bad idea! – James Jul 21 '20 at 21:43
  • Clarification: (you can see the connected app consumer_key in the ScratchOrgInfos object in your devhub, alongside a short lived auth_code used to grab a refresh_token on creation, and your connected app listed in Connected Apps Oauth Usage in the scratch org) – James Jul 21 '20 at 21:55
  • I understand how username/pw can be used; but I was trying to get clarification that if machine 2 uses JWT to access machine1's scratch org, machine 1 needs to have created the scratch org using JWT – cropredy Jul 21 '20 at 22:19

If possible on your home machine use

Sfdx Force:user:password:generate -u orgalias

The use the username and password displayed to authenticate from your work machine

If you need the password again use

Sfdx force:user:display

Not sure if the work machine would recognize it as a scratch org but you would then have it connected

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.