Step 5: Adding a correct known_hosts value Known_hosts: 'just-a-placeholder-so-we-dont-get-errors' For now, we simply have to add a random value to known_hosts so Shimataro’s Install SSH Key won’t give us an error. I’ll talk about this command in the next step. Thankfully, we can use a command to generate this weird hashed value. How do we even get this value in the first place?! Unfortunately, none of the Github Actions showed me how to do this, so I had to google around for a while -_. We’re supposed to add ONE of these values into a Github Actions secret. ssh server, you’ll see something like this: If you open up a known_hosts file in the. The known_hosts value is a weird hashed value. Key is the private key we added to Github Secrets. The Install SSH Key action requires two inputs - key and known_hosts value. The only action that worked for me was Shimataro’s Install SSH Key. I’m assuming you already know how to create a basic Github Actions file, so I’ll only talk about steps for adding the SSH Key here.Īdding the private key is a complex business, I chose to look for available Github Actions here. Step 4: Adding the Private key to a Github Actions Workflow Here, you’ll see SSH_PRIVATE_KEY under the repository’s secrets. Next, click on “Add secret” and you’ll be brought back to the secrets page. We need to copy everything and paste it inside the Secret value I just wanted to show you exactly what to expect :)). (Don’t worry about me exposing this key, I trashed it already. In this case, I chose to name the secret SSH_PRIVATE_KEY.įor the value, we need to go back into your server and open up the github-actions private key. This is a format we usually use for specifying secrets. When you write your secret name, please use uppercase letters with underscores as spaces (as shown in the placeholder). The secret name is used to get the contents later in a Github Actions workflow. This secret contains two things - a secret name and the contents. You should see a button that says “New repository secret”.Ĭlick “New repository secret” and you’ll be prompted to enter a secret. Go to your repository on Github and click on “Settings”, then “Secrets”. Be careful! Step 3: Adding the private key to your repository’s secrets Double means append, while single means overwrite. Note: Make sure you use double-right-angled brackets ( >) and not single-angled brackets ( >). Append to ~/.ssh/authorized_keys with >. ![]() Grab the contents of github-actions.pub with cat.It look like this: cat github-actions.pub > ~/.ssh/authorized_keys The easiest way is to use a cat command to append github-actions.pub into authorized_keys. We need to add the public key ( github-actions.pub) to authorized_keys so machines using the private key ( github-actions) can access the server. Step 2: Adding the Public Key to authorized_keys pub extension while the private key doesn’t. If you use the ls command now, you should see your keys in the. When you’re done generating your SSH keys you should get a cute image like this: Leave this empty since we can’t enter passwords when Github Actions run the SSH command for us. You’ll also be asked to provide a passphrase. It pays to be explicit when you view your SSH keys 6 months down the road. I recommend switching the file name to github-actions so we know this key is used for Github Actions. Here, I don’t recommend using the default file name (which is id_rsa). I’ve tested with the standard RSA format (which I recommended above) and it works. Note: Some Github Action authors said we need the PEM format for SSH keys to work. Remember to replace with your email address. We need to use the legacy command instead. This is because Github Actions doesn’t support the latest Ed22159 algorithm. When we generate the SSH Key, we cannot use the default instructions on Github’s generating an SSH key page. Once you’re in the server, navigate to the. It doesn’t matter since we can delete the key afterwards, but I recommend doing this on the server so you can reuse your SSH key for other Github Actions. You can generate the SSH key either on your local computer or on your server. This process works for any server, even if you don’t use Digital Ocean. ![]() Today, I want to share the exact steps to deploy via rsync and SSH. I got stuck with debugging for a few days before I finally figured out how to make the process work. I found most articles about Github actions and SSH didn’t help me much. ![]() I tried various Github actions like SSH Deploy and SSH Action, but I couldn’t get the permissions to work for A LONG TIME. The hardest part of this process is deploying to the server with SSH and rsync. I wanted to use Github Actions to deploy - when I push a commit into Github, I want Github Actions to build my site and deploy to my Digital Ocean server. Deploying to a server via SSH and Rsync in a Github Action 17th Mar 2021
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |