DEV Community

Cover image for Automating Server Deployments with GitHub Actions: Saving Time with SSH & rsync πŸš€
Robin Rana
Robin Rana

Posted on

Automating Server Deployments with GitHub Actions: Saving Time with SSH & rsync πŸš€

πŸš€ I was working with GitHub Actions. I hadn’t explored it before, but I wanted to make my deployment process a bit smoother.

πŸ”„ The task wasn’t exactly deployment, it was more about sending updated files and folders to the server. Previously, I had to manually update the code on the server again and again, so I decided to automate the process using GitHub Actions.

πŸ“œ To create a workflow in GitHub Actions, you need to define all instructions in a .yml file. Since I hadn’t worked with YAML before, I asked ChatGPT πŸ€– to generate the structure for me. It included server configurations and commands for copying the main branch to the server using rsync πŸš›.

πŸ”‘ However, to make this work, you need SSH keys for authentication between GitHub and the server. At first, I was using them incorrectly πŸ˜…. For authentication, the public key πŸ”“ needs to be authorized on the server, and the private key πŸ” should be stored in the Secrets environment of the repository settings on GitHub. This way, GitHub acts as a client.

πŸ’‘ How SSH authentication works:

SSH essentially works with a pair of keys:

βœ… Private key (secret key) β†’ Must always be securely saved on the client (local server).

βœ… Public key β†’ Stored on the remote server.

πŸ“‘ When the client sends an access request to the remote server, the private key on the client creates a digital signature ✍️. If this signature matches the public key’s signature on the remote server, access is granted βœ….

In the end, I automated the transfer of project files between my GitHub repository and the server, saving me a lot of time. β³πŸš€

Top comments (0)