iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💭
Fixing the "Could not connect to the server" Error in Xcode
The Issue
The authentication for the Apple account added to Xcode had expired. When I tried to add it again, the following dialog started to appear.
Could not connect to the server.

Environment
- macOS Sequoia 15.4
- Xcode 16.x
Cause
I don't remember adding it myself, but I found the following setting in /etc/hosts.
Even when Xcode tries to connect to Apple's servers for authentication, it's being redirected to localhost.
Removing or commenting this out will resolve the issue.
127.0.0.1 developerservices2.apple.com
Discussion