# Known\_hosts edit fails using local CLI

**URL:** <https://discuss.circleci.com/t/known-hosts-edit-fails-using-local-cli/21407>\
**Category:** Build Environment\
**Tags:** github, npm, cli\
**Created:** [April 11, 2018, 3:25pm UTC](https://discuss.circleci.com/t/known-hosts-edit-fails-using-local-cli/21407 "2018-04-11T15:25:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thatneat](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@thatneat](https://discuss.circleci.com/u/thatneat)\
**Post date:** [April 11, 2018, 3:25pm UTC](https://discuss.circleci.com/t/known-hosts-edit-fails-using-local-cli/21407/1 "2018-04-11T15:25:18Z")

</div>

I need to clone a separate GitHub repo (other than the one checked out by the `checkout` step) as part of my build process\*. It works in the actual CircleCI environment, but I’m having a `known_hosts` issue when I run `circleci build` [locally](https://circleci.com/docs/2.0/local-cli/).

This shows up during the build, and since it’s an interactive prompt, the build can’t continue:

```
The authenticity of host 'github.com (192.30.255.113)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? 

```

I tried appending to the `~/.ssh/known_hosts` file as discussed [here](https://discuss.circleci.com/t/known-hosts-in-circle-2-0/18544) but the `~/.ssh` directory doesn’t seem to exist. I get `/bin/bash: /home/circleci/.ssh/known_hosts: No such file or directory`.

Is this an intended difference between the local version and “actual” version of the docker image? Is there something I can do to test the build locally?

\*(probably irrelevant detail: it’s an npm package dependency in a private github repo)

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [April 11, 2018, 7:16pm UTC](https://discuss.circleci.com/t/known-hosts-edit-fails-using-local-cli/21407/4 "2018-04-11T19:16:14Z")

</div>

My usual way of fixing “known hosts” problems is to use the SSH feature on a (failing) build, do the SSH/Git operation on the console, and then grab the `~/.ssh/known_hosts` file generated. This file can then be committed to the repo and copied into place prior to executing the command that needs it.

If the `~/.ssh` folder does not exist, then just create it (both in SSH and also in the build process, prior to writing the `known_hosts` file manually).

---

<div class="post-metadata">

**Author:** ![eddiewebb](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/eddiewebb/32/11733_2.png) [@eddiewebb](https://discuss.circleci.com/u/eddiewebb)\
**Post date:** [April 11, 2018, 11:17pm UTC](https://discuss.circleci.com/t/known-hosts-edit-fails-using-local-cli/21407/5 "2018-04-11T23:17:35Z")

</div>

The simplest repeatable way is to use `ssh-keyscan` against the host name, but you’ll find lots of people will quickly tell you this exposes you to man-in-the-middle attacks by blindly trusting that you’re actually getting the right key.

A step up would be to use an authority you trust (google, openDNS, cloudflare, etc) and only add those IPs.

`for ip in $(dig @8.8.8.8 github.com +short); do ssh-keyscan github.com,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts`

This grabs all current IPs returned by google’s DNS and adds them to known\_hosts. You can replace 8.8.8.8 with another DNS provider’s IP.

You’ll end up with

```
cat ~/.ssh/known_hosts 
github.com,192.30.253.112 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
192.30.253.112 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6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
```

---

<div class="post-metadata">

**Author:** ![thatneat](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@thatneat](https://discuss.circleci.com/u/thatneat)\
**Post date:** [April 12, 2018, 12:01am UTC](https://discuss.circleci.com/t/known-hosts-edit-fails-using-local-cli/21407/6 "2018-04-12T00:01:21Z")

</div>

Hmm, looks like I can create the ~/.ssh directory… for some reason I thought I was getting access denied on that! I think I’m all set, then. Thanks!  
Still seems like a surprising difference between the CLI and the “real thing” but I’ve got it figured out for now, and other folks can find this page if they have the same issue.

---

<div class="post-metadata">

**Author:** ![thatneat](https://avatars.discourse-cdn.com/v4/letter/t/47e85d/32.png) [@thatneat](https://discuss.circleci.com/u/thatneat)\
**Post date:** [April 12, 2018, 12:02am UTC](https://discuss.circleci.com/t/known-hosts-edit-fails-using-local-cli/21407/7 "2018-04-12T00:02:47Z")

</div>

@eddiewebb I’m aware of that, but my issue was not being able to append to the `known_hosts` file which does not exist. Creating it seems to work just fine now.

---

<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:** [July 11, 2018, 12:02am UTC](https://discuss.circleci.com/t/known-hosts-edit-fails-using-local-cli/21407/8 "2018-07-11T00:02:48Z")

</div>

Closed on July 11, 2018, 12:02am UTC

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