My VPS is not allowing port 22
Asked by kwesiaryee:

I am getting the following errors anytime I use the pipelines.

ssh: connect to host IP port 22: Connection timed out lost connection

This started when the port number on my VPS was changed from 22 to 2013 due to security concerns (I was told).

Please, can anyone help me out on this, please?


Answers:
author: vikram
body: Hi [@kwesiaryee](/t5/user/viewprofilepage/user-id/3242517)

Welcome to Atlassian Community.

As per your information your port is changed to 2013 as per secuirty.

Please use 2013 port instead of 22 as below

ssh: connect to host IP port 2013 and try.

Let me know if it works.

Vikram P

comments: author: kwesiaryee
body: I've tried several times and the following is what i get:

INFO: Starting SCP deployment to IP:2013:/home/directory/public_html/...  
scp -rp -i /opt/atlassian/pipelines/agent/ssh/id_rsa_tmp dist/spa/assets dist/spa/favicon.ico dist/spa/icons dist/spa/index.html root@IP:2013:/home/directory/public_html/  
ssh: connect to host IP port 22: Connection refused  
lost connection  
? Deployment failed.  
aca9d7420f98: Pull complete  
0f3ac11eee9e: Pull complete  
Digest: sha256:92cc16bb0a383f038bdc2443d0ea83dc390aa2f19beb0f56bf3c77ffff78ef41  
Status: Downloaded newer image for bitbucketpipelines/scp-deploy:0.3.3  
INFO: Starting SCP deployment to IP:2013:/home/directory/public_html/...  
scp -rp -i /opt/atlassian/pipelines/agent/ssh/id_rsa_tmp dist/spa/assets dist/spa/favicon.ico dist/spa/icons dist/spa/index.html root@IP:2013:/home/directory/public_html/  
ssh: connect to host IP port 22: Connection refused  
lost connection  
? Deployment failed.


author: vikram
body: Hi [@kwesiaryee](/t5/user/viewprofilepage/user-id/3242517)

Thanks for update,

can you please try below commands to verify ssh server status:

systemctl status ssh ---- checks the status of the SSH service on systemd-based Linux system.  
service ssh status ---- checks the status of the SSH service on a system.  
ss -tln --- lists all listening TCP sockets on the system including SSH server's port.  
netstat -tuln --- same as above but also lists active listening TCP sockets including SSH port.  
ping \<hostname or IP\> ---- Test basic network connectivity to a remote host.  
traceroute \<hostname or IP\> --- Traces the route packets to reach remote host.

vikram P


author: Patrik S
body: Hey [@kwesiaryee](/t5/user/viewprofilepage/user-id/3242517) ,

based on the error message you shared, it seems you're using the [atlassian/scp-deploy](https://bitbucket.org/product/features/pipelines/integrations?search=scp-&p=atlassian/scp-deploy) pipe. Is that correct ?

If yes, then you need to define the custom port as part of the EXTRA_ARGS variable, as in the following example:

```
script:
  - pipe: atlassian/scp-deploy:1.5.1
    variables:
      USER: 'ec2-user'
      SERVER: '127.0.0.1'
      REMOTE_PATH: '/var/www/build/'
      LOCAL_PATH: 'build/'
      DEBUG: 'true'
      EXTRA_ARGS: ["-P", "2013"]
```

Thank you, [@kwesiaryee](/t5/user/viewprofilepage/user-id/3242517) !

Patrik S

comments: author: kwesiaryee
body: The following is my pipeline:

```
master:

 - step:

caches:

 - node

deployment: Production

script: # Pushing to the master branch

 - apt-get update

 - apt-get install -y openssh-client rsync

 - npm i -g @quasar/cli

 - npm install

 - npm run lint

 - npm run format

 - quasar build

artifacts:

 - dist/**

 - step:

name: Deploy dist folder to server via SCP

script:

 - pipe: atlassian/scp-deploy:0.3.3

variables:

USER: $USER

SERVER: $SERVER

REMOTE_PATH: "/home/directory/public_html/"

LOCAL_PATH: "${BITBUCKET_CLONE_DIR}/dist/spa/*"

DEBUG: "true"

EXTRA_ARGS: ["-P", "2013"]
```

This is per your sample above, but I'm still getting an error as follows:

```
Status: Downloaded newer image for bitbucketpipelines/scp-deploy:0.3.3
DEBUG: Using default ssh key
INFO: Starting SCP deployment to IP:2013:/home/directory/public_html/...
scp -rp -i /opt/atlassian/pipelines/agent/ssh/id_rsa_tmp /opt/atlassian/pipelines/agent/build/dist/spa/assets /opt/atlassian/pipelines/agent/build/dist/spa/favicon.ico /opt/atlassian/pipelines/agent/build/dist/spa/icons /opt/atlassian/pipelines/agent/build/dist/spa/index.html root@IP:2013:/home/directory/public_html/
ssh: connect to host IP port 22: Connection refused
lost connection
? Deployment failed.
aca9d7420f98: Pull complete
0f3ac11eee9e: Pull complete
Digest: sha256:92cc16bb0a383f038bdc2443d0ea83dc390aa2f19beb0f56bf3c77ffff78ef41
Status: Downloaded newer image for bitbucketpipelines/scp-deploy:0.3.3
DEBUG: Using default ssh key
INFO: Starting SCP deployment to IP:2013:/home/directory/public_html/...
scp -rp -i /opt/atlassian/pipelines/agent/ssh/id_rsa_tmp /opt/atlassian/pipelines/agent/build/dist/spa/assets /opt/atlassian/pipelines/agent/build/dist/spa/favicon.ico /opt/atlassian/pipelines/agent/build/dist/spa/icons /opt/atlassian/pipelines/agent/build/dist/spa/index.html root@IP:2013:/home/directory/public_html/
ssh: connect to host IP port 22: Connection refused
lost connection
? Deployment failed.
```

Kwesi


author: Patrik S
body: Hello [@kwesiaryee](/t5/user/viewprofilepage/user-id/3242517) ,

It looks like you're using a very old version of the pipe, that didn't yet support EXTRA_ARGS option, so that's the reason why it's not being taken into account.

Could you please update your command to use the latest version instead (1.5.1) ?

```
script:
  - pipe: atlassian/scp-deploy:1.5.1
    variables:
      USER: 'ec2-user'
      SERVER: '127.0.0.1'
      REMOTE_PATH: '/var/www/build/'
      LOCAL_PATH: 'build/'
      DEBUG: 'true'
      EXTRA_ARGS: ["-P", "2013"]
```

Also, it's important to highlight that the port number needs only to be provided as the EXTRA_ARGS value. The SERVER variable should only contain the IP/domain of your server, not the port.


author: kwesiaryee
body: Hi Vikram,

Thanks a lot for your response.

I got the following response from my terminal:

netstat -tuln: tcp 0 0 0.0.0.0:2013 0.0.0.0:\* LISTEN

service ssh status: Unit ssh.service could not be found.

service ssh status  
Redirecting to /bin/systemctl status ssh.service  
Unit ssh.service could not be found.  

ping \<hostname or IP\>: -bash: port: command not found

traceroute \<hostname or IP\> : command not found

I am using almaLinux 9 as server os.

Kwesi


Tags: bitbucket-cloud

cloud