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)