Update main.yml #19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test SSH Connection to VPS | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| test-ssh: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v3 | |
| - name: Install SSH Tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y openssh-client | |
| - name: Set up SSH Key with Passphrase | |
| env: | |
| SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
| VM_PASSPHRASE: ${{ secrets.VM_PASSPHRASE }} | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "$SSH_PRIVATE_KEY" > ~/.ssh/deployment_key | |
| chmod 600 ~/.ssh/deployment_key | |
| eval "$(ssh-agent -s)" | |
| ssh-add -D # Clear any previously loaded keys | |
| echo "$VM_PASSPHRASE" | ssh-add ~/.ssh/deployment_key | |
| - name: Add VM to known_hosts | |
| run: | | |
| ssh-keyscan -H ${{ secrets.VM_HOST }} >> ~/.ssh/known_hosts | |
| - name: Test SSH Connection to VPS | |
| run: | | |
| ssh -o IdentitiesOnly=yes -i ~/.ssh/deployment_key dev@${{ secrets.VM_HOST }} "echo SSH connection successful!" |