{"record":{"id":"0ac45e2ac733158d","repo":"netbirdio/netbird","slug":"read-config-file-s-v","errorCode":null,"errorMessage":"read config file %s: %v","messagePattern":"read config file (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/cmd/login.go","lineNumber":333,"sourceCode":"func doForegroundLogin(ctx context.Context, cmd *cobra.Command, setupKey string, activeProf *profilemanager.Profile) error {\n\n\terr := handleRebrand(cmd)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// update host's static platform and system information\n\tsystem.UpdateStaticInfoAsync()\n\n\tconfigFilePath, err := activeProf.FilePath()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get active profile file path: %v\", err)\n\n\t}\n\n\tconfig, err := profilemanager.ReadConfig(configFilePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"read config file %s: %v\", configFilePath, err)\n\t}\n\n\t// Mirror runInForegroundMode: recover residual state (DNS, firewall,\n\t// ssh config, legacy routing) from a previous unclean shutdown and\n\t// enable advanced routing before dialing management.\n\tif err := server.RestoreResidualState(ctx, profilemanager.NewServiceManager(configFilePath).GetStatePath()); err != nil {\n\t\tlog.Warnf(\"failed to restore residual state: %v\", err)\n\t}\n\tnbnet.Init()\n\n\terr = foregroundLogin(ctx, cmd, config, setupKey, activeProf.ID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"foreground login failed: %v\", err)\n\t}\n\tcmd.Println(\"Logging successfully\")\n\treturn nil\n}\n","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/cmd/login.go#L315-L351","documentation":"profilemanager.ReadConfig failed on the resolved config file path: the per-profile JSON either does not exist, cannot be opened (permissions), or does not parse. The config file is created when the profile is created; this error means it was deleted, corrupted (partial write), or its ownership/permissions changed after creation.","triggerScenarios":"Config file deleted or moved after profile creation; truncated JSON from an interrupted write (crash during save); ownership changed by running the daemon/CLI once under a different account (e.g., sudo); disk corruption.","commonSituations":"Mixed sudo/non-sudo usage leaving root-owned config files; Backup restores that skipped dotfiles; Cleanup scripts aggressively pruning ~/.netbird","solutions":["Check the path printed in the error: confirm existence and ownership (ls -l <path>)","Fix permissions/ownership on the file and config dir (chown to the invoking user)","If the file is missing or corrupt, recreate the profile ('netbird profile create' with the same management URL) so a fresh config is written, then login again","Keep the setup key or SSO credentials at hand since re-registration may be required"],"exampleFix":"# before\n$ netbird login\nError: read config file /home/user/.netbird/config.json: open ...: permission denied\n\n# after\n$ sudo chown \"$USER:\" /home/user/.netbird/config.json\n$ netbird login","handlingStrategy":"validation","validationCode":"// Existence + readability check before ReadConfig\ninfo, err := os.Stat(configFilePath)\nif err != nil {\n    return fmt.Errorf(\"config file missing: %w\", err)\n}\nif info.Mode().Perm()&0o400 == 0 {\n    return fmt.Errorf(\"config file %s not readable by this user\", configFilePath)\n}","typeGuard":null,"tryCatchPattern":"config, err := profilemanager.ReadConfig(configFilePath)\nif err != nil {\n    if errors.Is(err, os.ErrNotExist) {\n        // recreate the profile rather than failing the whole login\n        return recreateProfileAndLogin(ctx, configFilePath)\n    }\n    if isJSONErr(err) {\n        return fmt.Errorf(\"config corrupted, recreate profile: %w\", err)\n    }\n    return fmt.Errorf(\"read config file %s: %w\", configFilePath, err)\n}","preventionTips":["Keep strict ownership discipline: one user owns the config dir, no sudo CLI runs","Back up profile configs alongside the profile store when migrating hosts","Treat unreadable/corrupt config as recreate-and-reregister, and keep a valid setup key available"],"tags":["config","filesystem","permissions","corruption","netbird"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}