Getting an error when trying to deploy using SCP

Hello,

I’m new to CircleCI and setting up the environment. I have investigated on how to deploy to a remote server using SCP and I was able to set up everything according to the tutorials.

I have added a private SSH key to my project;
I have added the public key to my remote server;
I have tested the command on my computer and it works correctly;
And I have configured the config.yml file accordingly.

However when the process starts, I get the following error when it gets to the SCP command:

ssh: connect to host ******************* port 22: Network is unreachable

lost connection

Exited with code exit status 1

Here is my configuration file:

version: 2
jobs:
  build:
    machine:
      enabled: true
    working_directory: ~/repo
    steps:
      - checkout
      - add_ssh_keys:
          fingerprints:
            - 'd4:e1:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX'
      - run:
          name: Deploy Over SSH
          command: |
            if [ "${CIRCLE_BRANCH}" = "master" ]; then
              scp -r * <user>@<host>:<path>
            else
              echo "Not master branch, do nothing"
            fi

workflows:
  version: 2
  build:
    jobs:
      - build:
          filters:
            branches:
              only: master

I would really appreciate some help with this.

Thanks!

Network is unreachable likely does not have much to do with your SSH keys or permissions. The best way to debug this would be to retry this step over SSH. This will allow you to do some basic network troubleshooting such as:

  1. ping the host to make sure its reachable.
  2. telent 22 the host to make sure that the port 22 is open on the receiving host.

Thanks Lev. Unfortunately telnet doesn’t tell me anything - just that the network is unavailable.

I’ve made sure to allow access on my server on port 22. I’ve tested the connection from my computer and it works perfectly fine.

I don’t understand why CircleCI would pull from my repository, but then be unable to connect to another server on the internet.

After playing around with my server’s firewall and ip tables, I discovered that the issue is somewhere there. I disabled them completely and I was able to deploy my static files with CircleCI with the configuration above.

So there must be a rule which is blocking access for the CircleCi IPs when the firewall rules are in place. Now I just have to find out which rule it is.

Thanks for your help!

1 Like

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