I am trying to make one stage to learn how Gitlab CI/CD works. I made this Gitlab CI file which just reads ssh private key ($KEY) from Gitlab CI/CD variables, connects to server and writes message in server terminal.
stages:
- deploy
deploy:
stage: deploy
before_script:
- eval $(ssh-agent -s)
- echo "$KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh && chmod 700 ~/.shh
script:
- ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST "echo Hello"
Could you explain please why am I getting ssh: Operation timeout
error in the last row during code execution? There are no additional information about this error in terminal. Job fails after it and there is no message "Hello" in termainal.
I am also new to ssh connections. Maybe I am doing something wrong with passing private key?
This is likely because your $SSH_HOST(server IP) is incorrect. Double-check the value in the GitLab variable.
Additionally, verify that port 22 is open on your server.