Attach_workspace github keys not working in second job

Here my config

        `defaults: &defaults
  docker:
    - image: circleci/node:8.2.1
  working_directory: /home/circleci/revvy-ui


version: 2
jobs:
  build:
    <<: *defaults
    steps:
      - checkout
      - persist_to_workspace: 
          root: /home/circleci/revvy-ui
          paths:
            - .

  publish:
    <<: *defaults
    steps:
      - attach_workspace:
          at: /home/circleci/revvy-ui
      - run:
          name: Check
          command: ssh -T git@github.com
      
workflows:
  version: 2
  build-publish:
    jobs:
      - build
      - publish:
          requires:
            - build
          filters:
            branches:
              only: ci

So output i am getting

#!/bin/bash -eo pipefail
ssh -T git@github.com
The authenticity of host 'github.com (192.30.253.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)? 

Seems like in “publish” we don’t have public keys
If i will do
command: ssh -T git@github.com
in build job it works fine

1 Like

You can disable strict host key checking if you wish.

-o StrictHostKeyChecking=no

As shown in this SO post

Getting this error
#!/bin/bash -eo pipefail
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec]
[-O ctl_cmd] [-o option] [-p port]
[-Q cipher | cipher-auth | mac | kex | key]
[-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] [user@]hostname [command]
Exited with code 255

It looks like you missed the hostname in that attempt.

#!/bin/bash -eo pipefail
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no github.com
Warning: Permanently added ‘github.com,192.30.253.112’ (RSA) to the list of known hosts.

Permission denied (publickey).

Exited with code 255
Its give error

As i understand basically
when i do “checkout” step it add my public key command “ssh -T git@github.com” pass

but when i dont do “checkout” it gives
"The authenticity of host ‘github.com (192.30.253.113)’ can’t be established."

so question is how can i pass “ssh -T git@github.com” without checkout ?

i tried “add_ssh_keys” with fingerprints but no result ?

this way helps but don think its good solution

  • run: mkdir -p ~/.ssh
  • run: echo ‘github.com ssh-rsa C1yc2EAAAABIwAAAQEA…’ >> ~/.ssh/known_hosts