# Cannot add Private Key using flyctl to a environment variable

**URL:** <https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435>\
**Category:** Questions / Help\
**Created:** [January 30, 2023, 1:45pm UTC](https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435 "2023-01-30T13:45:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CyberX](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/cyberx/32/9080_2.png) [@CyberX](https://community.fly.io/u/CyberX)\
**Post date:** [January 30, 2023, 1:45pm UTC](https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435/1 "2023-01-30T13:45:51Z")

</div>

What am I trying to do?

flyctl secrets set SEARCH\_CONSOLE\_PRIVATE\_KEY=-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BA\nvnwq7Zd3diJpxE46aRQwlJ9LRNitjt2/OUcXkc7AIy7xasAl8c0jADttPpW26Slk\nd/VCCxH7JssXsV8dHvn1Xc3r\n-----END PRIVATE KEY-----\n

Error Im getting :

Error could not parse secrets: ‘PRIVATE’: must be in the format NAME=VALUE

next I tried passing through fly.toml

Error I got : Error failed loading app config from C:\Users\Administrator\xxx\fly.toml: toml: line 9 (last key “env.SEARCH\_CONSOLE\_PRIVATE\_KEY”): expected a digit but got ‘-’

Searching online hasnt been fruitful. Please help me out. ☹

---

<div class="post-metadata">

**Author:** ![greg](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/greg/32/2119_2.png) [@greg](https://community.fly.io/u/greg)\
**Post date:** [January 30, 2023, 2:37pm UTC](https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435/2 "2023-01-30T14:37:45Z")

</div>

Hi,

I’m guessing the characters in the key (like newlines) are confusing the CLI. It may be as simple as wrapping the _value_ in quotation marks. Try:

`flyctl secrets set SEARCH_CONSOLE_PRIVATE_KEY="the-value-here"`

---

<div class="post-metadata">

**Author:** ![ignoramous](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@ignoramous](https://community.fly.io/u/ignoramous)\
**Post date:** [January 30, 2023, 3:03pm UTC](https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435/3 "2023-01-30T15:03:06Z")

</div>

> [@CyberX](#):
>
> Searching online hasnt been fruitful.

To add to Greg’s answer, see these two handy tricks to load multi-line values into Fly _secrets_ via `flyctl`:

> [@How are you managing cert files with Fly?](https://community.fly.io/t/how-are-you-managing-cert-files-with-fly/2984/16):
>
> The hyphen means “STDIN until EOF”, a pipe or redirection sets the source and the hyphen instructs where to place it. echo "long text..." | flyctl secrets set LONG\_TEXT=- flyctl secrets set FROM\_A\_FILE=- \< file.txt

* * *

> [@CyberX](#):
>
> =-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BA\nvnwq7Zd3diJpxE46aRQwlJ9LRNitjt2/OUcXkc7AIy7xasAl8c0jADttPpW26Slk\nd/VCCxH7JssXsV8dHvn1Xc3r\n-----END PRIVATE KEY-----\n

I hope this isn’t a private key in actual use. If it is sensitive, rotate it.

---

<div class="post-metadata">

**Author:** ![CyberX](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/cyberx/32/9080_2.png) [@CyberX](https://community.fly.io/u/CyberX)\
**Post date:** [January 30, 2023, 3:04pm UTC](https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435/4 "2023-01-30T15:04:45Z")

</div>

It does works when I add it as " " but the problem is google search console wont load anything.

---

<div class="post-metadata">

**Author:** ![greg](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/greg/32/2119_2.png) [@greg](https://community.fly.io/u/greg)\
**Post date:** [January 30, 2023, 3:54pm UTC](https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435/5 "2023-01-30T15:54:06Z")

</div>

🤔

Well first, if that _was_ the real value, as @ignoramous says, rotate it. Which would mean at the very least it needs updating in Fly or Google.

You can check whether Fly has done _its_ bit by connecting to your app instance by running `fly ssh console` from the folder your `fly.toml` file is in. That should load you into the vm, and then run e.g `echo $SEARCH_CONSOLE_PRIVATE_KEY`. If that shows you your private key, well Fly’s bit is done at that point. You provided an environment variable, and in turn Fly passed it to the vm when it booted. Beyond that point, it’s down to what you do with it in your code/SDK.

On the other hand if the value is not shown, well yes, that would be an issue with how the secret is being passed in. In which case check out what @ignoramous suggests about loading it from a file instead.

---

<div class="post-metadata">

**Author:** ![CyberX](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/cyberx/32/9080_2.png) [@CyberX](https://community.fly.io/u/CyberX)\
**Post date:** [January 30, 2023, 5:15pm UTC](https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435/6 "2023-01-30T17:15:15Z")

</div>

Yes the both Private and Email are showing as they were entered and without " ". So the values are passed on correctly. Guess its not on [Fly.io](http://Fly.io) anymore but the developer side.

also the value I posted above is was 5% of the actual keys so its safe.

Thanks again guys. I’ll try checking through the coding part for the issue and update here once it starts working. Im really impressed with the active community.

---

<div class="post-metadata">

**Author:** ![ignoramous](https://avatars.discourse-cdn.com/v4/letter/i/a9adbd/32.png) [@ignoramous](https://community.fly.io/u/ignoramous)\
**Post date:** [January 30, 2023, 8:55pm UTC](https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435/7 "2023-01-30T20:55:43Z")

</div>

> [@CyberX](#):
>
> also the value I posted above is was 5% of the actual keys so its safe.

Even if you’re sure that its just the 5% of it, it is a good idea to rotate. See: [Recovering a full PEM Private Key when half of it is redacted | CryptoHack Blog](https://blog.cryptohack.org/twitter-secrets)

---

<div class="post-metadata">

**Author:** ![CyberX](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/cyberx/32/9080_2.png) [@CyberX](https://community.fly.io/u/CyberX)\
**Post date:** [January 31, 2023, 5:02pm UTC](https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435/8 "2023-01-31T17:02:12Z")

</div>

You are right. I just deleted the key. now running with a new one. this is still ongoing. will update 😃

---

<div class="post-metadata">

**Author:** ![CyberX](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/cyberx/32/9080_2.png) [@CyberX](https://community.fly.io/u/CyberX)\
**Post date:** [May 8, 2023, 6:23am UTC](https://community.fly.io/t/cannot-add-private-key-using-flyctl-to-a-environment-variable/10435/9 "2023-05-08T06:23:15Z")

</div>

@ignoramous @greg As I promised I’ll update this thread if this is resolved. This has been resolved. seems like implementation of script was at domain Level while I was running at url level. I had to verify the domain in Google Search Console using DNS and it sorted the issue. Your provided steps were correct for entering the keys.

Thanks again guys. 🙂
