# SSH key not added to known\_keys automatically?

**URL:** <https://discuss.circleci.com/t/ssh-key-not-added-to-known-keys-automatically/34049>\
**Category:** Build Environment\
**Created:** [January 9, 2020, 11:21pm UTC](https://discuss.circleci.com/t/ssh-key-not-added-to-known-keys-automatically/34049 "2020-01-09T23:21:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ottoo](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/ottoo/32/23777_2.png) [@ottoo](https://discuss.circleci.com/u/ottoo)\
**Post date:** [January 9, 2020, 11:21pm UTC](https://discuss.circleci.com/t/ssh-key-not-added-to-known-keys-automatically/34049/1 "2020-01-09T23:21:41Z")

</div>

Hi

I setup a deploy key on Gitlab for our project and add it in our config.yml with the following command

```
- add_ssh_keys:
      fingerprints:
        - "xx:xx:xx"

```

This used to work out of the box, but now for some reason the key is not added to known\_hosts automatically. I can see that the IdentityFile is added in .ssh/config, but only after I ssh in to the build machine and run the following cmd the key is added to known\_hosts.

```
ssh -T git@gitlab.com

The authenticity of host 'gitlab.com (35.231.145.151)' can't be established.
ECDSA key fingerprint is SHA256:xxx.
Are you sure you want to continue connecting (yes/no)? yes

```

Shouldn’t the `add_ssh_keys` command do this automatically or do I need to append the key manually to `known_hosts` or do something like `"echo -e "Host gitlab.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config"`?

---

<div class="post-metadata">

**Author:** ![levlaz](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/levlaz/32/36978_2.png) [@levlaz](https://discuss.circleci.com/u/levlaz)\
**Post date:** [January 12, 2020, 9:56pm UTC](https://discuss.circleci.com/t/ssh-key-not-added-to-known-keys-automatically/34049/2 "2020-01-12T21:56:34Z")

</div>

> [@ottoo](#):
>
> Shouldn’t the `add_ssh_keys` command do this automatically or do I need to append the key manually to `known_hosts` or do something like `"echo -e "Host gitlab.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config"` ?

`add_ssh_key` does not do this automatically. The first approach you describe would work great. The second approach would also work, but there is a security risk that you need to accept if you disable `StrictHostKeyChecking`.

We describe our recommended approaches here: [https://circleci.com/docs/2.0/gh-bb-integration/#establishing-the-authenticity-of-an-ssh-host](https://circleci.com/docs/2.0/gh-bb-integration/#establishing-the-authenticity-of-an-ssh-host)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [January 22, 2020, 9:56pm UTC](https://discuss.circleci.com/t/ssh-key-not-added-to-known-keys-automatically/34049/3 "2020-01-22T21:56:37Z")

</div>

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