# Error: invalid connection string: must include a username unless a service token is provided

**URL:** <https://discuss.elastic.co/t/error-invalid-connection-string-must-include-a-username-unless-a-service-token-is-provided/332668>\
**Category:** Elastic Agent\
**Tags:** fleet\
**Created:** [May 5, 2023, 4:24pm UTC](https://discuss.elastic.co/t/error-invalid-connection-string-must-include-a-username-unless-a-service-token-is-provided/332668 "2023-05-05T16:24:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![osdacita](https://avatars.discourse-cdn.com/v4/letter/o/c2a13f/32.png) [@osdacita](https://discuss.elastic.co/u/osdacita)\
**Post date:** [May 5, 2023, 4:24pm UTC](https://discuss.elastic.co/t/error-invalid-connection-string-must-include-a-username-unless-a-service-token-is-provided/332668/1 "2023-05-05T16:24:15Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/d/a/da6aea3d6f78736bef7dd560f180d4ee37d80608.png)  
I'm trying to enroll a host using the fleet to properly use EndPoint Security, but trying directly causes problems so I resorted to the following commands:  
_.\elastic-agent enroll --fleet-server-es=https://:443 --fleet-server-service-token= --fleet-server-policy=_

And now it generates the error that appears in the first image, I would like to know how I can solve these problems to add the hosts with fleet

---

<div class="post-metadata">

**Author:** ![Julia\_Bardi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julia_bardi/32/79463_2.png) [@Julia\_Bardi](https://discuss.elastic.co/u/Julia_Bardi)\
**Post date:** [May 8, 2023, 11:33am UTC](https://discuss.elastic.co/t/error-invalid-connection-string-must-include-a-username-unless-a-service-token-is-provided/332668/2 "2023-05-08T11:33:58Z")

</div>

Hi osdacita, welcome to the forum!

The recommended way to set up a Fleet Server is to generate a service token for it, see the guide: [Deploy on-premises and self-managed | Fleet and Elastic Agent Guide [8.7] | Elastic](https://www.elastic.co/guide/en/fleet/8.7/add-fleet-server-on-prem.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 5, 2023, 11:34am UTC](https://discuss.elastic.co/t/error-invalid-connection-string-must-include-a-username-unless-a-service-token-is-provided/332668/3 "2023-06-05T11:34:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
