How to copy my GitHub secrets (env) file to my server path using ssh deploy method?
The .env file created by GitHub action is not being uploaded to my Ubuntu server.
How to copy my GitHub secrets (env) file to my server path using ssh deploy method?
The .env file created by GitHub action is not being uploaded to my Ubuntu server.
Copyright © 2021 Jogjafile Inc.
"[...] to my server": that would assume your server is reachable through internet by GitHub itself (and its GitHub Actions runner servers)
But if it is reachable, then:
Generate an SSH key pair on your local machine, dedicated for that one usage (that way, you can revoke it easily, without touching any other key, including your default ones)
This will create a public and private key pair. The public key will be placed in
~/.ssh/keyToCopy.puband the private key in~/.ssh/keyToCopy.Copy your public key to your Ubuntu server:
This will append your public key to the
~username/.ssh/authorized_keysfile on your server, allowing you to log in with your private key.Then, using the
appleboy/scp-action, create a GitHub Actions workflow file in your repository (e.g.,.github/workflows/deploy.yml).It will create the
.env(see "How do I use an env file with GitHub Actions?") from your GitHub secrets. And copy it to the server.Add the following secrets to your GitHub repository:
SSH_PRIVATE_KEY: Your private SSH key, here the one from ~/.ssh/keyToCopySERVER_USER: Your Ubuntu server usernameSERVER_IP: Your Ubuntu server IP addressSERVER_PATH: The target directory on your server where you want to copy the.envfileENV_FILE: your .env file contentTo add these secrets, go to your GitHub repository's Settings tab, then click on Secrets in the left sidebar, and click on "New repository secret" to add each secret.