upload files via ssh via git Print

  • 0

Deploying a website to a server via SSH using GitHub Actions involves a similar process to using FTP, but instead, you'll be using SSH to connect to the server and transfer files. Here's how you can set up a GitHub Actions workflow to deploy your website to a server via SSH:

  1. Set up SSH key authentication: Instead of using FTP credentials, you'll use SSH key authentication to connect to your server. Generate an SSH key pair (if you haven't already) and add the public key to the ~/.ssh/authorized_keys file on your server.

  2. Store SSH private key as a secret: In your GitHub repository, go to "Settings" -> "Secrets" and add your SSH private key as a secret. You can copy the contents of your private key file and paste it into a secret named SSH_PRIVATE_KEY.

  3. Create a deployment workflow: In your GitHub repository, create a new workflow file under the .github/workflows directory. For example, you can name it deploy.yml.

  4. Define the deployment workflow: Configure the workflow to run on the push event and specify the steps to deploy your website via SSH. Here's an example workflow YAML file:

    yaml
    Copy code
    name: Deploy Website on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Install SSH key uses: webfactory/ssh-agent@v0.5.3 with: ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - name: Deploy via SSH run: | scp -r ./path/to/your/website/* username@your_server:/path/on/server

    Replace main with the branch you want to trigger the deployment on, ./path/to/your/website with the path to your website files within your repository, username with your SSH username, and your_server with the IP address or hostname of your server. Adjust the destination path (/path/on/server) as needed.

  5. Commit and push the workflow file: Commit the workflow file changes and push them to your repository.

  6. Monitor the workflow: After pushing changes to your repository, go to the "Actions" tab in your GitHub repository to monitor the deployment workflow. You should see the workflow listed there, and GitHub will automatically trigger it when changes are pushed to the specified branch.

  7. Check the deployed website: Once the workflow completes successfully, check your server to verify that the website has been deployed.

By following these steps, you can set up GitHub Actions to automatically deploy your website to a server via SSH whenever changes are pushed to your repository's specified branch.


Was this answer helpful?

« Back

Powered by WHMCompleteSolution