tl;dr: scroll down and copy/paste, then run the bash script.
I recently purchased my work laptop upon my departure from my previous gig. The machine had been bound to Active Directory in a Windows Domain, and that apparently left a bunch of residue behind that kept causing logging onto the machine to take several minutes and then would produce the following error:
![There was a problem connecting to the server](https://www.sn0ei.com/wp-content/uploads/2020/12/problem-connecting-to-server.png)
After spending a ton of time trying at least a dozen different things to resolve this error, I finally found a solution that worked to keep that pesky message away for good and return my login time to seconds instead of minutes. The solution was to use the dscl utility to delete anything and everything related to Active Directory and being bound to a domain.
This is the script I created to remove all domain associations using the dscl utility. Please note that this script has only been used on Mojave and Catalina. This will nuke everything that is related to being bound to a domain from orbit. Your mileage may vary, but it seems like most things will be restored correctly if you rejoin a domain. I wouldn’t recommend this if you need to be able to access network resources that have been configured by your IT Team.
You could, of course, just do a factory reset of your machine after backing up your data and that would fix things, but who has time for that?
Anyway, here’s the bash script to resolve that pesky “Problem connecting to server” error on your Mac:
#!/bin/bash
RemoveDomainAssociations(){
/usr/bin/dscl . -delete /users/%username% cached_groups
/usr/bin/dscl . -delete /users/%username% cached_auth_policy
/usr/bin/dscl . -delete /users/%username% CopyTimestamp
/usr/bin/dscl . -delete /users/%username% AltSecurityIdentities
/usr/bin/dscl . -delete /users/%username% SMBPrimaryGroupSID
/usr/bin/dscl . -delete /users/%username% OriginalAuthenticationAuthority
/usr/bin/dscl . -delete /users/%username% OriginalNodeName
/usr/bin/dscl . -delete /users/%username% SMBSID
/usr/bin/dscl . -delete /users/%username% SMBScriptPath
/usr/bin/dscl . -delete /users/%username% SMBPasswordLastSet
/usr/bin/dscl . -delete /users/%username% SMBGroupRID
/usr/bin/dscl . -delete /users/%username% PrimaryNTDomain
/usr/bin/dscl . -delete /users/%username% AppleMetaRecordName
/usr/bin/dscl . -delete /users/%username% PrimaryNTDomain
/usr/bin/dscl . -delete /users/%username% MCXSettings
/usr/bin/dscl . -delete /users/%username% MCXFlags
}
RemoveDomainAssociations
How to use the script:
- Copy and paste the above code into the text editor of your choice.
- Replace %username% with your login username.
- Save the file with the .sh extension.
- Open up Terminal. You can do this via the Command + Space keys and typing “Terminal”
- Navigate via Terminal to the location you saved the script in. If you need help with this, you can read Apple’s documentation, which can be found here.
- Make the script executable. You can find directions for that here.
- Run the script! You can find instructions for how to do that here.
- Restart your machine, and you should be good to go!