@@ -124,34 +124,51 @@ jobs:
124124
125125 - name : Set up SSH key
126126 run : |
127- # Create directory and set permissions
128- mkdir -p ~/.ssh
127+ # Create directory and set permissions with proper error handling
128+ mkdir -p ~/.ssh || { echo "Failed to create ~/.ssh directory"; exit 1; }
129+ chmod 700 ~/.ssh || { echo "Failed to set permissions on ~/.ssh"; exit 1; }
130+
131+ # Debug directory permissions
132+ ls -la ~ | grep .ssh
129133
130134 # Write the SSH key with proper error handling
131135 if [ -z "${{ secrets.SSH_PRIVATE_KEY }}" ]; then
132136 echo "ERROR: SSH_PRIVATE_KEY secret is not set!"
133137 exit 1
134138 fi
135139
136- echo "${{ secrets.SSH_PRIVATE_KEY }}" > ${{ env.SSH_KEY_PATH }}
137- chmod 600 ${{ env.SSH_KEY_PATH }}
140+ # Use tee command for more reliable file writing
141+ echo "${{ secrets.SSH_PRIVATE_KEY }}" | tee ${{ env.SSH_KEY_PATH }} > /dev/null || {
142+ echo "ERROR: Failed to write SSH key file!"
143+ exit 1
144+ }
145+
146+ # Set proper permissions on the key file
147+ chmod 600 ${{ env.SSH_KEY_PATH }} || {
148+ echo "ERROR: Failed to set permissions on SSH key file!"
149+ exit 1
150+ }
138151
139152 # Verify the key was written correctly
140153 if [ ! -f "${{ env.SSH_KEY_PATH }}" ]; then
141154 echo "ERROR: Failed to create SSH key file!"
142155 exit 1
143156 fi
144157
145- # Verify permissions
158+ # Verify permissions and file size
146159 ls -la ${{ env.SSH_KEY_PATH }}
160+ wc -l ${{ env.SSH_KEY_PATH }} || echo "Could not count lines in key file"
147161
148162 # Add VM to known hosts - verify VM_IP_ADDRESS is set
149163 if [ -z "${{ secrets.VM_IP_ADDRESS }}" ]; then
150164 echo "ERROR: VM_IP_ADDRESS secret is not set!"
151165 exit 1
152166 fi
153167
154- ssh-keyscan -H ${{ secrets.VM_IP_ADDRESS }} >> ~/.ssh/known_hosts
168+ ssh-keyscan -H ${{ secrets.VM_IP_ADDRESS }} >> ~/.ssh/known_hosts || {
169+ echo "ERROR: Failed to add VM to known hosts!"
170+ exit 1
171+ }
155172
156173 # Test SSH connection
157174 echo "Testing SSH connection..."
@@ -195,4 +212,4 @@ jobs:
195212 '
196213 else
197214 echo "SSH key file not found, cannot retrieve logs"
198- fi
215+ fi
0 commit comments